Search in sources :

Example 46 with CounterUpdate

use of com.google.api.services.dataflow.model.CounterUpdate 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)

Example 47 with CounterUpdate

use of com.google.api.services.dataflow.model.CounterUpdate 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 48 with CounterUpdate

use of com.google.api.services.dataflow.model.CounterUpdate in project beam by apache.

the class CounterUpdateAggregatorsTest method testAggregateSum.

@Test
public void testAggregateSum() {
    List<CounterUpdate> sumUpdates = new ArrayList<>();
    for (int i = 0; i < 10; i++) {
        sumUpdates.add(new CounterUpdate().setStructuredNameAndMetadata(new CounterStructuredNameAndMetadata().setMetadata(new CounterMetadata().setKind(Kind.SUM.toString()))).setInteger(longToSplitInt((long) i)));
    }
    List<CounterUpdate> aggregated = CounterUpdateAggregators.aggregate(sumUpdates);
    assertEquals(1, aggregated.size());
    CounterUpdate combined = aggregated.get(0);
    assertEquals(45L, splitIntToLong(combined.getInteger()));
}
Also used : CounterMetadata(com.google.api.services.dataflow.model.CounterMetadata) ArrayList(java.util.ArrayList) CounterStructuredNameAndMetadata(com.google.api.services.dataflow.model.CounterStructuredNameAndMetadata) CounterUpdate(com.google.api.services.dataflow.model.CounterUpdate) Test(org.junit.Test)

Example 49 with CounterUpdate

use of com.google.api.services.dataflow.model.CounterUpdate 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 50 with CounterUpdate

use of com.google.api.services.dataflow.model.CounterUpdate in project beam by apache.

the class SumCounterUpdateAggregatorTest method setUp.

@Before
public void setUp() {
    counterUpdates = new ArrayList<>();
    aggregator = new SumCounterUpdateAggregator();
    for (int i = 0; i < 10; i++) {
        counterUpdates.add(new CounterUpdate().setStructuredNameAndMetadata(new CounterStructuredNameAndMetadata().setMetadata(new CounterMetadata().setKind(Kind.SUM.toString()))).setInteger(longToSplitInt((long) i)));
    }
}
Also used : CounterMetadata(com.google.api.services.dataflow.model.CounterMetadata) CounterStructuredNameAndMetadata(com.google.api.services.dataflow.model.CounterStructuredNameAndMetadata) CounterUpdate(com.google.api.services.dataflow.model.CounterUpdate) Before(org.junit.Before)

Aggregations

CounterUpdate (com.google.api.services.dataflow.model.CounterUpdate)51 Test (org.junit.Test)33 CounterStructuredNameAndMetadata (com.google.api.services.dataflow.model.CounterStructuredNameAndMetadata)18 CounterMetadata (com.google.api.services.dataflow.model.CounterMetadata)16 CounterStructuredName (com.google.api.services.dataflow.model.CounterStructuredName)12 HashMap (java.util.HashMap)10 WorkItemStatus (com.google.api.services.dataflow.model.WorkItemStatus)9 ArrayList (java.util.ArrayList)9 MonitoringInfo (org.apache.beam.model.pipeline.v1.MetricsApi.MonitoringInfo)7 DataflowStepContext (org.apache.beam.runners.dataflow.worker.DataflowExecutionContext.DataflowStepContext)7 DistributionUpdate (com.google.api.services.dataflow.model.DistributionUpdate)6 NameContext (org.apache.beam.runners.dataflow.worker.counters.NameContext)6 Nullable (org.checkerframework.checker.nullness.qual.Nullable)6 NameAndKind (com.google.api.services.dataflow.model.NameAndKind)5 AtomicLong (java.util.concurrent.atomic.AtomicLong)5 DataflowCounterUpdateExtractor.splitIntToLong (org.apache.beam.runners.dataflow.worker.counters.DataflowCounterUpdateExtractor.splitIntToLong)5 WorkItemCommitRequest (org.apache.beam.runners.dataflow.worker.windmill.Windmill.WorkItemCommitRequest)4 IntegerMean (com.google.api.services.dataflow.model.IntegerMean)3 List (java.util.List)3 ConcurrentHashMap (java.util.concurrent.ConcurrentHashMap)3