Search in sources :

Example 21 with MonitoringInfo

use of org.apache.beam.model.pipeline.v1.MetricsApi.MonitoringInfo in project beam by apache.

the class MetricsContainerImplTest method testMonitoringInfosArePopulatedForUserCounters.

@Test
public void testMonitoringInfosArePopulatedForUserCounters() {
    MetricsContainerImpl testObject = new MetricsContainerImpl("step1");
    CounterCell c1 = testObject.getCounter(MetricName.named("ns", "name1"));
    CounterCell c2 = testObject.getCounter(MetricName.named("ns", "name2"));
    c1.inc(2L);
    c2.inc(4L);
    c1.inc(3L);
    SimpleMonitoringInfoBuilder builder1 = new SimpleMonitoringInfoBuilder();
    builder1.setUrn(MonitoringInfoConstants.Urns.USER_SUM_INT64).setLabel(MonitoringInfoConstants.Labels.NAMESPACE, "ns").setLabel(MonitoringInfoConstants.Labels.NAME, "name1").setInt64SumValue(5).setLabel(MonitoringInfoConstants.Labels.PTRANSFORM, "step1");
    SimpleMonitoringInfoBuilder builder2 = new SimpleMonitoringInfoBuilder();
    builder2.setUrn(MonitoringInfoConstants.Urns.USER_SUM_INT64).setLabel(MonitoringInfoConstants.Labels.NAMESPACE, "ns").setLabel(MonitoringInfoConstants.Labels.NAME, "name2").setInt64SumValue(4).setLabel(MonitoringInfoConstants.Labels.PTRANSFORM, "step1");
    ArrayList<MonitoringInfo> actualMonitoringInfos = new ArrayList<MonitoringInfo>();
    for (MonitoringInfo mi : testObject.getMonitoringInfos()) {
        actualMonitoringInfos.add(mi);
    }
    assertThat(actualMonitoringInfos, containsInAnyOrder(builder1.build(), builder2.build()));
}
Also used : MonitoringInfo(org.apache.beam.model.pipeline.v1.MetricsApi.MonitoringInfo) ArrayList(java.util.ArrayList) Test(org.junit.Test)

Example 22 with MonitoringInfo

use of org.apache.beam.model.pipeline.v1.MetricsApi.MonitoringInfo in project beam by apache.

the class MetricsContainerImplTest method testMonitoringInfosArePopulatedForABeamCounter.

@Test
public void testMonitoringInfosArePopulatedForABeamCounter() {
    MetricsContainerImpl testObject = new MetricsContainerImpl("step1");
    HashMap<String, String> labels = new HashMap<String, String>();
    labels.put(MonitoringInfoConstants.Labels.PCOLLECTION, "pcollection");
    MetricName name = MonitoringInfoMetricName.named(MonitoringInfoConstants.Urns.ELEMENT_COUNT, labels);
    CounterCell c1 = testObject.getCounter(name);
    c1.inc(2L);
    SimpleMonitoringInfoBuilder builder1 = new SimpleMonitoringInfoBuilder();
    builder1.setUrn(MonitoringInfoConstants.Urns.ELEMENT_COUNT);
    builder1.setLabel(MonitoringInfoConstants.Labels.PCOLLECTION, "pcollection");
    builder1.setInt64SumValue(2);
    ArrayList<MonitoringInfo> actualMonitoringInfos = new ArrayList<MonitoringInfo>();
    for (MonitoringInfo mi : testObject.getMonitoringInfos()) {
        actualMonitoringInfos.add(mi);
    }
    assertThat(actualMonitoringInfos, containsInAnyOrder(builder1.build()));
}
Also used : MetricName(org.apache.beam.sdk.metrics.MetricName) MonitoringInfo(org.apache.beam.model.pipeline.v1.MetricsApi.MonitoringInfo) HashMap(java.util.HashMap) ArrayList(java.util.ArrayList) Test(org.junit.Test)

Example 23 with MonitoringInfo

use of org.apache.beam.model.pipeline.v1.MetricsApi.MonitoringInfo in project beam by apache.

the class MetricsContainerImplTest method testMonitoringInfosArePopulatedForUserDistributions.

@Test
public void testMonitoringInfosArePopulatedForUserDistributions() {
    MetricsContainerImpl testObject = new MetricsContainerImpl("step1");
    DistributionCell c1 = testObject.getDistribution(MetricName.named("ns", "name1"));
    DistributionCell c2 = testObject.getDistribution(MetricName.named("ns", "name2"));
    c1.update(5L);
    c2.update(4L);
    SimpleMonitoringInfoBuilder builder1 = new SimpleMonitoringInfoBuilder();
    builder1.setUrn(MonitoringInfoConstants.Urns.USER_DISTRIBUTION_INT64).setLabel(MonitoringInfoConstants.Labels.NAMESPACE, "ns").setLabel(MonitoringInfoConstants.Labels.NAME, "name1").setLabel(MonitoringInfoConstants.Labels.PTRANSFORM, "step1").setInt64DistributionValue(DistributionData.create(5, 1, 5, 5));
    SimpleMonitoringInfoBuilder builder2 = new SimpleMonitoringInfoBuilder();
    builder2.setUrn(MonitoringInfoConstants.Urns.USER_DISTRIBUTION_INT64).setLabel(MonitoringInfoConstants.Labels.NAMESPACE, "ns").setLabel(MonitoringInfoConstants.Labels.NAME, "name2").setLabel(MonitoringInfoConstants.Labels.PTRANSFORM, "step1").setInt64DistributionValue(DistributionData.create(4, 1, 4, 4));
    ArrayList<MonitoringInfo> actualMonitoringInfos = new ArrayList<MonitoringInfo>();
    for (MonitoringInfo mi : testObject.getMonitoringInfos()) {
        actualMonitoringInfos.add(mi);
    }
    assertThat(actualMonitoringInfos, containsInAnyOrder(builder1.build(), builder2.build()));
}
Also used : MonitoringInfo(org.apache.beam.model.pipeline.v1.MetricsApi.MonitoringInfo) ArrayList(java.util.ArrayList) Test(org.junit.Test)

Example 24 with MonitoringInfo

use of org.apache.beam.model.pipeline.v1.MetricsApi.MonitoringInfo in project beam by apache.

the class MetricsContainerImplTest method testMonitoringInfosArePopulatedForSystemDistributions.

@Test
public void testMonitoringInfosArePopulatedForSystemDistributions() {
    MetricsContainerImpl testObject = new MetricsContainerImpl("step1");
    HashMap<String, String> labels = new HashMap<>();
    labels.put(MonitoringInfoConstants.Labels.PCOLLECTION, "pcoll1");
    DistributionCell c1 = testObject.getDistribution(MonitoringInfoMetricName.named(MonitoringInfoConstants.Urns.SAMPLED_BYTE_SIZE, labels));
    c1.update(5L);
    SimpleMonitoringInfoBuilder builder1 = new SimpleMonitoringInfoBuilder();
    builder1.setUrn(MonitoringInfoConstants.Urns.SAMPLED_BYTE_SIZE).setLabel(MonitoringInfoConstants.Labels.PCOLLECTION, "pcoll1").setInt64DistributionValue(DistributionData.create(5, 1, 5, 5));
    ArrayList<MonitoringInfo> actualMonitoringInfos = new ArrayList<MonitoringInfo>();
    for (MonitoringInfo mi : testObject.getMonitoringInfos()) {
        actualMonitoringInfos.add(mi);
    }
    assertThat(actualMonitoringInfos, containsInAnyOrder(builder1.build()));
}
Also used : MonitoringInfo(org.apache.beam.model.pipeline.v1.MetricsApi.MonitoringInfo) HashMap(java.util.HashMap) ArrayList(java.util.ArrayList) Test(org.junit.Test)

Example 25 with MonitoringInfo

use of org.apache.beam.model.pipeline.v1.MetricsApi.MonitoringInfo in project beam by apache.

the class SimpleMonitoringInfoBuilderTest method testReturnsExpectedMonitoringInfo.

@Test
public void testReturnsExpectedMonitoringInfo() throws Exception {
    SimpleMonitoringInfoBuilder builder = new SimpleMonitoringInfoBuilder();
    builder.setUrn(MonitoringInfoConstants.Urns.ELEMENT_COUNT);
    builder.setInt64SumValue(1);
    builder.setLabel(MonitoringInfoConstants.Labels.PCOLLECTION, "myPcollection");
    // Pass now that the spec is fully met.
    MonitoringInfo monitoringInfo = builder.build();
    assertTrue(monitoringInfo != null);
    assertEquals("myPcollection", monitoringInfo.getLabelsOrDefault(MonitoringInfoConstants.Labels.PCOLLECTION, null));
    assertEquals(MonitoringInfoConstants.Urns.ELEMENT_COUNT, monitoringInfo.getUrn());
    assertEquals(MonitoringInfoConstants.TypeUrns.SUM_INT64_TYPE, monitoringInfo.getType());
    assertEquals(1L, decodeInt64Counter(monitoringInfo.getPayload()));
    assertEquals("myPcollection", monitoringInfo.getLabelsMap().get(MonitoringInfoConstants.Labels.PCOLLECTION));
}
Also used : MonitoringInfo(org.apache.beam.model.pipeline.v1.MetricsApi.MonitoringInfo) Test(org.junit.Test)

Aggregations

MonitoringInfo (org.apache.beam.model.pipeline.v1.MetricsApi.MonitoringInfo)40 Test (org.junit.Test)39 HashMap (java.util.HashMap)23 DataflowStepContext (org.apache.beam.runners.dataflow.worker.DataflowExecutionContext.DataflowStepContext)11 SimpleMonitoringInfoBuilder (org.apache.beam.runners.core.metrics.SimpleMonitoringInfoBuilder)10 ArrayList (java.util.ArrayList)9 NameContext (org.apache.beam.runners.dataflow.worker.counters.NameContext)9 CounterUpdate (com.google.api.services.dataflow.model.CounterUpdate)7 WindowedValue (org.apache.beam.sdk.util.WindowedValue)4 SimpleCounter (org.apache.flink.metrics.SimpleCounter)4 MetricGroupTest (org.apache.flink.runtime.metrics.groups.MetricGroupTest)4 ExecutionStateTracker (org.apache.beam.runners.core.metrics.ExecutionStateTracker)3 MetricsContainerStepMap (org.apache.beam.runners.core.metrics.MetricsContainerStepMap)3 FnDataReceiver (org.apache.beam.sdk.fn.data.FnDataReceiver)3 ByteString (org.apache.beam.vendor.grpc.v1p43p2.com.google.protobuf.ByteString)3 DistributionData (org.apache.beam.runners.core.metrics.DistributionData)2 StringUtf8Coder (org.apache.beam.sdk.coders.StringUtf8Coder)2 DistributionResult (org.apache.beam.sdk.metrics.DistributionResult)2 ArgumentMatcher (org.mockito.ArgumentMatcher)2 PrepareForTest (org.powermock.core.classloader.annotations.PrepareForTest)2