Search in sources :

Example 1 with OutputStreamReporter

use of org.apache.gobblin.metrics.reporter.OutputStreamReporter in project incubator-gobblin by apache.

the class OutputStreamReporterTest method testReporter.

@Test
public void testReporter() throws IOException {
    MetricContext metricContext = MetricContext.builder(this.getClass().getCanonicalName()).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");
    OutputStreamReporter reporter = OutputStreamReporter.Factory.newBuilder().outputTo(this.stream).build(new Properties());
    counter.inc();
    meter.mark(2);
    histogram.update(1);
    histogram.update(1);
    histogram.update(2);
    reporter.report();
    String[] lines = this.stream.toString().split("\n");
    Map<String, Set<String>> expected = new HashMap<>();
    Set<String> counterSubMetrics = new HashSet<>();
    counterSubMetrics.add("count");
    expected.put("com.linkedin.example.counter", counterSubMetrics);
    Set<String> histogramSubMetrics = new HashSet<>();
    histogramSubMetrics.add("count");
    histogramSubMetrics.add("min");
    histogramSubMetrics.add("max");
    histogramSubMetrics.add("mean");
    histogramSubMetrics.add("stddev");
    histogramSubMetrics.add("median");
    histogramSubMetrics.add("75% <");
    histogramSubMetrics.add("95% <");
    expected.put("com.linkedin.example.histogram", histogramSubMetrics);
    Set<String> meterSubmetrics = new HashSet<>();
    meterSubmetrics.add("count");
    meterSubmetrics.add("mean rate");
    meterSubmetrics.add("1-minute rate");
    meterSubmetrics.add("5-minute rate");
    meterSubmetrics.add("15-minute rate");
    expected.put("com.linkedin.example.meter", meterSubmetrics);
    expectMetrics(expected, lines);
    reporter.close();
}
Also used : Histogram(com.codahale.metrics.Histogram) Set(java.util.Set) HashSet(java.util.HashSet) Meter(com.codahale.metrics.Meter) HashMap(java.util.HashMap) Properties(java.util.Properties) OutputStreamReporter(org.apache.gobblin.metrics.reporter.OutputStreamReporter) Counter(com.codahale.metrics.Counter) HashSet(java.util.HashSet) Test(org.testng.annotations.Test)

Example 2 with OutputStreamReporter

use of org.apache.gobblin.metrics.reporter.OutputStreamReporter in project incubator-gobblin by apache.

the class OutputStreamReporterTest method testTagsFromContext.

@Test
public void testTagsFromContext() throws IOException {
    Tag<?> tag1 = new Tag<>("tag1", "value1");
    MetricContext context = MetricContext.builder("context").addTag(tag1).build();
    Counter counter = context.counter("com.linkedin.example.counter");
    OutputStreamReporter reporter = OutputStreamReporter.Factory.newBuilder().outputTo(this.stream).build(new Properties());
    counter.inc();
    reporter.report();
    Assert.assertTrue(this.stream.toString().contains("tag1=value1"));
    String[] lines = this.stream.toString().split("\n");
    Map<String, Set<String>> expected = new HashMap<>();
    expectMetrics(expected, lines);
    Set<String> counterSubMetrics = new HashSet<>();
    counterSubMetrics.add("count");
    expected.put("com.linkedin.example.counter", counterSubMetrics);
    reporter.close();
}
Also used : Set(java.util.Set) HashSet(java.util.HashSet) HashMap(java.util.HashMap) Properties(java.util.Properties) OutputStreamReporter(org.apache.gobblin.metrics.reporter.OutputStreamReporter) Counter(com.codahale.metrics.Counter) HashSet(java.util.HashSet) Test(org.testng.annotations.Test)

Example 3 with OutputStreamReporter

use of org.apache.gobblin.metrics.reporter.OutputStreamReporter in project incubator-gobblin by apache.

the class OutputStreamReporterTest method testTags.

@Test
public void testTags() throws IOException {
    MetricContext metricContext = MetricContext.builder(this.getClass().getCanonicalName()).build();
    Counter counter = metricContext.counter("com.linkedin.example.counter");
    Map<String, String> tags = new HashMap<>();
    tags.put("testKey", "testValue");
    tags.put("key2", "value2");
    OutputStreamReporter reporter = OutputStreamReporter.Factory.newBuilder().withTags(tags).outputTo(this.stream).build(new Properties());
    counter.inc();
    reporter.report();
    Assert.assertTrue(this.stream.toString().contains("key2=value2"));
    Assert.assertTrue(this.stream.toString().contains("testKey=testValue"));
    String[] lines = this.stream.toString().split("\n");
    Map<String, Set<String>> expected = new HashMap<>();
    expectMetrics(expected, lines);
    Set<String> counterSubMetrics = new HashSet<>();
    counterSubMetrics.add("count");
    expected.put("com.linkedin.example.counter", counterSubMetrics);
    reporter.close();
}
Also used : Counter(com.codahale.metrics.Counter) Set(java.util.Set) HashSet(java.util.HashSet) HashMap(java.util.HashMap) Properties(java.util.Properties) OutputStreamReporter(org.apache.gobblin.metrics.reporter.OutputStreamReporter) HashSet(java.util.HashSet) Test(org.testng.annotations.Test)

Aggregations

Counter (com.codahale.metrics.Counter)3 HashMap (java.util.HashMap)3 HashSet (java.util.HashSet)3 Properties (java.util.Properties)3 Set (java.util.Set)3 OutputStreamReporter (org.apache.gobblin.metrics.reporter.OutputStreamReporter)3 Test (org.testng.annotations.Test)3 Histogram (com.codahale.metrics.Histogram)1 Meter (com.codahale.metrics.Meter)1