[3.x] Fix improper handling of metrics global tags #5812
Merged
Add this suggestion to a batch that can be applied as a single commit.
This suggestion is invalid because no changes were made to the code.
Suggestions cannot be applied while the pull request is closed.
Suggestions cannot be applied while viewing a subset of changes.
Only one suggestion per line can be applied in a batch.
Add this suggestion to a batch that can be applied as a single commit.
Applying suggestions on deleted lines is not supported.
You must change the existing code in this line in order to create a valid suggestion.
Outdated suggestions cannot be applied.
This suggestion has been applied or marked resolved.
Suggestions cannot be applied from pending reviews.
Suggestions cannot be applied on multi-line comments.
Suggestions cannot be applied while the pull request is queued to merge.
Suggestion cannot be applied right now. Please check back later.
Resolves #5791
MP Metrics requires that the config setting
mp.metrics.tags
(formattag1=value1,tag2=value2")
should cause MP metrics to assign the specified "global tags" to decorate everyMetricID
during output.In our SE implementation, we follow the same approach except with
metrics.tags
as the config key.Investigating the issue revealed one error and one not-great practice.
MetricsSettings
, (in SE), when using the default config to create an instance, usedConfig.create()
without also using.get("metrics")
to obtain the metrics-specific assignments. As a result, a top-level config key of "tags" (the issue described using an environment variable but a setting at the top level of any config source would show the problem) causedMetricsSettings
to try to use that as the global metrics tag settings. The value was not formatted as the code expected so it threw an exception.MetricsCdiExtension
, we have to merge settings frommp.metrics
andmetrics
if both are present to create the metrics settings we use in preparing theMetricsSupport
object. The code does this by creating a temporaryConfig
object with config sources from the two config nodes atmp.metrics
andmetrics
. But it did so by usingConfig.builder()...
without disabling the built-in env. var. and system property sources. This should not have affected anything, but it was confusing because themp.metrics
andmetrics
sections of config used to create the temporaryConfig
object would already have accounted for env. vars and properties.The code contains fixes in these two spots plus new tests that run in separate JVMs to avoid cross-contaminating the test configs with the tag settings. (I probably could have used custom
Config
objects in the tests to simplify the test executions but I wanted to reproduce the conditions reported in the issue, which used an env. var.)