use of org.apache.beam.sdk.metrics.MetricsContainer in project beam by apache.
the class LabeledMetricsTest method testOperationsUpdateCounterFromContainerWhenContainerIsPresent.
@Test
public void testOperationsUpdateCounterFromContainerWhenContainerIsPresent() {
HashMap<String, String> labels = new HashMap<String, String>();
String urn = MonitoringInfoConstants.Urns.ELEMENT_COUNT;
MonitoringInfoMetricName name = MonitoringInfoMetricName.named(urn, labels);
MetricsContainer mockContainer = Mockito.mock(MetricsContainer.class);
Counter mockCounter = Mockito.mock(Counter.class);
when(mockContainer.getCounter(name)).thenReturn(mockCounter);
Counter counter = LabeledMetrics.counter(name);
MetricsEnvironment.setCurrentContainer(mockContainer);
counter.inc();
verify(mockCounter).inc(1);
counter.inc(47L);
verify(mockCounter).inc(47);
counter.dec(5L);
verify(mockCounter).inc(-5);
}
use of org.apache.beam.sdk.metrics.MetricsContainer in project beam by apache.
the class FlinkMetricContainerTest method testCounter.
@Test
public void testCounter() {
SimpleCounter flinkCounter = new SimpleCounter();
when(metricGroup.counter("namespace.name")).thenReturn(flinkCounter);
MetricsContainer step = container.getMetricsContainer("step");
MetricName metricName = MetricName.named("namespace", "name");
Counter counter = step.getCounter(metricName);
counter.inc();
counter.inc();
assertThat(flinkCounter.getCount(), is(0L));
container.updateMetrics("step");
assertThat(flinkCounter.getCount(), is(2L));
}
use of org.apache.beam.sdk.metrics.MetricsContainer in project beam by apache.
the class FlinkMetricContainerTest method testGauge.
@Test
public void testGauge() {
FlinkMetricContainer.FlinkGauge flinkGauge = new FlinkMetricContainer.FlinkGauge(GaugeResult.empty());
when(metricGroup.gauge(eq("namespace.name"), anyObject())).thenReturn(flinkGauge);
MetricsContainer step = container.getMetricsContainer("step");
MetricName metricName = MetricName.named("namespace", "name");
Gauge gauge = step.getGauge(metricName);
assertThat(flinkGauge.getValue(), is(-1L));
// first set will install the mocked gauge
container.updateMetrics("step");
gauge.set(1);
gauge.set(42);
container.updateMetrics("step");
assertThat(flinkGauge.getValue(), is(42L));
}
use of org.apache.beam.sdk.metrics.MetricsContainer in project beam by apache.
the class BatchModeExecutionContextTest method extractMsecCounters.
@Test
public void extractMsecCounters() {
BatchModeExecutionContext executionContext = BatchModeExecutionContext.forTesting(PipelineOptionsFactory.create(), "testStage");
MetricsContainer metricsContainer = Mockito.mock(MetricsContainer.class);
ProfileScope profileScope = Mockito.mock(ProfileScope.class);
ExecutionState start1 = executionContext.executionStateRegistry.getState(NameContext.create("stage", "original-1", "system-1", "user-1"), ExecutionStateTracker.START_STATE_NAME, metricsContainer, profileScope);
ExecutionState process1 = executionContext.executionStateRegistry.getState(NameContext.create("stage", "original-1", "system-1", "user-1"), ExecutionStateTracker.PROCESS_STATE_NAME, metricsContainer, profileScope);
ExecutionState start2 = executionContext.executionStateRegistry.getState(NameContext.create("stage", "original-2", "system-2", "user-2"), ExecutionStateTracker.START_STATE_NAME, metricsContainer, profileScope);
ExecutionState other = executionContext.executionStateRegistry.getState(NameContext.forStage("stage"), "other", null, NoopProfileScope.NOOP);
other.takeSample(120);
start1.takeSample(100);
process1.takeSample(500);
assertThat(executionContext.extractMsecCounters(false), containsInAnyOrder(msecStage("other-msecs", "stage", 120), msec("start-msecs", "stage", "original-1", 100), msec("process-msecs", "stage", "original-1", 500)));
process1.takeSample(200);
start2.takeSample(200);
assertThat(executionContext.extractMsecCounters(false), containsInAnyOrder(msec("process-msecs", "stage", "original-1", 500 + 200), msec("start-msecs", "stage", "original-2", 200)));
process1.takeSample(300);
assertThat(executionContext.extractMsecCounters(true), hasItems(msecStage("other-msecs", "stage", 120), msec("start-msecs", "stage", "original-1", 100), msec("process-msecs", "stage", "original-1", 500 + 200 + 300), msec("start-msecs", "stage", "original-2", 200)));
}
use of org.apache.beam.sdk.metrics.MetricsContainer in project beam by apache.
the class StreamingModeExecutionContextTest method extractMsecCounters.
@Test
public void extractMsecCounters() {
MetricsContainer metricsContainer = Mockito.mock(MetricsContainer.class);
ProfileScope profileScope = Mockito.mock(ProfileScope.class);
ExecutionState start1 = executionContext.executionStateRegistry.getState(NameContext.create("stage", "original-1", "system-1", "user-1"), ExecutionStateTracker.START_STATE_NAME, metricsContainer, profileScope);
ExecutionState process1 = executionContext.executionStateRegistry.getState(NameContext.create("stage", "original-1", "system-1", "user-1"), ExecutionStateTracker.PROCESS_STATE_NAME, metricsContainer, profileScope);
ExecutionState start2 = executionContext.executionStateRegistry.getState(NameContext.create("stage", "original-2", "system-2", "user-2"), ExecutionStateTracker.START_STATE_NAME, metricsContainer, profileScope);
ExecutionState other = executionContext.executionStateRegistry.getState(NameContext.forStage("stage"), "other", null, NoopProfileScope.NOOP);
other.takeSample(120);
start1.takeSample(100);
process1.takeSample(500);
assertThat(executionStateRegistry.extractUpdates(false), containsInAnyOrder(msecStage("other-msecs", "stage", 120), msec("start-msecs", "stage", "original-1", 100), msec("process-msecs", "stage", "original-1", 500)));
process1.takeSample(200);
start2.takeSample(200);
assertThat(executionStateRegistry.extractUpdates(false), containsInAnyOrder(msec("process-msecs", "stage", "original-1", 200), msec("start-msecs", "stage", "original-2", 200)));
process1.takeSample(300);
assertThat(executionStateRegistry.extractUpdates(false), containsInAnyOrder(msec("process-msecs", "stage", "original-1", 300)));
}
Aggregations