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

Introduced a DynamicValueTag class to determine tag values at runtime #2285

Open
wants to merge 2 commits into
base: main
Choose a base branch
from

Conversation

SimonScholz
Copy link

Hi,

In our application we'd love to have common tags for each and every metric, but these common tags might change during runtime. Passing these dynamic common tag values to each and every counter or timer we create is really inconvenient!

This PR is related to this issue: #2223

I was also already able to test this new feature, by adding the following code to the io.micrometer.boot2.samples.components.ServiceLevelObjectiveConfiguration:

    @Bean
    MeterRegistryCustomizer<MeterRegistry> MeterRegistryCommonTagsCustomizer() {
        Tag staticTag = Tag.of("staticTagKey", "static data");
        Tag dynamicTag = Tag.of("dynamicTagKey", () -> "Millis:" + System.currentTimeMillis());
        return registry -> registry.config().commonTags(Arrays.asList(staticTag, dynamicTag));
    }

Then when I started the io.micrometer.boot2.samples.LoggingRegistrySample application together with the MeterRegistryCustomizer mentioned above, I was able to see the different currentTimeMillis in the system out.

Having this feature would save us a lot of effort, because otherwise we would need to pass these dynamic tag values to each and every counter or timer we create in our code.

@SimonScholz SimonScholz force-pushed the feature/dynamic_tag_values branch from 6603ddd to 843809a Compare October 9, 2020 12:33
@SimonScholz
Copy link
Author

@jackhammer2k and @jkschneider do you have any objections about this PR?

@jackhammer2k
Copy link

I really like the PR and could only find little things in the Javadocs.

}

@Override
public boolean equals(@Nullable Object o) {

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

MeterRegistry stores all meters in a map, where Meter.Id is used as key. But this means that Meter.Id.hashcode() or Meter.Id.equals() will be called and must not change over time. But because
Meter.Id.hashcode() calls Tags.hashcode() which calls DynamicValueTag.hashcode(), your implementation must only take the key into account to show the required stable bahavior. However I'm not completely sure if its an issue to not take the value into account in equality checks. Maybe thats the issue jkschneider was talking about.

Copy link
Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Let's see what @jkschneider or maybe @izeye think about the equals check.

@jonatan-ivanov
Copy link
Member

@SimonScholz Sorry for the big delay. Could you please give use some concrete use-cases with examples? The thing that you are doing in the description seems dangerous since it attaches high-cardinality tags to the meters (Tag.of("dynamicTagKey", () -> "Millis:" + System.currentTimeMillis());).

Also, could you please check if the new withRegistry feature (since 1.12.0) can help? See: #4097

@jonatan-ivanov jonatan-ivanov added the waiting for feedback We need additional information before we can continue label Jan 2, 2024
Copy link

If you would like us to look at this PR, please provide the requested information. If the information is not provided within the next 7 days this PR will be closed.

@SimonScholz
Copy link
Author

SimonScholz commented Jan 12, 2024

@jonatan-ivanov Thanks for asking. Meanwhile I left the company, where we've had the need for this feature, but you can find my description of the need here: #2223 (comment)

Basically we used to visualize metrics exposed by a third party (Resilience4J) in our dashboards and wanted to attach certain dynamic tags (e.g., obtain headers from the originating thread local request) to metrics not owned by us.

This comment was marked as outdated.

@jonatan-ivanov jonatan-ivanov removed the waiting for feedback We need additional information before we can continue label Feb 7, 2024
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Projects
None yet
Development

Successfully merging this pull request may close these issues.

4 participants