Skip to content

Commit 801c90d

Browse files
committed
Disallow 'quantile' as a label to Summary.
1 parent d87a393 commit 801c90d

File tree

2 files changed

+6
-0
lines changed

2 files changed

+6
-0
lines changed

prometheus_client/__init__.py

Lines changed: 5 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -136,6 +136,8 @@ def init(name, documentation, labelnames=(), namespace='', subsystem='', registr
136136
raise ValueError('Invalid label metric name: ' + l)
137137
if _RESERVED_METRIC_LABEL_NAME_RE.match(l):
138138
raise ValueError('Reserved label metric name: ' + l)
139+
if l in cls._reserved_labelnames:
140+
raise ValueError('Reserved label metric name: ' + l)
139141
collector = _LabelWrapper(cls, labelnames)
140142
else:
141143
collector = cls()
@@ -165,6 +167,7 @@ def collect():
165167
@_MetricWrapper
166168
class Counter(object):
167169
_type = 'counter'
170+
_reserved_labelnames = []
168171
def __init__(self):
169172
self._value = 0.0
170173
self._lock = Lock()
@@ -205,6 +208,7 @@ def _samples(self):
205208
@_MetricWrapper
206209
class Gauge(object):
207210
_type = 'gauge'
211+
_reserved_labelnames = []
208212
def __init__(self):
209213
self._value = 0.0
210214
self._lock = Lock()
@@ -257,6 +261,7 @@ def _samples(self):
257261
@_MetricWrapper
258262
class Summary(object):
259263
_type = 'summary'
264+
_reserved_labelnames = ['quantile']
260265
def __init__(self):
261266
self._count = 0.0
262267
self._sum = 0.0

tests/test_client.py

Lines changed: 1 addition & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -143,6 +143,7 @@ def test_invalid_names_raise(self):
143143
self.assertRaises(ValueError, Counter, '', 'help', subsystem='(')
144144
self.assertRaises(ValueError, Counter, 'c', '', labelnames=['^'])
145145
self.assertRaises(ValueError, Counter, 'c', '', labelnames=['__reserved'])
146+
self.assertRaises(ValueError, Summary, 'c', '', labelnames=['quantile'])
146147

147148
class TestGenerateText(unittest.TestCase):
148149
def setUp(self):

0 commit comments

Comments
 (0)