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

Don't report empty histograms to FastForward #140

Merged
merged 1 commit into from
Jun 5, 2023
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 @@ -286,14 +286,19 @@ private void reportCounter(MetricId key, Counting value) {
}

private void reportHistogram(MetricId key, Histogram value) {
final Snapshot snapshot = value.getSnapshot();
if (snapshot.size() == 0) {
return;
}

key = MetricId.join(prefix, key);

final Metric m = FastForward
.metric(key.getKey())
.attributes(key.getTags())
.attribute(METRIC_TYPE, "histogram");

reportHistogram(m, value.getSnapshot());
reportHistogram(m, snapshot);
}

private void reportMetered(MetricId key, Meter value) {
Expand All @@ -310,6 +315,11 @@ private void reportMetered(MetricId key, Meter value) {
}

private void reportTimer(MetricId key, Timer value) {
final Snapshot snapshot = value.getSnapshot();
if (snapshot.size() == 0) {
return;
}

key = MetricId.join(prefix, key);

final Metric m = FastForward
Expand All @@ -319,7 +329,7 @@ private void reportTimer(MetricId key, Timer value) {
.attribute("unit", "ns");

reportMetered(m, value);
reportHistogram(m, value.getSnapshot());
reportHistogram(m, snapshot);
}

private void reportDerivingMeter(MetricId key, DerivingMeter value) {
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -245,4 +245,26 @@ public void testKeyValuePrefixAddedOnce() throws Exception {

assertEquals(expectedKeys, actualKeys);
}

@Test
public void shouldNotReportEmptyHistogramsAndTimers() throws Exception {
ArgumentCaptor<Metric> argumentCaptor = ArgumentCaptor.forClass(Metric.class);

doNothing().when(fastForward).send(argumentCaptor.capture());

MetricId name = MetricId.build("thename");

registry.histogram(name.tagged("histogram", "true"));
registry.timer(name.tagged("timer", "true"));

reporter.start();

executorService.tick(REPORTING_PERIOD + REPORTING_PERIOD / 3, TimeUnit.MILLISECONDS);
verify(fastForward, atLeastOnce()).send(any(Metric.class));

Set<String> actualKeys = argumentCaptor.getAllValues().stream().map(Metric::getKey)
.collect(Collectors.toSet());

assertEquals(new HashSet<>(Arrays.asList("test.hi")), actualKeys);
}
}