Skip to content

Commit

Permalink
Merge pull request #4 from instacart/jeffdoering/placeholder_capture_…
Browse files Browse the repository at this point in the history
…blockers_rake_task

Placeholder integration hooks for rake task pghero:capture_query_bloc…
  • Loading branch information
jeffdoering authored May 10, 2019
2 parents 72d4298 + b235150 commit 7671917
Show file tree
Hide file tree
Showing 4 changed files with 32 additions and 0 deletions.
10 changes: 10 additions & 0 deletions lib/pghero.rb
Original file line number Diff line number Diff line change
Expand Up @@ -134,6 +134,16 @@ def capture_connection_stats(verbose: false)
end
end

def capture_query_blockers(verbose: false)
each_database do |database|
next unless database.capture_query_blockers?

puts "(Simulating) Capturing query blockers for #{database.id}..." if verbose
# TODO: actually implement database.capture_query_blockers
end
true
end

def analyze_all(**options)
each_database do |database|
next if database.replica?
Expand Down
4 changes: 4 additions & 0 deletions lib/pghero/database.rb
Original file line number Diff line number Diff line change
Expand Up @@ -36,6 +36,10 @@ def capture_query_stats?
config["capture_query_stats"] != false
end

def capture_query_blockers?
config["capture_query_blockers"] != false
end

def cache_hit_rate_threshold
(config["cache_hit_rate_threshold"] || PgHero.config["cache_hit_rate_threshold"] || PgHero.cache_hit_rate_threshold).to_i
end
Expand Down
5 changes: 5 additions & 0 deletions lib/tasks/pghero.rake
Original file line number Diff line number Diff line change
Expand Up @@ -14,6 +14,11 @@ namespace :pghero do
PgHero.capture_connection_stats(verbose: true)
end

desc 'capture_query_blockers'
task capture_query_blockers: :environment do
PgHero.capture_query_blockers(verbose: true)
end

desc "analyze tables"
task analyze: :environment do
PgHero.analyze_all(verbose: true, min_size: ENV["MIN_SIZE_GB"].to_f.gigabytes)
Expand Down
13 changes: 13 additions & 0 deletions test/capture_test.rb
Original file line number Diff line number Diff line change
@@ -0,0 +1,13 @@
# frozen_string_literal: true

require_relative 'test_helper'

class CaptureTest < Minitest::Test

def test_capture_query_blockers
# TODO: test needs to be in a transaction rollback as soon
# as capture_query_blockers implements real inserts
assert PgHero.capture_query_blockers(verbose: true)
end

end

0 comments on commit 7671917

Please sign in to comment.