8000 Add `HELP` output for auto-created metrics (#470) (#471) · sjs205/client_python@6214c3a · GitHub
[go: up one dir, main page]

Skip to content

Commit 6214c3a

Browse files
davidlukacbrian-brazil
authored andcommitted
Add HELP output for auto-created metrics (prometheus#470) (prometheus#471)
Signed-off-by: David Lukac <1215290+davidlukac@users.noreply.github.com>
1 parent 7ced8d3 commit 6214c3a

File tree

2 files changed

+8
-0
lines changed

2 files changed

+8
-0
lines changed

prometheus_client/exposition.py

Lines changed: 2 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -122,6 +122,8 @@ def sample_line(line):
122122
raise
123123

124124
for suffix, lines in sorted(om_samples.items()):
125+
output.append('# HELP {0}{1} {2}\n'.format(metric.name, suffix,
126+
metric.documentation.replace('\\', r'\\').replace('\n', r'\n')))
125127
output.append('# TYPE {0}{1} gauge\n'.format(metric.name, suffix))
126128
output.extend(lines)
127129
return ''.join(output).encode('utf-8')

tests/test_exposition.py

Lines changed: 6 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -56,6 +56,7 @@ def test_counter(self):
5656
self.assertEqual(b"""# HELP cc_total A counter
5757
# TYPE cc_total counter
5858
cc_total 1.0
59+
# HELP cc_created A counter
5960
# TYPE cc_created gauge
6061
cc_created 123.456
6162
""", generate_latest(self.registry))
@@ -66,6 +67,7 @@ def test_counter_total(self):
6667
self.assertEqual(b"""# HELP cc_total A counter
6768
# TYPE cc_total counter
6869
cc_total 1.0
70+
# HELP cc_created A counter
6971
# TYPE cc_created gauge
7072
cc_created 123.456
7173
""", generate_latest(self.registry))
@@ -82,6 +84,7 @@ def test_summary(self):
8284
# TYPE ss summary
8385
ss_count{a="c",b="d"} 1.0
8486
ss_sum{a="c",b="d"} 17.0
87+
# HELP ss_created A summary
8588
# TYPE ss_created gauge
8689
ss_created{a="c",b="d"} 123.456
8790
""", generate_latest(self.registry))
@@ -109,6 +112,7 @@ def test_histogram(self):
109112
hh_bucket{le="+Inf"} 1.0
110113
hh_count 1.0
111114
hh_sum 0.05
115+
# HELP hh_created A histogram
112116
# TYPE hh_created gauge
113117
hh_created 123.456
114118
""", generate_latest(self.registry))
@@ -119,8 +123,10 @@ def test_gaugehistogram(self):
119123
# TYPE gh histogram
120124
gh_bucket{le="1.0"} 4.0
121125
gh_bucket{le="+Inf"} 5.0
126+
# HELP gh_gcount help
122127
# TYPE gh_gcount gauge
123128
gh_gcount 5.0
129+
# HELP gh_gsum help
124130
# TYPE gh_gsum gauge
125131
gh_gsum 7.0
126132
""", generate_latest(self.registry))

0 commit comments

Comments
 (0)
0