Search in sources :

Example 26 with NameContext

use of org.apache.beam.runners.dataflow.worker.counters.NameContext in project beam by apache.

the class DataflowElementExecutionTrackerTest method testNoExecutionsSinceLastSample.

/**
 * Ensure that sampling is properly handled when there are no new executions since the last
 * sampling period.
 */
@Test
public void testNoExecutionsSinceLastSample() throws IOException {
    // Journal: IDLE
    tracker.takeSample(10);
    NameContext step = createStep("A");
    tracker.enter(step);
    // Journal: IDLE A1
    tracker.takeSample(10);
    // Journal: A1
    tracker.takeSample(10);
    tracker.exit();
    // Journal: A1 IDLE
    tracker.takeSample(10);
    assertThat(getCounterValue(step), equalTo(distribution(20)));
    // Journal: IDLE
    tracker.takeSample(10);
    assertThat(getCounterValue(step), equalTo(distribution(20)));
}
Also used : NameContext(org.apache.beam.runners.dataflow.worker.counters.NameContext) Test(org.junit.Test)

Example 27 with NameContext

use of org.apache.beam.runners.dataflow.worker.counters.NameContext in project beam by apache.

the class DataflowElementExecutionTrackerTest method testCurrentOperationCountedInNextSample.

/**
 * Test that the currently processing element at time of sampling is also counted in the next
 * sampling period.
 */
@Test
public void testCurrentOperationCountedInNextSample() throws IOException {
    NameContext step = createStep("A");
    tracker.enter(step);
    // Journal: IDLE A1
    tracker.takeSample(20);
    // Journal: A1
    tracker.takeSample(10);
    tracker.exit();
    // Journal: A1 IDLE
    tracker.takeSample(20);
    assertThat(getCounterValue(step), equalTo(distribution(30)));
}
Also used : NameContext(org.apache.beam.runners.dataflow.worker.counters.NameContext) Test(org.junit.Test)

Example 28 with NameContext

use of org.apache.beam.runners.dataflow.worker.counters.NameContext in project beam by apache.

the class DataflowElementExecutionTrackerTest method testSampledTimeDistributedBetweenExecutionFragments.

/**
 * Test that the sampling time is distributed evenly between all execution fragments since last
 * sampling.
 */
@Test
public void testSampledTimeDistributedBetweenExecutionFragments() throws IOException {
    NameContext stepA = createStep("A");
    NameContext stepB = createStep("B");
    tracker.enter(stepA);
    tracker.exit();
    tracker.enter(stepB);
    tracker.exit();
    // Expected journal: IDLE A1 IDLE B1 IDLE
    tracker.takeSample(50);
    assertThat(getCounterValue(stepA), equalTo(distribution(10)));
    assertThat(getCounterValue(stepB), equalTo(distribution(10)));
}
Also used : NameContext(org.apache.beam.runners.dataflow.worker.counters.NameContext) Test(org.junit.Test)

Example 29 with NameContext

use of org.apache.beam.runners.dataflow.worker.counters.NameContext in project beam by apache.

the class StreamingModeExecutionContextTest method testTimerInternalsSetTimer.

@Test
public void testTimerInternalsSetTimer() {
    Windmill.WorkItemCommitRequest.Builder outputBuilder = Windmill.WorkItemCommitRequest.newBuilder();
    NameContext nameContext = NameContextsForTests.nameContextForTest();
    DataflowOperationContext operationContext = executionContext.createOperationContext(nameContext);
    StreamingModeExecutionContext.StepContext stepContext = executionContext.getStepContext(operationContext);
    executionContext.start("key", Windmill.WorkItem.newBuilder().setKey(ByteString.EMPTY).setWorkToken(17L).build(), // input watermark
    new Instant(1000), // output watermark
    null, // synchronized processing time
    null, stateReader, stateFetcher, outputBuilder);
    TimerInternals timerInternals = stepContext.timerInternals();
    timerInternals.setTimer(TimerData.of(new StateNamespaceForTest("key"), new Instant(5000), new Instant(5000), TimeDomain.EVENT_TIME));
    executionContext.flushState();
    Windmill.Timer timer = outputBuilder.buildPartial().getOutputTimers(0);
    assertThat(timer.getTag().toStringUtf8(), equalTo("/skey+0:5000"));
    assertThat(timer.getTimestamp(), equalTo(TimeUnit.MILLISECONDS.toMicros(5000)));
    assertThat(timer.getType(), equalTo(Windmill.Timer.Type.WATERMARK));
}
Also used : TimerInternals(org.apache.beam.runners.core.TimerInternals) Instant(org.joda.time.Instant) NameContext(org.apache.beam.runners.dataflow.worker.counters.NameContext) StateNamespaceForTest(org.apache.beam.runners.core.StateNamespaceForTest) Windmill(org.apache.beam.runners.dataflow.worker.windmill.Windmill) StateNamespaceForTest(org.apache.beam.runners.core.StateNamespaceForTest) Test(org.junit.Test)

Example 30 with NameContext

use of org.apache.beam.runners.dataflow.worker.counters.NameContext in project beam by apache.

the class ExecutionTimeMonitoringInfoToCounterUpdateTransformerTest method testTransformReturnsValidCounterUpdateWhenValidMSecMonitoringInfoReceived.

@Test
public void testTransformReturnsValidCounterUpdateWhenValidMSecMonitoringInfoReceived() throws Exception {
    Map<String, DataflowStepContext> stepContextMapping = new HashMap<>();
    NameContext nc = NameContext.create("anyStageName", "anyOriginalName", "anySystemName", "anyUserName");
    DataflowStepContext dsc = mock(DataflowStepContext.class);
    when(dsc.getNameContext()).thenReturn(nc);
    stepContextMapping.put("anyValue", dsc);
    ExecutionTimeMonitoringInfoToCounterUpdateTransformer testObject = new ExecutionTimeMonitoringInfoToCounterUpdateTransformer(mockSpecValidator, stepContextMapping);
    when(mockSpecValidator.validate(any())).thenReturn(Optional.empty());
    // Execute
    MonitoringInfo monitoringInfo = MonitoringInfo.newBuilder().setUrn(Urns.PROCESS_BUNDLE_MSECS).setType(TypeUrns.SUM_INT64_TYPE).putLabels(MonitoringInfoConstants.Labels.PTRANSFORM, "anyValue").setPayload(encodeInt64Counter(1L)).build();
    CounterUpdate result = testObject.transform(monitoringInfo);
    // Validate
    assertNotNull(result);
    assertEqualsAsJson("{cumulative:true, integer:{highBits:0, lowBits:1}, " + "structuredNameAndMetadata:{metadata:{kind:'SUM'}, " + "name:{executionStepName:'anyStageName', name:'process-msecs', origin:'SYSTEM', " + "originalStepName:'anyOriginalName'}}}", result);
}
Also used : MonitoringInfo(org.apache.beam.model.pipeline.v1.MetricsApi.MonitoringInfo) HashMap(java.util.HashMap) NameContext(org.apache.beam.runners.dataflow.worker.counters.NameContext) DataflowStepContext(org.apache.beam.runners.dataflow.worker.DataflowExecutionContext.DataflowStepContext) CounterUpdate(com.google.api.services.dataflow.model.CounterUpdate) Test(org.junit.Test)

Aggregations

NameContext (org.apache.beam.runners.dataflow.worker.counters.NameContext)35 Test (org.junit.Test)24 HashMap (java.util.HashMap)14 MonitoringInfo (org.apache.beam.model.pipeline.v1.MetricsApi.MonitoringInfo)9 CounterUpdate (com.google.api.services.dataflow.model.CounterUpdate)6 Map (java.util.Map)5 DataflowStepContext (org.apache.beam.runners.dataflow.worker.DataflowExecutionContext.DataflowStepContext)5 ParallelInstructionNode (org.apache.beam.runners.dataflow.worker.graph.Nodes.ParallelInstructionNode)5 PCollectionView (org.apache.beam.sdk.values.PCollectionView)5 ImmutableMap (org.apache.beam.vendor.guava.v26_0_jre.com.google.common.collect.ImmutableMap)5 ParallelInstruction (com.google.api.services.dataflow.model.ParallelInstruction)4 IOException (java.io.IOException)4 RunnerApi (org.apache.beam.model.pipeline.v1.RunnerApi)4 ExecutionStateTracker (org.apache.beam.runners.core.metrics.ExecutionStateTracker)4 Instant (org.joda.time.Instant)4 CloudObject (org.apache.beam.runners.dataflow.util.CloudObject)3 Counter (org.apache.beam.runners.dataflow.worker.counters.Counter)3 Edge (org.apache.beam.runners.dataflow.worker.graph.Edges.Edge)3 TypeSafeNodeFunction (org.apache.beam.runners.dataflow.worker.graph.Networks.TypeSafeNodeFunction)3 InstructionOutputNode (org.apache.beam.runners.dataflow.worker.graph.Nodes.InstructionOutputNode)3