Skip to content
Open
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 @@ -100,6 +100,17 @@ public Enabler(String namespace, AmazonCloudWatchClient client) {
this.client = client;
}

/**
* Sets the endpoint for the AmazonCloudWatchClient
*
* @param endpoint the region specific endpoint url. Must be non-null and not empty.
* @return this Enabler.
*/
public Enabler withEndpoint(String endpoint) {
this.client.setEndpoint(endpoint);
return this;
}

/**
* <p>The histogram and meter percentiles to send. If <code>.5</code> is included, it'll be reported as
* <code>median</code>.This defaults to <code>.5, .95, and .99</code>.
Expand Down Expand Up @@ -401,7 +412,7 @@ private void sendToCloudWatch() {
}
}

private boolean sentTooSmall, sentTooLarge;
private boolean sentTooSmall, sentTooLarge, sentNaN;

private void sendValue(Date timestamp, String name, double value, StandardUnit unit, List<Dimension> dimensions) {
double absValue = Math.abs(value);
Expand All @@ -427,7 +438,14 @@ private void sendValue(Date timestamp, String name, double value, StandardUnit u
LOG.debug("Value for {} is larger than what CloudWatch supports; trimming to {}. Further large values won't be logged.", name, value);
sentTooLarge = true;
}
} else if (Double.isNaN(value)) {
if (!sentNaN) {
LOG.debug("Value for {} is NaN; setting to 0. Further NaN values won't be logged.", name, value);
sentNaN = true;
}
value = 0;
}

// TODO limit to 10 dimensions
MetricDatum datum = new MetricDatum()
.withTimestamp(timestamp)
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -23,7 +23,8 @@ public class CloudWatchReporterTest {
private MetricsRegistry testRegistry = new MetricsRegistry();
private DummyCloudWatchClient client = new DummyCloudWatchClient();
private CloudWatchReporter.Enabler enabler =
new CloudWatchReporter.Enabler("testnamespace", client).withRegistry(testRegistry);
new CloudWatchReporter.Enabler("testnamespace", client).withRegistry(testRegistry)
.withEndpoint("monitoring.us-west-2.amazonaws.com");

@After
public void shutdownRegistry() {
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -55,7 +55,13 @@ public Double value() {
return CloudWatchReporter.LARGEST_SENDABLE * 10;
}
});
new CloudWatchReporter.Enabler("cxabf", creds)
Metrics.newGauge(new MetricName("test", "limits", "NaN"), new Gauge<Double>() {
@Override
public Double value() {
return Double.NaN;
}
});
new CloudWatchReporter.Enabler("cxabf", creds).withEndpoint("monitoring.us-west-2.amazonaws.com")
.withInstanceIdDimension("test").build().run();

}
Expand Down