Skip to content

Preserve lag values when primary pressure rejects checks - #210

Merged
pradeepkintali merged 4 commits into
masterfrom
pkintali/lag-pressure-response-compat
Nov 23, 2026
Merged

pradeepkintali merged 4 commits into
masterfrom
pkintali/lag-pressure-response-compat

Conversation

@pradeepkintali

@pradeepkintali pradeepkintali commented Nov 23, 2026 •

Copy link
Copy Markdown
Contributor

What changed

Keep the requested MySQL store's MetricName, numeric Value, and Threshold in check responses when a required dependency rejects the request. Previously, a primary-pressure rejection replaced the lag result, so the existing Ruby replication_delay client interpreted Threads_running as 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 observationOnly flag 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 Dependencies and top-level BlockingMetricName. Dependency entries use the existing StatusCode, MetricName, Value, Threshold, and Message fields, 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"]
Loading

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 Value is replica lag in seconds; the dependency's Value is Threads_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.05 seconds, not 80 threads. 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

  • Full script/cibuild passed: formatting, binary build, and all nine package test suites with race detection and coverage.
  • The latest response-schema revision passed the race-enabled throttle and HTTP suites; all twelve Ruby HTTP scenarios were rerun successfully.
  • Thirteen response cases cover lag failures, dependency failures, recovery, missing measurements, and both measurements being reported; nested dependency failures are also covered.
  • Two cases verify that diagnostic checks after a lag or primary failure do not set additional low-priority throttling state.
  • Twelve real HTTP scenarios passed against the unchanged Ruby client, covering primary overload, recovery, probe errors, shared-domain health, lag overload, simultaneous overload, lag probe failure, and recovery. Both measurements remained present and admission correctly returned 429, 500, or 200. With healthy lag, Ruby continued to read 0.05 seconds rather than the primary thread count.
  • The unchanged Ruby client's existing suite passed: 46 tests, 181 assertions.
  • git diff --check passed.

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.

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
Copilot AI adaptive review requested due to automatic review settings November 23, 2026 16:36

Copilot AI left a comment

Copy link
Copy Markdown

Choose a reason for hiding this comment

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

🟡 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)

Comment thread pkg/throttle/check_result.go Resolved
Pradeep Kintali and others added 3 commits November 23, 2026 08:45
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
@pradeepkintali
pradeepkintali merged commit c6d00b7 into master Nov 23, 2026
6 checks passed
@pradeepkintali
pradeepkintali deleted the pkintali/lag-pressure-response-compat branch November 23, 2026 17:22
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