use of org.apache.gobblin.metrics.kafka.KafkaReporter in project incubator-gobblin by apache.
the class KafkaReporterTest method kafkaReporterTagsTest.
@Test
public void kafkaReporterTagsTest() throws IOException {
MetricContext metricContext = MetricContext.builder(this.getClass().getCanonicalName() + ".kafkaReporterTagsTest").build();
Counter counter = metricContext.counter("com.linkedin.example.counter");
Tag<?> tag1 = new Tag<>("tag1", "value1");
Tag<?> tag2 = new Tag<>("tag2", 2);
MockKafkaPusher pusher = new MockKafkaPusher();
KafkaReporter kafkaReporter = getBuilder(pusher).withTags(Lists.newArrayList(tag1, tag2)).build("localhost:0000", "topic", new Properties());
counter.inc();
kafkaReporter.report(metricContext);
try {
Thread.sleep(1000);
} catch (InterruptedException ex) {
Thread.currentThread().interrupt();
}
MetricReport metricReport = nextReport(pusher.messageIterator());
Assert.assertEquals(4, metricReport.getTags().size());
Assert.assertTrue(metricReport.getTags().containsKey(tag1.getKey()));
Assert.assertEquals(metricReport.getTags().get(tag1.getKey()), tag1.getValue().toString());
Assert.assertTrue(metricReport.getTags().containsKey(tag2.getKey()));
Assert.assertEquals(metricReport.getTags().get(tag2.getKey()), tag2.getValue().toString());
}
use of org.apache.gobblin.metrics.kafka.KafkaReporter in project incubator-gobblin by apache.
the class KafkaReporterTest method kafkaReporterContextTest.
@Test
public void kafkaReporterContextTest() throws IOException {
Tag<?> tag1 = new Tag<>("tag1", "value1");
MetricContext context = MetricContext.builder("context").addTag(tag1).build();
Counter counter = context.counter("com.linkedin.example.counter");
MockKafkaPusher pusher = new MockKafkaPusher();
KafkaReporter kafkaReporter = getBuilderFromContext(pusher).build("localhost:0000", "topic", new Properties());
counter.inc();
kafkaReporter.report(context);
try {
Thread.sleep(1000);
} catch (InterruptedException ex) {
Thread.currentThread().interrupt();
}
MetricReport metricReport = nextReport(pusher.messageIterator());
Assert.assertEquals(3, metricReport.getTags().size());
Assert.assertTrue(metricReport.getTags().containsKey(tag1.getKey()));
Assert.assertEquals(metricReport.getTags().get(tag1.getKey()), tag1.getValue().toString());
}
use of org.apache.gobblin.metrics.kafka.KafkaReporter 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