You are viewing a plain text version of this content. The canonical link for it is here.
Posted to commits@beam.apache.org by lc...@apache.org on 2020/02/26 03:40:18 UTC

[beam] branch master updated: [BEAM-2822, BEAM-2939, BEAM-6189, BEAM-4374] Enable passing completed and remaining amounts of work using new metrics format for splittable dofns in the Python SDK.

This is an automated email from the ASF dual-hosted git repository.

lcwik pushed a commit to branch master
in repository https://gitbox.apache.org/repos/asf/beam.git


The following commit(s) were added to refs/heads/master by this push:
     new 28d163b  [BEAM-2822, BEAM-2939, BEAM-6189, BEAM-4374] Enable passing completed and remaining amounts of work using new metrics format for splittable dofns in the Python SDK.
     new c0b6019  Merge pull request #10956 from lukecwik/splittabledofn2
28d163b is described below

commit 28d163b2ca9de449925837f7b733ee33511656b4
Author: Luke Cwik <lc...@google.com>
AuthorDate: Mon Feb 24 15:04:00 2020 -0800

    [BEAM-2822, BEAM-2939, BEAM-6189, BEAM-4374] Enable passing completed and remaining amounts of work using new metrics format for splittable dofns in the Python SDK.
---
 model/pipeline/src/main/proto/metrics.proto        | 39 ++++++++++++++++++++--
 .../python/apache_beam/metrics/monitoring_infos.py |  5 ++-
 .../apache_beam/runners/worker/operations.py       | 33 +++++++++++++++++-
 3 files changed, 72 insertions(+), 5 deletions(-)

diff --git a/model/pipeline/src/main/proto/metrics.proto b/model/pipeline/src/main/proto/metrics.proto
index 02fd5ae..99a87e4 100644
--- a/model/pipeline/src/main/proto/metrics.proto
+++ b/model/pipeline/src/main/proto/metrics.proto
@@ -137,8 +137,6 @@ message MonitoringInfoSpecs {
       } ]
     }];
 
-    // TODO(BEAM-6926): Add the PTRANSFORM name as a required label after
-    // upgrading the python SDK.
     USER_DISTRIBUTION_COUNTER = 6 [(monitoring_info_spec) = {
       urn: "beam:metric:user_distribution",
       type_urn: "beam:metrics:distribution_int_64",
@@ -148,6 +146,34 @@ message MonitoringInfoSpecs {
         value: "URN utilized to report user distribution counters."
       }]
     }];
+
+    // All values reported across all beam:metric:ptransform_progress:.* metrics
+    // are of the same magnitude.
+    WORK_REMAINING = 8 [(monitoring_info_spec) = {
+      urn: "beam:metric:ptransform_progress:remaining:v1",
+      type_urn: "beam:metrics:latest_doubles",
+      required_labels: [ "PTRANSFORM" ],
+      annotations: [{
+        key: "description",
+        value: "The remaining amount of work for each active element. Each active element represents an independent amount of work not shared with any other active element."
+      }]
+    }];
+
+    // All values reported across all beam:metric:ptransform_progress:.* metrics
+    // are of the same magnitude.
+    WORK_COMPLETED = 9 [(monitoring_info_spec) = {
+      urn: "beam:metric:ptransform_progress:completed:v1",
+      type_urn: "beam:metrics:latest_doubles",
+      required_labels: [ "PTRANSFORM" ],
+      annotations: [{
+        key: "description",
+        value: "The remaining amount of work for each active element. Each active element represents an independent amount of work not shared with any other active element."
+      }]
+    }];
+
+    // TODO: Support reporting the completed and remaining amount of work for
+    // active elements that share work such as a pubsub topic where each
+    // restriction may read from a shared queue.
   }
 }
 
@@ -178,13 +204,15 @@ message MonitoringInfo {
   // valid values are:
   // beam:metrics:[sum_int_64|latest_int_64|top_n_int_64|bottom_n_int_64|
   //     sum_double|latest_double|top_n_double|bottom_n_double|
-  //     distribution_int_64|distribution_double|monitoring_data_table
+  //     distribution_int_64|distribution_double|monitoring_data_table|
+  //     latest_doubles
   string type = 2;
 
   // The Metric or monitored state.
   oneof data {
     MonitoringTableData monitoring_table_data = 3;
     Metric metric = 4;
+    bytes payload = 7;
   }
 
   enum MonitoringInfoLabels {
@@ -226,6 +254,11 @@ message MonitoringInfoTypeUrns {
 
     LATEST_INT64_TYPE = 2 [(org.apache.beam.model.pipeline.v1.beam_urn) =
                                "beam:metrics:latest_int_64"];
+
+    // iterable<double> is encoded with a beam:coder:double:v1 coder for each
+    // element.
+    LATEST_DOUBLES_TYPE = 3 [(org.apache.beam.model.pipeline.v1.beam_urn) =
+                                 "beam:metrics:latest_doubles"];
   }
 }
 
diff --git a/sdks/python/apache_beam/metrics/monitoring_infos.py b/sdks/python/apache_beam/metrics/monitoring_infos.py
index 9e031da..f143eb7 100644
--- a/sdks/python/apache_beam/metrics/monitoring_infos.py
+++ b/sdks/python/apache_beam/metrics/monitoring_infos.py
@@ -48,9 +48,11 @@ PROCESS_BUNDLE_MSECS_URN = (
 FINISH_BUNDLE_MSECS_URN = (
     common_urns.monitoring_info_specs.FINISH_BUNDLE_MSECS.spec.urn)
 TOTAL_MSECS_URN = common_urns.monitoring_info_specs.TOTAL_MSECS.spec.urn
-USER_COUNTER_URN = (common_urns.monitoring_info_specs.USER_COUNTER.spec.urn)
+USER_COUNTER_URN = common_urns.monitoring_info_specs.USER_COUNTER.spec.urn
 USER_DISTRIBUTION_COUNTER_URN = (
     common_urns.monitoring_info_specs.USER_DISTRIBUTION_COUNTER.spec.urn)
+WORK_REMAINING_URN = common_urns.monitoring_info_specs.WORK_REMAINING.spec.urn
+WORK_COMPLETED_URN = common_urns.monitoring_info_specs.WORK_COMPLETED.spec.urn
 
 # TODO(ajamato): Implement the remaining types, i.e. Double types
 # Extrema types, etc. See:
@@ -59,6 +61,7 @@ SUM_INT64_TYPE = common_urns.monitoring_info_types.SUM_INT64_TYPE.urn
 DISTRIBUTION_INT64_TYPE = (
     common_urns.monitoring_info_types.DISTRIBUTION_INT64_TYPE.urn)
 LATEST_INT64_TYPE = common_urns.monitoring_info_types.LATEST_INT64_TYPE.urn
+LATEST_DOUBLES_TYPE = common_urns.monitoring_info_types.LATEST_DOUBLES_TYPE.urn
 
 COUNTER_TYPES = set([SUM_INT64_TYPE])
 DISTRIBUTION_TYPES = set([DISTRIBUTION_INT64_TYPE])
diff --git a/sdks/python/apache_beam/runners/worker/operations.py b/sdks/python/apache_beam/runners/worker/operations.py
index 0d2f02a..6dedc7c 100644
--- a/sdks/python/apache_beam/runners/worker/operations.py
+++ b/sdks/python/apache_beam/runners/worker/operations.py
@@ -28,6 +28,7 @@ import collections
 import logging
 import sys
 import threading
+import time
 from builtins import filter
 from builtins import object
 from builtins import zip
@@ -44,6 +45,7 @@ from typing import Optional
 from typing import Tuple
 from typing import Union
 
+from apache_beam import coders
 from apache_beam import pvalue
 from apache_beam.internal import pickler
 from apache_beam.io import iobase
@@ -68,7 +70,6 @@ from apache_beam.transforms.window import GlobalWindows
 from apache_beam.utils.windowed_value import WindowedValue
 
 if TYPE_CHECKING:
-  from apache_beam.coders import coders
   from apache_beam.runners.worker.bundle_processor import ExecutionContext
   from apache_beam.runners.worker.statesampler import StateSampler
 
@@ -812,6 +813,36 @@ class SdfProcessSizedElements(DoOperation):
           current_element_progress.fraction_remaining)
     return metrics
 
+  def monitoring_infos(self, transform_id):
+    # type: (str) -> Dict[FrozenSet, metrics_pb2.MonitoringInfo]
+    with self.lock:
+      infos = super(SdfProcessSizedElements,
+                    self).monitoring_infos(transform_id)
+      current_element_progress = self.current_element_progress()
+      if current_element_progress:
+        if current_element_progress.completed_work():
+          completed = current_element_progress.completed_work()
+          remaining = current_element_progress.remaining_work()
+        else:
+          completed = current_element_progress.fraction_completed()
+          remaining = current_element_progress.fraction_remaining()
+
+        completed_mi = metrics_pb2.MonitoringInfo(
+            urn=monitoring_infos.WORK_COMPLETED_URN,
+            type=monitoring_infos.LATEST_DOUBLES_URN,
+            labels=monitoring_infos.create_labels(ptransform=transform_id),
+            payload=coders.FloatCoder().get_impl().encode_nested(completed),
+            timestamp=monitoring_infos.to_timestamp_proto(time.time()))
+        remaining_mi = metrics_pb2.MonitoringInfo(
+            urn=monitoring_infos.WORK_REMAINING_URN,
+            type=monitoring_infos.LATEST_DOUBLES_URN,
+            labels=monitoring_infos.create_labels(ptransform=transform_id),
+            payload=coders.FloatCoder().get_impl().encode_nested(remaining),
+            timestamp=monitoring_infos.to_timestamp_proto(time.time()))
+        infos[monitoring_infos.to_key(completed_mi)] = completed_mi
+        infos[monitoring_infos.to_key(remaining_mi)] = remaining_mi
+    return infos
+
   def _total_output_bytes(self):
     total = 0
     for receiver in self.tagged_receivers.values():