Search in sources :

Example 1 with MetricQueryResults

use of org.apache.beam.sdk.metrics.MetricQueryResults 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 MetricQueryResults

use of org.apache.beam.sdk.metrics.MetricQueryResults 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 MetricQueryResults

use of org.apache.beam.sdk.metrics.MetricQueryResults 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 MetricQueryResults

use of org.apache.beam.sdk.metrics.MetricQueryResults 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 MetricQueryResults

use of org.apache.beam.sdk.metrics.MetricQueryResults 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

MetricQueryResults (org.apache.beam.sdk.metrics.MetricQueryResults)18 Test (org.junit.Test)16 MetricsContainerStepMap.asAttemptedOnlyMetricResults (org.apache.beam.runners.core.metrics.MetricsContainerStepMap.asAttemptedOnlyMetricResults)7 MetricResults (org.apache.beam.sdk.metrics.MetricResults)7 MetricsContainerStepMap.asMetricResults (org.apache.beam.runners.core.metrics.MetricsContainerStepMap.asMetricResults)5 JobMetrics (com.google.api.services.dataflow.model.JobMetrics)4 MetricUpdate (org.apache.beam.runners.core.metrics.MetricUpdates.MetricUpdate)3 PipelineResult (org.apache.beam.sdk.PipelineResult)3 GaugeResult (org.apache.beam.sdk.metrics.GaugeResult)2 MetricName (org.apache.beam.sdk.metrics.MetricName)2 Job (com.google.api.services.dataflow.model.Job)1 MetricUpdate (com.google.api.services.dataflow.model.MetricUpdate)1 BigDecimal (java.math.BigDecimal)1 HashMap (java.util.HashMap)1 StreamingTest (org.apache.beam.runners.spark.StreamingTest)1 DistributionResult (org.apache.beam.sdk.metrics.DistributionResult)1 MetricResult (org.apache.beam.sdk.metrics.MetricResult)1 IntegerSerializer (org.apache.kafka.common.serialization.IntegerSerializer)1 Category (org.junit.experimental.categories.Category)1