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

Fix type errors introduced by new annotations in the Prometheus Client library. #11832

Merged
merged 7 commits into from
Feb 2, 2022
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
1 change: 1 addition & 0 deletions changelog.d/11832.misc
Original file line number Diff line number Diff line change
@@ -0,0 +1 @@
Fix type errors introduced by new annotations in the Prometheus Client library.
10 changes: 9 additions & 1 deletion synapse/metrics/__init__.py
Original file line number Diff line number Diff line change
Expand Up @@ -30,6 +30,7 @@
Type,
TypeVar,
Union,
cast,
)

import attr
Expand Down Expand Up @@ -60,14 +61,21 @@
HAVE_PROC_SELF_STAT = os.path.exists("/proc/self/stat")


class RegistryProxy:
class _RegistryProxy:
@staticmethod
def collect() -> Iterable[Metric]:
for metric in REGISTRY.collect():
if not metric.name.startswith("__"):
yield metric


# A little bit nasty, but collect() above is static so a Protocol doesn't work.
# _RegistryProxy matches the signature of a CollectorRegistry instance enough
# for it to be usable in the contexts in which we use it.
# TODO Do something nicer about this.
RegistryProxy = cast(CollectorRegistry, _RegistryProxy)


@attr.s(slots=True, hash=True, auto_attribs=True)
class LaterGauge:

Expand Down
3 changes: 1 addition & 2 deletions synapse/python_dependencies.py
Original file line number Diff line number Diff line change
Expand Up @@ -76,8 +76,7 @@
"msgpack>=0.5.2",
"phonenumbers>=8.2.0",
# we use GaugeHistogramMetric, which was added in prom-client 0.4.0.
# 0.13.0 has an incorrect type annotation, see #11832.
"prometheus_client>=0.4.0,<0.13.0",
"prometheus_client>=0.4.0",
Copy link
Contributor

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Should we change this from <0.13.0 to !=0.13.0? Given that the change only relates to typechecking I think not---we implicitly use the latest release of all typechecking tools anyway.

Copy link
Contributor Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

I also think not — in the extreme, it'd end up with us maintaining a list of versions that don't work.

# we use `order`, which arrived in attrs 19.2.0.
# Note: 21.1.0 broke `/sync`, see #9936
"attrs>=19.2.0,!=21.1.0",
Expand Down