Skip to content

Commit 0d35a3a

Browse files
committed
WUO
1 parent 2261fec commit 0d35a3a

File tree

1 file changed

+23
-8
lines changed
  • opentelemetry-sdk/src/opentelemetry/sdk/metrics/_internal

1 file changed

+23
-8
lines changed

opentelemetry-sdk/src/opentelemetry/sdk/metrics/_internal/aggregation.py

Lines changed: 23 additions & 8 deletions
Original file line numberDiff line numberDiff line change
@@ -651,6 +651,11 @@ def aggregate(self, measurement: Measurement) -> None:
651651
measurement_value = -measurement_value
652652
value = self._value_negative
653653

654+
# The following code finds out if it is necessary to change the
655+
# buckets to hold the incoming measurement_value, changes them if
656+
# necessary. This process does not exist in
657+
# _ExplicitBucketHistogram aggregation because the buckets there
658+
# are constant in size and amount.
654659
index = self._mapping.map_to_index(measurement_value)
655660

656661
is_rescaling_needed = False
@@ -680,9 +685,6 @@ def aggregate(self, measurement: Measurement) -> None:
680685
if is_rescaling_needed:
681686

682687
scale_change = self._get_scale_change(low, high)
683-
# _downscale changes the buckets. This is the main difference
684-
# with the _ExplicitBucketHistogramAggregation, as values are
685-
# added to the histogram, the buckets can change in size.
686688
self._downscale(
687689
scale_change,
688690
self._value_positive,
@@ -717,6 +719,13 @@ def aggregate(self, measurement: Measurement) -> None:
717719
if bucket_index < 0:
718720
bucket_index += len(value.counts)
719721

722+
# Now the buckets have been changed if needed and bucket_index will
723+
# be used to increment the counter of the bucket that needs to be
724+
# incremented.
725+
726+
# This is analogous to
727+
# self._value[bisect_left(self._boundaries, measurement_value)] += 1
728+
# in _ExplicitBucketHistogramAggregation.aggregate
720729
value.increment_bucket(bucket_index)
721730

722731
def collect(
@@ -810,8 +819,6 @@ def collect(
810819
# need to be made so that they can be cumulatively aggregated
811820
# to the current buckets).
812821

813-
# TODO, implement this case
814-
815822
if (
816823
value_positive is None and
817824
self._previous_value_positive is None
@@ -913,14 +920,22 @@ def collect(
913920
- self._get_scale_change(low_negative, high_negative),
914921
)
915922

916-
# FIXME Go implementation checks if the histogram (not the mapping
917-
# but the histogram) has a count larger than zero, if not, scale
918-
# (the histogram scale) would be zero. See exponential.go 191
919923
self._downscale(
920924
self._previous_scale - min_scale,
921925
self._previous_value_positive,
922926
self._previous_value_negative,
923927
)
928+
929+
# self._merge adds the values from value to
930+
# self._previous_value, this is analogous to
931+
# self._previous_value = [
932+
# value_element + previous_value_element
933+
# for (
934+
# value_element,
935+
# previous_value_element,
936+
# ) in zip(value, self._previous_value)
937+
# ]
938+
# in _ExplicitBucketHistogramAggregation.collect.
924939
self._merge(
925940
self._previous_value_positive,
926941
value_positive,

0 commit comments

Comments
 (0)