Search in sources :

Example 26 with MetricsContainerImpl

use of org.apache.beam.runners.core.metrics.MetricsContainerImpl in project beam by apache.

the class ReduceFnRunnerTest method testOnElementBufferingDiscarding.

@Test
public void testOnElementBufferingDiscarding() throws Exception {
    // Test basic execution of a trigger using a non-combining window set and discarding mode.
    MetricsContainerImpl container = new MetricsContainerImpl("any");
    MetricsEnvironment.setCurrentContainer(container);
    ReduceFnTester<Integer, Iterable<Integer>, IntervalWindow> tester = ReduceFnTester.nonCombining(FixedWindows.of(Duration.millis(10)), mockTriggerStateMachine, AccumulationMode.DISCARDING_FIRED_PANES, Duration.millis(100), ClosingBehavior.FIRE_IF_NON_EMPTY);
    // Pane of {1, 2}
    injectElement(tester, 1);
    when(mockTriggerStateMachine.shouldFire(anyTriggerContext())).thenReturn(true);
    injectElement(tester, 2);
    assertThat(tester.extractOutput(), contains(isSingleWindowedValue(containsInAnyOrder(1, 2), 1, 0, 10)));
    // Pane of just 3, and finish
    when(mockTriggerStateMachine.shouldFire(anyTriggerContext())).thenReturn(true);
    triggerShouldFinish(mockTriggerStateMachine);
    injectElement(tester, 3);
    assertThat(tester.extractOutput(), contains(isSingleWindowedValue(containsInAnyOrder(3), 3, 0, 10)));
    assertTrue(tester.isMarkedFinished(firstWindow));
    tester.assertHasOnlyGlobalAndFinishedSetsFor(firstWindow);
    // This element shouldn't be seen, because the trigger has finished
    injectElement(tester, 4);
    long droppedElements = container.getCounter(MetricName.named(ReduceFnRunner.class, ReduceFnRunner.DROPPED_DUE_TO_CLOSED_WINDOW)).getCumulative();
    assertEquals(1, droppedElements);
}
Also used : MetricsContainerImpl(org.apache.beam.runners.core.metrics.MetricsContainerImpl) Matchers.emptyIterable(org.hamcrest.Matchers.emptyIterable) IntervalWindow(org.apache.beam.sdk.transforms.windowing.IntervalWindow) Test(org.junit.Test)

Example 27 with MetricsContainerImpl

use of org.apache.beam.runners.core.metrics.MetricsContainerImpl in project beam by apache.

the class LateDataDroppingDoFnRunnerTest method testLateDataFilter.

@Test
public void testLateDataFilter() throws Exception {
    MetricsContainerImpl container = new MetricsContainerImpl("any");
    MetricsEnvironment.setCurrentContainer(container);
    when(mockTimerInternals.currentInputWatermarkTime()).thenReturn(new Instant(15L));
    LateDataFilter lateDataFilter = new LateDataFilter(WindowingStrategy.of(WINDOW_FN), mockTimerInternals);
    Iterable<WindowedValue<Integer>> actual = lateDataFilter.filter("a", ImmutableList.of(createDatum(13, 13L), // late element, earlier than 4L.
    createDatum(5, 5L), createDatum(16, 16L), createDatum(18, 18L)));
    Iterable<WindowedValue<Integer>> expected = ImmutableList.of(createDatum(13, 13L), createDatum(16, 16L), createDatum(18, 18L));
    assertThat(expected, containsInAnyOrder(Iterables.toArray(actual, WindowedValue.class)));
    long droppedValues = container.getCounter(MetricName.named(LateDataDroppingDoFnRunner.class, LateDataDroppingDoFnRunner.DROPPED_DUE_TO_LATENESS)).getCumulative();
    assertEquals(1, droppedValues);
    // Ensure that reiterating returns the same results and doesn't increment the counter again.
    assertThat(expected, containsInAnyOrder(Iterables.toArray(actual, WindowedValue.class)));
    droppedValues = container.getCounter(MetricName.named(LateDataDroppingDoFnRunner.class, LateDataDroppingDoFnRunner.DROPPED_DUE_TO_LATENESS)).getCumulative();
    assertEquals(1, droppedValues);
}
Also used : LateDataFilter(org.apache.beam.runners.core.LateDataDroppingDoFnRunner.LateDataFilter) MetricsContainerImpl(org.apache.beam.runners.core.metrics.MetricsContainerImpl) WindowedValue(org.apache.beam.sdk.util.WindowedValue) Instant(org.joda.time.Instant) Test(org.junit.Test)

Example 28 with MetricsContainerImpl

use of org.apache.beam.runners.core.metrics.MetricsContainerImpl in project beam by apache.

the class DirectTransformExecutor method run.

@Override
public void run() {
    MetricsContainerImpl metricsContainer = new MetricsContainerImpl(transform.getFullName());
    try (Closeable metricsScope = MetricsEnvironment.scopedMetricsContainer(metricsContainer)) {
        Collection<ModelEnforcement<T>> enforcements = new ArrayList<>();
        for (ModelEnforcementFactory enforcementFactory : modelEnforcements) {
            ModelEnforcement<T> enforcement = enforcementFactory.forBundle(inputBundle, transform);
            enforcements.add(enforcement);
        }
        @Nullable TransformEvaluator<T> evaluator = evaluatorRegistry.forApplication(transform, inputBundle);
        if (evaluator == null) {
            onComplete.handleEmpty(transform);
            // Nothing to do
            return;
        }
        processElements(evaluator, metricsContainer, enforcements);
        finishBundle(evaluator, metricsContainer, enforcements);
    } catch (Exception e) {
        onComplete.handleException(inputBundle, e);
        if (e instanceof RuntimeException) {
            throw (RuntimeException) e;
        }
        throw new RuntimeException(e);
    } catch (Error err) {
        LOG.error("Error occurred within {}", this, err);
        onComplete.handleError(err);
        throw err;
    } finally {
        // Report the physical metrics from the end of this step.
        context.getMetrics().commitPhysical(inputBundle, metricsContainer.getCumulative());
        transformEvaluationState.complete(this);
    }
}
Also used : Closeable(java.io.Closeable) ArrayList(java.util.ArrayList) MetricsContainerImpl(org.apache.beam.runners.core.metrics.MetricsContainerImpl) Nullable(org.checkerframework.checker.nullness.qual.Nullable)

Example 29 with MetricsContainerImpl

use of org.apache.beam.runners.core.metrics.MetricsContainerImpl in project beam by apache.

the class BatchModeExecutionContext method extractThrottleTime.

public Long extractThrottleTime() {
    long totalThrottleMsecs = 0L;
    for (MetricsContainerImpl container : containerRegistry.getContainers()) {
        // TODO(BEAM-7863): Update throttling counters to use generic throttling-msecs metric.
        CounterCell dataStoreThrottlingTime = container.tryGetCounter(MetricName.named(DATASTORE_THROTTLE_TIME_NAMESPACE, THROTTLE_TIME_COUNTER_NAME));
        if (dataStoreThrottlingTime != null) {
            totalThrottleMsecs += dataStoreThrottlingTime.getCumulative();
        }
        CounterCell httpClientApiThrottlingTime = container.tryGetCounter(MetricName.named(HTTP_CLIENT_API_THROTTLE_TIME_NAMESPACE, THROTTLE_TIME_COUNTER_NAME));
        if (httpClientApiThrottlingTime != null) {
            totalThrottleMsecs += httpClientApiThrottlingTime.getCumulative();
        }
        CounterCell bigqueryStreamingInsertThrottleTime = container.tryGetCounter(MetricName.named(BIGQUERY_STREAMING_INSERT_THROTTLE_TIME_NAMESPACE, THROTTLE_TIME_COUNTER_NAME));
        if (bigqueryStreamingInsertThrottleTime != null) {
            totalThrottleMsecs += bigqueryStreamingInsertThrottleTime.getCumulative();
        }
        CounterCell bigqueryReadThrottleTime = container.tryGetCounter(MetricName.named(BIGQUERY_READ_THROTTLE_TIME_NAMESPACE, THROTTLE_TIME_COUNTER_NAME));
        if (bigqueryReadThrottleTime != null) {
            totalThrottleMsecs += bigqueryReadThrottleTime.getCumulative();
        }
        CounterCell throttlingMsecs = container.tryGetCounter(DataflowSystemMetrics.THROTTLING_MSECS_METRIC_NAME);
        if (throttlingMsecs != null) {
            totalThrottleMsecs += throttlingMsecs.getCumulative();
        }
    }
    return TimeUnit.MILLISECONDS.toSeconds(totalThrottleMsecs);
}
Also used : MetricsContainerImpl(org.apache.beam.runners.core.metrics.MetricsContainerImpl) CounterCell(org.apache.beam.runners.core.metrics.CounterCell)

Example 30 with MetricsContainerImpl

use of org.apache.beam.runners.core.metrics.MetricsContainerImpl in project beam by apache.

the class HarnessMonitoringInfosInstructionHandler method harnessMonitoringInfos.

public BeamFnApi.InstructionResponse.Builder harnessMonitoringInfos(BeamFnApi.InstructionRequest request) {
    BeamFnApi.HarnessMonitoringInfosResponse.Builder response = BeamFnApi.HarnessMonitoringInfosResponse.newBuilder();
    MetricsContainer container = MetricsEnvironment.getProcessWideContainer();
    if (container != null && container instanceof MetricsContainerImpl) {
        response.putAllMonitoringData(((MetricsContainerImpl) container).getMonitoringData(this.metricsShortIds));
    }
    return BeamFnApi.InstructionResponse.newBuilder().setHarnessMonitoringInfos(response);
}
Also used : MetricsContainerImpl(org.apache.beam.runners.core.metrics.MetricsContainerImpl) MetricsContainer(org.apache.beam.sdk.metrics.MetricsContainer)

Aggregations

MetricsContainerImpl (org.apache.beam.runners.core.metrics.MetricsContainerImpl)36 Test (org.junit.Test)16 IntervalWindow (org.apache.beam.sdk.transforms.windowing.IntervalWindow)12 Instant (org.joda.time.Instant)12 HashMap (java.util.HashMap)7 MonitoringInfoMetricName (org.apache.beam.runners.core.metrics.MonitoringInfoMetricName)7 Matchers.emptyIterable (org.hamcrest.Matchers.emptyIterable)7 WindowedValue (org.apache.beam.sdk.util.WindowedValue)6 KV (org.apache.beam.sdk.values.KV)5 Before (org.junit.Before)5 Closeable (java.io.Closeable)4 ArrayList (java.util.ArrayList)4 CounterCell (org.apache.beam.runners.core.metrics.CounterCell)4 WindowMatchers.isSingleWindowedValue (org.apache.beam.runners.core.WindowMatchers.isSingleWindowedValue)3 WindowMatchers.isWindowedValue (org.apache.beam.runners.core.WindowMatchers.isWindowedValue)3 Duration (org.joda.time.Duration)3 ByteString (com.google.protobuf.ByteString)2 IOException (java.io.IOException)2 CounterSet (org.apache.beam.runners.dataflow.worker.counters.CounterSet)2 TupleTag (org.apache.beam.sdk.values.TupleTag)2