Search in sources :

Example 11 with Tag

use of org.apache.gobblin.metrics.Tag in project incubator-gobblin by apache.

the class MRCompactor method initializeMetrics.

private GobblinMetrics initializeMetrics() {
    ImmutableList.Builder<Tag<?>> tags = ImmutableList.builder();
    tags.addAll(this.tags);
    tags.addAll(Tag.fromMap(ClusterNameTags.getClusterNameTags()));
    GobblinMetrics gobblinMetrics = GobblinMetrics.get(this.state.getProp(ConfigurationKeys.JOB_NAME_KEY), null, tags.build());
    gobblinMetrics.startMetricReporting(this.state.getProperties());
    return gobblinMetrics;
}
Also used : ImmutableList(com.google.common.collect.ImmutableList) GobblinMetrics(org.apache.gobblin.metrics.GobblinMetrics) Tag(org.apache.gobblin.metrics.Tag)

Example 12 with Tag

use of org.apache.gobblin.metrics.Tag in project incubator-gobblin by apache.

the class InfluxDBReporterTest 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();
        InfluxDBReporter influxDBReporter = InfluxDBReporter.Factory.newBuilder().withInfluxDBPusher(influxDBPusher).withMetricContextName(CONTEXT_NAME).build(new Properties())) {
        Counter counter = metricContext.counter(MetricRegistry.name(METRIC_PREFIX, COUNTER));
        counter.inc(5l);
        influxDBReporter.report(new TreeMap<String, Gauge>(), metricContext.getCounters(), new TreeMap<String, Histogram>(), new TreeMap<String, Meter>(), new TreeMap<String, Timer>(), metricContext.getTagMap());
        // InfluxDB converts all values to float64 internally
        Assert.assertEquals(getMetricValue("task_testjob_123.fork_1." + METRIC_PREFIX, COUNTER, Measurements.COUNT), Float.toString(5f));
    }
}
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 13 with Tag

use of org.apache.gobblin.metrics.Tag in project incubator-gobblin by apache.

the class Instrumented method getMetricContext.

/**
 * Get a {@link org.apache.gobblin.metrics.MetricContext} to be used by an object needing instrumentation.
 *
 * <p>
 * This method will read the property "metrics.context.name" from the input State, and will attempt
 * to find a MetricContext with that name in the global instance of {@link org.apache.gobblin.metrics.GobblinMetricsRegistry}.
 * If it succeeds, the generated MetricContext will be a child of the retrieved Context, otherwise it will
 * be a parent-less context.
 * </p>
 * <p>
 * The method will automatically add two tags to the context:
 * <ul>
 *  <li> construct will contain the name of the {@link org.apache.gobblin.Constructs} that klazz represents. </li>
 *  <li> class will contain the canonical name of the input class. </li>
 * </ul>
 * </p>
 *
 * @param state {@link org.apache.gobblin.configuration.State} used to find the parent MetricContext.
 * @param klazz Class of the object needing instrumentation.
 * @param tags Additional tags to add to the returned context.
 * @return A {@link org.apache.gobblin.metrics.MetricContext} with the appropriate tags and parent.
 */
public static MetricContext getMetricContext(State state, Class<?> klazz, List<Tag<?>> tags) {
    int randomId = RAND.nextInt(Integer.MAX_VALUE);
    List<Tag<?>> generatedTags = Lists.newArrayList();
    Constructs construct = null;
    if (Converter.class.isAssignableFrom(klazz)) {
        construct = Constructs.CONVERTER;
    } else if (ForkOperator.class.isAssignableFrom(klazz)) {
        construct = Constructs.FORK_OPERATOR;
    } else if (RowLevelPolicy.class.isAssignableFrom(klazz)) {
        construct = Constructs.ROW_QUALITY_CHECKER;
    } else if (Extractor.class.isAssignableFrom(klazz)) {
        construct = Constructs.EXTRACTOR;
    } else if (DataWriter.class.isAssignableFrom(klazz)) {
        construct = Constructs.WRITER;
    }
    if (construct != null) {
        generatedTags.add(new Tag<>(GobblinMetricsKeys.CONSTRUCT_META, construct.toString()));
    }
    if (!klazz.isAnonymousClass()) {
        generatedTags.add(new Tag<>(GobblinMetricsKeys.CLASS_META, klazz.getCanonicalName()));
    }
    Optional<GobblinMetrics> gobblinMetrics = state.contains(METRIC_CONTEXT_NAME_KEY) ? GobblinMetricsRegistry.getInstance().get(state.getProp(METRIC_CONTEXT_NAME_KEY)) : Optional.<GobblinMetrics>absent();
    MetricContext.Builder builder = gobblinMetrics.isPresent() ? gobblinMetrics.get().getMetricContext().childBuilder(klazz.getCanonicalName() + "." + randomId) : MetricContext.builder(klazz.getCanonicalName() + "." + randomId);
    return builder.addTags(generatedTags).addTags(tags).build();
}
Also used : MetricContext(org.apache.gobblin.metrics.MetricContext) ForkOperator(org.apache.gobblin.fork.ForkOperator) GobblinMetrics(org.apache.gobblin.metrics.GobblinMetrics) Tag(org.apache.gobblin.metrics.Tag) Extractor(org.apache.gobblin.source.extractor.Extractor) Constructs(org.apache.gobblin.Constructs)

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