Exemplo n.º 1
0
    @Override
    protected void reportInContext(
        MetricContext context,
        SortedMap<String, Gauge> gauges,
        SortedMap<String, Counter> counters,
        SortedMap<String, Histogram> histograms,
        SortedMap<String, Meter> meters,
        SortedMap<String, Timer> timers) {

      Assert.assertEquals(context.getName(), CONTEXT_NAME);

      Assert.assertEquals(gauges.size(), 1);
      Assert.assertTrue(gauges.containsKey(QUEUE_SIZE));

      Assert.assertEquals(counters.size(), 1);
      Assert.assertTrue(counters.containsKey(RECORDS_PROCESSED));

      Assert.assertEquals(histograms.size(), 1);
      Assert.assertTrue(histograms.containsKey(RECORD_SIZE_DISTRIBUTION));

      Assert.assertEquals(meters.size(), 1);
      Assert.assertTrue(meters.containsKey(RECORD_PROCESS_RATE));

      Assert.assertEquals(timers.size(), 2);
      Assert.assertTrue(timers.containsKey(TOTAL_DURATION));
    }
Exemplo n.º 2
0
  @BeforeClass
  public void setUp() {
    this.context =
        MetricContext.builder(CONTEXT_NAME)
            .addTag(new Tag<String>(JOB_ID_KEY, JOB_ID_PREFIX + 0))
            .addContextAwareScheduledReporter(
                new TestContextAwareScheduledReporter.TestContextAwareScheduledReporterBuilder(
                    TEST_REPORTER_NAME))
            .reportFullyQualifiedNames(false)
            .build();

    Assert.assertEquals(this.context.getName(), CONTEXT_NAME);
    Assert.assertFalse(this.context.getParent().isPresent());
    Assert.assertEquals(this.context.getTags().size(), 2); // uuid tag gets added automatically
    Assert.assertEquals(this.context.getTags().get(0).getKey(), JOB_ID_KEY);
    Assert.assertEquals(this.context.getTags().get(0).getValue(), JOB_ID_PREFIX + 0);
    // Second tag should be uuid
    Assert.assertTrue(
        this.context
            .getTags()
            .get(1)
            .getValue()
            .toString()
            .matches("[0-9a-f]{8}-[0-9a-f]{4}-[1-5][0-9a-f]{3}-[89ab][0-9a-f]{3}-[0-9a-f]{12}"));
    Assert.assertEquals(
        this.context.metricNamePrefix(false),
        this.context.getTags().get(0).getValue() + "." + this.context.getTags().get(1).getValue());
  }
Exemplo n.º 3
0
  @BeforeClass
  public void setUp() {
    String contextName = CONTEXT_NAME + "_" + UUID.randomUUID().toString();
    this.context =
        MetricContext.builder(contextName)
            .addTag(new Tag<String>(JOB_ID_KEY, JOB_ID_PREFIX + 0))
            .build();

    Assert.assertEquals(this.context.getName(), contextName);
    Assert.assertTrue(this.context.getParent().isPresent());
    Assert.assertEquals(this.context.getParent().get(), RootMetricContext.get());
    Assert.assertEquals(
        this.context.getTags().size(), 3); // uuid and name tag gets added automatically
    Assert.assertEquals(this.context.getTags().get(0).getKey(), JOB_ID_KEY);
    Assert.assertEquals(this.context.getTags().get(0).getValue(), JOB_ID_PREFIX + 0);
    // Second tag should be uuid
    Assert.assertTrue(
        this.context
            .getTags()
            .get(1)
            .getValue()
            .toString()
            .matches("[0-9a-f]{8}-[0-9a-f]{4}-[1-5][0-9a-f]{3}-[89ab][0-9a-f]{3}-[0-9a-f]{12}"));
  }
  /**
   * Creates {@link gobblin.metrics.MetricContext}. Tries to read the name of the parent context
   * from key "metrics.context.name" at state, and tries to get the parent context by name from the
   * {@link gobblin.metrics.MetricContext} registry (the parent context must be registered).
   *
   * <p>Automatically adds two tags to the inner context:
   *
   * <ul>
   *   <li>component: attempts to determine which component type within gobblin-api generated this
   *       instance.
   *   <li>class: the specific class of the object that generated this instance of Instrumented
   * </ul>
   */
  public MetricContext getMetricContext(State state, Class<?> klazz, List<Tag<?>> tags) {
    int randomId = new Random().nextInt(Integer.MAX_VALUE);

    List<Tag<?>> generatedTags = Lists.newArrayList();

    if (!klazz.isAnonymousClass()) {
      generatedTags.add(new Tag<>("class", klazz.getCanonicalName()));
    }

    Optional<GobblinMetrics> gobblinMetrics =
        state.contains(ConfigurationKeys.METRIC_CONTEXT_NAME_KEY)
            ? GobblinMetricsRegistry.getInstance()
                .get(state.getProp(ConfigurationKeys.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();
  }