use of org.apache.beam.sdk.metrics.Distribution in project beam by apache.
the class StreamingStepMetricsContainerTest method testDistributionUpdateExtraction.
@Test
public void testDistributionUpdateExtraction() {
Distribution distribution = c1.getDistribution(name1);
distribution.update(5);
distribution.update(6);
distribution.update(7);
Iterable<CounterUpdate> updates = StreamingStepMetricsContainer.extractMetricUpdates(registry);
assertThat(updates, containsInAnyOrder(new CounterUpdate().setStructuredNameAndMetadata(new CounterStructuredNameAndMetadata().setName(new CounterStructuredName().setOrigin(Origin.USER.toString()).setOriginNamespace("ns").setName("name1").setOriginalStepName("s1")).setMetadata(new CounterMetadata().setKind(Kind.DISTRIBUTION.toString()))).setCumulative(false).setDistribution(new DistributionUpdate().setCount(longToSplitInt(3)).setMax(longToSplitInt(7)).setMin(longToSplitInt(5)).setSum(longToSplitInt(18)))));
c1.getDistribution(name1).update(3);
updates = StreamingStepMetricsContainer.extractMetricUpdates(registry);
assertThat(updates, containsInAnyOrder(new CounterUpdate().setStructuredNameAndMetadata(new CounterStructuredNameAndMetadata().setName(new CounterStructuredName().setOrigin(Origin.USER.toString()).setOriginNamespace("ns").setName("name1").setOriginalStepName("s1")).setMetadata(new CounterMetadata().setKind(Kind.DISTRIBUTION.toString()))).setCumulative(false).setDistribution(new DistributionUpdate().setCount(longToSplitInt(1)).setMax(longToSplitInt(3)).setMin(longToSplitInt(3)).setSum(longToSplitInt(3)))));
}
use of org.apache.beam.sdk.metrics.Distribution in project beam by apache.
the class FlinkMetricContainerTest method testDistribution.
@Test
public void testDistribution() {
FlinkMetricContainer.FlinkDistributionGauge flinkGauge = new FlinkMetricContainer.FlinkDistributionGauge(DistributionResult.IDENTITY_ELEMENT);
when(metricGroup.gauge(eq("namespace.name"), anyObject())).thenReturn(flinkGauge);
MetricsContainer step = container.getMetricsContainer("step");
MetricName metricName = MetricName.named("namespace", "name");
Distribution distribution = step.getDistribution(metricName);
assertThat(flinkGauge.getValue(), is(DistributionResult.IDENTITY_ELEMENT));
// first set will install the mocked distribution
container.updateMetrics("step");
distribution.update(42);
distribution.update(-23);
distribution.update(0);
distribution.update(1);
container.updateMetrics("step");
assertThat(flinkGauge.getValue().getMax(), is(42L));
assertThat(flinkGauge.getValue().getMin(), is(-23L));
assertThat(flinkGauge.getValue().getCount(), is(4L));
assertThat(flinkGauge.getValue().getSum(), is(20L));
assertThat(flinkGauge.getValue().getMean(), is(5.0));
}
use of org.apache.beam.sdk.metrics.Distribution in project beam by apache.
the class MetricsContainerImpl method updateForDistributionInt64Type.
private void updateForDistributionInt64Type(MonitoringInfo monitoringInfo) {
MetricName metricName = MonitoringInfoMetricName.of(monitoringInfo);
Distribution distribution = getDistribution(metricName);
DistributionData data = decodeInt64Distribution(monitoringInfo.getPayload());
distribution.update(data.sum(), data.count(), data.min(), data.max());
}
use of org.apache.beam.sdk.metrics.Distribution in project beam by apache.
the class BatchModeExecutionContextTest method extractMetricUpdatesDistribution.
@Test
public void extractMetricUpdatesDistribution() {
BatchModeExecutionContext executionContext = BatchModeExecutionContext.forTesting(PipelineOptionsFactory.create(), "testStage");
DataflowOperationContext operationContext = executionContext.createOperationContext(NameContextsForTests.nameContextForTest());
Distribution distribution = operationContext.metricsContainer().getDistribution(MetricName.named("namespace", "some-distribution"));
distribution.update(2);
distribution.update(8);
final CounterUpdate expected = new CounterUpdate().setStructuredNameAndMetadata(new CounterStructuredNameAndMetadata().setName(new CounterStructuredName().setOrigin("USER").setOriginNamespace("namespace").setName("some-distribution").setOriginalStepName("originalName")).setMetadata(new CounterMetadata().setKind(Kind.DISTRIBUTION.toString()))).setCumulative(true).setDistribution(new DistributionUpdate().setCount(longToSplitInt(2)).setMax(longToSplitInt(8)).setMin(longToSplitInt(2)).setSum(longToSplitInt(10)));
assertThat(executionContext.extractMetricUpdates(false), containsInAnyOrder(expected));
}
Aggregations