Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Add support for skipping idle counters #93

Merged
merged 1 commit into from
Oct 21, 2018
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
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