use of org.apache.gobblin.metrics.Tag in project incubator-gobblin by apache.
the class ReporterExampleBase method addTask.
private void addTask(int taskIndex, CountDownLatch countDownLatch) {
// Build the context of this task, which is a child of the job's context.
// Tags of the job (parent) context will be inherited automatically.
MetricContext taskContext = this.context.childBuilder("Task" + taskIndex).addTag(new Tag<String>(TASK_ID_KEY, TASK_ID_PREFIX + taskIndex)).build();
Task task = new Task(taskContext, taskIndex, this.totalRecords, countDownLatch);
this.executor.execute(task);
}
use of org.apache.gobblin.metrics.Tag 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.Tag 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.Tag 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.Tag 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());
}
Aggregations