Search in sources :

Example 6 with MetricsContainer

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);
}
Also used : Counter(org.apache.beam.sdk.metrics.Counter) HashMap(java.util.HashMap) MetricsContainer(org.apache.beam.sdk.metrics.MetricsContainer) Test(org.junit.Test)

Example 7 with MetricsContainer

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));
}
Also used : MetricName(org.apache.beam.sdk.metrics.MetricName) MonitoringInfoMetricName(org.apache.beam.runners.core.metrics.MonitoringInfoMetricName) SimpleCounter(org.apache.flink.metrics.SimpleCounter) Counter(org.apache.beam.sdk.metrics.Counter) SimpleCounter(org.apache.flink.metrics.SimpleCounter) MetricsContainer(org.apache.beam.sdk.metrics.MetricsContainer) Test(org.junit.Test)

Example 8 with MetricsContainer

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));
}
Also used : MetricName(org.apache.beam.sdk.metrics.MetricName) MonitoringInfoMetricName(org.apache.beam.runners.core.metrics.MonitoringInfoMetricName) MetricsContainer(org.apache.beam.sdk.metrics.MetricsContainer) FlinkDistributionGauge(org.apache.beam.runners.flink.metrics.FlinkMetricContainer.FlinkDistributionGauge) Gauge(org.apache.beam.sdk.metrics.Gauge) Test(org.junit.Test)

Example 9 with MetricsContainer

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)));
}
Also used : ExecutionState(org.apache.beam.runners.core.metrics.ExecutionStateTracker.ExecutionState) BatchModeExecutionState(org.apache.beam.runners.dataflow.worker.BatchModeExecutionContext.BatchModeExecutionState) MetricsContainer(org.apache.beam.sdk.metrics.MetricsContainer) ProfileScope(org.apache.beam.runners.dataflow.worker.profiler.ScopedProfiler.ProfileScope) NoopProfileScope(org.apache.beam.runners.dataflow.worker.profiler.ScopedProfiler.NoopProfileScope) Test(org.junit.Test)

Example 10 with MetricsContainer

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)));
}
Also used : ExecutionState(org.apache.beam.runners.core.metrics.ExecutionStateTracker.ExecutionState) StreamingModeExecutionState(org.apache.beam.runners.dataflow.worker.StreamingModeExecutionContext.StreamingModeExecutionState) MetricsContainer(org.apache.beam.sdk.metrics.MetricsContainer) ProfileScope(org.apache.beam.runners.dataflow.worker.profiler.ScopedProfiler.ProfileScope) NoopProfileScope(org.apache.beam.runners.dataflow.worker.profiler.ScopedProfiler.NoopProfileScope) StateNamespaceForTest(org.apache.beam.runners.core.StateNamespaceForTest) Test(org.junit.Test)

Aggregations

MetricsContainer (org.apache.beam.sdk.metrics.MetricsContainer)10 Test (org.junit.Test)6 MonitoringInfoMetricName (org.apache.beam.runners.core.metrics.MonitoringInfoMetricName)3 MetricName (org.apache.beam.sdk.metrics.MetricName)3 Closeable (java.io.Closeable)2 IOException (java.io.IOException)2 ArrayList (java.util.ArrayList)2 ExecutionState (org.apache.beam.runners.core.metrics.ExecutionStateTracker.ExecutionState)2 MetricsContainerStepMap (org.apache.beam.runners.core.metrics.MetricsContainerStepMap)2 NoopProfileScope (org.apache.beam.runners.dataflow.worker.profiler.ScopedProfiler.NoopProfileScope)2 ProfileScope (org.apache.beam.runners.dataflow.worker.profiler.ScopedProfiler.ProfileScope)2 FlinkDistributionGauge (org.apache.beam.runners.flink.metrics.FlinkMetricContainer.FlinkDistributionGauge)2 MicrobatchSource (org.apache.beam.runners.spark.io.MicrobatchSource)2 Metadata (org.apache.beam.runners.spark.io.SparkUnboundedSource.Metadata)2 Source (org.apache.beam.sdk.io.Source)2 UnboundedSource (org.apache.beam.sdk.io.UnboundedSource)2 Counter (org.apache.beam.sdk.metrics.Counter)2 WindowedValue (org.apache.beam.sdk.util.WindowedValue)2 State (org.apache.spark.streaming.State)2 Instant (org.joda.time.Instant)2