feat(libsy): expose algorithm metrics through driver - #307
feat(libsy): expose algorithm metrics through driver#307nachiketb-nvidia wants to merge 3 commits into
Conversation
Signed-off-by: nachiketb <nachiketb@nvidia.com>
|
WalkthroughThe PR adds algorithm-defined counter and histogram metrics. Drivers emit observations to OpenTelemetry and run observers. Judge fail-open reporting uses the new driver API. Tests validate aggregation, finite samples, attributes, and server handling. ChangesAlgorithm metrics
Estimated code review effort: 3 (Moderate) | ~25 minutes Poem
🚥 Pre-merge checks | ✅ 5✅ Passed checks (5 passed)
Comment |
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/libsy/src/core/algorithm.rs`:
- Around line 272-283: Update record_algorithm_metric to reserve the "algorithm"
attribute key by filtering or rejecting any caller-provided MetricAttribute with
that key before constructing AlgorithmMetricObservation, preserving the
self.algorithm value as the sole algorithm attribute. Add a regression test
covering a caller-supplied "algorithm" attribute and verifying it cannot produce
duplicate observer or sink attributes.
🪄 Autofix
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: 264915bb-e85b-4361-842d-28f0244f0375
📒 Files selected for processing (6)
crates/libsy/src/algorithms/util/llm_judge.rscrates/libsy/src/core/algorithm.rscrates/libsy/src/lib.rscrates/libsy/src/observability.rscrates/libsy/tests/observability.rscrates/switchyard-server/src/lib.rs
Signed-off-by: nachiketb <nachiketb@nvidia.com>
Signed-off-by: nachiketb <nachiketb@nvidia.com>
| ("exploring", dimensions.exploring), | ||
| ("production_intensity", dimensions.production_intensity), | ||
| ] { | ||
| driver.record_histogram( |
There was a problem hiding this comment.
This is great! We can stick to reporting raw scores. can you update the routing algorithms page for stage router where Im talking about decision sources ?
| driver.record_histogram(CONFIDENCE_METRIC, confidence, []); | ||
|
|
||
| let dimensions = dimensions_from_signal(signal); | ||
| for (name, value) in [ |
There was a problem hiding this comment.
can we generalize this a bit? if we add a new signal, Ill have to manually update the strings here.
There was a problem hiding this comment.
that's probably best practice since that would be a meaningful update, can probably pull this up to a const variable would that be preferable?
What
Driver::record_counterandDriver::record_histogramAPIs for algorithm-defined metrics.RunObservation::AlgorithmMetricfor host-side aggregation.Why
Algorithms need to publish domain-specific measurements without receiving or depending on a server accumulator. This keeps algorithms server-independent while allowing both exported telemetry and local consumers to derive the same rollups.
Implements SWITCH-1227.
How
The Driver captures the algorithm name once per run, adds it to every custom metric, records the metric through the global OpenTelemetry provider, and forwards the same owned event to the existing
RunObserver. Metric names and attribute keys are static; attribute values must remain bounded and low-cardinality. Non-finite histogram samples are dropped from both outputs.The Rust server intentionally ignores the new observation variant for now. Endpoint integration remains separate work.
Aggregate proof
One comprehensive integration test emits two batches through the same observer and reconstructs the accumulator-style summary from raw events:
54, total100, min10, max40, average25, p5030, p9940This demonstrates that a host can derive the Python accumulator rollups without coupling algorithms to accumulator storage.
How tested
cargo fmt --all --checkcargo clippy --workspace --all-targets -- -D warningscargo test --workspaceChecklist
switchyard-libsyNotes for reviewers
Please focus on the typed metric API, the guarantee that OpenTelemetry and
RunObserversee the same event, and the intentional absence of server accumulator integration.Summary by CodeRabbit
New Features
Bug Fixes