-
Notifications
You must be signed in to change notification settings - Fork 4k
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
Fix prometheus metric format (#2825) #2899
base: master
Are you sure you want to change the base?
Conversation
To meet specification of prometheus metric, there should be only one TYPE field for the same metric name
<< name << " " << desc << '\n'; | ||
// To meet specification of prometheus metric, there should be only | ||
// one TYPE field for the same metric name. | ||
if (metrics_name.as_string() != _last_metric_name) { |
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.
Simply ignoring metrics that are duplicates of the previous ones does not completely solve the problem. If the metrics themselves are repetitive, perhaps we should try to identify and address the root cause; if it's just a matter of duplicate names, consider fixing the metrics name.
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.
Let me add some background knowledge. The metrics are stored in butil::FlatMap and the uniqueness of metric name is guaranteed. The problem arises from the introduction of mvar, where one metric name will correspond to multiple metric with different labels. My patch just handles this problem
This PR is similar to #2870, which one is better? |
The #2870 introduced a std::set container to remove duplicates, which is unnecessary and impacts performance. As the metrics are stored in butil::FlatMap and the uniqueness of metric name is guaranteed. When we just expose bvar, the current upstream code is fine. The problem arises from the introduction of mvar, where one metric name will correspond to multiple metric with different labels. My patch handles this problem and follow the specifition of Prometheus metric. |
LGTM |
There's a new dump_comment API when introducing mvar by @serverglen, is this the case to set some HELP/TYPE for it?
|
Reasonable. By overriding dump_comment method of PrometheusMetricsDumper to output HELP/TYPE for a metric, then the dump method should be changed to only output name and value (not including HELP/TYPE). I will try it this way. |
To meet specification of prometheus metric, there should be only one TYPE field for the same metric name.
We have meet this problem when implementing prometheus exporter for our own product, and this patch is applied with this problem fixed. The code is simple and efficient.
BTW, there are some other issue regarding to prometheus output format, which I will create issues and push PR. Thanks
What problem does this PR solve?
Issue Number:
#2825
Problem Summary:
What is changed and the side effects?
Changed:
Side effects:
Performance effects(性能影响): NO
Breaking backward compatibility(向后兼容性):
Check List: