Search in sources :

Example 1 with MonitoringInfoMetricName

use of org.apache.beam.runners.core.metrics.MonitoringInfoMetricName in project beam by apache.

the class GcsUtilTest method verifyMetricWasSet.

private void verifyMetricWasSet(String projectId, String bucketId, String method, String status, long count) {
    // Verify the metric as reported.
    HashMap<String, String> labels = new HashMap<>();
    labels.put(MonitoringInfoConstants.Labels.PTRANSFORM, "");
    labels.put(MonitoringInfoConstants.Labels.SERVICE, "Storage");
    labels.put(MonitoringInfoConstants.Labels.METHOD, method);
    labels.put(MonitoringInfoConstants.Labels.GCS_PROJECT_ID, projectId);
    labels.put(MonitoringInfoConstants.Labels.GCS_BUCKET, bucketId);
    labels.put(MonitoringInfoConstants.Labels.RESOURCE, GcpResourceIdentifiers.cloudStorageBucket(bucketId));
    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)

Example 2 with MonitoringInfoMetricName

use of org.apache.beam.runners.core.metrics.MonitoringInfoMetricName in project beam by apache.

the class HarnessMonitoringInfosInstructionHandlerTest method testReturnsProcessWideMonitoringInfos.

@Test
public void testReturnsProcessWideMonitoringInfos() {
    MetricsEnvironment.setProcessWideContainer(MetricsContainerImpl.createProcessWideContainer());
    HashMap<String, String> labels = new HashMap<String, String>();
    labels.put(MonitoringInfoConstants.Labels.SERVICE, "service");
    labels.put(MonitoringInfoConstants.Labels.METHOD, "method");
    labels.put(MonitoringInfoConstants.Labels.RESOURCE, "resource");
    labels.put(MonitoringInfoConstants.Labels.PTRANSFORM, "transform");
    labels.put(MonitoringInfoConstants.Labels.STATUS, "ok");
    MonitoringInfoMetricName name = MonitoringInfoMetricName.named(MonitoringInfoConstants.Urns.API_REQUEST_COUNT, labels);
    Counter counter = LabeledMetrics.counter(name, true);
    counter.inc(7);
    ShortIdMap metricsShortIds = new ShortIdMap();
    HarnessMonitoringInfosInstructionHandler testObject = new HarnessMonitoringInfosInstructionHandler(metricsShortIds);
    BeamFnApi.InstructionRequest.Builder builder = BeamFnApi.InstructionRequest.newBuilder();
    BeamFnApi.InstructionResponse.Builder responseBuilder = testObject.harnessMonitoringInfos(builder.build());
    BeamFnApi.InstructionResponse response = responseBuilder.build();
    assertEquals(1, response.getHarnessMonitoringInfos().getMonitoringDataMap().size());
    // Expect a payload to be set for "metric0".
    assertTrue(!response.getHarnessMonitoringInfos().getMonitoringDataMap().get("metric0").isEmpty());
}
Also used : HashMap(java.util.HashMap) BeamFnApi(org.apache.beam.model.fnexecution.v1.BeamFnApi) ShortIdMap(org.apache.beam.runners.core.metrics.ShortIdMap) MonitoringInfoMetricName(org.apache.beam.runners.core.metrics.MonitoringInfoMetricName) Counter(org.apache.beam.sdk.metrics.Counter) Test(org.junit.Test)

Example 3 with MonitoringInfoMetricName

use of org.apache.beam.runners.core.metrics.MonitoringInfoMetricName in project beam by apache.

the class DatastoreV1Test method verifyMetricWasSet.

private void verifyMetricWasSet(String method, String status, String namespace, long count) {
    // Verify the metric as reported.
    HashMap<String, String> labels = new HashMap<>();
    labels.put(MonitoringInfoConstants.Labels.PTRANSFORM, "");
    labels.put(MonitoringInfoConstants.Labels.SERVICE, "Datastore");
    labels.put(MonitoringInfoConstants.Labels.METHOD, method);
    labels.put(MonitoringInfoConstants.Labels.RESOURCE, "//bigtable.googleapis.com/projects/" + PROJECT_ID + "/namespaces/" + namespace);
    labels.put(MonitoringInfoConstants.Labels.DATASTORE_PROJECT, PROJECT_ID);
    labels.put(MonitoringInfoConstants.Labels.DATASTORE_NAMESPACE, namespace);
    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)

Example 4 with MonitoringInfoMetricName

use of org.apache.beam.runners.core.metrics.MonitoringInfoMetricName in project beam by apache.

the class BigtableServiceImplTest method verifyMetricWasSet.

private void verifyMetricWasSet(String method, String status, long count) {
    // Verify the metric as reported.
    HashMap<String, String> labels = new HashMap<>();
    labels.put(MonitoringInfoConstants.Labels.PTRANSFORM, "");
    labels.put(MonitoringInfoConstants.Labels.SERVICE, "BigTable");
    labels.put(MonitoringInfoConstants.Labels.METHOD, method);
    labels.put(MonitoringInfoConstants.Labels.RESOURCE, GcpResourceIdentifiers.bigtableResource(PROJECT_ID, INSTANCE_ID, TABLE_ID));
    labels.put(MonitoringInfoConstants.Labels.BIGTABLE_PROJECT_ID, PROJECT_ID);
    labels.put(MonitoringInfoConstants.Labels.INSTANCE_ID, INSTANCE_ID);
    labels.put(MonitoringInfoConstants.Labels.TABLE_ID, GcpResourceIdentifiers.bigtableTableID(PROJECT_ID, INSTANCE_ID, TABLE_ID));
    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 5 with MonitoringInfoMetricName

use of org.apache.beam.runners.core.metrics.MonitoringInfoMetricName in project beam by apache.

the class SpannerIOWriteTest method verifyMetricWasSet.

private void verifyMetricWasSet(String projectId, String databaseId, String tableId, String method, String status, 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, method);
    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);
    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)

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