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 custom tags to MicrometerCapability #2305

Merged
Merged
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
Original file line number Diff line number Diff line change
@@ -1,5 +1,5 @@
/*
* Copyright 2012-2023 The Feign Authors
* Copyright 2012-2024 The Feign Authors
*
* Licensed under the Apache License, Version 2.0 (the "License"); you may not use this file except
* in compliance with the License. You may obtain a copy of the License at
Expand All @@ -22,9 +22,14 @@
import io.micrometer.core.instrument.Clock;
import io.micrometer.core.instrument.MeterRegistry;
import io.micrometer.core.instrument.Metrics;
import io.micrometer.core.instrument.Tag;
import io.micrometer.core.instrument.simple.SimpleConfig;
import io.micrometer.core.instrument.simple.SimpleMeterRegistry;

import java.util.List;
import java.util.Map;
import java.util.stream.Collectors;

public class MicrometerCapability implements Capability {

private final MeterRegistry meterRegistry;
Expand All @@ -38,6 +43,17 @@ public MicrometerCapability(MeterRegistry meterRegistry) {
this.meterRegistry = meterRegistry;
}

public MicrometerCapability(MeterRegistry meterRegistry, List<Tag> tagsList) {
meterRegistry.config().commonTags(tagsList);
this.meterRegistry = meterRegistry;
}

public MicrometerCapability(MeterRegistry meterRegistry, Map<String, String> tagsMap) {
List<Tag> tagsList = mapTags(tagsMap);
meterRegistry.config().commonTags(tagsList);
Copy link
Member

Choose a reason for hiding this comment

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

Do you think this would be testable under our current tests?

Copy link
Member

Choose a reason for hiding this comment

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

@BartekBanachowicz what about this?

Copy link
Contributor Author

Choose a reason for hiding this comment

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

For now, the answer from my side is no. Not because it isn't doable, but because I don't know how to achieve it yet. I'm still digging through existing test classes

this.meterRegistry = meterRegistry;
}

@Override
public Client enrich(Client client) {
return new MeteredClient(client, meterRegistry);
Expand All @@ -62,4 +78,10 @@ public Decoder enrich(Decoder decoder) {
public InvocationHandlerFactory enrich(InvocationHandlerFactory invocationHandlerFactory) {
return new MeteredInvocationHandleFactory(invocationHandlerFactory, meterRegistry);
}

private List<Tag> mapTags(Map<String, String> tags) {
return tags.keySet().stream()
.map(tagKey -> Tag.of(tagKey, tags.get(tagKey)))
.collect(Collectors.toList());
}
}