use of org.apache.beam.runners.core.metrics.MonitoringInfoMetricName in project beam by apache.
the class SpannerIOReadTest method verifyMetricWasSet.
private void verifyMetricWasSet(String projectId, String databaseId, String tableId, String status, @Nullable String queryName, long count) {
// Verify the metric was reported.
HashMap<String, String> labels = new HashMap<>();
labels.put(MonitoringInfoConstants.Labels.PTRANSFORM, "");
labels.put(MonitoringInfoConstants.Labels.SERVICE, "Spanner");
labels.put(MonitoringInfoConstants.Labels.METHOD, "Read");
labels.put(MonitoringInfoConstants.Labels.RESOURCE, GcpResourceIdentifiers.spannerTable(projectId, databaseId, tableId));
labels.put(MonitoringInfoConstants.Labels.SPANNER_PROJECT_ID, projectId);
labels.put(MonitoringInfoConstants.Labels.SPANNER_DATABASE_ID, databaseId);
labels.put(MonitoringInfoConstants.Labels.SPANNER_INSTANCE_ID, tableId);
if (queryName != null) {
labels.put(MonitoringInfoConstants.Labels.SPANNER_QUERY_NAME, queryName);
}
labels.put(MonitoringInfoConstants.Labels.STATUS, status);
MonitoringInfoMetricName name = MonitoringInfoMetricName.named(MonitoringInfoConstants.Urns.API_REQUEST_COUNT, labels);
MetricsContainerImpl container = (MetricsContainerImpl) MetricsEnvironment.getProcessWideContainer();
assertEquals(count, (long) container.getCounter(name).getCumulative());
}
use of org.apache.beam.runners.core.metrics.MonitoringInfoMetricName in project beam by apache.
the class BigQueryServicesImplTest method verifyRequestMetricWasSet.
private void verifyRequestMetricWasSet(String method, String projectId, String dataset, String table, String status, long count) {
// Verify the metric as reported.
HashMap<String, String> labels = new HashMap<String, String>();
// TODO(ajamato): Add Ptransform label. Populate it as empty for now to prevent the
// SpecMonitoringInfoValidator from dropping the MonitoringInfo.
labels.put(MonitoringInfoConstants.Labels.PTRANSFORM, "");
labels.put(MonitoringInfoConstants.Labels.SERVICE, "BigQuery");
labels.put(MonitoringInfoConstants.Labels.METHOD, method);
labels.put(MonitoringInfoConstants.Labels.RESOURCE, GcpResourceIdentifiers.bigQueryTable(projectId, dataset, table));
labels.put(MonitoringInfoConstants.Labels.BIGQUERY_PROJECT_ID, projectId);
labels.put(MonitoringInfoConstants.Labels.BIGQUERY_DATASET, dataset);
labels.put(MonitoringInfoConstants.Labels.BIGQUERY_TABLE, table);
labels.put(MonitoringInfoConstants.Labels.STATUS, status);
MonitoringInfoMetricName name = MonitoringInfoMetricName.named(MonitoringInfoConstants.Urns.API_REQUEST_COUNT, labels);
MetricsContainerImpl container = (MetricsContainerImpl) MetricsEnvironment.getProcessWideContainer();
assertEquals(count, (long) container.getCounter(name).getCumulative());
}
use of org.apache.beam.runners.core.metrics.MonitoringInfoMetricName in project beam by apache.
the class PCollectionConsumerRegistryTest method testUnboundedCountersUponAccept.
@Test
public void testUnboundedCountersUponAccept() throws Exception {
mockStatic(MetricsEnvironment.class, withSettings().verboseLogging());
final String pCollectionA = "pCollectionA";
final String pTransformIdA = "pTransformIdA";
MetricsContainerStepMap metricsContainerRegistry = new MetricsContainerStepMap();
PCollectionConsumerRegistry consumers = new PCollectionConsumerRegistry(metricsContainerRegistry, mock(ExecutionStateTracker.class));
FnDataReceiver<WindowedValue<String>> consumer = mock(FnDataReceiver.class, withSettings().verboseLogging());
consumers.register(pCollectionA, pTransformIdA, consumer, StringUtf8Coder.of());
FnDataReceiver<WindowedValue<String>> wrapperConsumer = (FnDataReceiver<WindowedValue<String>>) (FnDataReceiver) consumers.getMultiplexingConsumer(pCollectionA);
WindowedValue<String> element = WindowedValue.valueInGlobalWindow("elem");
wrapperConsumer.accept(element);
verify(consumer, times(1)).accept(element);
HashMap<String, String> labels = new HashMap<String, String>();
labels.put(Labels.PCOLLECTION, "pCollectionA");
MonitoringInfoMetricName counterName = MonitoringInfoMetricName.named(MonitoringInfoConstants.Urns.ELEMENT_COUNT, labels);
assertEquals(1L, (long) metricsContainerRegistry.getUnboundContainer().getCounter(counterName).getCumulative());
}
Aggregations