Skip to content

feat(metrics): wire §6.3 barrier counter into all OTLP ingest paths - #51

Merged
zzylol merged 1 commit into
mainfrom
feat/otlp-barrier-metric
Apr 20, 2026
Merged

zzylol merged 1 commit into
mainfrom
feat/otlp-barrier-metric

Conversation

@zzylol

@zzylol zzylol commented Apr 20, 2026

Copy link
Copy Markdown
Contributor

Summary

Follow-up to #45 / #47. The Prometheus `CounterVec` `queryengine_ingest_samples_blocked_by_schema_barrier_total` (keyed by `agg_id`) was only bumped by the Prometheus / VictoriaMetrics remote-write path. The three OTLP barrier sites in `drivers/ingest/otel.rs` still silently dropped. This PR completes the observability story — no matter which driver the DataCollector ships through, a drop increments the same counter.

What's in this PR

  • `IngestState::record_barrier_drop(agg_id, count)` — single helper bumping both the in-process atomic AND the Prometheus `CounterVec`. All five ingest drivers funnel through it, so `/metrics` sees a unified sum.
  • `ingest_handler.rs` — refactored `route_decoded_samples` to call the helper instead of maintaining its own inline atomic + Prometheus increment loop. Same batched debug-log semantics; fewer moving parts.
  • `otel.rs` — new local `flush_barrier_drops(state, map, driver_tag)` helper; each of the three barrier sites (`otlp-raw`, `otlp-sketch-envelope`, `otlp-modified-proto`) tallies drops in a `HashMap<agg_id, count>` and calls flush at loop exit. One summary debug log per driver per batch.
  • New unit test `record_barrier_drop_advances_atomic_and_prom_counter` asserting both sides of the helper's contract (atomic delta == 7 and Prometheus CounterVec delta == 7 when called with count=7 on a fresh agg_id label).

Validation

  • `cargo test -p query_engine_rust --lib` — 738 pass (+1)
  • `cargo clippy --all-targets -- -D warnings` — clean
  • `cargo fmt --all -- --check` — clean

🤖 Generated with Claude Code

Follow-up to #45 / #47. The Prometheus `CounterVec`
`queryengine_ingest_samples_blocked_by_schema_barrier_total`
(keyed by `agg_id`) was only bumped by the Prometheus /
VictoriaMetrics remote-write path. The three OTLP barrier
sites in `drivers/ingest/otel.rs` still silently dropped.
This PR completes the observability story — no matter which
driver the DataCollector ships through, a drop increments the
same counter.

Changes:

- **`IngestState::record_barrier_drop(agg_id, count)`** —
  single helper that bumps both the in-process atomic AND the
  Prometheus `CounterVec`. All five ingest drivers funnel
  through it, so the `/metrics` number is a unified sum.
- **`ingest_handler.rs`** — refactored `route_decoded_samples`
  to call the helper instead of maintaining its own inline
  atomic-increment + Prometheus-increment loop. Same batched
  debug-log semantics; fewer moving parts.
- **`otel.rs`** — new local `flush_barrier_drops(state, map,
  driver_tag)` helper; each of the three barrier sites
  (`otlp-raw`, `otlp-sketch-envelope`, `otlp-modified-proto`)
  tallies drops in a `HashMap<agg_id, count>` and calls flush
  at loop exit. One summary debug log per driver per batch.

Also: a new unit test
`record_barrier_drop_advances_atomic_and_prom_counter`
that asserts both sides of the helper's contract (atomic
delta == 7 and Prometheus CounterVec delta == 7 when called
with count=7 on a fresh agg_id label).

738 lib tests pass (+1), clippy clean, fmt clean.

Co-Authored-By: Claude Opus 4.7 (1M context) <noreply@anthropic.com>
@zzylol
zzylol merged commit 316c25d into main Apr 20, 2026
@zzylol
zzylol deleted the feat/otlp-barrier-metric branch April 20, 2026 17:26
zzylol added a commit that referenced this pull request Apr 20, 2026
Captures the post-PR-#51 punch list for sketchDB:
- 5 blockers for paper submission (cold S3 fallback,
  accuracy-profile library, e2e capability-miss test,
  format-versioning tests, correctness proofs)
- 4 future-work items (Phase 4 compaction, Tier-2 read cache,
  cross-sketch-type combine, ingest-path error counter parity)

Accuracy-profile library references sketchlib-bench's DESIGN.md
for the theoretical derivations.

Co-authored-by: Claude Opus 4.7 (1M context) <noreply@anthropic.com>
zzylol added a commit that referenced this pull request Apr 21, 2026
Addresses TODO.md blocker #1. Unblocks the paper's "sketches for
hot, exact for cold" story: capability-miss queries now serve
exact answers from raw observability samples in the cold tier
instead of hitting Prometheus (or failing) unconditionally.

## What's new

* `drivers/query/fallback/cold_store/` — storage-agnostic
  `ColdStore` trait + `LocalFsColdStore` impl. On-disk layout
  (`raw/<metric>/YYYY/MM/DD/HH/part-NNNNNN.jsonl`) is identical
  to what a future S3 cold store will use, so the adapter stays
  source-compatible when we swap backends.
* `drivers/query/fallback/s3_adapter.rs` — `ColdFallback<S>`
  implements `FallbackClient`. Parses PromQL, extracts
  `(metric, predicates, op)`, scans the cold store, computes
  the answer. Supported shapes for v1:
  - bare instant vector selector (`metric{labels}`)
  - no-grouping scalar aggregation
    (`sum|count|avg|min|max(metric{...})`)
  Label matchers: `=`, `!=` — regex delegated upstream.
  Anything outside this surface falls through to the optional
  inner `FallbackClient` (chain-of-responsibility, typically
  the existing Prometheus proxy).
* `drivers/query/fallback/metrics.rs` — hot/cold telemetry
  counters (`queryengine_hot_queries_total`,
  `queryengine_cold_queries_total`,
  `queryengine_cold_bytes_served_total`), keyed by
  `(metric, shape)`. Mirrors the PR #51
  schema-barrier-counter pattern.
* `AdapterConfig::prometheus_promql_with_cold` convenience
  constructor that composes the cold adapter in front of a
  Prometheus proxy.

## Routing

No engine changes needed. The existing `process_query_request`
already falls through to `FallbackClient` on engine-miss —
configuring the fallback as a `ColdFallback` naturally routes
Purged-segment / capability-miss queries through the cold tier
with the Prometheus proxy as the tail-of-chain for unsupported
shapes.

## Tests

752 → 777 tests (+25):

* 5 unit tests on the JSONL format + hour-prefix helpers
* 4 on `LocalFsColdStore::scan` (range filter, missing prefix,
  hour-boundary span)
* 10 on `ColdFallback` plan extraction + aggregation + float
  formatting
* 6 end-to-end HTTP integration tests in
  `tests/cold_fallback_tests.rs` covering: bare selector, sum
  aggregation, label filtering, unsupported-shape delegation,
  telemetry-counter increments, and the "Purged range served
  from raw" paper story.
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.

1 participant