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

Commit

Permalink
Drop support for ancient prometheus_client
Browse files Browse the repository at this point in the history
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.
  • Loading branch information
richvdh committed Sep 30, 2020
1 parent 450ec48 commit b244136
Show file tree
Hide file tree
Showing 3 changed files with 8 additions and 23 deletions.
1 change: 1 addition & 0 deletions changelog.d/8426.removal
Original file line number Diff line number Diff line change
@@ -0,0 +1 @@
Drop support for `prometheus_client` older than 0.4.0.
24 changes: 2 additions & 22 deletions synapse/metrics/_exposition.py
Original file line number Diff line number Diff line change
Expand Up @@ -24,7 +24,6 @@

import math
import threading
from collections import namedtuple
from http.server import BaseHTTPRequestHandler, HTTPServer
from socketserver import ThreadingMixIn
from urllib.parse import parse_qs, urlparse
Expand All @@ -35,14 +34,6 @@

from synapse.util import caches

try:
from prometheus_client.samples import Sample
except ImportError:
Sample = namedtuple( # type: ignore[no-redef] # noqa
"Sample", ["name", "labels", "value", "timestamp", "exemplar"]
)


CONTENT_TYPE_LATEST = str("text/plain; version=0.0.4; charset=utf-8")


Expand Down Expand Up @@ -93,17 +84,6 @@ def sample_line(line, name):
)


def nameify_sample(sample):
"""
If we get a prometheus_client<0.4.0 sample as a tuple, transform it into a
namedtuple which has the names we expect.
"""
if not isinstance(sample, Sample):
sample = Sample(*sample, None, None)

return sample


def generate_latest(registry, emit_help=False):

# Trigger the cache metrics to be rescraped, which updates the common
Expand Down Expand Up @@ -144,7 +124,7 @@ def generate_latest(registry, emit_help=False):
)
)
output.append("# TYPE {0} {1}\n".format(mname, mtype))
for sample in map(nameify_sample, metric.samples):
for sample in metric.samples:
# Get rid of the OpenMetrics specific samples
for suffix in ["_created", "_gsum", "_gcount"]:
if sample.name.endswith(suffix):
Expand Down Expand Up @@ -172,7 +152,7 @@ def generate_latest(registry, emit_help=False):
)
)
output.append("# TYPE {0} {1}\n".format(mnewname, mtype))
for sample in map(nameify_sample, metric.samples):
for sample in metric.samples:
# Get rid of the OpenMetrics specific samples
for suffix in ["_created", "_gsum", "_gcount"]:
if sample.name.endswith(suffix):
Expand Down
6 changes: 5 additions & 1 deletion synapse/python_dependencies.py
Original file line number Diff line number Diff line change
Expand Up @@ -68,7 +68,11 @@
"pymacaroons>=0.13.0",
"msgpack>=0.5.2",
"phonenumbers>=8.2.0",
"prometheus_client>=0.0.18,<0.9.0",
# we use GaugeHistogramMetric, which was added in prom-client 0.4.0.
# prom-client has a history of breaking backwards compatibility between
# minor versions (https://github.com/prometheus/client_python/issues/317),
# so we also pin the minor version.
"prometheus_client>=0.4.0,<0.9.0",
# we use attr.validators.deep_iterable, which arrived in 19.1.0 (Note:
# Fedora 31 only has 19.1, so if we want to upgrade we should wait until 33
# is out in November.)
Expand Down

0 comments on commit b244136

Please sign in to comment.