ihji commented on a change in pull request #13017:
URL: https://github.com/apache/beam/pull/13017#discussion_r505806435



##########
File path: sdks/python/apache_beam/metrics/cells.py
##########
@@ -238,6 +250,57 @@ def to_runner_api_monitoring_info(self, name, 
transform_id):
         ptransform=transform_id)
 
 
+class HistogramCell(MetricCell):
+  """For internal use only; no backwards-compatibility guarantees.
+
+  Tracks the current value and delta for a histogram metric.
+
+  Each cell tracks the state of a metric independently per context per bundle.
+  Therefore, each metric has a different cell in each bundle, that is later
+  aggregated.
+
+  This class is thread safe since underlying histogram object is thread safe.
+  """
+  def __init__(self, bucket_type):
+    self._bucket_type = bucket_type
+    self.data = HistogramAggregator(bucket_type).identity_element()
+
+  def reset(self):
+    self.data = HistogramAggregator(self._bucket_type).identity_element()
+
+  def combine(self, other):
+    # type: (HistogramCell) -> HistogramCell
+    result = HistogramCell(self._bucket_type)
+    result.data = self.data.combine(other.data)
+    return result
+
+  def update(self, value):
+    self.data.histogram.record(value)
+
+  def get_cumulative(self):
+    # type: () -> HistogramData
+    return self.data.get_cumulative()
+
+  def to_runner_api_monitoring_info(self, name, transform_id):
+    return None
+
+
+class HistogramCellFactory(MetricCellFactory):

Review comment:
       `MetricCellFactory` creates a customized factory instance for creating 
`MetricCell`. Currently, `MetricCell` is created from `Type[MetricCell]` and 
cannot be parameterized. `HistogramCell` needs to support multiple bucket types 
with their own parameters so creating from singleton type objects didn't work. 




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


Reply via email to