Search in sources :

Example 1 with Tag

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);
}
Also used : MetricContext(org.apache.gobblin.metrics.MetricContext) Tag(org.apache.gobblin.metrics.Tag)

Example 2 with Tag

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));
    }
}
Also used : Histogram(com.codahale.metrics.Histogram) Meter(com.codahale.metrics.Meter) Properties(java.util.Properties) ContextAwareGauge(org.apache.gobblin.metrics.ContextAwareGauge) Gauge(com.codahale.metrics.Gauge) Counter(com.codahale.metrics.Counter) Timer(com.codahale.metrics.Timer) MetricContext(org.apache.gobblin.metrics.MetricContext) Tag(org.apache.gobblin.metrics.Tag) Test(org.testng.annotations.Test)

Example 3 with Tag

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);
}
Also used : GobblinTrackingEvent(org.apache.gobblin.metrics.GobblinTrackingEvent) MetricContext(org.apache.gobblin.metrics.MetricContext) KafkaEventReporter(org.apache.gobblin.metrics.kafka.KafkaEventReporter) Tag(org.apache.gobblin.metrics.Tag) Test(org.testng.annotations.Test)

Example 4 with Tag

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());
}
Also used : Counter(com.codahale.metrics.Counter) MetricContext(org.apache.gobblin.metrics.MetricContext) Tag(org.apache.gobblin.metrics.Tag) MetricReport(org.apache.gobblin.metrics.MetricReport) Properties(java.util.Properties) KafkaReporter(org.apache.gobblin.metrics.kafka.KafkaReporter) Test(org.testng.annotations.Test)

Example 5 with Tag

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());
}
Also used : Counter(com.codahale.metrics.Counter) MetricContext(org.apache.gobblin.metrics.MetricContext) Tag(org.apache.gobblin.metrics.Tag) MetricReport(org.apache.gobblin.metrics.MetricReport) Properties(java.util.Properties) KafkaReporter(org.apache.gobblin.metrics.kafka.KafkaReporter) Test(org.testng.annotations.Test)

Aggregations

Tag (org.apache.gobblin.metrics.Tag)13 Properties (java.util.Properties)7 MetricContext (org.apache.gobblin.metrics.MetricContext)7 Test (org.testng.annotations.Test)7 Counter (com.codahale.metrics.Counter)4 GobblinMetrics (org.apache.gobblin.metrics.GobblinMetrics)3 JobState (org.apache.gobblin.runtime.JobState)3 Gauge (com.codahale.metrics.Gauge)2 Histogram (com.codahale.metrics.Histogram)2 Meter (com.codahale.metrics.Meter)2 Timer (com.codahale.metrics.Timer)2 ImmutableList (com.google.common.collect.ImmutableList)2 ConcurrentHashMap (java.util.concurrent.ConcurrentHashMap)2 ContextAwareGauge (org.apache.gobblin.metrics.ContextAwareGauge)2 MetricReport (org.apache.gobblin.metrics.MetricReport)2 KafkaReporter (org.apache.gobblin.metrics.kafka.KafkaReporter)2 File (java.io.File)1 CountDownLatch (java.util.concurrent.CountDownLatch)1 Schema (org.apache.avro.Schema)1 Constructs (org.apache.gobblin.Constructs)1