ajamato commented on a change in pull request #15183:
URL: https://github.com/apache/beam/pull/15183#discussion_r678533074



##########
File path: 
sdks/java/io/google-cloud-platform/src/main/java/org/apache/beam/sdk/io/gcp/datastore/DatastoreV1.java
##########
@@ -1460,6 +1495,12 @@ private void flushBatch() throws DatastoreException, 
IOException, InterruptedExc
           // Break if the commit threw no exception.
           break;
         } catch (DatastoreException exception) {
+          GoogleJsonError.ErrorInfo errorInfo = getErrorInfo(exception);
+          if (errorInfo == null) {
+            serviceCallMetric.call(ServiceCallMetric.CANONICAL_STATUS_UNKNOWN);
+          } else {
+            serviceCallMetric.call(errorInfo.getReason());

Review comment:
       I am not fully convinced this is the proper error handling logic to 
extract the http or grpc status code here.
   
   DatastoreException has an
   int getCode() this should return the http code which serviceCallMetri.call() 
will convert to a grpc status code.
   
   So lets's just change the logic to
   
    } catch (DatastoreException exception) {
             serviceCallMetric.call(exception.getCode());
              ....
              
   and we can remove getErrorInfo

##########
File path: 
sdks/java/io/google-cloud-platform/src/main/java/org/apache/beam/sdk/io/gcp/datastore/DatastoreV1.java
##########
@@ -1630,4 +1671,17 @@ public QuerySplitter getQuerySplitter() {
       return DatastoreHelper.getQuerySplitter();
     }
   }
+
+  private static GoogleJsonError.ErrorInfo getErrorInfo(Exception e) {
+    if (!(e instanceof GoogleJsonResponseException)) {
+      return null;
+    }
+    GoogleJsonError jsonError = ((GoogleJsonResponseException) e).getDetails();
+    GoogleJsonError.ErrorInfo errorInfo = 
Iterables.getFirst(jsonError.getErrors(), null);
+    return errorInfo;
+  }
+
+  private static String getNameSpace(String projectId, String namespace) {

Review comment:
       Please add this to 
GCPResourceIdentifiers.java/GCPResourceIdentifiersTest.java
   and use this signature
     public static String datastoreNamespace(String projectId, String 
namespace) {
   
   
   
https://github.com/apache/beam/blob/master/runners/core-java/src/main/java/org/apache/beam/runners/core/metrics/GcpResourceIdentifiers.java
   

##########
File path: 
sdks/java/io/google-cloud-platform/src/main/java/org/apache/beam/sdk/io/gcp/datastore/DatastoreV1.java
##########
@@ -1447,9 +1471,20 @@ private void flushBatch() throws DatastoreException, 
IOException, InterruptedExc
           continue;
         }
 
+        HashMap<String, String> baseLabels = new HashMap<>();
+        baseLabels.put(MonitoringInfoConstants.Labels.PTRANSFORM, "");
+        baseLabels.put(MonitoringInfoConstants.Labels.SERVICE, "Datastore");
+        baseLabels.put(MonitoringInfoConstants.Labels.METHOD, "flushBatch");

Review comment:
       Lets use this method name
   "BatchDatastoreWrite"
   
   To refer to writing a batch of elements to datastore.
   Thus, if we change the API in a refactoring at some point, we can continue 
to use this method label.

##########
File path: 
sdks/java/io/google-cloud-platform/src/main/java/org/apache/beam/sdk/io/gcp/datastore/DatastoreV1.java
##########
@@ -901,12 +907,30 @@ private RunQueryResponse 
runQueryWithRetries(RunQueryRequest request) throws Exc
         Sleeper sleeper = Sleeper.DEFAULT;
         BackOff backoff = RUNQUERY_BACKOFF.backoff();
         while (true) {
+          HashMap<String, String> baseLabels = new HashMap<>();
+          baseLabels.put(MonitoringInfoConstants.Labels.PTRANSFORM, "");
+          baseLabels.put(MonitoringInfoConstants.Labels.SERVICE, "Datastore");
+          baseLabels.put(MonitoringInfoConstants.Labels.METHOD, 
"runQueryWithRetries");

Review comment:
       Lets use this method name
   "BatchDatastoreRead"
   
   To refer to reading a batch of elements to datastore.
   Thus, if we change the API in a refactoring at some point, we can continue 
to use this method label.




-- 
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