Skip to content

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.

3 participants