Skip to content

feat(rag): embedding-cache hits and misses as counters #817

Closed

Description

@dan-petty

Context & Rationale

Embedding-cache use is sent twice, both times as single-point gauges:

  • devops_cli_embedding_cache_hits_total and _misses_total, per batch (src/devops_cli/ai/rag/embeddings.py:567-568);
  • rag.embedding_cache.hit and .miss, per lookup (src/devops_cli/ai/rag/cache.py:51, 54).

Each command is its own process, so a gauge keeps only the last process's value (src/devops_cli/telemetry/instruments.py:1-7), and no dashboard may query one.

Scope & Deliverables

  • Deliverable:
    • Add one counter to INSTRUMENTS for embedding-cache lookups, labelled by result (hit or miss).
    • Remove the two duplicated gauge pairs.
    • Add a hit-share panel to devops-cli.json.
  • Acceptance criteria:
    • A batch with 3 hits and 2 misses sends exactly those counts once.
    • The panel query passes tests/test_telemetry_instruments.py, and its series sit inside rate( or increase(.
  • Key questions: Is it counted per lookup or per batch? (proposed) Per text looked up, recorded once at the batch level.
  • Constraint: Tests stay offline.

Strategic Alignment

Consolidated from #974, #816 (as sub-issues; both stay open)

Problem (added). The gauge pair above is one instance of a wider pattern. tracer.record_metric sends a single-point OTLP gauge, and about 58 call sites in 24 files under src/ call it (rg -n 'record_metric\(' src, 14e5da1). Most use names for counts or durations that are not in INSTRUMENTS, for example devops_cli_vulnerability_lookups_total, ai.gateway.failover_events and devops_cli_subprocess_seconds. In a short-lived process a gauge keeps only the last value. Dashboard queries are already checked by tests, but nothing checks what is emitted, so items fix one or two sites each (this item, #816).

Acceptance criteria (added; the parent's own scope).

  • The PR lists every record_metric( call site and classifies it as a counter, a histogram, a gauge (a true snapshot) or a delete.
  • Each count or duration becomes an INSTRUMENTS counter or histogram. True snapshots, such as gateway health, replica counts and cache size, become InstrumentKind.GAUGE entries; fix(telemetry): the project velocity dashboard reads the latest snapshot of each gauge, and the project gauges drop the _total suffix #974 adds that kind. Dead names are deleted.
  • record_metric is called only from telemetry/instruments.emit(). A test fails on any other caller and on any emitted name that is not in INSTRUMENTS.
  • No dashboard query names a removed gauge, and the existing dashboard tests pass.
  • This item's original criteria stay: one embedding-cache lookup counter, the 3-hits/2-misses case and the hit-share panel.

Sub-issues and order.

Key questions (added).

  • Is record_metric deleted? (proposed) No. emit() dispatches InstrumentKind.GAUGE to it, so it becomes private to that path.

Placement. This item stays P3 in the backlog. Its sub-issues keep their own placement, and the roadmap tooling places this item. Effort grows from Low to Medium (24 files).

Update 2026-10-08: refinement

Gauges landed with #1253, so this no longer waits on #974. No llm_cache gauge remains (#816). devops_cli_embedding_cache_size (ai/rag/embeddings.py:739) becomes a declared gauge. (proposed) Delete the module-level record_metric and record_gauge (telemetry/tracer.py:1362, :1372); the test fails on any other caller.

Metadata

Metadata

Assignees

No one assigned

    Labels

    priority/p3-lowscope/telemetrytype/feature

    Type

    No type

    Projects

    Milestone

    No milestone

    Relationships

    None yet

    Development

    No branches or pull requests

    Issue actions