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()));
}
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()));
}
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()));
}
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()));
}
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));
}
Aggregations