Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Stats: Remove min and max from Distribution. #501

Merged
merged 4 commits into from
Feb 12, 2019
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Jump to
Jump to file
Failed to load files.
Diff view
Diff view
1 change: 1 addition & 0 deletions CHANGELOG.md
Original file line number Diff line number Diff line change
Expand Up @@ -5,6 +5,7 @@
- Fix bugs in Prometheus exporter. Use ordered list for histogram buckets.
Use `UnknownMetricFamily` for `SumData` instead of `UntypedMetricFamily`.
Check if label keys and values match before exporting.
- Remove min and max from Distribution.

## 0.2.0
Released 2019-01-18
Expand Down
2 changes: 1 addition & 1 deletion opencensus/stats/aggregation.py
Original file line number Diff line number Diff line change
Expand Up @@ -153,7 +153,7 @@ def __init__(self,
self._boundaries = bucket_boundaries.BucketBoundaries(boundaries)
self._distribution = distribution or {}
self.aggregation_data = aggregation_data.DistributionAggregationData(
0, 0, float('inf'), float('-inf'), 0, None, boundaries)
0, 0, 0, None, boundaries)

@property
def boundaries(self):
Expand Down
24 changes: 0 additions & 24 deletions opencensus/stats/aggregation_data.py
Original file line number Diff line number Diff line change
Expand Up @@ -147,12 +147,6 @@ class DistributionAggregationData(BaseAggregationData):
:type count_data: int
:param count_data: the count value of the distribution

:type min_: double
:param min_: the minimum value of the distribution

:type max_: double
:param max_: the maximum value of the distribution

:type sum_of_sqd_deviations: float
:param sum_of_sqd_deviations: the sum of the sqd deviations from the mean

Expand All @@ -170,8 +164,6 @@ class DistributionAggregationData(BaseAggregationData):
def __init__(self,
mean_data,
count_data,
min_,
max_,
sum_of_sqd_deviations,
counts_per_bucket=None,
bounds=None,
Expand All @@ -184,8 +176,6 @@ def __init__(self,
super(DistributionAggregationData, self).__init__(mean_data)
self._mean_data = mean_data
self._count_data = count_data
self._min = min_
self._max = max_
self._sum_of_sqd_deviations = sum_of_sqd_deviations

if bounds is None:
Expand Down Expand Up @@ -225,16 +215,6 @@ def count_data(self):
"""The current count data"""
return self._count_data

@property
def min(self):
"""The current min value"""
return self._min

@property
def max(self):
"""The current max value"""
return self._max

@property
def sum_of_sqd_deviations(self):
"""The current sum of squared deviations from the mean"""
Expand Down Expand Up @@ -269,10 +249,6 @@ def variance(self):

def add_sample(self, value, timestamp, attachments):
"""Adding a sample to Distribution Aggregation Data"""
if value < self.min:
self._min = value
if value > self.max:
self._max = value
self._count_data += 1
bucket = self.increment_bucket_count(value)

Expand Down
2 changes: 0 additions & 2 deletions tests/unit/stats/exporters/test_stackdriver_stats.py
Original file line number Diff line number Diff line change
Expand Up @@ -886,8 +886,6 @@ def test_create_timeseries_from_distribution(self):
dad = aggregation_data_module.DistributionAggregationData(
mean_data=4.5,
count_data=100,
min_=0,
max_=9,
sum_of_sqd_deviations=825,
counts_per_bucket=[20, 20, 20, 20, 20],
bounds=[2, 4, 6, 8],
Expand Down
13 changes: 0 additions & 13 deletions tests/unit/stats/test_aggregation.py
Original file line number Diff line number Diff line change
Expand Up @@ -12,7 +12,6 @@
# See the License for the specific language governing permissions and
# limitations under the License.

from datetime import datetime
import unittest

from opencensus.stats import aggregation as aggregation_module
Expand Down Expand Up @@ -111,18 +110,6 @@ def test_constructor_explicit(self):
self.assertEqual(aggregation_module.Type.DISTRIBUTION,
distribution_aggregation.aggregation_type)

def test_min_max(self):
da = aggregation_module.DistributionAggregation([])

self.assertEqual(da.aggregation_data.min, float('inf'))
self.assertEqual(da.aggregation_data.max, float('-inf'))

for dp in range(-10, 11):
da.aggregation_data.add_sample(dp, datetime(1999, 12, 31), {})

self.assertEqual(da.aggregation_data.min, -10)
self.assertEqual(da.aggregation_data.max, 10)

def test_init_bad_boundaries(self):
"""Check that boundaries must be sorted and unique."""
with self.assertRaises(ValueError):
Expand Down
66 changes: 0 additions & 66 deletions tests/unit/stats/test_aggregation_data.py
Original file line number Diff line number Diff line change
Expand Up @@ -127,25 +127,19 @@ class TestDistributionAggregationData(unittest.TestCase):
def test_constructor(self):
mean_data = 1
count_data = 0
_min = 0
_max = 1
sum_of_sqd_deviations = mock.Mock()
counts_per_bucket = [1, 1, 1]
bounds = [1.0 / 2.0, 1]

dist_agg_data = aggregation_data_module.DistributionAggregationData(
mean_data=mean_data,
count_data=count_data,
min_=_min,
max_=_max,
sum_of_sqd_deviations=sum_of_sqd_deviations,
counts_per_bucket=counts_per_bucket,
bounds=bounds)

self.assertEqual(1, dist_agg_data.mean_data)
self.assertEqual(0, dist_agg_data.count_data)
self.assertEqual(0, dist_agg_data.min)
self.assertEqual(1, dist_agg_data.max)
self.assertEqual(sum_of_sqd_deviations,
dist_agg_data.sum_of_sqd_deviations)
self.assertEqual([1, 1, 1], dist_agg_data.counts_per_bucket)
Expand All @@ -160,8 +154,6 @@ def test_init_bad_bucket_counts(self):
aggregation_data_module.DistributionAggregationData(
mean_data=mock.Mock(),
count_data=mock.Mock(),
min_=mock.Mock(),
max_=mock.Mock(),
sum_of_sqd_deviations=mock.Mock(),
counts_per_bucket=[0, 0, 0],
bounds=[1, 2, 3])
Expand All @@ -171,8 +163,6 @@ def test_init_bad_bucket_counts(self):
aggregation_data_module.DistributionAggregationData(
mean_data=mock.Mock(),
count_data=mock.Mock(),
min_=mock.Mock(),
max_=mock.Mock(),
sum_of_sqd_deviations=mock.Mock(),
counts_per_bucket=[0, 2, -2, 0],
bounds=[1, 2, 3])
Expand All @@ -181,8 +171,6 @@ def test_init_bad_bucket_counts(self):
aggregation_data_module.DistributionAggregationData(
mean_data=mock.Mock(),
count_data=mock.Mock(),
min_=mock.Mock(),
max_=mock.Mock(),
sum_of_sqd_deviations=mock.Mock(),
counts_per_bucket=[0, 0, 0, 0],
bounds=[1, 2, 3])
Expand All @@ -193,8 +181,6 @@ def test_init_bad_bounds(self):
aggregation_data_module.DistributionAggregationData(
mean_data=mock.Mock(),
count_data=mock.Mock(),
min_=mock.Mock(),
max_=mock.Mock(),
sum_of_sqd_deviations=mock.Mock(),
counts_per_bucket=[0, 0, 0, 0],
bounds=[1, 2, 2])
Expand All @@ -204,8 +190,6 @@ def test_init_bad_bounds(self):
aggregation_data_module.DistributionAggregationData(
mean_data=mock.Mock(),
count_data=mock.Mock(),
min_=mock.Mock(),
max_=mock.Mock(),
sum_of_sqd_deviations=mock.Mock(),
counts_per_bucket=[0, 0, 0, 0],
bounds=[1, 3, 2])
Expand All @@ -215,8 +199,6 @@ def test_init_bad_bounds(self):
aggregation_data_module.DistributionAggregationData(
mean_data=mock.Mock(),
count_data=mock.Mock(),
min_=mock.Mock(),
max_=mock.Mock(),
sum_of_sqd_deviations=mock.Mock(),
counts_per_bucket=[0, 0, 0, 0],
bounds=[-1, 1, 2])
Expand All @@ -227,8 +209,6 @@ def test_init_bad_exemplars(self):
aggregation_data_module.DistributionAggregationData(
mean_data=mock.Mock(),
count_data=mock.Mock(),
min_=mock.Mock(),
max_=mock.Mock(),
sum_of_sqd_deviations=mock.Mock(),
counts_per_bucket=mock.Mock(),
bounds=None,
Expand All @@ -239,8 +219,6 @@ def test_init_bad_exemplars(self):
aggregation_data_module.DistributionAggregationData(
mean_data=mock.Mock(),
count_data=mock.Mock(),
min_=mock.Mock(),
max_=mock.Mock(),
sum_of_sqd_deviations=mock.Mock(),
counts_per_bucket=mock.Mock(),
bounds=[0, 1],
Expand All @@ -256,26 +234,20 @@ def test_constructor_with_exemplar(self):
]
mean_data = 2.59
count_data = 3
_min = .07
_max = 7
sum_of_sqd_deviations = mock.Mock()
counts_per_bucket = [1, 1, 1]
bounds = [1.0 / 2.0, 1]

dist_agg_data = aggregation_data_module.DistributionAggregationData(
mean_data=mean_data,
count_data=count_data,
min_=_min,
max_=_max,
sum_of_sqd_deviations=sum_of_sqd_deviations,
exemplars=exemplars,
counts_per_bucket=counts_per_bucket,
bounds=bounds)

self.assertEqual(dist_agg_data.mean_data, mean_data)
self.assertEqual(dist_agg_data.count_data, count_data)
self.assertEqual(dist_agg_data.min, _min)
self.assertEqual(dist_agg_data.max, _max)
self.assertEqual(dist_agg_data.sum_of_sqd_deviations,
sum_of_sqd_deviations)
self.assertEqual(dist_agg_data.counts_per_bucket, counts_per_bucket)
Expand Down Expand Up @@ -339,16 +311,12 @@ def test_exemplar_int_attachment_value(self):
def test_variance(self):
mean_data = mock.Mock()
count_data = 0
_min = mock.Mock()
_max = mock.Mock()
sum_of_sqd_deviations = mock.Mock()
counts_per_bucket = [1, 1, 1]
bounds = [1.0 / 2.0, 1]
dist_agg_data = aggregation_data_module.DistributionAggregationData(
mean_data=mean_data,
count_data=count_data,
min_=_min,
max_=_max,
sum_of_sqd_deviations=sum_of_sqd_deviations,
counts_per_bucket=counts_per_bucket,
bounds=bounds)
Expand All @@ -359,8 +327,6 @@ def test_variance(self):
dist_agg_data = aggregation_data_module.DistributionAggregationData(
mean_data=mean_data,
count_data=count_data,
min_=_min,
max_=_max,
sum_of_sqd_deviations=sum_of_sqd_deviations,
counts_per_bucket=counts_per_bucket,
bounds=bounds)
Expand All @@ -369,8 +335,6 @@ def test_variance(self):
def test_add_sample(self):
mean_data = 1.0
count_data = 0
_min = 0
_max = 1
sum_of_sqd_deviations = 2
counts_per_bucket = [1, 1, 1, 1]
bounds = [0.5, 1, 1.5]
Expand All @@ -380,24 +344,18 @@ def test_add_sample(self):
dist_agg_data = aggregation_data_module.DistributionAggregationData(
mean_data=mean_data,
count_data=count_data,
min_=_min,
max_=_max,
sum_of_sqd_deviations=sum_of_sqd_deviations,
counts_per_bucket=counts_per_bucket,
bounds=bounds)

dist_agg_data.add_sample(value, None, None)
self.assertEqual(0, dist_agg_data.min)
self.assertEqual(3, dist_agg_data.max)
self.assertEqual(1, dist_agg_data.count_data)
self.assertEqual(value, dist_agg_data.mean_data)

count_data = 1
dist_agg_data = aggregation_data_module.DistributionAggregationData(
mean_data=mean_data,
count_data=count_data,
min_=_min,
max_=_max,
sum_of_sqd_deviations=sum_of_sqd_deviations,
counts_per_bucket=counts_per_bucket,
bounds=bounds)
Expand All @@ -408,15 +366,9 @@ def test_add_sample(self):
self.assertEqual(4.0, dist_agg_data.sum_of_sqd_deviations)
self.assertIsNot(0, dist_agg_data.count_data)

value_2 = -1
dist_agg_data.add_sample(value_2, None, None)
self.assertEqual(value_2, dist_agg_data.min)

def test_add_sample_attachment(self):
mean_data = 1.0
count_data = 1
_min = 0
_max = 1
sum_of_sqd_deviations = 2
counts_per_bucket = [1, 1, 1, 1]
bounds = [0.5, 1, 1.5]
Expand All @@ -430,8 +382,6 @@ def test_add_sample_attachment(self):
dist_agg_data = aggregation_data_module.DistributionAggregationData(
mean_data=mean_data,
count_data=count_data,
min_=_min,
max_=_max,
sum_of_sqd_deviations=sum_of_sqd_deviations,
counts_per_bucket=counts_per_bucket,
bounds=bounds,
Expand All @@ -440,8 +390,6 @@ def test_add_sample_attachment(self):
self.assertEqual(dist_agg_data.exemplars[3], exemplar_1)

dist_agg_data.add_sample(value, timestamp, attachments)
self.assertEqual(0, dist_agg_data.min)
self.assertEqual(3, dist_agg_data.max)
self.assertEqual(2, dist_agg_data.count_data)
self.assertEqual(2.0, dist_agg_data.mean_data)
# Check that adding a sample overwrites the bucket's exemplar
Expand All @@ -453,8 +401,6 @@ def test_add_sample_attachment(self):
dist_agg_data = aggregation_data_module.DistributionAggregationData(
mean_data=mean_data,
count_data=count_data,
min_=_min,
max_=_max,
sum_of_sqd_deviations=sum_of_sqd_deviations,
counts_per_bucket=[2, 1, 2, 1, 1, 1],
bounds=[1, 2, 3, 4, 5])
Expand All @@ -469,8 +415,6 @@ def test_add_sample_attachment(self):
def test_increment_bucket_count(self):
mean_data = mock.Mock()
count_data = mock.Mock()
_min = 0
_max = 1
sum_of_sqd_deviations = mock.Mock()
counts_per_bucket = [0]
bounds = []
Expand All @@ -480,8 +424,6 @@ def test_increment_bucket_count(self):
dist_agg_data = aggregation_data_module.DistributionAggregationData(
mean_data=mean_data,
count_data=count_data,
min_=_min,
max_=_max,
sum_of_sqd_deviations=sum_of_sqd_deviations,
counts_per_bucket=counts_per_bucket,
bounds=bounds)
Expand All @@ -495,8 +437,6 @@ def test_increment_bucket_count(self):
dist_agg_data = aggregation_data_module.DistributionAggregationData(
mean_data=mean_data,
count_data=count_data,
min_=_min,
max_=_max,
sum_of_sqd_deviations=sum_of_sqd_deviations,
counts_per_bucket=counts_per_bucket,
bounds=bounds)
Expand All @@ -509,8 +449,6 @@ def test_increment_bucket_count(self):
dist_agg_data = aggregation_data_module.DistributionAggregationData(
mean_data=mean_data,
count_data=count_data,
min_=_min,
max_=_max,
sum_of_sqd_deviations=sum_of_sqd_deviations,
counts_per_bucket=counts_per_bucket,
bounds=bounds)
Expand All @@ -529,8 +467,6 @@ def test_to_point(self):
dist_agg_data = aggregation_data_module.DistributionAggregationData(
mean_data=50,
count_data=99,
min_=1,
max_=99,
sum_of_sqd_deviations=80850.0,
counts_per_bucket=[0, 9, 90, 0],
bounds=[1, 10, 100],
Expand Down Expand Up @@ -561,8 +497,6 @@ def test_to_point_no_histogram(self):
dist_agg_data = aggregation_data_module.DistributionAggregationData(
mean_data=50,
count_data=99,
min_=1,
max_=99,
sum_of_sqd_deviations=80850.0,
)
converted_point = dist_agg_data.to_point(timestamp)
Expand Down