Skip to content
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

Merged
merged 10 commits into from
Dec 21, 2023

Conversation

octo
Copy link
Member

@octo octo commented Dec 21, 2023

ChangeLog: Write Prometheus plugin: Escaping for metric and label names has been added. Test coverage has been improved.
Fixes: #4204

@octo octo added the Bug A genuine bug label Dec 21, 2023
@collectd-bot collectd-bot added this to the 6.0 milestone Dec 21, 2023
@octo octo linked an issue Dec 21, 2023 that may be closed by this pull request
Copy link
Contributor

@eero-t eero-t left a 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?

@octo
Copy link
Member Author

octo commented Dec 21, 2023

Created a separate PR for Makefile.am changes: #4207

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.

@octo octo marked this pull request as ready for review December 21, 2023 10:58
@octo octo requested a review from a team as a code owner December 21, 2023 10:58
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.
Copy link
Contributor

@eero-t eero-t left a 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.

src/utils/strbuf/strbuf.c Outdated Show resolved Hide resolved
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.
Copy link
Contributor

@eero-t eero-t left a 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

src/utils/strbuf/strbuf.c Outdated Show resolved Hide resolved
Co-authored-by: Eero Tamminen <eero.t.tamminen@intel.com>
Copy link
Contributor

@eero-t eero-t left a 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.)

@octo octo merged commit 345c52d into collectd:collectd-6.0 Dec 21, 2023
19 of 24 checks passed
@octo octo deleted the 6/write_prometheus branch December 21, 2023 17:54
@octo octo added Fix A pull request fixing a bug and removed Bug A genuine bug labels Jan 15, 2024
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
Fix A pull request fixing a bug
Projects
None yet
Development

Successfully merging this pull request may close these issues.

v6 regression: resource labels break metrics reporting to Prometheus
3 participants