Search in sources :

Example 1 with MetricResults

use of org.apache.beam.sdk.metrics.MetricResults in project beam by apache.

the class MetricsContainerStepMapTest method testAttemptedAndCommittedAccumulatedMetricResults.

@Test
public void testAttemptedAndCommittedAccumulatedMetricResults() {
    MetricsContainerStepMap attemptedMetrics = new MetricsContainerStepMap();
    attemptedMetrics.update(STEP1, metricsContainer);
    attemptedMetrics.update(STEP1, metricsContainer);
    attemptedMetrics.update(STEP2, metricsContainer);
    attemptedMetrics.update(STEP2, metricsContainer);
    attemptedMetrics.update(STEP2, metricsContainer);
    MetricsContainerStepMap committedMetrics = new MetricsContainerStepMap();
    committedMetrics.update(STEP1, metricsContainer);
    committedMetrics.update(STEP2, metricsContainer);
    committedMetrics.update(STEP2, metricsContainer);
    MetricResults metricResults = asMetricResults(attemptedMetrics, committedMetrics);
    MetricQueryResults step1res = metricResults.queryMetrics(MetricsFilter.builder().addStep(STEP1).build());
    assertIterableSize(step1res.counters(), 1);
    assertIterableSize(step1res.distributions(), 1);
    assertIterableSize(step1res.gauges(), 1);
    assertCounter(COUNTER_NAME, step1res, STEP1, VALUE * 2, false);
    assertDistribution(DISTRIBUTION_NAME, step1res, STEP1, DistributionResult.create(VALUE * 6, 4, VALUE, VALUE * 2), false);
    assertGauge(GAUGE_NAME, step1res, STEP1, GaugeResult.create(VALUE, Instant.now()), false);
    assertCounter(COUNTER_NAME, step1res, STEP1, VALUE, true);
    assertDistribution(DISTRIBUTION_NAME, step1res, STEP1, DistributionResult.create(VALUE * 3, 2, VALUE, VALUE * 2), true);
    assertGauge(GAUGE_NAME, step1res, STEP1, GaugeResult.create(VALUE, Instant.now()), true);
    MetricQueryResults step2res = metricResults.queryMetrics(MetricsFilter.builder().addStep(STEP2).build());
    assertIterableSize(step2res.counters(), 1);
    assertIterableSize(step2res.distributions(), 1);
    assertIterableSize(step2res.gauges(), 1);
    assertCounter(COUNTER_NAME, step2res, STEP2, VALUE * 3, false);
    assertDistribution(DISTRIBUTION_NAME, step2res, STEP2, DistributionResult.create(VALUE * 9, 6, VALUE, VALUE * 2), false);
    assertGauge(GAUGE_NAME, step2res, STEP2, GaugeResult.create(VALUE, Instant.now()), false);
    assertCounter(COUNTER_NAME, step2res, STEP2, VALUE * 2, true);
    assertDistribution(DISTRIBUTION_NAME, step2res, STEP2, DistributionResult.create(VALUE * 6, 4, VALUE, VALUE * 2), true);
    assertGauge(GAUGE_NAME, step2res, STEP2, GaugeResult.create(VALUE, Instant.now()), true);
    MetricQueryResults allres = metricResults.queryMetrics(MetricsFilter.builder().build());
    assertIterableSize(allres.counters(), 2);
    assertIterableSize(allres.distributions(), 2);
    assertIterableSize(allres.gauges(), 2);
}
Also used : MetricsContainerStepMap.asMetricResults(org.apache.beam.runners.core.metrics.MetricsContainerStepMap.asMetricResults) MetricsContainerStepMap.asAttemptedOnlyMetricResults(org.apache.beam.runners.core.metrics.MetricsContainerStepMap.asAttemptedOnlyMetricResults) MetricResults(org.apache.beam.sdk.metrics.MetricResults) MetricQueryResults(org.apache.beam.sdk.metrics.MetricQueryResults) Test(org.junit.Test)

Example 2 with MetricResults

use of org.apache.beam.sdk.metrics.MetricResults in project beam by apache.

the class MetricsContainerStepMapTest method testAttemptedAccumulatedMetricResults.

@Test
public void testAttemptedAccumulatedMetricResults() {
    MetricsContainerStepMap attemptedMetrics = new MetricsContainerStepMap();
    attemptedMetrics.update(STEP1, metricsContainer);
    attemptedMetrics.update(STEP2, metricsContainer);
    attemptedMetrics.update(STEP2, metricsContainer);
    MetricResults metricResults = asAttemptedOnlyMetricResults(attemptedMetrics);
    MetricQueryResults step1res = metricResults.queryMetrics(MetricsFilter.builder().addStep(STEP1).build());
    assertIterableSize(step1res.counters(), 1);
    assertIterableSize(step1res.distributions(), 1);
    assertIterableSize(step1res.gauges(), 1);
    assertCounter(COUNTER_NAME, step1res, STEP1, VALUE, false);
    assertDistribution(DISTRIBUTION_NAME, step1res, STEP1, DistributionResult.create(VALUE * 3, 2, VALUE, VALUE * 2), false);
    assertGauge(GAUGE_NAME, step1res, STEP1, GaugeResult.create(VALUE, Instant.now()), false);
    MetricQueryResults step2res = metricResults.queryMetrics(MetricsFilter.builder().addStep(STEP2).build());
    assertIterableSize(step2res.counters(), 1);
    assertIterableSize(step2res.distributions(), 1);
    assertIterableSize(step2res.gauges(), 1);
    assertCounter(COUNTER_NAME, step2res, STEP2, VALUE * 2, false);
    assertDistribution(DISTRIBUTION_NAME, step2res, STEP2, DistributionResult.create(VALUE * 6, 4, VALUE, VALUE * 2), false);
    assertGauge(GAUGE_NAME, step2res, STEP2, GaugeResult.create(VALUE, Instant.now()), false);
    MetricQueryResults allres = metricResults.queryMetrics(MetricsFilter.builder().build());
    assertIterableSize(allres.counters(), 2);
    assertIterableSize(allres.distributions(), 2);
    assertIterableSize(allres.gauges(), 2);
}
Also used : MetricsContainerStepMap.asMetricResults(org.apache.beam.runners.core.metrics.MetricsContainerStepMap.asMetricResults) MetricsContainerStepMap.asAttemptedOnlyMetricResults(org.apache.beam.runners.core.metrics.MetricsContainerStepMap.asAttemptedOnlyMetricResults) MetricResults(org.apache.beam.sdk.metrics.MetricResults) MetricQueryResults(org.apache.beam.sdk.metrics.MetricQueryResults) Test(org.junit.Test)

Example 3 with MetricResults

use of org.apache.beam.sdk.metrics.MetricResults in project beam by apache.

the class MetricsContainerStepMapTest method testGaugeCommittedUnsupportedInAttemptedAccumulatedMetricResults.

@Test
public void testGaugeCommittedUnsupportedInAttemptedAccumulatedMetricResults() {
    MetricsContainerStepMap attemptedMetrics = new MetricsContainerStepMap();
    attemptedMetrics.update(STEP1, metricsContainer);
    MetricResults metricResults = asAttemptedOnlyMetricResults(attemptedMetrics);
    MetricQueryResults step1res = metricResults.queryMetrics(MetricsFilter.builder().addStep(STEP1).build());
    thrown.expect(UnsupportedOperationException.class);
    thrown.expectMessage("This runner does not currently support committed metrics results.");
    assertGauge(GAUGE_NAME, step1res, STEP1, GaugeResult.empty(), true);
}
Also used : MetricsContainerStepMap.asMetricResults(org.apache.beam.runners.core.metrics.MetricsContainerStepMap.asMetricResults) MetricsContainerStepMap.asAttemptedOnlyMetricResults(org.apache.beam.runners.core.metrics.MetricsContainerStepMap.asAttemptedOnlyMetricResults) MetricResults(org.apache.beam.sdk.metrics.MetricResults) MetricQueryResults(org.apache.beam.sdk.metrics.MetricQueryResults) Test(org.junit.Test)

Example 4 with MetricResults

use of org.apache.beam.sdk.metrics.MetricResults in project beam by apache.

the class MetricsContainerStepMapTest method testCounterCommittedUnsupportedInAttemptedAccumulatedMetricResults.

@Test
public void testCounterCommittedUnsupportedInAttemptedAccumulatedMetricResults() {
    MetricsContainerStepMap attemptedMetrics = new MetricsContainerStepMap();
    attemptedMetrics.update(STEP1, metricsContainer);
    MetricResults metricResults = asAttemptedOnlyMetricResults(attemptedMetrics);
    MetricQueryResults step1res = metricResults.queryMetrics(MetricsFilter.builder().addStep(STEP1).build());
    thrown.expect(UnsupportedOperationException.class);
    thrown.expectMessage("This runner does not currently support committed metrics results.");
    assertCounter(COUNTER_NAME, step1res, STEP1, VALUE, true);
}
Also used : MetricsContainerStepMap.asMetricResults(org.apache.beam.runners.core.metrics.MetricsContainerStepMap.asMetricResults) MetricsContainerStepMap.asAttemptedOnlyMetricResults(org.apache.beam.runners.core.metrics.MetricsContainerStepMap.asAttemptedOnlyMetricResults) MetricResults(org.apache.beam.sdk.metrics.MetricResults) MetricQueryResults(org.apache.beam.sdk.metrics.MetricQueryResults) Test(org.junit.Test)

Example 5 with MetricResults

use of org.apache.beam.sdk.metrics.MetricResults in project beam by apache.

the class FlinkMetricContainer method updateMetrics.

void updateMetrics() {
    MetricResults metricResults = asAttemptedOnlyMetricResults(metricsAccumulator.getLocalValue());
    MetricQueryResults metricQueryResults = metricResults.queryMetrics(MetricsFilter.builder().build());
    updateCounters(metricQueryResults.counters());
    updateDistributions(metricQueryResults.distributions());
    updateGauge(metricQueryResults.gauges());
}
Also used : MetricsContainerStepMap.asAttemptedOnlyMetricResults(org.apache.beam.runners.core.metrics.MetricsContainerStepMap.asAttemptedOnlyMetricResults) MetricResults(org.apache.beam.sdk.metrics.MetricResults) MetricQueryResults(org.apache.beam.sdk.metrics.MetricQueryResults)

Aggregations

MetricsContainerStepMap.asAttemptedOnlyMetricResults (org.apache.beam.runners.core.metrics.MetricsContainerStepMap.asAttemptedOnlyMetricResults)7 MetricQueryResults (org.apache.beam.sdk.metrics.MetricQueryResults)7 MetricResults (org.apache.beam.sdk.metrics.MetricResults)7 MetricsContainerStepMap.asMetricResults (org.apache.beam.runners.core.metrics.MetricsContainerStepMap.asMetricResults)5 Test (org.junit.Test)5 HashMap (java.util.HashMap)1 DistributionResult (org.apache.beam.sdk.metrics.DistributionResult)1 GaugeResult (org.apache.beam.sdk.metrics.GaugeResult)1