|
24 | 24 |
|
25 | 25 | import math
|
26 | 26 | import threading
|
27 |
| -from collections import namedtuple |
28 | 27 | from http.server import BaseHTTPRequestHandler, HTTPServer
|
29 | 28 | from socketserver import ThreadingMixIn
|
30 | 29 | from urllib.parse import parse_qs, urlparse
|
|
35 | 34 |
|
36 | 35 | from synapse.util import caches
|
37 | 36 |
|
38 |
| -try: |
39 |
| - from prometheus_client.samples import Sample |
40 |
| -except ImportError: |
41 |
| - Sample = namedtuple( # type: ignore[no-redef] # noqa |
42 |
| - "Sample", ["name", "labels", "value", "timestamp", "exemplar"] |
43 |
| - ) |
44 |
| - |
45 |
| - |
46 | 37 | CONTENT_TYPE_LATEST = str("text/plain; version=0.0.4; charset=utf-8")
|
47 | 38 |
|
48 | 39 |
|
@@ -93,17 +84,6 @@ def sample_line(line, name):
|
93 | 84 | )
|
94 | 85 |
|
95 | 86 |
|
96 |
| -def nameify_sample(sample): |
97 |
| - """ |
98 |
| - If we get a prometheus_client<0.4.0 sample as a tuple, transform it into a |
99 |
| - namedtuple which has the names we expect. |
100 |
| - """ |
101 |
| - if not isinstance(sample, Sample): |
102 |
| - sample = Sample(*sample, None, None) |
103 |
| - |
104 |
| - return sample |
105 |
| - |
106 |
| - |
107 | 87 | def generate_latest(registry, emit_help=False):
|
108 | 88 |
|
109 | 89 | # Trigger the cache metrics to be rescraped, which updates the common
|
@@ -144,7 +124,7 @@ def generate_latest(registry, emit_help=False):
|
144 | 124 | )
|
145 | 125 | )
|
146 | 126 | output.append("# TYPE {0} {1}\n".format(mname, mtype))
|
147 |
| - for sample in map(nameify_sample, metric.samples): |
| 127 | + for sample in metric.samples: |
148 | 128 | # Get rid of the OpenMetrics specific samples
|
149 | 129 | for suffix in ["_created", "_gsum", "_gcount"]:
|
150 | 130 | if sample.name.endswith(suffix):
|
@@ -172,7 +152,7 @@ def generate_latest(registry, emit_help=False):
|
172 | 152 | )
|
173 | 153 | )
|
174 | 154 | output.append("# TYPE {0} {1}\n".format(mnewname, mtype))
|
175 |
| - for sample in map(nameify_sample, metric.samples): |
| 155 | + for sample in metric.samples: |
176 | 156 | # Get rid of the OpenMetrics specific samples
|
177 | 157 | for suffix in ["_created", "_gsum", "_gcount"]:
|
178 | 158 | if sample.name.endswith(suffix):
|
|
0 commit comments