feat(metrics-endpoint): count /metrics scrape failures by outcome#3686
Conversation
|
Note Reviews pausedIt looks like this branch is under active development. To avoid overwhelming you with review comments due to an influx of new commits, CodeRabbit has automatically paused this review. You can configure this behavior by changing the Use the following commands to manage reviews:
Use the checkboxes below for quick actions:
WalkthroughThe metrics endpoint now emits ChangesMetrics scrape observability
Estimated code review effort: 3 (Moderate) | ~20 minutes Sequence Diagram(s)sequenceDiagram
participant ScrapeHandler as Metrics scrape handler
participant FailureEvent as MetricsScrapeFailed
participant Counter as Failure counter
ScrapeHandler->>FailureEvent: emit labeled failure outcome
FailureEvent->>Counter: increment outcome counter
ScrapeHandler-->>ScrapeHandler: return HTTP error response
🚥 Pre-merge checks | ✅ 5✅ Passed checks (5 passed)
✨ Finishing Touches🧪 Generate unit tests (beta)
Comment |
|
🌿 Preview your docs: https://nvidia-preview-pull-request-3686.docs.buildwithfern.com/infra-controller |
There was a problem hiding this comment.
Actionable comments posted: 1
🤖 Prompt for all review comments with AI agents
Verify each finding against current code. Fix only still-valid issues, skip the
rest with a brief reason, keep changes minimal, and validate.
Inline comments:
In `@crates/metrics-endpoint/src/lib.rs`:
- Around line 591-628: Update the test scrape_failures_count_per_outcome to
invoke handle_metrics_request for each failure scenario instead of emitting
MetricsScrapeFailed directly. Use a table-driven set of cases that exercises all
five handler failure outcomes, then assert carbide_metrics_scrape_failures_total
deltas for every outcome label, including zero where appropriate.
🪄 Autofix (Beta)
Fix all unresolved CodeRabbit comments on this PR:
- Push a commit to this branch (recommended)
- Create a new PR with the fixes
ℹ️ Review info
⚙️ Run configuration
Configuration used: Path: .coderabbit.yaml
Review profile: CHILL
Plan: Enterprise
Run ID: 03dceb13-5362-4cd2-b120-b965825b69a2
📒 Files selected for processing (3)
crates/metrics-endpoint/Cargo.tomlcrates/metrics-endpoint/src/lib.rsdocs/observability/core_metrics.md
ff978be to
5ae90e8
Compare
|
Good call — reworked the tests to drive the handler rather than emit directly. |
5ae90e8 to
6348f12
Compare
| metric_name = "carbide_metrics_scrape_failures_total", | ||
| component = "metrics-endpoint", | ||
| metric = counter, | ||
| log = off, |
There was a problem hiding this comment.
Replace log = off with:
log = dynamic,
message = dynamic,
| #[label] | ||
| outcome: ScrapeOutcome, | ||
| } | ||
|
|
There was a problem hiding this comment.
And then add this here:
impl DynamicLog for MetricsScrapeFailed {
fn log_at(&self) -> LogAt {
match self.outcome {
ScrapeOutcome::EncoderBusy => LogAt::Level(Level::WARN),
_ => LogAt::Level(Level::ERROR),
}
}
}
impl DynamicMessage for MetricsScrapeFailed {
fn message(&self) -> &'static str {
match self.outcome {
ScrapeOutcome::EncoderBusy => "metrics encoder busy; shedding scrape with 503",
ScrapeOutcome::EncoderGone => "metrics encoder thread is gone; cannot encode metrics",
ScrapeOutcome::EncodeFailed => "failed to encode metrics",
ScrapeOutcome::EncoderPanicked => "metrics encoder caught a panic while encoding",
ScrapeOutcome::ReplyDropped => "metrics encoder dropped the reply without responding",
}
}
}
| @@ -448,13 +483,19 @@ async fn handle_metrics_request<B>( | |||
| // The single encoder is already busy with a backlog; shed this | |||
| // scrape rather than pile on more work. | |||
| tracing::warn!("metrics encoder busy; shedding scrape with 503"); | |||
There was a problem hiding this comment.
...and then you can drop all of the tracing::warn and tracing::error lines (emit will now take care of it for you)
|
This is awesome @hatamzad-nv ! Thanks so much for doing this. One adjustment you can make, and otherwise looks great. Thanks! |
The shared metrics-endpoint handler can fail a scrape five distinct ways (encoder queue full -> 503; encoder gone, encode error, encoder panic, dropped reply -> 500). Each was only logged. Add a carbide_metrics_scrape_failures_total counter, labeled by a bounded ScrapeOutcome enum, emitted at each failure branch alongside the existing logs. This meta-observability surfaces a busy or erroring encoder on the next successful scrape, where aggregatable/alertable counters beat logs alone. Closes NVIDIA#3546
6348f12 to
2f080df
Compare
90cba68 to
22f2a84
Compare
Closes #3546. Adds a carbide_metrics_scrape_failures_total counter labeled by a bounded ScrapeOutcome enum, emitted at each of the five /metrics failure branches alongside the existing logs. Includes a catalogue row in docs/observability/core_metrics.md and a unit test.