feat: add sentinel label value for global metric visibility#220
Conversation
|
Alternative proposal: To remove the need to maintain this allowlist, we could recognize global metrics through a sentinel value in the If we go with the allowlist design, I would like to request for them to be regexes. Ref: https://github.com/sapcc/limes/blob/57e7e18a1ba2aefb91c69d8f91a400c0575a322a/internal/collector/metrics.go#L864-L869 |
cce9b21 to
e7dfe19
Compare
Introduces a configurable `maia.label_value_for_global_visibility` setting that appends a sentinel value to project_id/domain_id scope constraints, making metrics carrying this value visible to all tenants. - Server validates sentinel contains no regex metacharacters at startup - Scope injection appends sentinel to regex alternatives - New API tests cover sentinel behavior for label_values endpoint - Config example updated with new option
c88ba63 to
bd74181
Compare
There was a problem hiding this comment.
Pull request overview
This PR introduces a configurable “global visibility” sentinel label value that gets appended to tenant scope constraints, allowing metrics tagged with the sentinel to be visible across all authenticated tenants (useful for cluster/info metrics that otherwise lack tenant labels).
Changes:
- Add
maia.label_value_for_global_visibilityconfig default and server-side startup validation (reject regex metacharacters). - Append the resolved sentinel value to project/domain scope label constraints, affecting all endpoints that rely on scope resolution.
- Extend API tests and fixtures to cover sentinel behavior; adjust PromQL matcher equality logic to avoid incorrect duplication.
Reviewed changes
Copilot reviewed 9 out of 9 changed files in this pull request and generated 1 comment.
Show a summary per file
| File | Description |
|---|---|
| pkg/api/server.go | Resolves + validates the sentinel config once at startup. |
| pkg/api/util.go | Appends the configured sentinel to scope-derived label value lists. |
| pkg/api/api_test.go | Adds integration-style tests ensuring sentinel appears in injected scope constraints. |
| pkg/api/fixtures/label_values_sentinel_names_query_range.json | New fixture for label-values tests involving globally visible metrics. |
| pkg/api/fixtures/label_values_sentinel_node_query_range.json | New fixture for label-values tests involving globally visible metrics. |
| pkg/util/promqlmod.go | Fixes matcher equality to avoid reliance on reflect.DeepEqual for labels.Matcher. |
| pkg/cmd/root.go | Adds Viper default for the new configuration key. |
| etc/maia.conf | Documents the new config option in the sample config. |
| CHANGELOG.md | Adds an Unreleased entry documenting the new feature. |
💡 Add Copilot custom instructions for smarter, more guided reviews. Learn how to get started.
Co-authored-by: Copilot Autofix powered by AI <175728472+Copilot@users.noreply.github.com>
majewsky
left a comment
There was a problem hiding this comment.
Looks good to me, thanks!
viennaa
left a comment
There was a problem hiding this comment.
Really like the idea of having this value configurable, small thing before I can stamp :)
Co-authored-by: Tommy Sauer <tommy.sauer@sap.com>
Merging this branch will decrease overall coverage
Coverage by fileChanged files (no unit tests)
Please note that the "Total", "Covered", and "Missed" counts above refer to code statements instead of lines of code. The value in brackets refers to the test coverage of that file in the old version of the code. Changed unit test files
|
Summary
maia.label_value_for_global_visibilityconfig option: a sentinel value appended to tenant scope regexes so metrics tagged with it become visible to all tenantskube_node_info) that lack tenant labels being invisible to authenticated tenantsDesign
"all") is appended to every scope constraint, soproject_id=~"p1|p2"becomesproject_id=~"p1|p2|all"regexp.QuoteMetavalidation)appendSentinelValue) called after everyscopeToLabelConstraint()Configuration
Files Changed
pkg/api/util.goappendSentinelValue()function + INVARIANT commentpkg/api/util_test.gopkg/api/server.gopkg/api/v1api.goappendSentinelValuein Query, QueryRange, LabelValuespkg/api/api_test.gopkg/util/promqlmod.goreflect.DeepEqual→ field comparison for matcher equalitypkg/cmd/root.goetc/maia.confCHANGELOG.mdTest plan
appendSentinelValue(empty sentinel, single/multiple values, spare capacity)make checkpasses (tests + golangci-lint)