use of com.amazonaws.services.cloudwatch.model.DimensionFilter in project wildfly-camel by wildfly-extras.
the class CloudWatchIntegrationTest method testKeyValueOperations.
@Test
public void testKeyValueOperations() throws Exception {
AmazonCloudWatchClient cwClient = provider.getClient();
Assume.assumeNotNull("AWS client not null", cwClient);
List<Metric> staleMetrics = cwClient.listMetrics(new ListMetricsRequest().withNamespace(NAMESPACE)).getMetrics().stream().filter(metric -> !metric.getMetricName().startsWith(CloudWatchIntegrationTest.class.getSimpleName()) || System.currentTimeMillis() - AWSUtils.toEpochMillis(metric.getMetricName()) > //
AWSUtils.TWO_WEEKS).collect(Collectors.toList());
if (staleMetrics.size() > 0) {
Assert.fail("Found '" + CloudWatchIntegrationTest.class.getName() + "-*' metrics older than two weeks: " + staleMetrics);
}
WildFlyCamelContext camelctx = new WildFlyCamelContext();
camelctx.getNamingContext().bind("cwClient", cwClient);
camelctx.addRoutes(new RouteBuilder() {
@Override
public void configure() throws Exception {
from("direct:metrics").to("aws-cw://" + NAMESPACE + "?amazonCwClient=#cwClient");
}
});
camelctx.start();
try {
Map<String, Object> headers = new HashMap<>();
headers.put(CwConstants.METRIC_NAME, METRIC_NAME);
headers.put(CwConstants.METRIC_DIMENSION_NAME, DIM_NAME);
headers.put(CwConstants.METRIC_DIMENSION_VALUE, DIM_VALUE);
ListMetricsRequest request = new ListMetricsRequest().withNamespace(NAMESPACE).withMetricName(METRIC_NAME).withDimensions(new DimensionFilter().withName(DIM_NAME).withValue(DIM_VALUE));
List<Metric> metrics = Collections.emptyList();
ProducerTemplate producer = camelctx.createProducerTemplate();
for (int i = 100; i < 105 && metrics.size() == 0; i++) {
producer.sendBodyAndHeaders("direct:metrics", new Double(i), headers);
metrics = cwClient.listMetrics(request).getMetrics();
System.out.println("metrics #" + i + ": " + metrics);
Thread.sleep(1000);
}
// It may take several minutes for the metric to show up
// Assert.assertEquals(1, metrics.size());
} finally {
camelctx.stop();
}
}
Aggregations