Skip to content

Commit

Permalink
Add support for skipping idle counters (#93)
Browse files Browse the repository at this point in the history
This is the same issue as reported in #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
arteam authored and xiaodong xie committed Oct 21, 2018
1 parent 05e68bd commit 42e7478
Show file tree
Hide file tree
Showing 2 changed files with 23 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,24 @@ 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)
.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 42e7478

Please sign in to comment.