Support optional health check queries in MultiActiveRecordCheck#55
Open
mdkent wants to merge 2 commits into
Open
Support optional health check queries in MultiActiveRecordCheck#55mdkent wants to merge 2 commits into
mdkent wants to merge 2 commits into
Conversation
Instead of relying solely on connection.active?, a health check query returning a single truthy/falsey value (e.g. 1/0 from MySQL) can be supplied — either as a default for all connections via the query: option, or per connection by pairing a connection with its query in the block's hash. Per-connection queries take precedence over the default, and plain connections continue to use connection.active?. Co-Authored-By: Claude Opus 4.8 (1M context) <noreply@anthropic.com>
There was a problem hiding this comment.
Pull request overview
Adds support for running an optional per-connection (or default) SQL health-check query in Easymon::MultiActiveRecordCheck, allowing richer DB health semantics than connection.active? alone (e.g., read-only state checks).
Changes:
- Add
query:support toMultiActiveRecordCheck, including per-connection query overrides and boolean casting of query results. - Extend unit tests to cover query-based checks, precedence rules, falsey results, and raised errors.
Tip
If you aren't ready for review, convert to a draft PR.
Click "Convert to draft" or run gh pr ready --undo.
Click "Ready for review" or run gh pr ready to reengage.
Reviewed changes
Copilot reviewed 2 out of 2 changed files in this pull request and generated 4 comments.
| File | Description |
|---|---|
| lib/easymon/checks/multi_active_record_check.rb | Adds optional query-based health checking (default and per-connection) and updates inline docs. |
| test/unit/checks/multi_active_record_check_test.rb | Adds unit tests for query-based behavior and precedence. |
💡 Add Copilot custom instructions for smarter, more guided reviews. Learn how to get started.
Co-Authored-By: Claude Opus 4.8 (1M context) <noreply@anthropic.com>
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment
Add this suggestion to a batch that can be applied as a single commit.This suggestion is invalid because no changes were made to the code.Suggestions cannot be applied while the pull request is closed.Suggestions cannot be applied while viewing a subset of changes.Only one suggestion per line can be applied in a batch.Add this suggestion to a batch that can be applied as a single commit.Applying suggestions on deleted lines is not supported.You must change the existing code in this line in order to create a valid suggestion.Outdated suggestions cannot be applied.This suggestion has been applied or marked resolved.Suggestions cannot be applied from pending reviews.Suggestions cannot be applied on multi-line comments.Suggestions cannot be applied while the pull request is queued to merge.Suggestion cannot be applied right now. Please check back later.
Summary
Easymon::MultiActiveRecordCheckpreviously determined database health solely viaconnection.active?. This adds support for an optional health check query that returns a single truthy/falsey value (e.g.1/0from MySQL), useful for richer checks like read-only state or replication lag.Two ways to supply a query:
Default for all connections via the
query:option:Per connection, by pairing a connection with its query (takes precedence over the default):
Query results are cast with
ActiveModel::Type::Boolean, so MySQL's1/0map to Up/Down and an empty result (nil) is treated as Down. Any raise during the query still rescues to Down, and existing callers without queries are unchanged.Testing
bin/rails test test/unit/checks/multi_active_record_check_test.rb— 9 runs, 0 failures🤖 Generated with Claude Code