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

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

                Author: ASF GitHub Bot
            Created on: 20/Dec/18 19:45
            Start Date: 20/Dec/18 19:45
    Worklog Time Spent: 10m 
      Work Description: ajamato commented on a change in pull request #7323: 
[BEAM-6181] Implemented msec counters support in FnApi world.
URL: https://github.com/apache/beam/pull/7323#discussion_r243388929
 
 

 ##########
 File path: 
runners/google-cloud-dataflow-java/worker/src/main/java/org/apache/beam/runners/dataflow/worker/fn/control/MSecMonitoringInfoToCounterUpdateTransformer.java
 ##########
 @@ -0,0 +1,139 @@
+/*
+ * 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.CounterMetadata;
+import com.google.api.services.dataflow.model.CounterStructuredName;
+import com.google.api.services.dataflow.model.CounterStructuredNameAndMetadata;
+import com.google.api.services.dataflow.model.CounterUpdate;
+import com.google.common.annotations.VisibleForTesting;
+import java.util.HashMap;
+import java.util.Map;
+import java.util.Optional;
+import org.apache.beam.model.fnexecution.v1.BeamFnApi.MonitoringInfo;
+import org.apache.beam.runners.core.metrics.SpecMonitoringInfoValidator;
+import 
org.apache.beam.runners.dataflow.worker.DataflowExecutionContext.DataflowStepContext;
+import 
org.apache.beam.runners.dataflow.worker.counters.DataflowCounterUpdateExtractor;
+import org.slf4j.Logger;
+import org.slf4j.LoggerFactory;
+
+public class MSecMonitoringInfoToCounterUpdateTransformer
+    implements MonitoringInfoToCounterUpdateTransformer {
+
+  private static final Logger LOG = 
LoggerFactory.getLogger(BeamFnMapTaskExecutor.class);
+
+  private SpecMonitoringInfoValidator specValidator;
+  private Map<String, DataflowStepContext> transformIdMapping;
+  private Map<String, String> urnToCounterNameMapping;
+
+  /**
+   * @param specValidator SpecMonitoringInfoValidator to utilize for default 
validation.
+   * @param transformIdMapping Mapping of PTransform ID string to 
DataflowStepContext.
+   */
+  public MSecMonitoringInfoToCounterUpdateTransformer(
+      SpecMonitoringInfoValidator specValidator,
+      Map<String, DataflowStepContext> transformIdMapping) {
+    this.specValidator = specValidator;
+    this.transformIdMapping = transformIdMapping;
+    urnToCounterNameMapping = createKnownUrnToCounterNameMapping();
+  }
+
+  /** Allows to inject members for cleaner testing. */
+  @VisibleForTesting
+  protected MSecMonitoringInfoToCounterUpdateTransformer(
+      SpecMonitoringInfoValidator specValidator,
+      Map<String, DataflowStepContext> transformIdMapping,
+      Map<String, String> urnToCounterNameMapping) {
+    this.specValidator = specValidator;
+    this.transformIdMapping = transformIdMapping;
+    this.urnToCounterNameMapping = urnToCounterNameMapping;
+  }
+
+  @VisibleForTesting
+  protected Map<String, String> createKnownUrnToCounterNameMapping() {
+    Map<String, String> result = new HashMap<>();
+    result.put("beam:metric:pardo_execution_time:start_bundle_msecs:v1", 
"start-msecs");
+    result.put("beam:metric:pardo_execution_time:process_bundle_msecs:v1", 
"process-msecs");
+    result.put("beam:metric:pardo_execution_time:finish_bundle_msecs:v1", 
"finish-msecs");
+    return result;
+  }
+
+  /**
+   * 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 (!urnToCounterNameMapping.keySet().contains(urn)) {
+      throw new RuntimeException(String.format("Received unexpected counter 
urn: %s", urn));
 
 Review comment:
   Please just drop metrics if they are invalid, don't throw an exception. This 
would be bad for many of our users, who don't care about metrics but just want 
their pipeline to finish properly.

----------------------------------------------------------------
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:
[email protected]


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

    Worklog Id:     (was: 177737)

> 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: 10h
>  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