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

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

                Author: ASF GitHub Bot
            Created on: 25/Mar/19 18:08
            Start Date: 25/Mar/19 18:08
    Worklog Time Spent: 10m 
      Work Description: pabloem commented on pull request #8095: [BEAM-6824] 
Add Element count transformer for Java worker FnApi
URL: https://github.com/apache/beam/pull/8095#discussion_r268782000
 
 

 ##########
 File path: 
runners/google-cloud-dataflow-java/worker/src/main/java/org/apache/beam/runners/dataflow/worker/fn/control/ElementCountMonitoringInfoToCounterUpdateTransformer.java
 ##########
 @@ -0,0 +1,113 @@
+/*
+ * Licensed to the Apache Software Foundation (ASF) under one
+ * or more contributor license agreements.  See the NOTICE file
+ * distributed with this work for additional information
+ * regarding copyright ownership.  The ASF licenses this file
+ * to you under the Apache License, Version 2.0 (the
+ * "License"); you may not use this file except in compliance
+ * with the License.  You may obtain a copy of the License at
+ *
+ *     http://www.apache.org/licenses/LICENSE-2.0
+ *
+ * Unless required by applicable law or agreed to in writing, software
+ * distributed under the License is distributed on an "AS IS" BASIS,
+ * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
+ * See the License for the specific language governing permissions and
+ * limitations under the License.
+ */
+package org.apache.beam.runners.dataflow.worker.fn.control;
+
+import com.google.api.services.dataflow.model.CounterUpdate;
+import com.google.api.services.dataflow.model.NameAndKind;
+import java.util.Map;
+import java.util.Optional;
+import org.apache.beam.model.pipeline.v1.MetricsApi.MonitoringInfo;
+import org.apache.beam.runners.core.metrics.SpecMonitoringInfoValidator;
+import 
org.apache.beam.runners.dataflow.worker.counters.DataflowCounterUpdateExtractor;
+import org.apache.beam.runners.dataflow.worker.counters.NameContext;
+import org.slf4j.Logger;
+import org.slf4j.LoggerFactory;
+
+/** MonitoringInfo to CounterUpdate transformer capable to transform 
ElementCount counters. */
+public class ElementCountMonitoringInfoToCounterUpdateTransformer
+    implements MonitoringInfoToCounterUpdateTransformer {
+
+  private static final Logger LOG = 
LoggerFactory.getLogger(BeamFnMapTaskExecutor.class);
+
+  private final SpecMonitoringInfoValidator specValidator;
+  private final Map<String, NameContext> pcollectionIdToNameContext;
+  private static final String supportedUrn = "beam:metric:element_count:v1";
+
+  /**
+   * @param specValidator SpecMonitoringInfoValidator to utilize for default 
validation.
+   * @param pcollectionIdToNameContext This mapping is utilized to generate 
DFE CounterUpdate name.
+   */
+  public ElementCountMonitoringInfoToCounterUpdateTransformer(
+      SpecMonitoringInfoValidator specValidator,
+      Map<String, NameContext> pcollectionIdToNameContext) {
+    this.specValidator = specValidator;
+    this.pcollectionIdToNameContext = pcollectionIdToNameContext;
+  }
+
+  /**
+   * Validates provided monitoring info against specs and common safety checks.
+   *
+   * @param monitoringInfo to validate.
+   * @return Optional.empty() all validation checks are passed. Optional with 
error text otherwise.
+   * @throws RuntimeException if received unexpected urn.
+   */
+  protected Optional<String> validate(MonitoringInfo monitoringInfo) {
+    Optional<String> validatorResult = specValidator.validate(monitoringInfo);
+    if (validatorResult.isPresent()) {
+      return validatorResult;
+    }
+
+    String urn = monitoringInfo.getUrn();
+    if (!urn.equals(supportedUrn)) {
+      throw new RuntimeException(String.format("Received unexpected counter 
urn: %s", urn));
+    }
+
+    // todo(migryz): extract and utilize pcollection label from 
beam_fn_api.proto
+    if 
(!pcollectionIdToNameContext.containsKey(monitoringInfo.getLabelsMap().get("PCOLLECTION")))
 {
+      return Optional.of(
+          "Encountered ElementCount MonitoringInfo with unknown PCollectionId: 
"
+              + monitoringInfo.toString());
+    }
+
+    return Optional.empty();
+  }
+
+  /**
+   * Generates CounterUpdate to send to DFE based on ElementCount 
MonitoringInfo.
+   *
+   * @param monitoringInfo Monitoring info to transform.
+   * @return CounterUpdate generated based on provided monitoringInfo
+   */
+  @Override
+  public CounterUpdate transform(MonitoringInfo monitoringInfo) {
+    Optional<String> validationResult = validate(monitoringInfo);
+    if (validationResult.isPresent()) {
+      LOG.info(validationResult.get());
+      return null;
+    }
+
+    long value = monitoringInfo.getMetric().getCounterData().getInt64Value();
+
+    final String pcollectionId = 
monitoringInfo.getLabelsMap().get("PCOLLECTION");
+    final String pcollectionName = 
pcollectionIdToNameContext.get(pcollectionId).userName();
 
 Review comment:
   I don't quite remember for sure, so I want to validate: We're supposed to 
use the user-given name of the step here? We don't use the `s2`-looking, 
system-generated one?
 
----------------------------------------------------------------
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.
 
For queries about this service, please contact Infrastructure at:
[email protected]


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

    Worklog Id:     (was: 218193)
    Time Spent: 2h 10m  (was: 2h)

> Plumb FnApi ElementCount metrics in Dataflow Runner.
> ----------------------------------------------------
>
>                 Key: BEAM-6824
>                 URL: https://issues.apache.org/jira/browse/BEAM-6824
>             Project: Beam
>          Issue Type: New Feature
>          Components: runner-dataflow
>            Reporter: Mikhail Gryzykhin
>            Assignee: Mikhail Gryzykhin
>            Priority: Major
>          Time Spent: 2h 10m
>  Remaining Estimate: 0h
>
> We want to provide FnApi metrics to Dataflow Users.
> This bug covers ElementCount metric.
> Current approach utilizes mapping of PCollectionID based on WorkItem and 
> ProcessBundle graphs.



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

Reply via email to