Search in sources :

Example 1 with KafkaReporter

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());
}
Also used : Counter(com.codahale.metrics.Counter) MetricContext(org.apache.gobblin.metrics.MetricContext) Tag(org.apache.gobblin.metrics.Tag) MetricReport(org.apache.gobblin.metrics.MetricReport) Properties(java.util.Properties) KafkaReporter(org.apache.gobblin.metrics.kafka.KafkaReporter) Test(org.testng.annotations.Test)

Example 2 with KafkaReporter

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());
}
Also used : Counter(com.codahale.metrics.Counter) MetricContext(org.apache.gobblin.metrics.MetricContext) Tag(org.apache.gobblin.metrics.Tag) MetricReport(org.apache.gobblin.metrics.MetricReport) Properties(java.util.Properties) KafkaReporter(org.apache.gobblin.metrics.kafka.KafkaReporter) Test(org.testng.annotations.Test)

Example 3 with KafkaReporter

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();
}
Also used : Histogram(com.codahale.metrics.Histogram) Meter(com.codahale.metrics.Meter) HashMap(java.util.HashMap) Properties(java.util.Properties) Counter(com.codahale.metrics.Counter) MetricContext(org.apache.gobblin.metrics.MetricContext) MetricReport(org.apache.gobblin.metrics.MetricReport) KafkaReporter(org.apache.gobblin.metrics.kafka.KafkaReporter) HashSet(java.util.HashSet) Test(org.testng.annotations.Test)

Aggregations

Counter (com.codahale.metrics.Counter)3 Properties (java.util.Properties)3 MetricContext (org.apache.gobblin.metrics.MetricContext)3 MetricReport (org.apache.gobblin.metrics.MetricReport)3 KafkaReporter (org.apache.gobblin.metrics.kafka.KafkaReporter)3 Test (org.testng.annotations.Test)3 Tag (org.apache.gobblin.metrics.Tag)2 Histogram (com.codahale.metrics.Histogram)1 Meter (com.codahale.metrics.Meter)1 HashMap (java.util.HashMap)1 HashSet (java.util.HashSet)1