Skip to content

Add query blocker tracking based on pg_blocking_pids() - #3

Open
jeffdoering wants to merge 7 commits into
masterfrom
jeffdoering/blocker_tracking
Open

Add query blocker tracking based on pg_blocking_pids()#3
jeffdoering wants to merge 7 commits into
masterfrom
jeffdoering/blocker_tracking

Conversation

@jeffdoering

Copy link
Copy Markdown

The feature is modeled after other historical data tracking in PgHero (e.g. query stats). The tracked stats are not shown in PgHero UI yet (it still shows the older live blockers information with no history) but will be visible via direct table queries. Separate PR will enable rendering of query blockers.

Each sample creates a row in pghero_blocker_samples even if there are no blockers; this is to ensure that historical data can be accurately distinguished from missing data. Actual blockers and blockees are stored in pghero_blocker_sample_sessions.

The PR also restructures the base methods and objects to cleanly separate the monitored DB from the respository used to store historical data and allow reuse of methods for both cases. It also includes minor cosmetic changes to files that were touched to accomplish the restructuring (e.g. RuboCop suggestions on strings, etc).

def server_version_num
@server_version_num ||= select_one("SHOW server_version_num").to_i
@server_version_num ||= select_one('SHOW server_version_num').to_i
end

Copy link
Copy Markdown

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Any functional reason why you're updating all the quote types?

Copy link
Copy Markdown
Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Rubocop was complaining about double-quoted strings that didn't require interpolation. It made sense so I updated files I was working on anyway to suppress the warning and make the distinction clear.

Now that you asked it looks like the Ruby style guide leaves this open-ended and the Rubocop setting is configurable in my IDE (RubyMine). I hadn't checked that context and which (if any) model Instacart uses standard.

I can revert the unnecessary changed lines now that I see it's not an agreed Ruby standard:

https://github.com/rubocop-hq/ruby-style-guide#strings

Copy link
Copy Markdown

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

String quote style in ruby is a vi/emacs style holy war.

@mmontagna

mmontagna commented May 3, 2019

Copy link
Copy Markdown

This is looking great! I'm excited for this feature.

How as this tested? Asking cause it's a large change and I'm also curious how to develop on this app.

@jeffdoering

Copy link
Copy Markdown
Author

This is looking great! I'm excited for this feature.

How as this tested? Asking cause it's a large change and I'm also curious how to develop on this app.

Good question. I developed and did primary testing in a standalone Rails app I created locally and pulled PgHero into. I manually tested via the UI on the local environment. I also added test cases for the blocker functionality and added some extra test cases for existing functionality. The cases are not deep in terms of verifying output data but they ensure that the code executes successfully and appears to return something useful. They did catch many small bugs during my refactoring.

But now that I've dug deeper; the same is possible by running Blazer locally. I have that 95% working but didn't do the full Blazer setup around sign-on - still need to try that part.

@jeffdoering
jeffdoering force-pushed the jeffdoering/blocker_tracking branch from ea1d41b to fda3767 Compare May 13, 2019 19:07
Comment thread lib/pghero.rb

module PgHero
autoload :Connection, "pghero/connection"
autoload :QueryStats, "pghero/query_stats"

Copy link
Copy Markdown

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Is there a reason to disable autoloading, without requiring these? Are these effectively dead code now?

def server_version_num
@server_version_num ||= select_one("SHOW server_version_num").to_i
@server_version_num ||= select_one('SHOW server_version_num').to_i
end

Copy link
Copy Markdown

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

String quote style in ruby is a vi/emacs style holy war.

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment

Labels

None yet

Projects

None yet

Development

Successfully merging this pull request may close these issues.

3 participants