diff --git a/opencensus/metrics/export/time_series.py b/opencensus/metrics/export/time_series.py index 860d885cf..022f83197 100644 --- a/opencensus/metrics/export/time_series.py +++ b/opencensus/metrics/export/time_series.py @@ -38,8 +38,8 @@ class TimeSeries(object): """ # noqa def __init__(self, label_values, points, start_timestamp): - if not label_values: - raise ValueError("label_values must not be null or empty") + if label_values is None: + raise ValueError("label_values must not be None") if not points: raise ValueError("points must not be null or empty") self._label_values = label_values diff --git a/tests/unit/metrics/export/test_time_series.py b/tests/unit/metrics/export/test_time_series.py index 52646b3e9..b3948361a 100644 --- a/tests/unit/metrics/export/test_time_series.py +++ b/tests/unit/metrics/export/test_time_series.py @@ -49,8 +49,6 @@ def test_init_invalid(self): time_series.TimeSeries(LABEL_VALUES, POINTS, None) with self.assertRaises(ValueError): time_series.TimeSeries(None, POINTS, START_TIMESTAMP) - with self.assertRaises(ValueError): - time_series.TimeSeries([], POINTS, START_TIMESTAMP) with self.assertRaises(ValueError): time_series.TimeSeries(LABEL_VALUES, None, START_TIMESTAMP) with self.assertRaises(ValueError): diff --git a/tests/unit/stats/test_metric_utils.py b/tests/unit/stats/test_metric_utils.py index 9c81eb0ed..71cd6bbf4 100644 --- a/tests/unit/stats/test_metric_utils.py +++ b/tests/unit/stats/test_metric_utils.py @@ -171,3 +171,36 @@ def test_view_data_to_metric(self): ] for args in args_list: self.do_test_view_data_to_metric(*args) + + def test_convert_view_without_labels(self): + mock_measure = mock.Mock(spec=measure.MeasureFloat) + mock_aggregation = mock.Mock(spec=aggregation.DistributionAggregation) + mock_aggregation.aggregation_type = aggregation.Type.DISTRIBUTION + + vd = mock.Mock(spec=view_data.ViewData) + vd.view = view.View( + name=mock.Mock(), + description=mock.Mock(), + columns=[], + measure=mock_measure, + aggregation=mock_aggregation) + vd.start_time = '2019-04-11T22:33:44.555555Z' + + mock_point = mock.Mock(spec=point.Point) + mock_point.value = mock.Mock(spec=value.ValueDistribution) + + mock_agg = mock.Mock(spec=aggregation_data.SumAggregationDataFloat) + mock_agg.to_point.return_value = mock_point + + vd.tag_value_aggregation_data_map = {tuple(): mock_agg} + + current_time = '2019-04-11T22:33:55.666666Z' + metric = metric_utils.view_data_to_metric(vd, current_time) + + self.assertEqual(metric.descriptor.label_keys, []) + self.assertEqual(len(metric.time_series), 1) + [ts] = metric.time_series + self.assertEqual(ts.label_values, []) + self.assertEqual(len(ts.points), 1) + [pt] = ts.points + self.assertEqual(pt, mock_point)