Skip to content

feat(telemetry): opt-in telemetry for headless binaries (mecatequi, mecak8s) - #393

Merged
JAORMX merged 2 commits into
mainfrom
feat/343-headless-telemetry
Aug 6, 2026
Merged

JAORMX merged 2 commits into
mainfrom
feat/343-headless-telemetry

Conversation

@JAORMX

@JAORMX JAORMX commented Aug 5, 2026

Copy link
Copy Markdown
Contributor

Closes #343. Part of the dark-factory epic (stacklok/stacklok-epics#297), Phase 3.

Gap

mecatequi and mecak8s deliberately wired Sink/ToolCallRecorder/metrics to nil — no Prometheus, no OTel. A factory running many one-shot invocations got no fleet-level telemetry beyond exit codes and JSONL event files.

What this does

Reuses the existing internal/adapter/telemetry pipeline (the SAME Setup + NewMetrics + WithRole role-scoper path mecated already uses) behind opt-in, default-off flags. The no-telemetry posture stays byte-identical (Config.Sink == nil pinned by test).

  • internal/adapter/telemetry — new optional OTLP metrics push reader (PeriodicReader over otlpmetricgrpc/otlpmetrichttp) alongside the always-on prometheus reader, gated on new OTLPConfig.Metrics* fields. Existing scrape-only callers untouched.
  • mecatequi (short-lived one-shot — scrape doesn't fit a sub-second process): opt-in --otlp-* / --otlp-metrics-* push flags with an explicit flush-before-exit bounded by --otlp-shutdown-timeout so a dead collector can't hang CI.
  • mecak8s (long-lived server — scrape fits): opt-in --metrics-addr loopback /metrics listener (non-loopback rejected fail-closed per ADR 0018 decision 6) + opt-in OTLP push twin for non-scrape deployments.
  • internal/cliconfig — shared HeadlessTelemetry helper (Rule of Three across the two new mains) + a canonical IsLoopbackAddr replacing the duplicated loopback checks in mecated and mecak8s.

Metrics / labels

Reuses the existing mecatl.* instruments — adds none. Per-run token counters ride EvResult.Usage (mecatl.tokens), run outcomes via mecatl.runs. Labels stay the issue-#47 closed Role* set — no session-id / model-id / free-text cardinality. A mecatl.cost counter is deferred to #192 (pricing deliberately unparsed in providercatalog).

Flags

mecatequi mecak8s default
--otlp-endpoint --otlp-endpoint "" (off)
--otlp-protocol --otlp-protocol grpc
--otlp-insecure --otlp-insecure false
--otlp-metrics-endpoint --otlp-metrics-endpoint "" (off)
--otlp-metrics-protocol --otlp-metrics-protocol grpc
--otlp-shutdown-timeout --otlp-shutdown-timeout 5s
— --metrics-addr (loopback-only) "" (off)

Coverage

  • internal/adapter/telemetry/otlp_metrics_test.go — scrape-only byte-identical regression guard; push+flush-on-shutdown to a fake collector; shutdown bounded by ctx; bad-protocol fail-closed.
  • internal/cliconfig/telemetry_test.go + loopback_test.go — no-endpoint no-op; loopback gate accepts/rejections.
  • cmd/mecatequi/telemetry_test.go — default-nil posture; full realMain e2e pushes mecatl.runs/mecatl.events to a fake collector; shutdown-timeout bounded against a stalling collector (fails if the bound is removed).
  • cmd/mecak8s/telemetry_test.go — default-nil posture; /metrics served on loopback through the full serve() path; non-loopback rejected at parse; OTLP-push e2e through serve() + SIGTERM flush.

Docs

ADR 0097; ADR 0027 List-1 inventory rows; usage + user-docs for both binaries; llms.txt regenerated.

Verification

task build, task lint (0 issues, all modules), task test (root + engine + standalone + provider), go run ./cmd/mecademo, task docs && task docs:check, task site:build — all green.

Follow-ups (noted in ADR 0097, out of scope here)

Co-Authored-By: Juan Antonio Osorio [email protected]

@JAORMX
JAORMX force-pushed the feat/343-headless-telemetry branch 2 times, most recently from 2de4e30 to 94330cc Compare August 5, 2026 21:08
JAORMX and others added 2 commits August 6, 2026 06:52
…ecak8s) (#343)

The headless mains deliberately wired Sink/ToolCallRecorder/metrics to nil,
leaving a factory running many one-shot invocations with no fleet-level
telemetry beyond exit codes and JSONL event files. Reuse the existing
internal/adapter/telemetry pipeline (the SAME Setup + NewMetrics +
WithRole role-scoper path mecated uses) behind opt-in, default-off flags
so the no-telemetry posture stays byte-identical.

- internal/adapter/telemetry: add an optional OTLP METRICS push reader
  (PeriodicReader over otlpmetricgrpc/http) alongside the always-on
  prometheus reader, gated on new OTLPConfig.Metrics* fields. Existing
  scrape-only callers are untouched.
- mecatequi (short-lived one-shot, scrape does not fit): opt-in
  --otlp-* / --otlp-metrics-* push flags with an explicit flush-before-exit
  bounded by --otlp-shutdown-timeout so a dead collector can't hang CI.
- mecak8s (long-lived server, scrape fits): opt-in --metrics-addr loopback
  /metrics listener (non-loopback rejected fail-closed per ADR 0018) plus
  opt-in OTLP push twin for non-scrape deployments.
- internal/cliconfig: shared HeadlessTelemetry helper (Rule of Three across
  the two new mains) + a canonical IsLoopbackAddr replacing the duplicated
  loopback checks in mecated and mecak8s.
- Reuses the existing mecatl.* instruments (no new metrics); per-run token
  counters ride EvResult.Usage. Labels stay the issue-#47 closed Role set.
  Cost counter deferred to #192 (pricing deliberately unparsed).
- ADR 0097 + ADR 0027 List-1 inventory rows + usage/user-docs.

Co-Authored-By: Juan Antonio Osorio <[email protected]>
…ck provider

The scrape e2e called app.Build without --mock, so it depended on a real
provider key in the environment. It passed locally (a key was present) but
failed in CI with "no LLM provider available". Pin it to --mock like the
sibling telemetry tests so it is hermetic and offline.

Co-Authored-By: Juan Antonio Osorio <[email protected]>
@JAORMX
JAORMX force-pushed the feat/343-headless-telemetry branch from 94330cc to 1909e9d Compare August 6, 2026 03:56
@JAORMX
JAORMX merged commit 7a0cc92 into main Aug 6, 2026
16 checks passed
@JAORMX
JAORMX deleted the feat/343-headless-telemetry branch August 6, 2026 04:09
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.

Telemetry for the headless binaries (mecatequi, mecak8s)

1 participant