Search in sources :

Example 31 with NameContext

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

the class MeanByteCountMonitoringInfoToCounterUpdateTransformerTest method testTransformReturnsValidCounterUpdateWhenValidMonitoringInfoReceived.

@Test
public void testTransformReturnsValidCounterUpdateWhenValidMonitoringInfoReceived() throws Exception {
    Map<String, NameContext> pcollectionNameMapping = new HashMap<>();
    pcollectionNameMapping.put("anyValue", NameContext.create("anyStageName", "anyOriginName", "anySystemName", "transformedValue"));
    MonitoringInfo monitoringInfo = MonitoringInfo.newBuilder().setUrn(Urns.SAMPLED_BYTE_SIZE).setType(TypeUrns.DISTRIBUTION_INT64_TYPE).putLabels(MonitoringInfoConstants.Labels.PCOLLECTION, "anyValue").setPayload(encodeInt64Distribution(DistributionData.create(2L, /* sum */
    1L, /* count */
    3L, /* min */
    4L))).build();
    MeanByteCountMonitoringInfoToCounterUpdateTransformer testObject = new MeanByteCountMonitoringInfoToCounterUpdateTransformer(mockSpecValidator, pcollectionNameMapping);
    when(mockSpecValidator.validate(any())).thenReturn(Optional.empty());
    CounterUpdate result = testObject.transform(monitoringInfo);
    assertNotNull(result);
    assertEqualsAsJson("{cumulative:true, integerMean:{count:{highBits:0, lowBits:1}, " + "sum:{highBits:0, lowBits:2}}, " + "nameAndKind:{kind:'MEAN', " + "name:'transformedValue-MeanByteCount'}}", 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) CounterUpdate(com.google.api.services.dataflow.model.CounterUpdate) Test(org.junit.Test)

Example 32 with NameContext

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

the class MeanByteCountMonitoringInfoToCounterUpdateTransformerTest method testTransformThrowsIfMonitoringInfoWithWrongUrnReceived.

@Test
public void testTransformThrowsIfMonitoringInfoWithWrongUrnReceived() {
    Map<String, NameContext> pcollectionNameMapping = new HashMap<>();
    MonitoringInfo monitoringInfo = MonitoringInfo.newBuilder().setUrn(Urns.ELEMENT_COUNT).setType(TypeUrns.SUM_INT64_TYPE).build();
    MeanByteCountMonitoringInfoToCounterUpdateTransformer testObject = new MeanByteCountMonitoringInfoToCounterUpdateTransformer(mockSpecValidator, pcollectionNameMapping);
    when(mockSpecValidator.validate(any())).thenReturn(Optional.empty());
    exception.expect(RuntimeException.class);
    testObject.transform(monitoringInfo);
}
Also used : MonitoringInfo(org.apache.beam.model.pipeline.v1.MetricsApi.MonitoringInfo) HashMap(java.util.HashMap) NameContext(org.apache.beam.runners.dataflow.worker.counters.NameContext) Test(org.junit.Test)

Example 33 with NameContext

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

the class ElementCountMonitoringInfoToCounterUpdateTransformerTest method testTransformReturnsNullIfMonitoringInfoWithUnknownPCollectionLabelPresent.

@Test
public void testTransformReturnsNullIfMonitoringInfoWithUnknownPCollectionLabelPresent() {
    Map<String, NameContext> pcollectionNameMapping = new HashMap<>();
    MonitoringInfo monitoringInfo = MonitoringInfo.newBuilder().setUrn(Urns.ELEMENT_COUNT).setType(TypeUrns.SUM_INT64_TYPE).putLabels(MonitoringInfoConstants.Labels.PCOLLECTION, "anyValue").build();
    ElementCountMonitoringInfoToCounterUpdateTransformer testObject = new ElementCountMonitoringInfoToCounterUpdateTransformer(mockSpecValidator, pcollectionNameMapping);
    when(mockSpecValidator.validate(any())).thenReturn(Optional.empty());
    assertNull(testObject.transform(monitoringInfo));
}
Also used : MonitoringInfo(org.apache.beam.model.pipeline.v1.MetricsApi.MonitoringInfo) HashMap(java.util.HashMap) NameContext(org.apache.beam.runners.dataflow.worker.counters.NameContext) Test(org.junit.Test)

Example 34 with NameContext

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

the class ElementCountMonitoringInfoToCounterUpdateTransformerTest method testTransformReturnsValidCounterUpdateWhenValidMonitoringInfoReceived.

@Test
public void testTransformReturnsValidCounterUpdateWhenValidMonitoringInfoReceived() throws Exception {
    Map<String, NameContext> pcollectionNameMapping = new HashMap<>();
    pcollectionNameMapping.put("anyValue", NameContext.create("anyStageName", "anyOriginName", "anySystemName", "transformedValue"));
    MonitoringInfo monitoringInfo = MonitoringInfo.newBuilder().setUrn(Urns.ELEMENT_COUNT).setType(TypeUrns.SUM_INT64_TYPE).putLabels(MonitoringInfoConstants.Labels.PCOLLECTION, "anyValue").setPayload(encodeInt64Counter(1L)).build();
    ElementCountMonitoringInfoToCounterUpdateTransformer testObject = new ElementCountMonitoringInfoToCounterUpdateTransformer(mockSpecValidator, pcollectionNameMapping);
    when(mockSpecValidator.validate(any())).thenReturn(Optional.empty());
    CounterUpdate result = testObject.transform(monitoringInfo);
    assertNotNull(result);
    assertEqualsAsJson("{cumulative:true, integer:{highBits:0, lowBits:1}, " + "nameAndKind:{kind:'SUM', " + "name:'transformedValue-ElementCount'}}", 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) CounterUpdate(com.google.api.services.dataflow.model.CounterUpdate) Test(org.junit.Test)

Example 35 with NameContext

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

the class ElementCountMonitoringInfoToCounterUpdateTransformerTest method testTransformThrowsIfMonitoringInfoWithWrongUrnPrefixReceived.

@Test
public void testTransformThrowsIfMonitoringInfoWithWrongUrnPrefixReceived() {
    Map<String, NameContext> pcollectionNameMapping = new HashMap<>();
    MonitoringInfo monitoringInfo = MonitoringInfo.newBuilder().setUrn(Urns.USER_SUM_INT64).build();
    ElementCountMonitoringInfoToCounterUpdateTransformer testObject = new ElementCountMonitoringInfoToCounterUpdateTransformer(mockSpecValidator, pcollectionNameMapping);
    when(mockSpecValidator.validate(any())).thenReturn(Optional.empty());
    exception.expect(RuntimeException.class);
    testObject.transform(monitoringInfo);
}
Also used : MonitoringInfo(org.apache.beam.model.pipeline.v1.MetricsApi.MonitoringInfo) HashMap(java.util.HashMap) NameContext(org.apache.beam.runners.dataflow.worker.counters.NameContext) 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