use of co.cask.cdap.api.metrics.MetricValues in project cdap by caskdata.
the class MetricsMessageCallback method addProcessingStats.
private void addProcessingStats(List<MetricValues> records, long now) {
if (records.isEmpty()) {
return;
}
int count = records.size();
long delay = now - TimeUnit.SECONDS.toMillis(records.get(records.size() - 1).getTimestamp());
records.add(new MetricValues(metricsContext, TimeUnit.MILLISECONDS.toSeconds(now), ImmutableList.of(new MetricValue("metrics.process.count", MetricType.COUNTER, count), new MetricValue("metrics.process.delay.ms", MetricType.GAUGE, delay))));
}
use of co.cask.cdap.api.metrics.MetricValues in project cdap by caskdata.
the class MessagingMetricsCollectionServiceTest method checkReceivedMetrics.
protected void checkReceivedMetrics(Table<String, String, Long> expected, Map<String, MetricValues> actual) {
for (String expectedContext : expected.rowKeySet()) {
MetricValues metricValues = actual.get(expectedContext);
Assert.assertNotNull("Missing expected value for " + expectedContext, metricValues);
for (Map.Entry<String, Long> entry : expected.row(expectedContext).entrySet()) {
boolean found = false;
for (MetricValue metricValue : metricValues.getMetrics()) {
if (entry.getKey().equals(metricValue.getName())) {
Assert.assertEquals(entry.getValue().longValue(), metricValue.getValue());
found = true;
break;
}
}
Assert.assertTrue(found);
}
}
}
use of co.cask.cdap.api.metrics.MetricValues in project cdap by caskdata.
the class MessagingMetricsCollectionServiceTest method testMessagingPublish.
@Test
public void testMessagingPublish() throws UnsupportedTypeException, InterruptedException, TopicNotFoundException, IOException {
MetricsCollectionService collectionService = new MessagingMetricsCollectionService(TOPIC_PREFIX, PARTITION_SIZE, CConfiguration.create(), messagingService, recordWriter);
collectionService.startAndWait();
// publish metrics for different context
for (int i = 1; i <= 3; i++) {
collectionService.getContext(ImmutableMap.of("tag", "" + i)).increment("processed", i);
}
collectionService.stopAndWait();
// <Context, metricName, value>
Table<String, String, Long> expected = HashBasedTable.create();
expected.put("tag.1", "processed", 1L);
expected.put("tag.2", "processed", 2L);
expected.put("tag.3", "processed", 3L);
ReflectionDatumReader<MetricValues> recordReader = new ReflectionDatumReader<>(schema, metricValueType);
assertMetricsFromMessaging(schema, recordReader, expected);
}
Aggregations