-
Notifications
You must be signed in to change notification settings - Fork 720
add WithLabelsFromContext prometheus interceptor option #758
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
add WithLabelsFromContext prometheus interceptor option #758
Conversation
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.
I'd usually insist on an issue first, but this is well reasoned, with concrete use cases and even added examples. Thank you!
Ha, just realized there is an issue already, looks like you forgot to reference it? #445 |
Yep, apologies I did not realize linking was part of the process. |
@johanbrandhorst I managed to remove the toolchain directive, while still |
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.
The go
field update is fine :)
Thank you for your contribution! |
Changes
This pull request introduces support for extracting and using dynamic labels from Go context / gRPC metadata in Prometheus metrics. The changes include updates to the server metrics configuration, enhancements to label extraction and handling, and the addition of comprehensive tests for the new functionality.
Enhancements to Prometheus Metrics:
WithContextLabels
andWithLabelsFromContext
options in theproviders/prometheus/options.go
file. These allow configuring which labels will later be extracted dynamically, as well as a function to actually extract them.ServerMetrics
to includecontextLabelNames
for storing dynamic label names and modified metric initialization to include these labels. This ensures that all metrics (e.g., counters, histograms) are pre-registered with the appropriate label names.reporter
logic to append dynamic labels to metrics during runtime, ensuring that the extracted labels are applied to counters, histograms, and other metric types.Integration with Example Server:
examples/server/main.go
) to demonstrate the use of dynamic labels. This includes extracting thetenant_name
label from metadata and configuring the server metrics to use it.Verification
providers/prometheus/context_labels_test.go
to validate the functionality of dynamic labels. These tests cover scenarios such as missing labels, label extraction, and integration with histograms.WithLabelsFromContext
function configured to append that metadata to the metrics. Finally, I queried the prometheus metrics endpoint to view the raw metric values and confirmed that labels from context were being properly applied.