otlp/translator: Use separate function for metric names with UTF8 characters#15664
otlp/translator: Use separate function for metric names with UTF8 characters#15664ArthurSens merged 13 commits intomainfrom
Conversation
4863399 to
90ce391
Compare
|
Can you change the name of this PR? Refactoring per definition doesn't fix any bugs. Refactoring just means changing code for maintainability reasons. |
90ce391 to
d1934e8
Compare
|
merge conflict resolved :) |
|
Thanks, going to take a look. |
aknuds1
left a comment
There was a problem hiding this comment.
Please see comments for bugs I could spot.
storage/remote/otlptranslator/prometheus/metric_name_builder.go
Outdated
Show resolved
Hide resolved
storage/remote/otlptranslator/prometheus/metric_name_builder.go
Outdated
Show resolved
Hide resolved
storage/remote/otlptranslator/prometheus/metric_name_builder.go
Outdated
Show resolved
Hide resolved
aknuds1
left a comment
There was a problem hiding this comment.
I forgot to include one of the bugs I spotted in the previous review.
There was a problem hiding this comment.
I've defined a test that catches a bug in this PR. If you try that with this PR, you'll see that the suffix comes out as _km_per_, instead of just _km.
It's probably a good idea to copy said test to this PR, to guard against the regression in question.
Sounds good, I'm merging that PR and rebasing this one |
bf1c8ff to
960edd8
Compare
|
Hmmm, I'm not really sure about what should be the expected behavior in the failing test 😵 require.Equal(t, "broken_metric_speed_km", normalizeName(createGauge("broken.metric.speed", "km/°"), ""))
// Not equal:
// expected: "broken_metric_speed_km"
// actual : "broken_metric_speed_km_per_"We see a |
@ArthurSens It's the other way around. The current behaviour is what's in main, i.e. before the changes in this PR, and since the test in question passes there (on the main branch), the current behaviour is to drop the "per" part. The expectation of the test represents the current, desired, behaviour. This PR is not supposed to change the classical translation mode, only the UTF-8 translation mode, so it follows that the implementation should merely pass the test. |
BuildCompliantName no longer takes UTF8 support into consideration and fully focus on building a metric name that follows Prometheus conventions. Signed-off-by: Arthur Silva Sens <[email protected]>
Signed-off-by: Arthur Silva Sens <[email protected]>
Signed-off-by: Arthur Silva Sens <[email protected]>
Signed-off-by: Arthur Silva Sens <[email protected]>
Signed-off-by: Arthur Silva Sens <[email protected]>
By making it return only the appropriate suffixes without modifying them. Character transformation is now done by the caller if necessary. Signed-off-by: Arthur Silva Sens <[email protected]>
Signed-off-by: Arthur Silva Sens <[email protected]>
Signed-off-by: Arthur Silva Sens <[email protected]>
8a30da4 to
2026c5b
Compare
Signed-off-by: Arthur Silva Sens <[email protected]>
|
Finally coming back to this after the holidays 👋 |
aknuds1
left a comment
There was a problem hiding this comment.
Looks much better now, but please see my suggestion for cleaning up a hairy code block that I think has a bug:
storage/remote/otlptranslator/prometheus/metric_name_builder.go
Outdated
Show resolved
Hide resolved
storage/remote/otlptranslator/prometheus/metric_name_builder.go
Outdated
Show resolved
Hide resolved
storage/remote/otlptranslator/prometheus/metric_name_builder_test.go
Outdated
Show resolved
Hide resolved
storage/remote/otlptranslator/prometheus/metric_name_builder_test.go
Outdated
Show resolved
Hide resolved
storage/remote/otlptranslator/prometheus/metric_name_builder_test.go
Outdated
Show resolved
Hide resolved
Co-authored-by: Arve Knudsen <[email protected]> Signed-off-by: Arthur Silva Sens <[email protected]>
Signed-off-by: Arthur Silva Sens <[email protected]>
Signed-off-by: Arthur Silva Sens <[email protected]>
aknuds1
left a comment
There was a problem hiding this comment.
LGTM, but I think there's a misleading test case comment. Should we remove the test case?
storage/remote/otlptranslator/prometheus/metric_name_builder_test.go
Outdated
Show resolved
Hide resolved
Signed-off-by: Arthur Silva Sens <[email protected]>
After many discussions with the team, it seems that our previous approach of using the method
BuildCompliantNameto translate all kinds of translation strategies stretched its usefulness too much.This is an alternative for #15440. Here, concerns are split into two separate functions.
BuildCompliantNamewas renamed toBuildCompliantMetricNameand focuses only on building metric names that follow Prometheus naming conventions.The new function
BuildMetricNameis responsible for building metric names that keep characters as they come. The only thing it does is append prefixes and suffixes, if asked.For the reviewers, I recommend reviewing commits individually :)
Fixes #15534
Fixes #15362