use of org.apache.gobblin.metrics.MetricContext in project incubator-gobblin by apache.
the class GraphiteReporterTest method testWithTags.
@Test
public void testWithTags() throws IOException {
try (MetricContext metricContext = MetricContext.builder(this.getClass().getCanonicalName() + ".testGraphiteReporter").addTag(new Tag<String>("taskId", "task_testjob_123")).addTag(new Tag<String>("forkBranchName", "fork_1")).build();
GraphiteReporter graphiteReporter = GraphiteReporter.Factory.newBuilder().withGraphitePusher(graphitePusher).withMetricContextName(CONTEXT_NAME).build(new Properties())) {
Counter counter = metricContext.counter(MetricRegistry.name(METRIC_PREFIX, COUNTER));
counter.inc(5l);
graphiteReporter.report(new TreeMap<String, Gauge>(), metricContext.getCounters(), new TreeMap<String, Histogram>(), new TreeMap<String, Meter>(), new TreeMap<String, Timer>(), metricContext.getTagMap());
Assert.assertEquals(getMetricValue("task_testjob_123.fork_1." + METRIC_PREFIX, COUNTER, Measurements.COUNT), Long.toString(5l));
}
}
use of org.apache.gobblin.metrics.MetricContext in project incubator-gobblin by apache.
the class KafkaEventReporterTest method testTagInjection.
@Test
public void testTagInjection() throws IOException {
String tag1 = "tag1";
String value1 = "value1";
String metadataValue1 = "metadata1";
String tag2 = "tag2";
String value2 = "value2";
MetricContext context = MetricContext.builder("context").addTag(new Tag<String>(tag1, value1)).addTag(new Tag<String>(tag2, value2)).build();
MockKafkaPusher pusher = new MockKafkaPusher();
KafkaEventReporter kafkaReporter = getBuilder(context, pusher).build("localhost:0000", "topic");
String namespace = "gobblin.metrics.test";
String eventName = "testEvent";
GobblinTrackingEvent event = new GobblinTrackingEvent();
event.setName(eventName);
event.setNamespace(namespace);
Map<String, String> metadata = Maps.newHashMap();
metadata.put(tag1, metadataValue1);
event.setMetadata(metadata);
context.submitEvent(event);
try {
Thread.sleep(100);
} catch (InterruptedException ex) {
Thread.currentThread().interrupt();
}
kafkaReporter.report();
try {
Thread.sleep(100);
} catch (InterruptedException ex) {
Thread.currentThread().interrupt();
}
GobblinTrackingEvent retrievedEvent = nextEvent(pusher.messageIterator());
Assert.assertEquals(retrievedEvent.getNamespace(), namespace);
Assert.assertEquals(retrievedEvent.getName(), eventName);
Assert.assertEquals(retrievedEvent.getMetadata().size(), 4);
Assert.assertEquals(retrievedEvent.getMetadata().get(tag1), metadataValue1);
Assert.assertEquals(retrievedEvent.getMetadata().get(tag2), value2);
}
use of org.apache.gobblin.metrics.MetricContext 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.MetricContext 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.MetricContext in project incubator-gobblin by apache.
the class InfluxDBEventReporterTest method testMultiPartEvent.
@Test
public void testMultiPartEvent() throws IOException {
try (MetricContext metricContext = MetricContext.builder(this.getClass().getCanonicalName() + ".testInfluxDBReporter2").build();
InfluxDBEventReporter influxEventReporter = getBuilder(metricContext).build()) {
Map<String, String> metadata = Maps.newHashMap();
metadata.put(JobEvent.METADATA_JOB_ID, "job2");
metadata.put(TaskEvent.METADATA_TASK_ID, "task2");
metadata.put(EventSubmitter.EVENT_TYPE, "JobStateEvent");
metadata.put(JobEvent.METADATA_JOB_START_TIME, "1457736710521");
metadata.put(JobEvent.METADATA_JOB_END_TIME, "1457736710734");
metadata.put(JobEvent.METADATA_JOB_LAUNCHED_TASKS, "3");
metadata.put(JobEvent.METADATA_JOB_COMPLETED_TASKS, "2");
metadata.put(JobEvent.METADATA_JOB_STATE, "FAILED");
metricContext.submitEvent(GobblinTrackingEvent.newBuilder().setName(MultiPartEvent.JOBSTATE_EVENT.getEventName()).setNamespace(NAMESPACE).setMetadata(metadata).build());
try {
Thread.sleep(100);
} catch (InterruptedException ex) {
Thread.currentThread().interrupt();
}
influxEventReporter.report();
try {
Thread.sleep(100);
} catch (InterruptedException ex) {
Thread.currentThread().interrupt();
}
String prefix = "gobblin.metrics.job2.task2.events.JobStateEvent";
Assert.assertEquals(influxDB.getMetric(prefix + ".jobBeginTime").getValue(), "1457736710521.0");
Assert.assertEquals(influxDB.getMetric(prefix + ".jobEndTime").getValue(), "1457736710734.0");
Assert.assertEquals(influxDB.getMetric(prefix + ".jobLaunchedTasks").getValue(), "3.0");
Assert.assertEquals(influxDB.getMetric(prefix + ".jobCompletedTasks").getValue(), "2.0");
Assert.assertEquals(influxDB.getMetric(prefix + ".jobState").getValue(), "\"FAILED\"");
}
}
Aggregations