-
Notifications
You must be signed in to change notification settings - Fork 7
feat: add sparrow_instance_info metric for ownership metadata (#354) #391
New issue
Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.
By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.
Already on GitHub? Sign in to your account
Open
ayoub3bidi
wants to merge
3
commits into
telekom:main
Choose a base branch
from
ayoub3bidi:feat/354-ownership-metadata
base: main
Could not load branches
Branch not found: {{ refName }}
Loading
Could not load tags
Nothing to show
Loading
Are you sure you want to change the base?
Some commits from the old base branch may be removed from the timeline,
and old review comments may become outdated.
Open
Changes from all commits
Commits
Show all changes
3 commits
Select commit
Hold shift + click to select a range
822f851
feat: add sparrow_instance_info metric for ownership metadata (#354)
ayoub3bidi b232c92
refactor: update instance metadata handling in sparrow_instance_info …
ayoub3bidi 9fe31fa
chore: update Prometheus common dependency and enhance instance metad…
ayoub3bidi File filter
Filter by extension
Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
There are no files selected for viewing
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
| Original file line number | Diff line number | Diff line change |
|---|---|---|
| @@ -0,0 +1,37 @@ | ||
| <!-- | ||
| SPDX-FileCopyrightText: 2025 Deutsche Telekom IT GmbH | ||
|
|
||
| SPDX-License-Identifier: CC-BY-4.0 | ||
| --> | ||
|
|
||
| # Design: Sparrow Instance Ownership Metadata (Issue #354) | ||
|
|
||
| ## Summary | ||
|
|
||
| Sparrow exposes optional instance metadata via a dedicated Prometheus **info metric** (`sparrow_instance_info`), so operators can identify owners, route alerts correctly, and correlate metrics across multiple Sparrow deployments. | ||
|
|
||
| ## Why a Dedicated Info Metric | ||
|
|
||
| - **Prometheus best practice:** Info-style metrics (gauge with value 1 and descriptive labels) are the standard way to expose static attributes (e.g. `kube_pod_info`, `node_uname_info`). They avoid polluting every time series with extra labels and keep cardinality under control. | ||
| - **No impact on existing metrics:** We do **not** add metadata labels to check metrics (health, latency, DNS, traceroute). That would multiply cardinality and complicate existing dashboards. Joining with `sparrow_instance_info` in PromQL when needed is explicit and flexible. | ||
| - **Works without target manager:** The metric is registered at startup from startup config only. It does not depend on the target manager or any runtime component. | ||
| - **Single emission per instance:** The metric is registered once during `sparrow.New()` and emits one time series per instance. No periodic updates or lifecycle complexity. | ||
|
|
||
| ## Implementation Choices | ||
|
|
||
| 1. **Config shape:** `metadata` is a map of arbitrary key-value pairs under startup config (e.g. `team_name`, `platform`, `region`). All fields optional; omitted keys are not emitted as labels. The key `instance_name` is reserved and set from the Sparrow DNS name. | ||
| 2. **Registration point:** Instance info is registered in `sparrow.New()` after the metrics provider is created. Registration failure is logged but non-fatal so the process still starts. | ||
| 3. **Metrics package:** A small `RegisterInstanceInfo(registry, instanceName, metadata)` in `pkg/sparrow/metrics` keeps the metrics package independent of `pkg/config` and makes the behaviour easy to test. | ||
| 4. **Helm:** Metadata is optional under `sparrowConfig` in values; backward compatibility is preserved when metadata is not provided. | ||
|
|
||
| ## Prometheus Usage | ||
|
|
||
| - **Alert routing:** Alertmanager or routing rules can use `sparrow_instance_info` to add ownership metadata to alerts. | ||
| - **Dashboards:** `group_left(...) sparrow_instance_info` joins metadata onto any Sparrow metric by scrape `instance`. | ||
| - **Multi-team views:** Filter or group by `team_name`, `platform`, `region`, or any other configured labels without changing existing metric names or labels. | ||
|
|
||
| ## Deliverables | ||
|
|
||
| - **Code:** `pkg/config` (Metadata map), `pkg/sparrow/metrics` (RegisterInstanceInfo + test), `pkg/sparrow` (registration in New). | ||
| - **Helm:** `chart/values.yaml` extended with commented metadata example; config is merged into existing sparrowConfig. | ||
| - **Docs:** README (metadata config, instance info metric, PromQL examples), this design summary. |
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
| Original file line number | Diff line number | Diff line change |
|---|---|---|
| @@ -0,0 +1,60 @@ | ||
| // SPDX-FileCopyrightText: 2025 Deutsche Telekom IT GmbH | ||
| // | ||
| // SPDX-License-Identifier: Apache-2.0 | ||
|
|
||
| package metrics | ||
|
|
||
| import ( | ||
| "fmt" | ||
| "sort" | ||
|
|
||
| "github.com/prometheus/client_golang/prometheus" | ||
| "github.com/prometheus/common/model" | ||
| ) | ||
|
|
||
| const ( | ||
| instanceInfoMetricName = "sparrow_instance_info" | ||
| instanceInfoHelp = "Ownership and platform metadata for this Sparrow instance. Emitted once per instance for alert routing and multi-team correlation." | ||
| ) | ||
|
|
||
| // RegisterInstanceInfo registers the sparrow_instance_info info-style metric on the given registry. | ||
| // It sets the gauge to 1 with labels instance_name and any user-defined metadata keys. | ||
| // Empty strings are allowed for metadata values; instanceName should be the Sparrow DNS name. | ||
| // Metadata keys must be valid Prometheus label names and must not include "instance_name". | ||
| func RegisterInstanceInfo(registry *prometheus.Registry, instanceName string, metadata map[string]string) error { | ||
| if metadata == nil { | ||
| metadata = map[string]string{} | ||
| } | ||
|
|
||
| keys := make([]string, 0, len(metadata)) | ||
| for k := range metadata { | ||
| keys = append(keys, k) | ||
| } | ||
| sort.Strings(keys) | ||
|
|
||
| labels := make([]string, 0, len(keys)+1) | ||
| values := make([]string, 0, len(keys)+1) | ||
| labels = append(labels, "instance_name") | ||
| values = append(values, instanceName) | ||
|
|
||
| for _, k := range keys { | ||
| if k == "instance_name" { | ||
| return fmt.Errorf("metadata key %q is reserved", k) | ||
| } | ||
| if !model.UTF8Validation.IsValidLabelName(k) { | ||
| return fmt.Errorf("metadata key %q is not a valid Prometheus label name", k) | ||
| } | ||
| labels = append(labels, k) | ||
| values = append(values, metadata[k]) | ||
| } | ||
|
|
||
| info := prometheus.NewGaugeVec( | ||
| prometheus.GaugeOpts{ | ||
| Name: instanceInfoMetricName, | ||
| Help: instanceInfoHelp, | ||
| }, | ||
| labels, | ||
| ) | ||
| info.WithLabelValues(values...).Set(1) | ||
| return registry.Register(info) | ||
| } |
Oops, something went wrong.
Oops, something went wrong.
Add this suggestion to a batch that can be applied as a single commit.
This suggestion is invalid because no changes were made to the code.
Suggestions cannot be applied while the pull request is closed.
Suggestions cannot be applied while viewing a subset of changes.
Only one suggestion per line can be applied in a batch.
Add this suggestion to a batch that can be applied as a single commit.
Applying suggestions on deleted lines is not supported.
You must change the existing code in this line in order to create a valid suggestion.
Outdated suggestions cannot be applied.
This suggestion has been applied or marked resolved.
Suggestions cannot be applied from pending reviews.
Suggestions cannot be applied on multi-line comments.
Suggestions cannot be applied while the pull request is queued to merge.
Suggestion cannot be applied right now. Please check back later.
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
please add this header to the table of contents above