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

Commit 817249a

Browse files
samnc24t
authored andcommitted
Allow empty metric descriptor label keys (#611)
1 parent e400b8b commit 817249a

File tree

2 files changed

+7
-2
lines changed

2 files changed

+7
-2
lines changed

opencensus/metrics/export/metric_descriptor.py

Lines changed: 2 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -130,8 +130,8 @@ def __init__(self, name, description, unit, type_, label_keys):
130130
if type_ not in MetricDescriptorType:
131131
raise ValueError("Invalid type")
132132

133-
if not label_keys:
134-
raise ValueError("label_keys must not be empty or null")
133+
if label_keys is None:
134+
raise ValueError("label_keys must not be None")
135135

136136
if any(key is None for key in label_keys):
137137
raise ValueError("label_keys must not contain null keys")

tests/unit/metrics/export/test_metric_descriptor.py

Lines changed: 5 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -53,6 +53,11 @@ def test_null_label_keys(self):
5353
NAME, DESCRIPTION, UNIT,
5454
metric_descriptor.MetricDescriptorType.GAUGE_DOUBLE, None)
5555

56+
def test_empty_label_keys(self):
57+
metric_descriptor.MetricDescriptor(
58+
NAME, DESCRIPTION, UNIT,
59+
metric_descriptor.MetricDescriptorType.GAUGE_DOUBLE, [])
60+
5661
def test_null_label_key_values(self):
5762
with self.assertRaises(ValueError):
5863
metric_descriptor.MetricDescriptor(

0 commit comments

Comments
 (0)