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()))));
}
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)));
}
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;
}
Aggregations