Search in sources :

Example 6 with MetricReport

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();
}
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

MetricReport (org.apache.gobblin.metrics.MetricReport)6 Test (org.testng.annotations.Test)5 Counter (com.codahale.metrics.Counter)4 Properties (java.util.Properties)3 MetricContext (org.apache.gobblin.metrics.MetricContext)3 KafkaReporter (org.apache.gobblin.metrics.kafka.KafkaReporter)3 Histogram (com.codahale.metrics.Histogram)2 Meter (com.codahale.metrics.Meter)2 Metric (org.apache.gobblin.metrics.Metric)2 Tag (org.apache.gobblin.metrics.Tag)2 AvroBinarySerializer (org.apache.gobblin.metrics.reporter.util.AvroBinarySerializer)2 NoopSchemaVersionWriter (org.apache.gobblin.metrics.reporter.util.NoopSchemaVersionWriter)2 Gauge (com.codahale.metrics.Gauge)1 Timer (com.codahale.metrics.Timer)1 HashMap (java.util.HashMap)1 HashSet (java.util.HashSet)1 List (java.util.List)1 Map (java.util.Map)1 SortedMap (java.util.SortedMap)1 Nullable (javax.annotation.Nullable)1