Skip to content

Commit 6c472df

Browse files
authored
Stats: Remove min and max from Distribution. (census-instrumentation#501)
1 parent b99997d commit 6c472df

File tree

6 files changed

+2
-106
lines changed

6 files changed

+2
-106
lines changed

CHANGELOG.md

Lines changed: 1 addition & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -5,6 +5,7 @@
55
- Fix bugs in Prometheus exporter. Use ordered list for histogram buckets.
66
Use `UnknownMetricFamily` for `SumData` instead of `UntypedMetricFamily`.
77
Check if label keys and values match before exporting.
8+
- Remove min and max from Distribution.
89

910
## 0.2.0
1011
Released 2019-01-18

opencensus/stats/aggregation.py

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -153,7 +153,7 @@ def __init__(self,
153153
self._boundaries = bucket_boundaries.BucketBoundaries(boundaries)
154154
self._distribution = distribution or {}
155155
self.aggregation_data = aggregation_data.DistributionAggregationData(
156-
0, 0, float('inf'), float('-inf'), 0, None, boundaries)
156+
0, 0, 0, None, boundaries)
157157

158158
@property
159159
def boundaries(self):

opencensus/stats/aggregation_data.py

Lines changed: 0 additions & 24 deletions
Original file line numberDiff line numberDiff line change
@@ -147,12 +147,6 @@ class DistributionAggregationData(BaseAggregationData):
147147
:type count_data: int
148148
:param count_data: the count value of the distribution
149149
150-
:type min_: double
151-
:param min_: the minimum value of the distribution
152-
153-
:type max_: double
154-
:param max_: the maximum value of the distribution
155-
156150
:type sum_of_sqd_deviations: float
157151
:param sum_of_sqd_deviations: the sum of the sqd deviations from the mean
158152
@@ -170,8 +164,6 @@ class DistributionAggregationData(BaseAggregationData):
170164
def __init__(self,
171165
mean_data,
172166
count_data,
173-
min_,
174-
max_,
175167
sum_of_sqd_deviations,
176168
counts_per_bucket=None,
177169
bounds=None,
@@ -184,8 +176,6 @@ def __init__(self,
184176
super(DistributionAggregationData, self).__init__(mean_data)
185177
self._mean_data = mean_data
186178
self._count_data = count_data
187-
self._min = min_
188-
self._max = max_
189179
self._sum_of_sqd_deviations = sum_of_sqd_deviations
190180

191181
if bounds is None:
@@ -225,16 +215,6 @@ def count_data(self):
225215
"""The current count data"""
226216
return self._count_data
227217

228-
@property
229-
def min(self):
230-
"""The current min value"""
231-
return self._min
232-
233-
@property
234-
def max(self):
235-
"""The current max value"""
236-
return self._max
237-
238218
@property
239219
def sum_of_sqd_deviations(self):
240220
"""The current sum of squared deviations from the mean"""
@@ -269,10 +249,6 @@ def variance(self):
269249

270250
def add_sample(self, value, timestamp, attachments):
271251
"""Adding a sample to Distribution Aggregation Data"""
272-
if value < self.min:
273-
self._min = value
274-
if value > self.max:
275-
self._max = value
276252
self._count_data += 1
277253
bucket = self.increment_bucket_count(value)
278254

tests/unit/stats/exporters/test_stackdriver_stats.py

Lines changed: 0 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -886,8 +886,6 @@ def test_create_timeseries_from_distribution(self):
886886
dad = aggregation_data_module.DistributionAggregationData(
887887
mean_data=4.5,
888888
count_data=100,
889-
min_=0,
890-
max_=9,
891889
sum_of_sqd_deviations=825,
892890
counts_per_bucket=[20, 20, 20, 20, 20],
893891
bounds=[2, 4, 6, 8],

tests/unit/stats/test_aggregation.py

Lines changed: 0 additions & 13 deletions
Original file line numberDiff line numberDiff line change
@@ -12,7 +12,6 @@
1212
# See the License for the specific language governing permissions and
1313
# limitations under the License.
1414

15-
from datetime import datetime
1615
import unittest
1716

1817
from opencensus.stats import aggregation as aggregation_module
@@ -111,18 +110,6 @@ def test_constructor_explicit(self):
111110
self.assertEqual(aggregation_module.Type.DISTRIBUTION,
112111
distribution_aggregation.aggregation_type)
113112

114-
def test_min_max(self):
115-
da = aggregation_module.DistributionAggregation([])
116-
117-
self.assertEqual(da.aggregation_data.min, float('inf'))
118-
self.assertEqual(da.aggregation_data.max, float('-inf'))
119-
120-
for dp in range(-10, 11):
121-
da.aggregation_data.add_sample(dp, datetime(1999, 12, 31), {})
122-
123-
self.assertEqual(da.aggregation_data.min, -10)
124-
self.assertEqual(da.aggregation_data.max, 10)
125-
126113
def test_init_bad_boundaries(self):
127114
"""Check that boundaries must be sorted and unique."""
128115
with self.assertRaises(ValueError):

tests/unit/stats/test_aggregation_data.py

Lines changed: 0 additions & 66 deletions
Original file line numberDiff line numberDiff line change
@@ -127,25 +127,19 @@ class TestDistributionAggregationData(unittest.TestCase):
127127
def test_constructor(self):
128128
mean_data = 1
129129
count_data = 0
130-
_min = 0
131-
_max = 1
132130
sum_of_sqd_deviations = mock.Mock()
133131
counts_per_bucket = [1, 1, 1]
134132
bounds = [1.0 / 2.0, 1]
135133

136134
dist_agg_data = aggregation_data_module.DistributionAggregationData(
137135
mean_data=mean_data,
138136
count_data=count_data,
139-
min_=_min,
140-
max_=_max,
141137
sum_of_sqd_deviations=sum_of_sqd_deviations,
142138
counts_per_bucket=counts_per_bucket,
143139
bounds=bounds)
144140

145141
self.assertEqual(1, dist_agg_data.mean_data)
146142
self.assertEqual(0, dist_agg_data.count_data)
147-
self.assertEqual(0, dist_agg_data.min)
148-
self.assertEqual(1, dist_agg_data.max)
149143
self.assertEqual(sum_of_sqd_deviations,
150144
dist_agg_data.sum_of_sqd_deviations)
151145
self.assertEqual([1, 1, 1], dist_agg_data.counts_per_bucket)
@@ -160,8 +154,6 @@ def test_init_bad_bucket_counts(self):
160154
aggregation_data_module.DistributionAggregationData(
161155
mean_data=mock.Mock(),
162156
count_data=mock.Mock(),
163-
min_=mock.Mock(),
164-
max_=mock.Mock(),
165157
sum_of_sqd_deviations=mock.Mock(),
166158
counts_per_bucket=[0, 0, 0],
167159
bounds=[1, 2, 3])
@@ -171,8 +163,6 @@ def test_init_bad_bucket_counts(self):
171163
aggregation_data_module.DistributionAggregationData(
172164
mean_data=mock.Mock(),
173165
count_data=mock.Mock(),
174-
min_=mock.Mock(),
175-
max_=mock.Mock(),
176166
sum_of_sqd_deviations=mock.Mock(),
177167
counts_per_bucket=[0, 2, -2, 0],
178168
bounds=[1, 2, 3])
@@ -181,8 +171,6 @@ def test_init_bad_bucket_counts(self):
181171
aggregation_data_module.DistributionAggregationData(
182172
mean_data=mock.Mock(),
183173
count_data=mock.Mock(),
184-
min_=mock.Mock(),
185-
max_=mock.Mock(),
186174
sum_of_sqd_deviations=mock.Mock(),
187175
counts_per_bucket=[0, 0, 0, 0],
188176
bounds=[1, 2, 3])
@@ -193,8 +181,6 @@ def test_init_bad_bounds(self):
193181
aggregation_data_module.DistributionAggregationData(
194182
mean_data=mock.Mock(),
195183
count_data=mock.Mock(),
196-
min_=mock.Mock(),
197-
max_=mock.Mock(),
198184
sum_of_sqd_deviations=mock.Mock(),
199185
counts_per_bucket=[0, 0, 0, 0],
200186
bounds=[1, 2, 2])
@@ -204,8 +190,6 @@ def test_init_bad_bounds(self):
204190
aggregation_data_module.DistributionAggregationData(
205191
mean_data=mock.Mock(),
206192
count_data=mock.Mock(),
207-
min_=mock.Mock(),
208-
max_=mock.Mock(),
209193
sum_of_sqd_deviations=mock.Mock(),
210194
counts_per_bucket=[0, 0, 0, 0],
211195
bounds=[1, 3, 2])
@@ -215,8 +199,6 @@ def test_init_bad_bounds(self):
215199
aggregation_data_module.DistributionAggregationData(
216200
mean_data=mock.Mock(),
217201
count_data=mock.Mock(),
218-
min_=mock.Mock(),
219-
max_=mock.Mock(),
220202
sum_of_sqd_deviations=mock.Mock(),
221203
counts_per_bucket=[0, 0, 0, 0],
222204
bounds=[-1, 1, 2])
@@ -227,8 +209,6 @@ def test_init_bad_exemplars(self):
227209
aggregation_data_module.DistributionAggregationData(
228210
mean_data=mock.Mock(),
229211
count_data=mock.Mock(),
230-
min_=mock.Mock(),
231-
max_=mock.Mock(),
232212
sum_of_sqd_deviations=mock.Mock(),
233213
counts_per_bucket=mock.Mock(),
234214
bounds=None,
@@ -239,8 +219,6 @@ def test_init_bad_exemplars(self):
239219
aggregation_data_module.DistributionAggregationData(
240220
mean_data=mock.Mock(),
241221
count_data=mock.Mock(),
242-
min_=mock.Mock(),
243-
max_=mock.Mock(),
244222
sum_of_sqd_deviations=mock.Mock(),
245223
counts_per_bucket=mock.Mock(),
246224
bounds=[0, 1],
@@ -256,26 +234,20 @@ def test_constructor_with_exemplar(self):
256234
]
257235
mean_data = 2.59
258236
count_data = 3
259-
_min = .07
260-
_max = 7
261237
sum_of_sqd_deviations = mock.Mock()
262238
counts_per_bucket = [1, 1, 1]
263239
bounds = [1.0 / 2.0, 1]
264240

265241
dist_agg_data = aggregation_data_module.DistributionAggregationData(
266242
mean_data=mean_data,
267243
count_data=count_data,
268-
min_=_min,
269-
max_=_max,
270244
sum_of_sqd_deviations=sum_of_sqd_deviations,
271245
exemplars=exemplars,
272246
counts_per_bucket=counts_per_bucket,
273247
bounds=bounds)
274248

275249
self.assertEqual(dist_agg_data.mean_data, mean_data)
276250
self.assertEqual(dist_agg_data.count_data, count_data)
277-
self.assertEqual(dist_agg_data.min, _min)
278-
self.assertEqual(dist_agg_data.max, _max)
279251
self.assertEqual(dist_agg_data.sum_of_sqd_deviations,
280252
sum_of_sqd_deviations)
281253
self.assertEqual(dist_agg_data.counts_per_bucket, counts_per_bucket)
@@ -339,16 +311,12 @@ def test_exemplar_int_attachment_value(self):
339311
def test_variance(self):
340312
mean_data = mock.Mock()
341313
count_data = 0
342-
_min = mock.Mock()
343-
_max = mock.Mock()
344314
sum_of_sqd_deviations = mock.Mock()
345315
counts_per_bucket = [1, 1, 1]
346316
bounds = [1.0 / 2.0, 1]
347317
dist_agg_data = aggregation_data_module.DistributionAggregationData(
348318
mean_data=mean_data,
349319
count_data=count_data,
350-
min_=_min,
351-
max_=_max,
352320
sum_of_sqd_deviations=sum_of_sqd_deviations,
353321
counts_per_bucket=counts_per_bucket,
354322
bounds=bounds)
@@ -359,8 +327,6 @@ def test_variance(self):
359327
dist_agg_data = aggregation_data_module.DistributionAggregationData(
360328
mean_data=mean_data,
361329
count_data=count_data,
362-
min_=_min,
363-
max_=_max,
364330
sum_of_sqd_deviations=sum_of_sqd_deviations,
365331
counts_per_bucket=counts_per_bucket,
366332
bounds=bounds)
@@ -369,8 +335,6 @@ def test_variance(self):
369335
def test_add_sample(self):
370336
mean_data = 1.0
371337
count_data = 0
372-
_min = 0
373-
_max = 1
374338
sum_of_sqd_deviations = 2
375339
counts_per_bucket = [1, 1, 1, 1]
376340
bounds = [0.5, 1, 1.5]
@@ -380,24 +344,18 @@ def test_add_sample(self):
380344
dist_agg_data = aggregation_data_module.DistributionAggregationData(
381345
mean_data=mean_data,
382346
count_data=count_data,
383-
min_=_min,
384-
max_=_max,
385347
sum_of_sqd_deviations=sum_of_sqd_deviations,
386348
counts_per_bucket=counts_per_bucket,
387349
bounds=bounds)
388350

389351
dist_agg_data.add_sample(value, None, None)
390-
self.assertEqual(0, dist_agg_data.min)
391-
self.assertEqual(3, dist_agg_data.max)
392352
self.assertEqual(1, dist_agg_data.count_data)
393353
self.assertEqual(value, dist_agg_data.mean_data)
394354

395355
count_data = 1
396356
dist_agg_data = aggregation_data_module.DistributionAggregationData(
397357
mean_data=mean_data,
398358
count_data=count_data,
399-
min_=_min,
400-
max_=_max,
401359
sum_of_sqd_deviations=sum_of_sqd_deviations,
402360
counts_per_bucket=counts_per_bucket,
403361
bounds=bounds)
@@ -408,15 +366,9 @@ def test_add_sample(self):
408366
self.assertEqual(4.0, dist_agg_data.sum_of_sqd_deviations)
409367
self.assertIsNot(0, dist_agg_data.count_data)
410368

411-
value_2 = -1
412-
dist_agg_data.add_sample(value_2, None, None)
413-
self.assertEqual(value_2, dist_agg_data.min)
414-
415369
def test_add_sample_attachment(self):
416370
mean_data = 1.0
417371
count_data = 1
418-
_min = 0
419-
_max = 1
420372
sum_of_sqd_deviations = 2
421373
counts_per_bucket = [1, 1, 1, 1]
422374
bounds = [0.5, 1, 1.5]
@@ -430,8 +382,6 @@ def test_add_sample_attachment(self):
430382
dist_agg_data = aggregation_data_module.DistributionAggregationData(
431383
mean_data=mean_data,
432384
count_data=count_data,
433-
min_=_min,
434-
max_=_max,
435385
sum_of_sqd_deviations=sum_of_sqd_deviations,
436386
counts_per_bucket=counts_per_bucket,
437387
bounds=bounds,
@@ -440,8 +390,6 @@ def test_add_sample_attachment(self):
440390
self.assertEqual(dist_agg_data.exemplars[3], exemplar_1)
441391

442392
dist_agg_data.add_sample(value, timestamp, attachments)
443-
self.assertEqual(0, dist_agg_data.min)
444-
self.assertEqual(3, dist_agg_data.max)
445393
self.assertEqual(2, dist_agg_data.count_data)
446394
self.assertEqual(2.0, dist_agg_data.mean_data)
447395
# Check that adding a sample overwrites the bucket's exemplar
@@ -453,8 +401,6 @@ def test_add_sample_attachment(self):
453401
dist_agg_data = aggregation_data_module.DistributionAggregationData(
454402
mean_data=mean_data,
455403
count_data=count_data,
456-
min_=_min,
457-
max_=_max,
458404
sum_of_sqd_deviations=sum_of_sqd_deviations,
459405
counts_per_bucket=[2, 1, 2, 1, 1, 1],
460406
bounds=[1, 2, 3, 4, 5])
@@ -469,8 +415,6 @@ def test_add_sample_attachment(self):
469415
def test_increment_bucket_count(self):
470416
mean_data = mock.Mock()
471417
count_data = mock.Mock()
472-
_min = 0
473-
_max = 1
474418
sum_of_sqd_deviations = mock.Mock()
475419
counts_per_bucket = [0]
476420
bounds = []
@@ -480,8 +424,6 @@ def test_increment_bucket_count(self):
480424
dist_agg_data = aggregation_data_module.DistributionAggregationData(
481425
mean_data=mean_data,
482426
count_data=count_data,
483-
min_=_min,
484-
max_=_max,
485427
sum_of_sqd_deviations=sum_of_sqd_deviations,
486428
counts_per_bucket=counts_per_bucket,
487429
bounds=bounds)
@@ -495,8 +437,6 @@ def test_increment_bucket_count(self):
495437
dist_agg_data = aggregation_data_module.DistributionAggregationData(
496438
mean_data=mean_data,
497439
count_data=count_data,
498-
min_=_min,
499-
max_=_max,
500440
sum_of_sqd_deviations=sum_of_sqd_deviations,
501441
counts_per_bucket=counts_per_bucket,
502442
bounds=bounds)
@@ -509,8 +449,6 @@ def test_increment_bucket_count(self):
509449
dist_agg_data = aggregation_data_module.DistributionAggregationData(
510450
mean_data=mean_data,
511451
count_data=count_data,
512-
min_=_min,
513-
max_=_max,
514452
sum_of_sqd_deviations=sum_of_sqd_deviations,
515453
counts_per_bucket=counts_per_bucket,
516454
bounds=bounds)
@@ -529,8 +467,6 @@ def test_to_point(self):
529467
dist_agg_data = aggregation_data_module.DistributionAggregationData(
530468
mean_data=50,
531469
count_data=99,
532-
min_=1,
533-
max_=99,
534470
sum_of_sqd_deviations=80850.0,
535471
counts_per_bucket=[0, 9, 90, 0],
536472
bounds=[1, 10, 100],
@@ -561,8 +497,6 @@ def test_to_point_no_histogram(self):
561497
dist_agg_data = aggregation_data_module.DistributionAggregationData(
562498
mean_data=50,
563499
count_data=99,
564-
min_=1,
565-
max_=99,
566500
sum_of_sqd_deviations=80850.0,
567501
)
568502
converted_point = dist_agg_data.to_point(timestamp)

0 commit comments

Comments
 (0)