Skip to content

Commit

Permalink
The counter indicator increases by 2 each time (on happy path) (OpenF…
Browse files Browse the repository at this point in the history
…eign#1548)

* The counter indicator increases by 2 each time (on happy path).

* Add test coverage

* Make test beaty again

* Fix license header

* Move new tests to the common abstract class
  • Loading branch information
vitalijr2 committed Dec 13, 2021
1 parent afc1d67 commit 24635e6
Show file tree
Hide file tree
Showing 6 changed files with 62 additions and 1 deletion.
Original file line number Diff line number Diff line change
Expand Up @@ -13,6 +13,7 @@
*/
package feign.metrics4;

import com.codahale.metrics.Metered;
import com.codahale.metrics.Metric;
import com.codahale.metrics.MetricRegistry;
import feign.Capability;
Expand Down Expand Up @@ -99,4 +100,14 @@ protected boolean doesMetricIncludeUri(String metricId, String uri) {
return metricId.contains(uri);
}

@Override
protected boolean doesMetricHasCounter(Metric metric) {
return metric instanceof Metered;
}

@Override
protected long getMetricCounter(Metric metric) {
return ((Metered) metric).getCount();
}

}
Original file line number Diff line number Diff line change
Expand Up @@ -20,6 +20,7 @@
import feign.Capability;
import feign.Util;
import feign.micrometer.AbstractMetricsTestBase;
import io.dropwizard.metrics5.Metered;
import io.dropwizard.metrics5.Metric;
import io.dropwizard.metrics5.MetricName;
import io.dropwizard.metrics5.MetricRegistry;
Expand Down Expand Up @@ -103,4 +104,14 @@ protected boolean doesMetricIncludeUri(MetricName metricId, String uri) {
return uri.equals(metricId.getTags().get("uri"));
}

@Override
protected boolean doesMetricHasCounter(Metric metric) {
return metric instanceof Metered;
}

@Override
protected long getMetricCounter(Metric metric) {
return ((Metered) metric).getCount();
}

}
6 changes: 6 additions & 0 deletions micrometer/pom.xml
Original file line number Diff line number Diff line change
Expand Up @@ -44,6 +44,12 @@
<artifactId>micrometer-core</artifactId>
<version>1.3.5</version>
</dependency>
<dependency>
<groupId>org.mockito</groupId>
<artifactId>mockito-core</artifactId>
<version>${mockito.version}</version>
<scope>test</scope>
</dependency>
<dependency>
<groupId>org.hamcrest</groupId>
<artifactId>hamcrest</artifactId>
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -54,7 +54,6 @@ public Response execute(Request request, Options options) throws IOException {
final Response response = client.execute(request, options);
countResponseCode(request, response, options, response.status(), null);
timer = createTimer(request, response, options, null);
sample.stop(timer);
return response;
} catch (FeignException e) {
timer = createTimer(request, null, options, e);
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -65,6 +65,15 @@ public final void addMetricsCapability() {
metrics.keySet().forEach(metricId -> assertThat(
"Expect all metric names to include host name:" + metricId,
doesMetricIncludeHost(metricId)));

final Map<METRIC_ID, METRIC> clientMetrics = getFeignMetrics().entrySet().stream()
.filter(entry -> isClientMetric(entry.getKey()))
.collect(Collectors.toMap(Map.Entry::getKey, Map.Entry::getValue));

clientMetrics.values().stream()
.filter(this::doesMetricHasCounter)
.forEach(metric -> assertEquals(1, getMetricCounter(metric)));

}

protected abstract boolean doesMetricIncludeHost(METRIC_ID metricId);
Expand Down Expand Up @@ -221,4 +230,8 @@ public void decoderExceptionCounterHasUriLabelWithPathExpression() {

protected abstract boolean doesMetricIncludeUri(METRIC_ID metricId, String uri);

protected abstract boolean doesMetricHasCounter(METRIC metric);

protected abstract long getMetricCounter(METRIC metric);

}
Original file line number Diff line number Diff line change
Expand Up @@ -15,6 +15,7 @@

import feign.Capability;
import feign.Util;
import io.micrometer.core.instrument.Measurement;
import io.micrometer.core.instrument.Meter;
import io.micrometer.core.instrument.Meter.Id;
import io.micrometer.core.instrument.MockClock;
Expand Down Expand Up @@ -113,4 +114,24 @@ protected boolean doesMetricIncludeUri(Id metricId, String uri) {
return uri.equals(metricId.getTag("uri"));
}

@Override
protected boolean doesMetricHasCounter(Meter meter) {
for (Measurement measurement : meter.measure()) {
if ("COUNT".equals(measurement.getStatistic().name())) {
return true;
}
}
return false;
}

@Override
protected long getMetricCounter(Meter meter) {
for (Measurement measurement : meter.measure()) {
if ("COUNT".equals(measurement.getStatistic().name())) {
return (long) measurement.getValue();
}
}
return 0;
}

}

0 comments on commit 24635e6

Please sign in to comment.