[ 
https://issues.apache.org/jira/browse/BEAM-6181?focusedWorklogId=172501&page=com.atlassian.jira.plugin.system.issuetabpanels:worklog-tabpanel#worklog-172501
 ]

ASF GitHub Bot logged work on BEAM-6181:
----------------------------------------

                Author: ASF GitHub Bot
            Created on: 05/Dec/18 22:04
            Start Date: 05/Dec/18 22:04
    Worklog Time Spent: 10m 
      Work Description: ajamato commented on a change in pull request #7202: 
[BEAM-6181] Reporting user counters via MonitoringInfos in Portable Dataflow 
Runner.
URL: https://github.com/apache/beam/pull/7202#discussion_r239254686
 
 

 ##########
 File path: 
runners/google-cloud-dataflow-java/worker/src/main/java/org/apache/beam/runners/dataflow/worker/fn/control/BeamFnMapTaskExecutor.java
 ##########
 @@ -351,7 +398,106 @@ void updateProgress() {
       }
     }
 
-    private void updateMetrics(BeamFnApi.Metrics metrics) {
+    // Keeping this as static class for this iteration. Will extract to 
separate file and generalize
+    // when more counter types are added.
+    // todomigryz: define counter transformer factory
+    // that can provide respective counter transformer for different type of 
counters.
+    // (ie RowCountCounterTranformer, MSecCounterTransformer, 
UserCounterTransformer, etc)
+    private static class MonitoringInfoToCounterUpdateTransformer {
+
+      private final Map<String, DataflowStepContext> transformIdMapping;
+
+      public MonitoringInfoToCounterUpdateTransformer(
+          final Map<String, DataflowStepContext> transformIdMapping) {
+        this.transformIdMapping = transformIdMapping;
+      }
+
+      // todo: search code for "beam:metrics"... and replace them with 
relevant enums from
+      // proto after rebasing above https://github.com/apache/beam/pull/6799 
that
+      // introduces relevant proto entries.
+      final String BEAM_METRICS_USER_PREFIX = "beam:metric:user";
+
+      private CounterUpdate monitoringInfoToCounterUpdate(MonitoringInfo 
monitoringInfo) {
+        long value = 
monitoringInfo.getMetric().getCounterData().getInt64Value();
+        String urn = monitoringInfo.getUrn();
+
+        String type = monitoringInfo.getType();
+
+        // todo: run MonitoringInfo through validation process.
+        // refer to https://github.com/apache/beam/pull/6799
+
+        if (urn.startsWith(BEAM_METRICS_USER_PREFIX)) {
+          if (!type.equals("beam:metrics:sum_int_64")) {
+            return null;
+          }
+
+          final String ptransform = 
monitoringInfo.getLabelsMap().get("PTRANSFORM");
+          if (ptransform == null) {
+            return null;
+          }
+
+          DataflowStepContext stepContext = transformIdMapping.get(ptransform);
+
+          CounterStructuredNameAndMetadata name = new 
CounterStructuredNameAndMetadata();
+
+          String nameWithNamespace =
+              monitoringInfo
+                  .getUrn()
+                  .substring(BEAM_METRICS_USER_PREFIX.length())
+                  .replace("^:", "");
+
+          final int lastColonIndex = nameWithNamespace.lastIndexOf(':');
+          String counterName = nameWithNamespace.substring(lastColonIndex + 1);
+          String counterNamespace = nameWithNamespace.substring(0, 
lastColonIndex);
+
+          name.setName(
+                  new CounterStructuredName()
+                      .setOrigin(Origin.USER.toString())
+                      // Workaround for bug in python sdk that missed colon 
after ...metric:user.
+                      .setName(counterName)
+                      .setOriginalStepName(
+                          stepContext == null ? null : 
stepContext.getNameContext().originalName())
+                      .setExecutionStepName(
+                          stepContext == null ? null : 
stepContext.getNameContext().systemName())
+                      .setOriginNamespace(counterNamespace))
+              .setMetadata(new CounterMetadata().setKind("SUM"));
+
+          return new CounterUpdate()
+              .setStructuredNameAndMetadata(name)
+              .setCumulative(false)
+              
.setInteger(DataflowCounterUpdateExtractor.longToSplitInt(value));
+        }
+        return null;
+      }
+    }
+
+    private void updateMetrics(List<MonitoringInfo> monitoringInfos) {
+      final MonitoringInfoToCounterUpdateTransformer 
monitoringInfoToCounterUpdateTransformer =
+          new MonitoringInfoToCounterUpdateTransformer(
+              bundleProcessOperation.getPtransformIdToUserStepContext());
+      String miDump =
 
 Review comment:
   rm debug code

----------------------------------------------------------------
This is an automated message from the Apache Git Service.
To respond to the message, please log on GitHub and use the
URL above to go to the specific comment.
 
For queries about this service, please contact Infrastructure at:
us...@infra.apache.org


Issue Time Tracking
-------------------

    Worklog Id:     (was: 172501)
    Time Spent: 2.5h  (was: 2h 20m)

> Utilize MetricInfo for reporting user metrics in Portable Dataflow Java 
> Runner.
> -------------------------------------------------------------------------------
>
>                 Key: BEAM-6181
>                 URL: https://issues.apache.org/jira/browse/BEAM-6181
>             Project: Beam
>          Issue Type: Bug
>          Components: java-fn-execution
>            Reporter: Mikhail Gryzykhin
>            Assignee: Mikhail Gryzykhin
>            Priority: Major
>          Time Spent: 2.5h
>  Remaining Estimate: 0h
>
> New approach to report metrics in FnApi is to utilize MetricInfo structures.
> This approach is implemented in Python SDK and work is ongoing in Java SDK.
> This tasks includes plumbing User metrics reported via MetricInfos through 
> Dataflow Java Runner. 



--
This message was sent by Atlassian JIRA
(v7.6.3#76005)

Reply via email to