metrics-exporter-prometheus: properly sanitize metric names#290
metrics-exporter-prometheus: properly sanitize metric names#290tobz merged 4 commits intometrics-rs:mainfrom
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. |
tobz
left a comment
There was a problem hiding this comment.
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_namefunction 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_namehave been moved in thetestmodule to act as oracles in the property tests.