-
Notifications
You must be signed in to change notification settings - Fork 1.2k
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
[collectd 6] Write Prometheus plugin: Ensure metric and label names are properly formatted. #4206
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.
Code changes themselves look fine, but Makefile.am
changes for other plugins should be in a separate PR.
Are test-cases and handling for resource labels coming in some future PR?
5c4dc1c
to
c47deae
Compare
Created a separate PR for Yes, test cases for metric/label names with invalid characters was still in the works, hence the draft status. This is ready for review now. |
This new function is similar to `strbuf_print_escaped` but differs in two important aspects: * `strbuf_print_restricted` expects a list of acceptable characters, i.e. an allow list. `strbuf_print_escaped` expects a deny list. * `strbuf_print_restricted` *replaces* characters not in the allow list. `strbuf_print_escaped` adds an escape character in front of the denied character.
d197258
to
1a56a90
Compare
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.
Code seems OK otherwise, but it think strbuf_print_restricted()
could be more effective.
Instead of building the buffer piece by piece, copy the entire string into the buffer and do the replacements there. I think the code is quite efficient, but I haven't profiled either version so can't say for sure that there is a speedup. The new code *may* be easier to reason about, since the "copy and replace" approach has a much simpler loop body than the previous approach.
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.
There's some leftover code, but otherwise looks good!
PS. I think this is the first time I came across C99 static array declarator use, so I learned something new! According to GCC but tracker, although support for them was added in v4.x, only v11.x gives warnings if the specified bounds are not respected: https://gcc.gnu.org/bugzilla/show_bug.cgi?id=50584
Co-authored-by: Eero Tamminen <eero.t.tamminen@intel.com>
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.
Approved, looks great!
(Have time to test only after it's merged though, for a fix PR to Sysman plugin.)
ChangeLog: Write Prometheus plugin: Escaping for metric and label names has been added. Test coverage has been improved.
Fixes: #4204