Search in sources :

Example 16 with MetricQueryResults

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

the class DirectMetricsTest method testApplyCommittedNoFilter.

@SuppressWarnings("unchecked")
@Test
public void testApplyCommittedNoFilter() {
    metrics.commitLogical(bundle1, MetricUpdates.create(ImmutableList.of(MetricUpdate.create(MetricKey.create("step1", NAME1), 5L), MetricUpdate.create(MetricKey.create("step1", NAME2), 8L)), ImmutableList.of(MetricUpdate.create(MetricKey.create("step1", NAME1), DistributionData.create(8, 2, 3, 5))), ImmutableList.of(MetricUpdate.create(MetricKey.create("step1", NAME4), GaugeData.create(15L)))));
    metrics.commitLogical(bundle1, MetricUpdates.create(ImmutableList.of(MetricUpdate.create(MetricKey.create("step2", NAME1), 7L), MetricUpdate.create(MetricKey.create("step1", NAME2), 4L)), ImmutableList.of(MetricUpdate.create(MetricKey.create("step1", NAME1), DistributionData.create(4, 1, 4, 4))), ImmutableList.of(MetricUpdate.create(MetricKey.create("step1", NAME4), GaugeData.create(27L)))));
    MetricQueryResults results = metrics.queryMetrics(MetricsFilter.builder().build());
    assertThat(results.counters(), containsInAnyOrder(attemptedMetricsResult("ns1", "name1", "step1", 0L), attemptedMetricsResult("ns1", "name2", "step1", 0L), attemptedMetricsResult("ns1", "name1", "step2", 0L)));
    assertThat(results.counters(), containsInAnyOrder(committedMetricsResult("ns1", "name1", "step1", 5L), committedMetricsResult("ns1", "name2", "step1", 12L), committedMetricsResult("ns1", "name1", "step2", 7L)));
    assertThat(results.distributions(), contains(attemptedMetricsResult("ns1", "name1", "step1", DistributionResult.ZERO)));
    assertThat(results.distributions(), contains(committedMetricsResult("ns1", "name1", "step1", DistributionResult.create(12, 3, 3, 5))));
    assertThat(results.gauges(), contains(attemptedMetricsResult("ns2", "name2", "step1", GaugeResult.empty())));
    assertThat(results.gauges(), contains(committedMetricsResult("ns2", "name2", "step1", GaugeResult.create(27L, Instant.now()))));
}
Also used : MetricQueryResults(org.apache.beam.sdk.metrics.MetricQueryResults) Test(org.junit.Test)

Example 17 with MetricQueryResults

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

the class DirectMetricsTest method testApplyAttemptedQueryCompositeScope.

@SuppressWarnings("unchecked")
@Test
public void testApplyAttemptedQueryCompositeScope() {
    metrics.updatePhysical(bundle1, MetricUpdates.create(ImmutableList.of(MetricUpdate.create(MetricKey.create("Outer1/Inner1", NAME1), 5L), MetricUpdate.create(MetricKey.create("Outer1/Inner2", NAME1), 8L)), ImmutableList.<MetricUpdate<DistributionData>>of(), ImmutableList.<MetricUpdate<GaugeData>>of()));
    metrics.updatePhysical(bundle1, MetricUpdates.create(ImmutableList.of(MetricUpdate.create(MetricKey.create("Outer1/Inner1", NAME1), 12L), MetricUpdate.create(MetricKey.create("Outer2/Inner2", NAME1), 18L)), ImmutableList.<MetricUpdate<DistributionData>>of(), ImmutableList.<MetricUpdate<GaugeData>>of()));
    MetricQueryResults results = metrics.queryMetrics(MetricsFilter.builder().addStep("Outer1").build());
    assertThat(results.counters(), containsInAnyOrder(attemptedMetricsResult("ns1", "name1", "Outer1/Inner1", 12L), attemptedMetricsResult("ns1", "name1", "Outer1/Inner2", 8L)));
    assertThat(results.counters(), containsInAnyOrder(committedMetricsResult("ns1", "name1", "Outer1/Inner1", 0L), committedMetricsResult("ns1", "name1", "Outer1/Inner2", 0L)));
}
Also used : MetricQueryResults(org.apache.beam.sdk.metrics.MetricQueryResults) MetricUpdate(org.apache.beam.runners.core.metrics.MetricUpdates.MetricUpdate) Test(org.junit.Test)

Example 18 with MetricQueryResults

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

the class SparkBeamMetric method renderAll.

Map<String, ?> renderAll() {
    Map<String, Object> metrics = new HashMap<>();
    MetricResults metricResults = asAttemptedOnlyMetricResults(MetricsAccumulator.getInstance().value());
    MetricQueryResults metricQueryResults = metricResults.queryMetrics(MetricsFilter.builder().build());
    for (MetricResult<Long> metricResult : metricQueryResults.counters()) {
        metrics.put(renderName(metricResult), metricResult.attempted());
    }
    for (MetricResult<DistributionResult> metricResult : metricQueryResults.distributions()) {
        DistributionResult result = metricResult.attempted();
        metrics.put(renderName(metricResult) + ".count", result.count());
        metrics.put(renderName(metricResult) + ".sum", result.sum());
        metrics.put(renderName(metricResult) + ".min", result.min());
        metrics.put(renderName(metricResult) + ".max", result.max());
        metrics.put(renderName(metricResult) + ".mean", result.mean());
    }
    for (MetricResult<GaugeResult> metricResult : metricQueryResults.gauges()) {
        metrics.put(renderName(metricResult), metricResult.attempted().value());
    }
    return metrics;
}
Also used : DistributionResult(org.apache.beam.sdk.metrics.DistributionResult) HashMap(java.util.HashMap) MetricsContainerStepMap.asAttemptedOnlyMetricResults(org.apache.beam.runners.core.metrics.MetricsContainerStepMap.asAttemptedOnlyMetricResults) MetricResults(org.apache.beam.sdk.metrics.MetricResults) MetricQueryResults(org.apache.beam.sdk.metrics.MetricQueryResults) GaugeResult(org.apache.beam.sdk.metrics.GaugeResult)

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