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

Add support for creating KeyValues from any iterable #3503

Merged
merged 1 commit into from Oct 26, 2022

Conversation

philwebb
Copy link
Contributor

We're finding quite often that we need to adapt Iterable<Tag> to a KeyValues instance and writing code like this:

Iterable<Tag> tags = this.tagsProvider.getTags(context.getUriTemplate(), context.getCarrier(),
		context.getResponse());
KeyValues keyValues = KeyValues.empty();
for (Tag tag : tags) {
	keyValues = keyValues.and(tag.getKey(), tag.getValue());
}
return keyValues;

It seems like this pattern might be quite common (for example you might want to adapt a Map). It would be nice if it could be a oneliner:

return KeyValues.of(tags, Tag::getKey, Tag::getValue);

Add new `of` and `and` methods that allow `KeyValues` to be created
from any iterable.
@philwebb
Copy link
Contributor Author

If #3502 gets fixed before this then the test class I added will need to be rebased on top of it.

@shakuzen shakuzen added enhancement A general enhancement module: micrometer-common An issue that is related to our common module labels Oct 26, 2022
@shakuzen shakuzen added this to the 1.10.0 milestone Oct 26, 2022
@sonatype-lift
Copy link
Contributor

sonatype-lift bot commented Oct 26, 2022

⚠️ 10 God Classes were detected by Lift in this project. Visit the Lift web console for more details.

Copy link
Member

@shakuzen shakuzen left a comment

Choose a reason for hiding this comment

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

Sounds reasonable to me. Thank you for the pull request.

@shakuzen shakuzen merged commit c574021 into micrometer-metrics:main Oct 26, 2022
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
enhancement A general enhancement module: micrometer-common An issue that is related to our common module
Projects
None yet
Development

Successfully merging this pull request may close these issues.

None yet

3 participants