Skip to content
This repository was archived by the owner on Apr 26, 2024. It is now read-only.

Commit ceafb5a

Browse files
authored
Drop support for ancient prometheus_client (#8426)
Drop compatibility hacks for prometheus-client pre 0.4.0. Debian stretch and Fedora 31 both have newer versions, so hopefully this will be ok.
1 parent c429dfc commit ceafb5a

File tree

3 files changed

+8
-23
lines changed

3 files changed

+8
-23
lines changed

changelog.d/8426.removal

+1
Original file line numberDiff line numberDiff line change
@@ -0,0 +1 @@
1+
Drop support for `prometheus_client` older than 0.4.0.

synapse/metrics/_exposition.py

+2-22
Original file line numberDiff line numberDiff line change
@@ -24,7 +24,6 @@
2424

2525
import math
2626
import threading
27-
from collections import namedtuple
2827
from http.server import BaseHTTPRequestHandler, HTTPServer
2928
from socketserver import ThreadingMixIn
3029
from urllib.parse import parse_qs, urlparse
@@ -35,14 +34,6 @@
3534

3635
from synapse.util import caches
3736

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-
4637
CONTENT_TYPE_LATEST = str("text/plain; version=0.0.4; charset=utf-8")
4738

4839

@@ -93,17 +84,6 @@ def sample_line(line, name):
9384
)
9485

9586

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-
10787
def generate_latest(registry, emit_help=False):
10888

10989
# Trigger the cache metrics to be rescraped, which updates the common
@@ -144,7 +124,7 @@ def generate_latest(registry, emit_help=False):
144124
)
145125
)
146126
output.append("# TYPE {0} {1}\n".format(mname, mtype))
147-
for sample in map(nameify_sample, metric.samples):
127+
for sample in metric.samples:
148128
# Get rid of the OpenMetrics specific samples
149129
for suffix in ["_created", "_gsum", "_gcount"]:
150130
if sample.name.endswith(suffix):
@@ -172,7 +152,7 @@ def generate_latest(registry, emit_help=False):
172152
)
173153
)
174154
output.append("# TYPE {0} {1}\n".format(mnewname, mtype))
175-
for sample in map(nameify_sample, metric.samples):
155+
for sample in metric.samples:
176156
# Get rid of the OpenMetrics specific samples
177157
for suffix in ["_created", "_gsum", "_gcount"]:
178158
if sample.name.endswith(suffix):

synapse/python_dependencies.py

+5-1
Original file line numberDiff line numberDiff line change
@@ -68,7 +68,11 @@
6868
"pymacaroons>=0.13.0",
6969
"msgpack>=0.5.2",
7070
"phonenumbers>=8.2.0",
71-
"prometheus_client>=0.0.18,<0.9.0",
71+
# we use GaugeHistogramMetric, which was added in prom-client 0.4.0.
72+
# prom-client has a history of breaking backwards compatibility between
73+
# minor versions (https://github.com/prometheus/client_python/issues/317),
74+
# so we also pin the minor version.
75+
"prometheus_client>=0.4.0,<0.9.0",
7276
# we use attr.validators.deep_iterable, which arrived in 19.1.0 (Note:
7377
# Fedora 31 only has 19.1, so if we want to upgrade we should wait until 33
7478
# is out in November.)

0 commit comments

Comments
 (0)