Skip to content

Commit

Permalink
Add support for skipping idle counters
Browse files Browse the repository at this point in the history
This is the same issue as reported in iZettle#78. For some reason,
idle counters still get reported. It would be nice if we could
not send anything from the client during its idle period.
  • Loading branch information
Artem Prigoda committed Oct 20, 2018
1 parent 05e68bd commit 45210bd
Show file tree
Hide file tree
Showing 2 changed files with 27 additions and 0 deletions.
Original file line number Diff line number Diff line change
Expand Up @@ -395,6 +395,9 @@ private void reportHistogram(String name, Histogram histogram, long now) {
}

private void reportCounter(String name, Counter counter, long now) {
if (canSkipMetric(name, counter)) {
return;
}
Map<String, Object> fields = new HashMap<String, Object>();
fields.put("count", counter.getCount());

Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -26,9 +26,11 @@
import java.util.SortedMap;
import java.util.TreeMap;
import java.util.concurrent.TimeUnit;

import org.junit.Before;
import org.junit.Test;
import org.mockito.ArgumentCaptor;
import org.mockito.ArgumentMatchers;
import org.mockito.Mock;
import org.mockito.Mockito;
import org.mockito.MockitoAnnotations;
Expand Down Expand Up @@ -517,6 +519,28 @@ public void shouldSkipIdleMetrics() throws Exception {
verify(influxDb, times(1)).appendPoints(Mockito.any(InfluxDbPoint.class));
}

@Test
public void shouldSkipIdleCounters() {
when(influxDb.hasSeriesData()).thenReturn(true);

final Counter counter = mock(Counter.class);
when(counter.getCount()).thenReturn(42L);

InfluxDbReporter skippingReporter = InfluxDbReporter
.forRegistry(registry)
.convertRatesTo(TimeUnit.SECONDS)
.convertDurationsTo(TimeUnit.MILLISECONDS)
.filter(MetricFilter.ALL)
.withTags(globalTags)
.skipIdleMetrics(true)
.build(influxDb);

skippingReporter.report(map(), map("question-of-life", counter), map(), map(), map());
skippingReporter.report(map(), map("question-of-life", counter), map(), map(), map());

verify(influxDb, times(1)).appendPoints(ArgumentMatchers.any(InfluxDbPoint.class));
}

@Test
public void shouldCatchExceptions() throws Exception {
doThrow(ConnectException.class).when(influxDb).writeData();
Expand Down

0 comments on commit 45210bd

Please sign in to comment.