use of org.apache.gobblin.metrics.MetricReport in project incubator-gobblin by apache.
the class KafkaReporterTest method testKafkaReporter.
@Test
public void testKafkaReporter() throws IOException {
MetricContext metricContext = MetricContext.builder(this.getClass().getCanonicalName() + ".testKafkaReporter").build();
Counter counter = metricContext.counter("com.linkedin.example.counter");
Meter meter = metricContext.meter("com.linkedin.example.meter");
Histogram histogram = metricContext.histogram("com.linkedin.example.histogram");
MockKafkaPusher pusher = new MockKafkaPusher();
KafkaReporter kafkaReporter = getBuilder(pusher).build("localhost:0000", "topic", new Properties());
counter.inc();
meter.mark(2);
histogram.update(1);
histogram.update(1);
histogram.update(2);
kafkaReporter.report(metricContext);
try {
Thread.sleep(1000);
} catch (InterruptedException ex) {
Thread.currentThread().interrupt();
}
Map<String, Double> expected = new HashMap<>();
expected.put("com.linkedin.example.counter." + Measurements.COUNT, 1.0);
expected.put("com.linkedin.example.meter." + Measurements.COUNT, 2.0);
expected.put("com.linkedin.example.histogram." + Measurements.COUNT, 3.0);
MetricReport nextReport = nextReport(pusher.messageIterator());
expectMetricsWithValues(nextReport, expected);
kafkaReporter.report(metricContext);
try {
Thread.sleep(1000);
} catch (InterruptedException ex) {
Thread.currentThread().interrupt();
}
Set<String> expectedSet = new HashSet<>();
expectedSet.add("com.linkedin.example.counter." + Measurements.COUNT);
expectedSet.add("com.linkedin.example.meter." + Measurements.COUNT);
expectedSet.add("com.linkedin.example.meter." + Measurements.MEAN_RATE);
expectedSet.add("com.linkedin.example.meter." + Measurements.RATE_1MIN);
expectedSet.add("com.linkedin.example.meter." + Measurements.RATE_5MIN);
expectedSet.add("com.linkedin.example.meter." + Measurements.RATE_15MIN);
expectedSet.add("com.linkedin.example.histogram." + Measurements.MEAN);
expectedSet.add("com.linkedin.example.histogram." + Measurements.MIN);
expectedSet.add("com.linkedin.example.histogram." + Measurements.MAX);
expectedSet.add("com.linkedin.example.histogram." + Measurements.MEDIAN);
expectedSet.add("com.linkedin.example.histogram." + Measurements.PERCENTILE_75TH);
expectedSet.add("com.linkedin.example.histogram." + Measurements.PERCENTILE_95TH);
expectedSet.add("com.linkedin.example.histogram." + Measurements.PERCENTILE_99TH);
expectedSet.add("com.linkedin.example.histogram." + Measurements.PERCENTILE_999TH);
expectedSet.add("com.linkedin.example.histogram." + Measurements.COUNT);
nextReport = nextReport(pusher.messageIterator());
expectMetrics(nextReport, expectedSet, true);
kafkaReporter.close();
}
Aggregations