-
Notifications
You must be signed in to change notification settings - Fork 159
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
metrics-exporter-prometheus: properly sanitize metric names #290
Conversation
@gnuvince Thanks for opening the initial issue and the subsequent PR to fix it. I think the lookup table approach is a bit too optimized. I know, this might sound silly, but given the pattern of how an exporter is used -- typically on an interval or polled infrequently -- the lookup table-based approach feels like it's trading far too much in terms of obviousness and readability for what is likely a small improvement in overall performance. I'd like to a see a more iterative, straightforward approach -- replace the initial character, even if it results in a suboptimal clone, then do the remaining steps -- as a first pass of fixing this issue. |
How about this version? If performance is not much of an issue, I think this is the clearest I can make it. |
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.
Looking a lot simpler and straightforward, just one more small tweak.
Co-authored-by: Toby Lawrence <tobz@users.noreply.github.com>
Released in |
…rs#290) Co-authored-by: Toby Lawrence <tobz@users.noreply.github.com>
Closes #289
#289 describes a case when a valid metric name is sanitized (i.e., changed) when it need not be. I added a test to exercise this case and modified the
sanitize_metrics_name
function to pass this test. In terms of approach, I changed from using methods on strings to using a pre-constructed lookup table. The helper functions that were previously used to implementsanitize_metrics_name
have been moved in thetest
module to act as oracles in the property tests.