Search in sources :

Example 1 with GobblinMetrics

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

the class YarnService method buildGobblinMetrics.

private GobblinMetrics buildGobblinMetrics() {
    // Create tags list
    ImmutableList.Builder<Tag<?>> tags = new ImmutableList.Builder<>();
    tags.add(new Tag<>(GobblinClusterMetricTagNames.APPLICATION_ID, this.applicationId));
    tags.add(new Tag<>(GobblinClusterMetricTagNames.APPLICATION_NAME, this.applicationName));
    // Intialize Gobblin metrics and start reporters
    GobblinMetrics gobblinMetrics = GobblinMetrics.get(this.applicationId, null, tags.build());
    gobblinMetrics.startMetricReporting(ConfigUtils.configToProperties(config));
    return gobblinMetrics;
}
Also used : ImmutableList(com.google.common.collect.ImmutableList) GobblinMetrics(org.apache.gobblin.metrics.GobblinMetrics) Tag(org.apache.gobblin.metrics.Tag)

Example 2 with GobblinMetrics

use of org.apache.gobblin.metrics.GobblinMetrics 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 3 with GobblinMetrics

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

the class InstrumentedTest method testInstrumented.

@Test
public void testInstrumented() {
    GobblinMetrics gobblinMetrics = GobblinMetrics.get("parent.context");
    State state = new State();
    state.setProp(ConfigurationKeys.METRICS_ENABLED_KEY, Boolean.toString(true));
    state.setProp(Instrumented.METRIC_CONTEXT_NAME_KEY, gobblinMetrics.getName());
    Instrumented instrumented = new Instrumented(state, InstrumentedExtractor.class);
    Assert.assertNotNull(instrumented.getMetricContext());
    Assert.assertTrue(instrumented.getMetricContext().getParent().isPresent());
    Assert.assertEquals(instrumented.getMetricContext().getParent().get(), gobblinMetrics.getMetricContext());
    Map<String, ?> tags = instrumented.getMetricContext().getTagMap();
    Map<String, String> expectedTags = new HashMap<>();
    expectedTags.put("construct", Constructs.EXTRACTOR.toString());
    expectedTags.put("class", InstrumentedExtractor.class.getCanonicalName());
    expectedTags.put(MetricContext.METRIC_CONTEXT_ID_TAG_NAME, tags.get(MetricContext.METRIC_CONTEXT_ID_TAG_NAME).toString());
    expectedTags.put(MetricContext.METRIC_CONTEXT_NAME_TAG_NAME, tags.get(MetricContext.METRIC_CONTEXT_NAME_TAG_NAME).toString());
    Assert.assertEquals(tags.size(), expectedTags.size());
    for (Map.Entry<String, ?> tag : tags.entrySet()) {
        Assert.assertTrue(expectedTags.containsKey(tag.getKey()));
        Assert.assertEquals(expectedTags.get(tag.getKey()), tag.getValue().toString());
    }
}
Also used : InstrumentedExtractor(org.apache.gobblin.instrumented.extractor.InstrumentedExtractor) HashMap(java.util.HashMap) State(org.apache.gobblin.configuration.State) GobblinMetrics(org.apache.gobblin.metrics.GobblinMetrics) Map(java.util.Map) HashMap(java.util.HashMap) Test(org.testng.annotations.Test)

Example 4 with GobblinMetrics

use of org.apache.gobblin.metrics.GobblinMetrics 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

GobblinMetrics (org.apache.gobblin.metrics.GobblinMetrics)4 Tag (org.apache.gobblin.metrics.Tag)3 ImmutableList (com.google.common.collect.ImmutableList)2 HashMap (java.util.HashMap)1 Map (java.util.Map)1 Constructs (org.apache.gobblin.Constructs)1 State (org.apache.gobblin.configuration.State)1 ForkOperator (org.apache.gobblin.fork.ForkOperator)1 InstrumentedExtractor (org.apache.gobblin.instrumented.extractor.InstrumentedExtractor)1 MetricContext (org.apache.gobblin.metrics.MetricContext)1 Extractor (org.apache.gobblin.source.extractor.Extractor)1 Test (org.testng.annotations.Test)1