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

Commit a91d20e

Browse files
authored
Allow TimeSeries to have empty label values (#614)
1 parent 8cf88d2 commit a91d20e

File tree

3 files changed

+35
-4
lines changed

3 files changed

+35
-4
lines changed

opencensus/metrics/export/time_series.py

Lines changed: 2 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -38,8 +38,8 @@ class TimeSeries(object):
3838
""" # noqa
3939

4040
def __init__(self, label_values, points, start_timestamp):
41-
if not label_values:
42-
raise ValueError("label_values must not be null or empty")
41+
if label_values is None:
42+
raise ValueError("label_values must not be None")
4343
if not points:
4444
raise ValueError("points must not be null or empty")
4545
self._label_values = label_values

tests/unit/metrics/export/test_time_series.py

Lines changed: 0 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -49,8 +49,6 @@ def test_init_invalid(self):
4949
time_series.TimeSeries(LABEL_VALUES, POINTS, None)
5050
with self.assertRaises(ValueError):
5151
time_series.TimeSeries(None, POINTS, START_TIMESTAMP)
52-
with self.assertRaises(ValueError):
53-
time_series.TimeSeries([], POINTS, START_TIMESTAMP)
5452
with self.assertRaises(ValueError):
5553
time_series.TimeSeries(LABEL_VALUES, None, START_TIMESTAMP)
5654
with self.assertRaises(ValueError):

tests/unit/stats/test_metric_utils.py

Lines changed: 33 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -171,3 +171,36 @@ def test_view_data_to_metric(self):
171171
]
172172
for args in args_list:
173173
self.do_test_view_data_to_metric(*args)
174+
175+
def test_convert_view_without_labels(self):
176+
mock_measure = mock.Mock(spec=measure.MeasureFloat)
177+
mock_aggregation = mock.Mock(spec=aggregation.DistributionAggregation)
178+
mock_aggregation.aggregation_type = aggregation.Type.DISTRIBUTION
179+
180+
vd = mock.Mock(spec=view_data.ViewData)
181+
vd.view = view.View(
182+
name=mock.Mock(),
183+
description=mock.Mock(),
184+
columns=[],
185+
measure=mock_measure,
186+
aggregation=mock_aggregation)
187+
vd.start_time = '2019-04-11T22:33:44.555555Z'
188+
189+
mock_point = mock.Mock(spec=point.Point)
190+
mock_point.value = mock.Mock(spec=value.ValueDistribution)
191+
192+
mock_agg = mock.Mock(spec=aggregation_data.SumAggregationDataFloat)
193+
mock_agg.to_point.return_value = mock_point
194+
195+
vd.tag_value_aggregation_data_map = {tuple(): mock_agg}
196+
197+
current_time = '2019-04-11T22:33:55.666666Z'
198+
metric = metric_utils.view_data_to_metric(vd, current_time)
199+
200+
self.assertEqual(metric.descriptor.label_keys, [])
201+
self.assertEqual(len(metric.time_series), 1)
202+
[ts] = metric.time_series
203+
self.assertEqual(ts.label_values, [])
204+
self.assertEqual(len(ts.points), 1)
205+
[pt] = ts.points
206+
self.assertEqual(pt, mock_point)

0 commit comments

Comments
 (0)