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