Search in sources :

Example 6 with MonitoringInfoMetricName

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());
}
Also used : MonitoringInfoMetricName(org.apache.beam.runners.core.metrics.MonitoringInfoMetricName) MetricsContainerImpl(org.apache.beam.runners.core.metrics.MetricsContainerImpl) HashMap(java.util.HashMap) ByteString(com.google.protobuf.ByteString)

Example 7 with MonitoringInfoMetricName

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());
}
Also used : MonitoringInfoMetricName(org.apache.beam.runners.core.metrics.MonitoringInfoMetricName) MetricsContainerImpl(org.apache.beam.runners.core.metrics.MetricsContainerImpl) HashMap(java.util.HashMap) Matchers.containsString(org.hamcrest.Matchers.containsString)

Example 8 with MonitoringInfoMetricName

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());
}
Also used : MonitoringInfoMetricName(org.apache.beam.runners.core.metrics.MonitoringInfoMetricName) MetricsContainerStepMap(org.apache.beam.runners.core.metrics.MetricsContainerStepMap) FnDataReceiver(org.apache.beam.sdk.fn.data.FnDataReceiver) ExecutionStateTracker(org.apache.beam.runners.core.metrics.ExecutionStateTracker) HashMap(java.util.HashMap) WindowedValue(org.apache.beam.sdk.util.WindowedValue) PrepareForTest(org.powermock.core.classloader.annotations.PrepareForTest) Test(org.junit.Test)

Aggregations

HashMap (java.util.HashMap)8 MonitoringInfoMetricName (org.apache.beam.runners.core.metrics.MonitoringInfoMetricName)8 MetricsContainerImpl (org.apache.beam.runners.core.metrics.MetricsContainerImpl)6 ByteString (com.google.protobuf.ByteString)2 Test (org.junit.Test)2 BeamFnApi (org.apache.beam.model.fnexecution.v1.BeamFnApi)1 ExecutionStateTracker (org.apache.beam.runners.core.metrics.ExecutionStateTracker)1 MetricsContainerStepMap (org.apache.beam.runners.core.metrics.MetricsContainerStepMap)1 ShortIdMap (org.apache.beam.runners.core.metrics.ShortIdMap)1 FnDataReceiver (org.apache.beam.sdk.fn.data.FnDataReceiver)1 Counter (org.apache.beam.sdk.metrics.Counter)1 WindowedValue (org.apache.beam.sdk.util.WindowedValue)1 Matchers.containsString (org.hamcrest.Matchers.containsString)1 PrepareForTest (org.powermock.core.classloader.annotations.PrepareForTest)1