-
Notifications
You must be signed in to change notification settings - Fork 921
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
dnsdist: add support for labels on custom metrics #14956
Conversation
This adds support for prometheus labels on custom metrics. Changes the metrics maps to hold a map of labels to metric values for each metric. Metrics without labels have an empty string label combination value. Adds an optional options table as the last parameter of `incMetric`, `decMetric`, `setMetric` and `getMetric`, which can be used to set labels by using the `label` key or to set the previously used parameter (either `step` or `value`). Closes: PowerDNS#13359
Pull Request Test Coverage Report for Build 12356677632Warning: This coverage report may be inaccurate.This pull request's base commit is no longer the HEAD commit of its target branch. This means it includes changes from outside the original pull request, including, potentially, unrelated coverage changes.
Details
💛 - Coveralls |
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 made a few comments, and I think we need to exclude metrics with labels from both Carbon export and dumpStats()
, but I'm quite happy with the general concept, and the code itself is good as well.
pdns/dnsdistdist/dnsdist-metrics.cc
Outdated
auto combinationOfLabels = generateCombinationOfLabels(labels); | ||
auto metricEntry = metric->second.find(combinationOfLabels); | ||
if (metricEntry == metric->second.end()) { | ||
metricEntry = metric->second.emplace(combinationOfLabels, MutableCounter()).first; | ||
g_stats.entries.write_lock()->emplace_back(Stats::EntryTriple{std::string(name), combinationOfLabels, &metricEntry->second.d_value}); | ||
} | ||
metricEntry->second.d_value -= step; | ||
return metricEntry->second.d_value.load(); |
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.
Just a nit but it looks like we could get rid of a bit of code duplication by turning this into a (templated to handle both counters and gauges?) function.
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.
That makes sense, I will try to clean it up. My C++ skills are not good, so expect a messy first attempt 😄
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.
No problem, and please feel free to ask for help if needed, or even to just leave the cleanup to me when you are done, that's completely fine!
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.
Thank you! I will take a shot and let you know if I get stuck
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 have added a template function for this. Let me know if it looks okay or if it needs some work.
By the way, an unrelated question: |
Version 11 was the one that was available in our CI when we started enforcing formatting. Later we noticed differences with newer clang-format versions, so we fixated the version. It mights be time to move to a newer version... |
I think everything is covered now. I still need to update documentation though. |
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.
Looks good to me, I suggested a few changes to appease the static analyzer. A new regression test would be nice, and of course as you already mentioned this needs to be documented :)
Co-authored-by: Remi Gacogne <github@coredump.fr>
I have added the documentation. I was not sure what to set as |
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.
A couple nits but the documentation looks OK and the tests are quite nice, thanks!
Co-authored-by: Remi Gacogne <github@coredump.fr>
Thank you! I think for 2.0.0 (if breaking changes are allowed between major versions), we could just leave opts for |
Breaking changes in major versions are of course OK when they are needed or particularly useful, but my feeling is that it's neither in this case. The solution you came with is backward-compatible and quite clean 👍. |
Short description
This adds support for prometheus labels on custom metrics. Changes the metrics maps to hold a map of labels to metric values for each metric. Metrics without labels have an empty string label combination value.
Adds an optional options table as the last parameter of
incMetric
,decMetric
,setMetric
andgetMetric
, which can be used to set labels by using thelabel
key or to set the previously used parameter (eitherstep
orvalue
).Closes: #13359
Checklist
I have: