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 option to report raw count values instead of delta values #17

Merged
merged 2 commits into from
Aug 20, 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
1 change: 1 addition & 0 deletions README.md
Original file line number Diff line number Diff line change
Expand Up @@ -130,6 +130,7 @@ The reporter provides a fine-grained configuration options through its builder t
.withJvmMetrics()
.withGlobalDimensions("Region=us-west-2", "Instance=stage")
.withZeroValuesSubmission()
.withReportRawCountValue()
.withDryRun()
.build();

Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -220,9 +220,15 @@ private void processCounter(final String metricName, final Counting counter, fin
lastCount = 0L;
}

// Only submit metrics that have changed - let's save some money!
final long delta = currentCount - lastCount;
stageMetricDatum(true, metricName, delta, StandardUnit.Count, DIMENSION_COUNT, metricData);
final long reportValue;
if (builder.withReportRawCountValue) {
reportValue = currentCount;
} else {
// Only submit metrics that have changed - let's save some money!
reportValue = currentCount - lastCount;
}

stageMetricDatum(true, metricName, reportValue, StandardUnit.Count, DIMENSION_COUNT, metricData);
}

/**
Expand Down Expand Up @@ -464,6 +470,7 @@ public static class Builder {
private boolean withZeroValuesSubmission;
private boolean withStatisticSet;
private boolean withJvmMetrics;
private boolean withReportRawCountValue;
private MetricFilter metricFilter;
private TimeUnit rateUnit;
private TimeUnit durationUnit;
Expand Down Expand Up @@ -669,6 +676,18 @@ public Builder withZeroValuesSubmission() {
return this;
}

/**
* Will report the raw value of count metrics instead of reporting only the count difference since the last
* report
* {@code false} by default.
*
* @return {@code this}
*/
public Builder withReportRawCountValue() {
withReportRawCountValue = true;
return this;
}

/**
* The {@link Histogram} and {@link Timer} percentiles to send. If <code>0.5</code> is included, it'll be
* reported as <code>median</code>.This defaults to <code>0.75, 0.95 and 0.999</code>.
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -447,7 +447,31 @@ public void shouldReportHistogramSubsequentSnapshotValues_SumMaxMinValues() thro
assertThat(secondMetricData.getStatisticValues().getSampleCount().intValue()).isEqualTo(4);
assertThat(secondMetricData.getStatisticValues().getSum().intValue()).isEqualTo(115);
assertThat(secondMetricData.getUnit()).isEqualTo(None.toString());
}

@Test
public void shouldNotReportCounterValueDeltaWhenReportingRawCountValue() throws Exception {
metricRegistry.counter(ARBITRARY_COUNTER_NAME).inc();
metricRegistry.counter(ARBITRARY_COUNTER_NAME).inc();
final CloudWatchReporter cloudWatchReporter = reporterBuilder.withReportRawCountValue().build();

cloudWatchReporter.report();
MetricDatum metricDatum = firstMetricDatumFromCapturedRequest();
assertThat(metricDatum.getValue().intValue()).isEqualTo(2);
metricDataRequestCaptor.getAllValues().clear();

metricRegistry.counter(ARBITRARY_COUNTER_NAME).inc();
metricRegistry.counter(ARBITRARY_COUNTER_NAME).inc();
metricRegistry.counter(ARBITRARY_COUNTER_NAME).inc();
metricRegistry.counter(ARBITRARY_COUNTER_NAME).inc();
metricRegistry.counter(ARBITRARY_COUNTER_NAME).inc();
metricRegistry.counter(ARBITRARY_COUNTER_NAME).inc();

cloudWatchReporter.report();
metricDatum = firstMetricDatumFromCapturedRequest();
assertThat(metricDatum.getValue().intValue()).isEqualTo(8);

verify(mockAmazonCloudWatchAsyncClient, times(2)).putMetricDataAsync(any(PutMetricDataRequest.class));
}

private MetricDatum metricDatumByDimensionFromCapturedRequest(final String dimensionValue) {
Expand Down