feat(sketchdb): surface accuracy envelope on PromQL response (§6.4, A+C) - #56
Merged
Merged
Conversation
Addresses TODO.md blocker #2 subitem #3. Queries answered by the sketch DB now carry a theoretical accuracy bound back to the client as two fields on the Prometheus HTTP response: * **A — structured `accuracy` (top-level)**: ```json "accuracy": { "epsilon": 0.008125, "delta": 0.0, "kind": "relative_cardinality", "per_segment": [...] // populated on schema-timeline crossings } ``` * **C — human-readable `infos` (Prometheus 3.0 / Grafana 11+)**: ```json "infos": ["accuracy: ε=0.008125, δ=0, kind=relative_cardinality"] ``` Both are standard Prometheus-tolerant extensions — unknown top-level fields are ignored by the upstream client/Grafana 10. A regression test confirms a stripped-down "standard Prometheus" decoder round-trips through our extended response. ## Wire shape `warnings` stays reserved for partial-result / fallback advisories (PR #49's schema-timeline dispatcher still uses it); accuracy gets its own dedicated field so the semantics don't mix. When a query crosses a schema-timeline boundary, `per_segment` lists each segment's `(agg_id, range_ms, profile)`. The top-level `profile` is the max-ε, max-δ envelope across segments — a conservative upper bound. ## Changes * `stores/sketch_db/accuracy.rs`: * `AccuracyEnvelope { profile, per_segment }` + builders (`single`, `from_segments`) * `PerSegmentAccuracy { agg_id, range_ms, profile }` * `AccuracyProfile::summary()` / `AccuracyEnvelope::summary()` emit the `infos` one-liner. * `engines/query_result.rs`: `InstantVector` / `RangeVector` carry `accuracy: Option<AccuracyEnvelope>`; new `QueryResult::{accuracy(), with_accuracy()}`. * `drivers/query/adapters/prometheus_http.rs`: `PrometheusResponse::{infos, accuracy}` fields + `with_accuracy()` builder. `format_success_response` / `format_range_success_response` thread `result.accuracy()` onto the response. * `engines/simple_engine.rs`: * `SimpleEngine::accuracy_envelope_for(agg_id)` — single- aggregation helper. * `execute_context` attaches single-agg accuracy. * Timeline dispatch builds per-segment accuracy list and attaches the multi-segment envelope. ## Tests 777 → 784 (+5 green): * `prometheus_response_carries_accuracy_top_level_and_infos_mirror` * `prometheus_response_without_accuracy_skips_both_fields` * `prometheus_response_per_segment_contains_all_segments_with_worst_case_top` * `accuracy_coexists_with_warnings_without_interference` * `promql_standard_client_can_decode_response_ignoring_extensions` clippy + fmt clean.
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.
Addresses TODO.md blocker #2 sub-item #3. Queries answered by the sketch DB now carry a theoretical accuracy bound back to the client as two fields on the Prometheus HTTP response:
A — structured `accuracy` (top-level)
```json
"accuracy": {
"epsilon": 0.008125,
"delta": 0.0,
"kind": "relative_cardinality",
"per_segment": [ /* populated on schema-timeline crossings */ ]
}
```
C — human-readable `infos` (Prometheus 3.0 / Grafana 11+)
```json
"infos": ["accuracy: ε=0.008125, δ=0, kind=relative_cardinality"]
```
Compatibility
warnings#49); accuracy doesn't hijack it.Cross-boundary semantics
When a query crosses a schema-timeline reconfigure, `per_segment` lists each piece's `(agg_id, range_ms, profile)`; the top-level envelope is (max ε, max δ) — a conservative upper bound across segments.
Tests
777 → 784 (+5), clippy + fmt clean.
🤖 Generated with Claude Code