Repository navigation
Preserve lag values when primary pressure rejects checks - #210
Merged
Merged
Conversation
Keep requested measurements separate from dependency admission failures and retain first-failure short-circuiting. Add response diagnostics and regression coverage, including unchanged Ruby client HTTP compatibility. Co-authored-by: Copilot <223556219+Copilot@users.noreply.github.com> Copilot-Session: fbc83df2-d1af-406f-b97b-51cf0aaa570d
There was a problem hiding this comment.
🟡 Changes recommended
A missing runtime metric for a directly requested configured cluster returns HTTP 404 without a RejectionReason, inconsistently omitting the missing_metric reason reported for dependencies.
1 open issue
What changed in this PR
This PR preserves requested MySQL lag measurements when a required dependency rejects admission, preventing existing Ruby clients from interpreting primary pressure as lag seconds.
Changes:
- Keep requested metric fields while reporting evaluated dependencies and the blocking metric separately.
- Add measurement availability and rejection metadata while preserving blocker-based telemetry.
- Update HTTP documentation and regression coverage, including an opt-in unchanged Ruby-client test.
| File | Description |
|---|---|
pkg/throttle/throttler_test.go |
Update dependency assertions and add a shared-health test helper. |
pkg/throttle/safety_telemetry_test.go |
Verify logs retain the blocking primary’s value and threshold. |
pkg/throttle/ruby_client_compatibility_test.go |
Add opt-in Ruby-client compatibility checks over HTTP. |
pkg/throttle/check.go |
Preserve requested measurements and collect dependency results. |
pkg/throttle/check_result.go |
Add dependency, availability, and rejection response metadata. |
pkg/throttle/check_response_test.go |
Cover response fields, missing readings, and dependency short-circuiting. |
pkg/throttle/api_dependencies_test.go |
Verify HTTP responses retain lag alongside primary measurements. |
doc/http.md |
Document response semantics, compatibility limits, and Ruby test usage. |
Review effort: Balanced (adaptive)
Report required measurements consistently while retaining the first admission failure and the original combined dependency guard. Prevent diagnostic-only checks from setting low-priority throttling state and cover lag failure and recovery with the unchanged Ruby client. Co-authored-by: Copilot <223556219+Copilot@users.noreply.github.com> Copilot-Session: fbc83df2-d1af-406f-b97b-51cf0aaa570d
Keep measurement errors, numeric values and admission diagnostics while omitting the unneeded availability flag. Update response tests and HTTP documentation. Co-authored-by: Copilot <223556219+Copilot@users.noreply.github.com> Copilot-Session: fbc83df2-d1af-406f-b97b-51cf0aaa570d
Expose only Dependencies and top-level BlockingMetricName as new JSON properties. Preserve existing result fields and messages in nested measurements, remove redundant reason/error properties, and keep internal rejection telemetry unchanged. Co-authored-by: Copilot <223556219+Copilot@users.noreply.github.com> Copilot-Session: fbc83df2-d1af-406f-b97b-51cf0aaa570d
UyumazHakan
approved these changes
Nov 23, 2026
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.

What changed
Keep the requested MySQL store's
MetricName, numericValue, andThresholdin check responses when a required dependency rejects the request. Previously, a primary-pressure rejection replaced the lag result, so the existing Rubyreplication_delayclient interpretedThreads_runningas seconds of replication lag.Return both lag and primary-pressure results under the same response shape whether lag passes or fails. Keep lag in the top-level fields and include evaluated required metrics under
Dependencies. The first failure still determines the overall status and reason: lag first, then dependencies in configured order.Keep the original combined nil/healthy dependency guard. Collect non-nil results before that guard so healthy primary measurements are included too. Once a failure is found, the internal
observationOnlyflag prevents later diagnostic checks from setting additional low-priority throttling state. These checks use cached measurements, not extra SQL queries.The only new JSON properties are
Dependenciesand top-levelBlockingMetricName. Dependency entries use the existingStatusCode,MetricName,Value,Threshold, andMessagefields, plus evaluated nested dependencies if configured. They do not repeat the blocker or add separate reason/error fields. Rejection counters and logs still describe the actual blocking metric and its detailed reason and value. Update the HTTP documentation and regression tests.Workflow
flowchart TD A["Client requests a lag check"] --> B["Read replica lag"] B --> C{"Does lag pass?"} C -->|No| D["Keep lag failure as the decision"] D --> E["Collect primary pressure for diagnostics"] E --> F["Return lag status and reason, lag value, and primary result"] C -->|Yes| G["Check primary pressure"] G --> H{"Does primary pass?"} H -->|Yes| I["HTTP 200: lag and primary result"] H -->|No| J["HTTP 429/500: lag and primary result, primary rejection reason"]A probe failure is reported through the failing metric's status and
Message; its legacy numeric error-path value is not a valid reading. Additional required dependencies follow the same first-failure decision order while still being reported.Sample responses
These illustrative responses assume one required primary dependency. Top-level
Valueis replica lag in seconds; the dependency'sValueisThreads_running, a thread count. The thresholds below are examples, not production settings.Both checks pass: HTTP 200
{ "StatusCode": 200, "MetricName": "mysql/repositories", "Value": 0.05, "Threshold": 1, "Message": "", "Dependencies": [ { "StatusCode": 200, "MetricName": "mysql/repositories-primary", "Value": 35, "Threshold": 75, "Message": "" } ] }Lag fails; primary pressure is healthy: HTTP 429
Primary pressure is still included, but lag remains the blocking metric.
{ "StatusCode": 429, "MetricName": "mysql/repositories", "Value": 6, "Threshold": 1, "Message": "Threshold exceeded", "BlockingMetricName": "mysql/repositories", "Dependencies": [ { "StatusCode": 200, "MetricName": "mysql/repositories-primary", "Value": 35, "Threshold": 75, "Message": "" } ] }Lag passes; primary pressure fails: HTTP 429
The Ruby lag client still reads
0.05seconds, not80threads. Admission is rejected because primary pressure exceeds its threshold.{ "StatusCode": 429, "MetricName": "mysql/repositories", "Value": 0.05, "Threshold": 1, "Message": "Threshold exceeded", "BlockingMetricName": "mysql/repositories-primary", "Dependencies": [ { "StatusCode": 429, "MetricName": "mysql/repositories-primary", "Value": 80, "Threshold": 75, "Message": "Threshold exceeded" } ] }Compatibility
No Ruby-client changes are required or included. Existing status-based admission decisions remain unchanged, and the lag field stays numeric.
Unavailable readings retain their legacy numeric error-path value, with errors explained by status and
Message. The unchanged Ruby lag client ignores status and error messages; this patch fixes pressure/lag unit confusion, not that existing error-handling limitation.Validation
script/cibuildpassed: formatting, binary build, and all nine package test suites with race detection and coverage.git diff --checkpassed.The Ruby HTTP test is opt-in via
FRENO_RUBY_CLIENT_PATH; it was explicitly run locally. Full Rails jobs, production canary, and load testing were not run. This PR does not change production configuration or re-enable primary protection.