Browse Source

Track number of exception that happen while decoding payload (#1288)

pull/1303/head
Marvin Froeder 4 years ago committed by GitHub
parent
commit
336f2cebee
No known key found for this signature in database
GPG Key ID: 4AEE18F83AFDEB23
  1. 12
      dropwizard-metrics5/src/main/java/feign/metrics5/MeteredDecoder.java
  2. 8
      micrometer/src/main/java/feign/micrometer/FeignMetricName.java
  3. 11
      micrometer/src/main/java/feign/micrometer/MeteredDecoder.java

12
dropwizard-metrics5/src/main/java/feign/metrics5/MeteredDecoder.java

@ -59,6 +59,18 @@ public class MeteredDecoder implements Decoder { @@ -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) {

8
micrometer/src/main/java/feign/micrometer/FeignMetricName.java

@ -23,7 +23,7 @@ import java.util.List; @@ -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 { @@ -43,17 +43,17 @@ public final class FeignMetricName {
return meteredComponent.getName();
}
public List<Tag> 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> tag(Class<?> targetType, Method method, String url, Tag... extraTags) {
public Tags tag(Class<?> targetType, Method method, String url, Tag... extraTags) {
List<Tag> 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) {

11
micrometer/src/main/java/feign/micrometer/MeteredDecoder.java

@ -23,6 +23,7 @@ import feign.Response; @@ -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 { @@ -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);
}

Loading…
Cancel
Save