nielm commented on a change in pull request #16547:
URL: https://github.com/apache/beam/pull/16547#discussion_r787090397



##########
File path: 
sdks/java/io/google-cloud-platform/src/main/java/org/apache/beam/sdk/io/gcp/spanner/BatchSpannerRead.java
##########
@@ -193,15 +193,16 @@ public void processElement(ProcessContext c) throws 
Exception {
     }
 
     private ServiceCallMetric createServiceCallMetric(
-        String projectId, String databaseId, String tableId) {
+        @Nullable String projectId, String databaseId, String tableId) {
       HashMap<String, String> baseLabels = new HashMap<>();
       baseLabels.put(MonitoringInfoConstants.Labels.PTRANSFORM, "");
       baseLabels.put(MonitoringInfoConstants.Labels.SERVICE, "Spanner");
       baseLabels.put(MonitoringInfoConstants.Labels.METHOD, "Read");
       baseLabels.put(
           MonitoringInfoConstants.Labels.RESOURCE,
           GcpResourceIdentifiers.spannerTable(projectId, databaseId, tableId));
-      baseLabels.put(MonitoringInfoConstants.Labels.SPANNER_PROJECT_ID, 
projectId);
+      baseLabels.put(
+          MonitoringInfoConstants.Labels.SPANNER_PROJECT_ID, (projectId == 
null ? "" : projectId));

Review comment:
       Agreed - I was going for the quick fix :) 
   
   Looking further, I am also not sure why the ServiceCallMetric is being 
rebuilt for each element processed (instead of in `@Setup`) which seems 
wasteful  -- moving to `@Setup` method there in both files.

##########
File path: 
sdks/java/io/google-cloud-platform/src/main/java/org/apache/beam/sdk/io/gcp/spanner/BatchSpannerRead.java
##########
@@ -193,15 +193,16 @@ public void processElement(ProcessContext c) throws 
Exception {
     }
 
     private ServiceCallMetric createServiceCallMetric(
-        String projectId, String databaseId, String tableId) {
+        @Nullable String projectId, String databaseId, String tableId) {
       HashMap<String, String> baseLabels = new HashMap<>();
       baseLabels.put(MonitoringInfoConstants.Labels.PTRANSFORM, "");
       baseLabels.put(MonitoringInfoConstants.Labels.SERVICE, "Spanner");
       baseLabels.put(MonitoringInfoConstants.Labels.METHOD, "Read");
       baseLabels.put(
           MonitoringInfoConstants.Labels.RESOURCE,
           GcpResourceIdentifiers.spannerTable(projectId, databaseId, tableId));
-      baseLabels.put(MonitoringInfoConstants.Labels.SPANNER_PROJECT_ID, 
projectId);
+      baseLabels.put(
+          MonitoringInfoConstants.Labels.SPANNER_PROJECT_ID, (projectId == 
null ? "" : projectId));

Review comment:
       Agreed - I was going for the quick fix :) 
   
   Looking further, I am also not sure why the ServiceCallMetric is being 
rebuilt for each element processed (instead of in `@Setup`) which seems 
wasteful  -- moving to `@Setup` method there in both files.
   
   PTAL




-- 
This is an automated message from the Apache Git Service.
To respond to the message, please log on to GitHub and use the
URL above to go to the specific comment.

To unsubscribe, e-mail: [email protected]

For queries about this service, please contact Infrastructure at:
[email protected]


Reply via email to