Skip to content
This repository was archived by the owner on Sep 17, 2025. It is now read-only.
This repository was archived by the owner on Sep 17, 2025. It is now read-only.

Multiple apparent bugs in DistributionAggregation implementation #373

@c24t

Description

@c24t

It looks like there were a few bugs added in #149 and #287:

Exemplars are always attached to the last bucket:

from opencensus.stats.aggregation import DistributionAggregation

da = DistributionAggregation(list(map(float, range(0, 11))))
ad = da.aggregation_data

for dp in range(10):
    ad.add_sample(dp, dt.now(), {"trace_id": "dead", "span_id": "beef"})
    
ad.exemplars
{11: <opencensus.stats.aggregation_data.Exemplar at 0x10ccf6390>}

Off-by-one error adding a value greater than the last bucket boundary:

from datetime import datetime as dt

da = DistributionAggregation([1, 3, 5])
ad = da.aggregation_data

ad.add_sample(float('-inf'), dt.now(), {"trace_id": "dead", "span_id": "beef"})
ad.add_sample(2, dt.now(), {"trace_id": "dead", "span_id": "beef"})
ad.add_sample(4, dt.now(), {"trace_id": "dead", "span_id": "beef"})
ad.add_sample(float('inf'), dt.now(), {"trace_id": "dead", "span_id": "beef"})
  
ad.counts_per_bucket
[1, 1, 2, 0]

Min/max are 0 by default, which doesn't work for e.g. histograms without 0-valued points:

da = DistributionAggregation(list(map(float, range(0, 11))))
ad = da.aggregation_data

for dp in range(10, 20):
    ad.add_sample(dp, dt.now(), {"trace_id": "dead", "span_id": "beef"})
    
ad.min  # should be 10
0

...or histograms with all negative points:

da = DistributionAggregation(list(map(float, range(0, 11))))
ad = da.aggregation_data

for dp in range(-20, -10):
    ad.add_sample(dp, dt.now(), {"trace_id": "dead", "span_id": "beef"})
    
ad.max  # should be -10
0

Metadata

Metadata

Assignees

Labels

Type

No type

Projects

No projects

Milestone

No milestone

Relationships

None yet

Development

No branches or pull requests

Issue actions