8000 OM changes untyped to unknown · sxlstevengit/client_python@1b840fb · GitHub
[go: up one dir, main page]

Skip to content

Commit 1b840fb

Browse files
committed
OM changes untyped to unknown
Signed-off-by: Brian Brazil <brian.brazil@robustperception.io>
1 parent 7e19da9 commit 1b840fb

File tree

3 files changed

+13
-7
lines changed

3 files changed

+13
-7
lines changed

prometheus_client/core.py

Lines changed: 8 additions & 4 deletions
Original file line numberDiff line numberDiff line change
@@ -181,7 +181,7 @@ def get_sample_value(self, name, labels=None):
181181
'''The default registry.'''
182182

183183
_METRIC_TYPES = ('counter', 'gauge', 'summary', 'histogram',
184-
'gaugehistogram', 'untyped', 'info', 'stateset')
184+
'gaugehistogram', 'unknown', 'info', 'stateset')
185185

186186

187187
class Metric(object):
@@ -200,6 +200,8 @@ def __init__(self, name, documentation, typ, unit=''):
200200
if unit and not name.endswith("_" + unit):
201201
raise ValueError("Metric name not suffixed by unit: " + name)
202202
self.unit = unit
203+
if typ == 'untyped':
204+
typ = 'unknown'
203205
if typ not in _METRIC_TYPES:
204206
raise ValueError('Invalid metric type: ' + typ)
205207
self.type = typ
@@ -228,12 +230,12 @@ def __repr__(self):
228230
self.type, self.unit, self.samples)
229231

230232

231-
class UntypedMetricFamily(Metric):
232-
'''A single untyped metric and its samples.
233+
class UnknownMetricFamily(Metric):
234+
'''A single unknwon metric and its samples.
233235
For use by custom collectors.
234236
'''
235237
def __init__(self, name, documentation, value=None, labels=None):
236-
Metric.__init__(self, name, documentation, 'untyped')
238+
Metric.__init__(self, name, documentation, 'unknown')
237239
if labels is not None and value is not None:
238240
raise ValueError('Can only specify at most one of value and labels.')
239241
if labels is None:
@@ -250,6 +252,8 @@ def add_metric(self, labels, value, timestamp=None):
250252
'''
251253
self.samples.append(Sample(self.name, dict(zip(self._labelnames, labels)), value, timestamp))
252254

255+
# For backward compatibility.
256+
UntypedMetricFamily = UnknownMetricFamily
253257

254258
class CounterMetricFamily(Metric):
255259
'''A single counter and its samples.

prometheus_client/exposition.py

Lines changed: 2 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -82,6 +82,8 @@ def generate_latest(registry=core.REGISTRY):
8282
# A gauge histogram is really a gauge,
8383
# but this captures the strucutre better.
8484
mtype = 'histogram'
85+
elif mtype == 'unknown':
86+
mtype = 'untyped'
8587
output.append('# HELP {0} {1}'.format(
8688
mname, metric.documentation.replace('\\', r'\\').replace('\n', r'\n')))
8789
output.append('\n# TYPE {0} {1}\n'.format(mname, mtype))

tests/openmetrics/test_exposition.py

Lines changed: 3 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -150,12 +150,12 @@ def collect(self):
150150
yield metric
151151

152152
self.registry.register(MyCollector())
153-
self.assertEqual(b'# HELP nonnumber Non number\n# TYPE nonnumber untyped\nnonnumber 123.0\n# EOF\n', generate_latest(self.registry))
153+
self.assertEqual(b'# HELP nonnumber Non number\n# TYPE nonnumber unknown\nnonnumber 123.0\n# EOF\n', generate_latest(self.registry))
154154

155155
def test_timestamp(self):
156156
class MyCollector(object):
157157
def collect(self):
158-
metric = Metric("ts", "help", 'untyped')
158+
metric = Metric("ts", "help", 'unknown')
159159
metric.add_sample("ts", {"foo": "a"}, 0, 123.456)
160160
metric.add_sample("ts", {"foo": "b"}, 0, -123.456)
161161
metric.add_sample("ts", {"foo": "c"}, 0, 123)
@@ -166,7 +166,7 @@ def collect(self):
166166

167167
self.registry.register(MyCollector())
168168
self.assertEqual(b'''# HELP ts help
169-
# TYPE ts untyped
169+
# TYPE ts unknown
170170
ts{foo="a"} 0.0 123.456
171171
ts{foo="b"} 0.0 -123.456
172172
ts{foo="c"} 0.0 123

0 commit comments

Comments
 (0)
0