Skip to content

[Feature]: Add opt-in authenticated Prometheus metrics endpoint #504

Closed

Description

@le-shi

Existing issues

  • I searched open and closed issues and did not find a duplicate.

Problem or use case

I want to monitor Win-CodexBar quota state from Prometheus across Windows machines. The existing serve command exposes authenticated JSON endpoints, but Prometheus users currently need a separate adapter such as json_exporter and must duplicate field mapping, error semantics, and cache handling outside Win-CodexBar.

Proposed solution

Add an opt-in Prometheus endpoint to the existing CLI server:

codexbar serve --metrics

The proposed behavior is:

  • /metrics is disabled by default and returns 404 unless --metrics is set.
  • It reuses the existing serve Host validation, Bearer-token gate, dashboard snapshot cache, and single-flight refresh path.
  • It exposes Prometheus text format for exporter health, provider collection state, quota used/remaining percentages, reset timestamps, and other stable numeric fields already present in the dashboard snapshot.
  • It does not expose account email, plan text, display labels, credential material, or free-form provider error messages.
  • It does not invoke an AI model or consume Codex/ChatGPT inference quota; it only reads the same usage data already collected by Win-CodexBar.

I have a working Windows prototype and can submit a focused PR containing only the CLI flag, endpoint, renderer, tests, and minimal documentation after the preferred metric scope and naming are confirmed.

Questions for maintainers:

  1. Should the endpoint expose every enabled provider, or initially limit the contract to Codex?
  2. Is reusing the dashboard snapshot contract/cache the preferred source, or should metrics have a smaller dedicated snapshot type?
  3. Should stable local account identifiers be omitted entirely from metric labels in the first version?

Affected area

  • CLI
  • Startup / background behavior
  • Documentation
  • Provider-specific behavior for the initial core endpoint

Alternatives considered

  • Configure Prometheus json_exporter against /dashboard/v1/snapshot.
  • Run a separate local exporter that calls Win-CodexBar JSON endpoints.

Both work, but they duplicate authentication, cache/error interpretation, metric naming, and privacy filtering. Keeping the renderer beside the existing cached snapshot makes the exported contract testable with the same source data and avoids another credential-bearing process.

Additional context

The first PR can deliberately exclude Grafana dashboards, alert rules, reset-credit-specific behavior, installers, and release workflow changes so the core endpoint remains small and reviewable.

Activity

  1. Finesssee commented on Sep 15, 2026

    @Finesssee
    Collaborator

    Thanks for the feature request, I will think about it.

  2. Finesssee commented on Sep 15, 2026

    @Finesssee
    Collaborator

    Thanks for the proposal. The direction looks good, and a native endpoint is preferable to a separate exporter if V1 remains a thin projection of the existing authenticated serve path.

    For the first PR, please use this contract:

    • codexbar serve --metrics enables authenticated GET /metrics; without the flag, /metrics returns 404.
    • Reuse the existing Host validation, Bearer authentication, snapshot/cache policy, and single-flight refresh path. A scrape must not create a second provider-polling loop or duplicate concurrent refreshes.
    • Expose stable numeric/bounded data for enabled providers where the semantics are valid. A bounded provider slug is the only label needed initially; omit account identifiers entirely.
    • Exclude emails, usernames, plans, display labels, account IDs, credentials, URLs, raw provider errors, and other free-form values from metric names and labels.
    • Freeze units in the contract: prefer ratios in the 0..1 range and reset timestamps in seconds. Omit unknown values instead of reporting zero.
    • Partial provider failures should still return usable metrics with bounded provider health state. Reserve non-2xx responses for an exporter-level failure where no meaningful snapshot can be produced.
    • The endpoint must not invoke an AI model or consume Codex/ChatGPT inference quota.

    Please keep the PR limited to the CLI flag, endpoint, renderer, focused tests, and minimal documentation. Tests should cover the disabled 404, Host/authentication gates, privacy filtering, metric units, partial failures, cache/single-flight behavior, and no-inference behavior. Open it as a draft PR when ready so we can review the concrete metric contract.

  3. le-shi commented on Sep 17, 2026

    @le-shi
    Author

    PR #511 is ready for review, and CodeRabbit has completed successfully with no actionable comments. The current head is b6b29dc.

    The remaining required check, ci/circleci: pr-check, stays at Expected - Waiting for status to be reported. I verified that no CircleCI pipeline is created for this fork branch, while same-repository PRs run pr-check normally. The project uses CircleCI's GitHub App integration, for which CircleCI currently lists "Build Pull Requests From Forked Repositories" as unsupported: https://circleci.com/docs/guides/integration/version-control-system-integration-overview/#feature-support-for-each-pipeline-type

    Do I need to take any further action on PR #511, or would you prefer to mirror the branch into nesszer/Win-CodexBar so the required CircleCI check can run? I can also provide any additional validation or make further changes if needed.

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment

Metadata

Metadata

Assignees

No one assigned

    Labels

    No labels
    No labels

    Type

    No type

    Projects

    No projects

      Milestone

      No milestone

      Relationships

      None yet

      Development

      No branches or pull requests

      Issue actions