-
Notifications
You must be signed in to change notification settings - Fork 1.9k
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
Micrometer metrics tags extension #1322
Merged
velo
merged 13 commits into
OpenFeign:master
from
Kuvaldis:micrometer-support-tags-extension
Jul 20, 2021
Merged
Changes from all commits
Commits
Show all changes
13 commits
Select commit
Hold shift + click to select a range
7dafd58
Micrometer metrics tags extension
4f4d029
Merge branch 'master' into micrometer-support-tags-extension
61a585b
Merge parent
603b155
Fix license
be02d21
Add tags to response code counter metric
cdc3cbb
Fix format
05589ba
Improve tags resolution for exceptions, decrease amount of similar me…
5df8f6a
Make MeteredEncoder timer and counter methods protected
74c93a7
Fix formatting
ff7d86a
Add finally blocks
cb15f9c
Merge branch 'master' into micrometer-support-tags-extension
Kuvaldis 3f5d6a1
Merge branch 'master' into micrometer-support-tags-extension
velo f96229e
Merge branch 'master' into micrometer-support-tags-extension
velo File filter
Filter by extension
Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
There are no files selected for viewing
2 changes: 1 addition & 1 deletion
2
micrometer/src/main/java/feign/micrometer/CountingInputStream.java
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
75 changes: 75 additions & 0 deletions
75
micrometer/src/main/java/feign/micrometer/FeignMetricTagResolver.java
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,75 @@ | ||
/** | ||
* Copyright 2012-2021 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 | ||
* | ||
* http://www.apache.org/licenses/LICENSE-2.0 | ||
* | ||
* Unless required by applicable law or agreed to in writing, software distributed under the License | ||
* is distributed on an "AS IS" BASIS, WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express | ||
* or implied. See the License for the specific language governing permissions and limitations under | ||
* the License. | ||
*/ | ||
package feign.micrometer; | ||
|
||
import feign.MethodMetadata; | ||
import feign.Target; | ||
import io.micrometer.core.instrument.Tag; | ||
import io.micrometer.core.instrument.Tags; | ||
import java.lang.reflect.Method; | ||
import java.net.URI; | ||
import java.net.URISyntaxException; | ||
import java.util.ArrayList; | ||
import java.util.Arrays; | ||
import java.util.Collections; | ||
import java.util.List; | ||
|
||
public class FeignMetricTagResolver implements MetricTagResolver { | ||
|
||
@Override | ||
public Tags tag(MethodMetadata methodMetadata, Target<?> target, Tag... tags) { | ||
return tag(methodMetadata, target, null, tags); | ||
} | ||
|
||
@Override | ||
public Tags tag(MethodMetadata methodMetadata, Target<?> target, Throwable e, Tag... tags) { | ||
return tag(methodMetadata.targetType(), methodMetadata.method(), target.url(), tags); | ||
} | ||
|
||
@Override | ||
public Tags tag(Class<?> targetType, Method method, String url, Tag... extraTags) { | ||
return tag(targetType, method, url, null, extraTags); | ||
} | ||
|
||
@Override | ||
public Tags tag(Class<?> targetType, Method method, String url, Throwable e, Tag... extraTags) { | ||
List<Tag> tags = new ArrayList<>(defaultTags()); | ||
tags.add(Tag.of("client", targetType.getName())); | ||
tags.add(Tag.of("method", method.getName())); | ||
tags.add(Tag.of("host", extractHost(url))); | ||
if (e != null) { | ||
tags.add(Tag.of("exception_name", e.getClass().getSimpleName())); | ||
} | ||
tags.addAll(Arrays.asList(extraTags)); | ||
return Tags.of(tags); | ||
} | ||
|
||
protected List<Tag> defaultTags() { | ||
return Collections.emptyList(); | ||
} | ||
|
||
private String extractHost(final String targetUrl) { | ||
try { | ||
String host = new URI(targetUrl).getHost(); | ||
if (host != null) | ||
return host; | ||
} catch (final URISyntaxException e) { | ||
} | ||
|
||
// can't get the host, in that case, just read first 20 chars from url | ||
return targetUrl.length() <= 20 | ||
? targetUrl | ||
: targetUrl.substring(0, 20); | ||
} | ||
} |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Oops, something went wrong.
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.
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
it would be nice not to change import ordering... but, don't worry too much about it =)