8000 Added tenant_id config to send X-Scope-OrgID for Mimir by abd-ulbasit · Pull Request #21 · dominikhei/cardamon · GitHub
[go: up one dir, main page]

Skip to content

Added tenant_id config to send X-Scope-OrgID for Mimir - #21

Open
abd-ulbasit wants to merge 2 commits into
dominikhei:mainfrom
abd-ulbasit:cardamon-10
Open

abd-ulbasit wants to merge 2 commits into
dominikhei:mainfrom
abd-ulbasit:cardamon-10

Conversation

@abd-ulbasit
@abd-ulbasit abd-ulbasit commented Oct 17, 2026 •
Copy link
Copy Markdown

Refs #10

Mimir serves the Prometheus HTTP API under /prometheus and reads the tenant from the X-Scope-OrgID header. path_prefix already covers the first part, so this adds prometheus.tenant_id and sends it as X-Scope-OrgID on every Prometheus request (label values, rules, series, query). If it's empty no header is sent, so nothing changes for plain Prometheus.

This is only the first part of #10: one run audits one tenant. Federated tenant IDs (team-a|team-b) don't work, because Mimir's rules endpoint only accepts a single tenant, and the README says so. Matching Grafana dashboards to tenants isn't in here either; I'd like to agree on an approach with you in #10 first.

What changed:

  • prometheus.tenant_id in the config, passed to prom.NewClient and set in the existing round tripper next to the auth headers.
  • pkg/prom/client_test.go: runs GetAllMetricNames against an httptest server under /prometheus and checks the header with no tenant, one tenant, a value containing | (sent unchanged), and a tenant together with a bearer token.
  • README: tenant_id in the config example, a "Using cardamon with Grafana Mimir" section, and an updated Limitations paragraph.
  • A separate commit removes a trailing space on README line 14. The pre-commit job on main has been failing on it since 93ba198.

Testing:

  • go test -race ./..., go vet ./..., gofmt, goimports and golangci-lint run (v2.15.0) are clean.
  • I also ran the binary against a small fake Prometheus API that rejects requests without X-Scope-OrgID and serves different metrics per tenant. All four endpoints got the header, each tenant only saw its own metrics, and an empty tenant_id got a 401, as Mimir does with multi-tenancy enabled. I haven't run it against a real Mimir yet.

Notes:

  • There's no go test step in CI, so the new test won't run there. Happy to add one to ci.yaml, here or in a separate PR.
  • govulncheck currently fails on main because Go 1.25.12 has known standard library vulnerabilities. Some of them, published in October, are fixed only in Go 1.26.9+, so it needs a move to Go 1.26. This PR doesn't touch that; I can send it separately.
  • prom.NewClient gets a fifth parameter, which changes an exported function. I don't know of anyone importing the package, but I can switch to an options struct if you'd prefer.
  • If you'd rather have a generic headers map instead of tenant_id (Thanos uses THANOS-TENANT by default, e.g. the querier's --query.tenant-header), that's a small change.

The trailing-whitespace hook fails on README.md line 14 since 93ba198,
which turns the pre-commit CI job red for every run.
Mimir serves the Prometheus HTTP API under /prometheus and reads the
tenant from the X-Scope-OrgID header. path_prefix already covers the
first part, so the new prometheus.tenant_id option adds the header to
every Prometheus request. Empty means no header, as before.

Added a client test against an httptest server, and a README section
on running cardamon against Mimir.

Refs dominikhei#10
@abd-ulbasit
Copy link
Copy Markdown
Author

@dominikhei, this adds a tenant_id setting that sends X-Scope-OrgID for Mimir (#10). CI is waiting for a workflow approval, and I can rename the key if you prefer another.

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

0