From 336f2cebeef3825652e8d89cb3de436999b6f1fb Mon Sep 17 00:00:00 2001 From: Marvin Froeder Date: Tue, 27 Oct 2020 20:18:54 +1300 Subject: [PATCH] Track number of exception that happen while decoding payload (#1288) --- .../src/main/java/feign/metrics5/MeteredDecoder.java | 12 ++++++++++++ .../main/java/feign/micrometer/FeignMetricName.java | 8 ++++---- .../main/java/feign/micrometer/MeteredDecoder.java | 11 +++++++++++ 3 files changed, 27 insertions(+), 4 deletions(-) diff --git a/dropwizard-metrics5/src/main/java/feign/metrics5/MeteredDecoder.java b/dropwizard-metrics5/src/main/java/feign/metrics5/MeteredDecoder.java index d82ab381..4bbb8a1e 100644 --- a/dropwizard-metrics5/src/main/java/feign/metrics5/MeteredDecoder.java +++ b/dropwizard-metrics5/src/main/java/feign/metrics5/MeteredDecoder.java @@ -59,6 +59,18 @@ public class MeteredDecoder implements Decoder { metricSuppliers.timers()) .time()) { decoded = decoder.decode(response, type); + } catch (IOException | RuntimeException e) { + metricRegistry.meter( + metricName.metricName(template.methodMetadata(), template.feignTarget(), "error_count") + .tagged("exception_name", e.getClass().getSimpleName()), + metricSuppliers.meters()).mark(); + throw e; + } catch (Exception e) { + metricRegistry.meter( + metricName.metricName(template.methodMetadata(), template.feignTarget(), "error_count") + .tagged("exception_name", e.getClass().getSimpleName()), + metricSuppliers.meters()).mark(); + throw new IOException(e); } if (body != null) { diff --git a/micrometer/src/main/java/feign/micrometer/FeignMetricName.java b/micrometer/src/main/java/feign/micrometer/FeignMetricName.java index 578be8b0..f4692727 100644 --- a/micrometer/src/main/java/feign/micrometer/FeignMetricName.java +++ b/micrometer/src/main/java/feign/micrometer/FeignMetricName.java @@ -23,7 +23,7 @@ import java.util.List; import feign.MethodMetadata; import feign.Target; import io.micrometer.core.instrument.Tag; -import io.micrometer.core.instrument.config.NamingConvention; +import io.micrometer.core.instrument.Tags; public final class FeignMetricName { @@ -43,17 +43,17 @@ public final class FeignMetricName { return meteredComponent.getName(); } - public List tag(MethodMetadata methodMetadata, Target target, Tag... tags) { + public Tags tag(MethodMetadata methodMetadata, Target target, Tag... tags) { return tag(methodMetadata.targetType(), methodMetadata.method(), target.url(), tags); } - public List tag(Class targetType, Method method, String url, Tag... extraTags) { + public Tags tag(Class targetType, Method method, String url, Tag... extraTags) { List tags = new ArrayList<>(); tags.add(Tag.of("client", targetType.getName())); tags.add(Tag.of("method", method.getName())); tags.add(Tag.of("host", extractHost(url))); tags.addAll(Arrays.asList(extraTags)); - return tags; + return Tags.of(tags); } private String extractHost(final String targetUrl) { diff --git a/micrometer/src/main/java/feign/micrometer/MeteredDecoder.java b/micrometer/src/main/java/feign/micrometer/MeteredDecoder.java index de674883..a6f6587d 100644 --- a/micrometer/src/main/java/feign/micrometer/MeteredDecoder.java +++ b/micrometer/src/main/java/feign/micrometer/MeteredDecoder.java @@ -23,6 +23,7 @@ import feign.Response; import feign.codec.DecodeException; import feign.codec.Decoder; import io.micrometer.core.instrument.MeterRegistry; +import io.micrometer.core.instrument.Tag; /** * Warp feign {@link Decoder} with metrics. @@ -56,8 +57,18 @@ public class MeteredDecoder implements Decoder { metricName.tag(template.methodMetadata(), template.feignTarget())) .recordCallable(() -> decoder.decode(meteredResponse, type)); } catch (IOException | RuntimeException e) { + meterRegistry.counter( + metricName.name("error_count"), + metricName.tag(template.methodMetadata(), template.feignTarget()) + .and(Tag.of("exception_name", e.getClass().getSimpleName()))) + .count(); throw e; } catch (Exception e) { + meterRegistry.counter( + metricName.name("error_count"), + metricName.tag(template.methodMetadata(), template.feignTarget()) + .and(Tag.of("exception_name", e.getClass().getSimpleName()))) + .count(); throw new IOException(e); }