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



##########
File path: sdks/python/apache_beam/utils/histogram.py
##########
@@ -0,0 +1,176 @@
+#
+# 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.
+#
+
+from __future__ import absolute_import
+from __future__ import division
+
+import logging
+import math
+import threading
+
+_LOGGER = logging.getLogger(__name__)
+
+
+class Histogram(object):
+  """A histogram that supports estimated percentile with linear interpolation.
+
+  This class is considered experimental and may break or receive backwards-
+  incompatible changes in future versions of the Apache Beam SDK.
+  """
+  def __init__(self, bucket_type):
+    self._lock = threading.Lock()
+    self._bucket_type = bucket_type
+    self._buckets = {}
+    self._num_records = 0
+    self._num_top_records = 0
+    self._num_bot_records = 0
+
+  def clear(self):
+    with self._lock:
+      self._buckets = {}
+      self._num_records = 0
+      self._num_top_records = 0
+      self._num_bot_records = 0
+
+  def record(self, *args):
+    for arg in args:
+      self._record(arg)
+
+  def _record(self, value):
+    range_from = self._bucket_type.range_from()
+    range_to = self._bucket_type.range_to()
+    with self._lock:
+      if value >= range_to:
+        _LOGGER.warning('record is out of upper bound %s: %s', range_to, value)
+        self._num_top_records += 1
+      elif value < range_from:
+        _LOGGER.warning(
+            'record is out of lower bound %s: %s', range_from, value)
+        self._num_bot_records += 1
+      else:

Review comment:
       The latency is always recorded. `self._num_bot_records` and 
`self._num_top_records` represent the buckets (-oo, range_from) and [range_to, 
-oo) respectively.




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