Search in sources :

Example 11 with MetricContext

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));
    }
}
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 12 with MetricContext

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);
}
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 13 with MetricContext

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());
}
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 14 with MetricContext

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());
}
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 15 with MetricContext

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

Aggregations

MetricContext (org.apache.gobblin.metrics.MetricContext)27 Test (org.testng.annotations.Test)20 Properties (java.util.Properties)8 Counter (com.codahale.metrics.Counter)7 Meter (com.codahale.metrics.Meter)7 Tag (org.apache.gobblin.metrics.Tag)7 Timer (com.codahale.metrics.Timer)6 Histogram (com.codahale.metrics.Histogram)5 Map (java.util.Map)4 GobblinTrackingEvent (org.apache.gobblin.metrics.GobblinTrackingEvent)4 ImmutableMap (com.google.common.collect.ImmutableMap)3 Config (com.typesafe.config.Config)3 MetricReport (org.apache.gobblin.metrics.MetricReport)3 KafkaEventReporter (org.apache.gobblin.metrics.kafka.KafkaEventReporter)3 KafkaReporter (org.apache.gobblin.metrics.kafka.KafkaReporter)3 Gauge (com.codahale.metrics.Gauge)2 RestLiServiceException (com.linkedin.restli.server.RestLiServiceException)2 SimpleScopeType (org.apache.gobblin.broker.SimpleScopeType)2 NotConfiguredException (org.apache.gobblin.broker.iface.NotConfiguredException)2 ContextAwareGauge (org.apache.gobblin.metrics.ContextAwareGauge)2