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

Commit

Permalink
Convert labels to str ourselves
Browse files Browse the repository at this point in the history
This is done internally (if you read the code) but the type annotations
now require str.
  • Loading branch information
reivilibre committed Jan 26, 2022
1 parent 74e4419 commit 676ea6d
Show file tree
Hide file tree
Showing 4 changed files with 11 additions and 11 deletions.
12 changes: 6 additions & 6 deletions synapse/handlers/register.py
Original file line number Diff line number Diff line change
Expand Up @@ -68,11 +68,11 @@ def init_counters_for_auth_provider(auth_provider_id: str) -> None:
until the user first logs in/registers.
"""
for is_guest in (True, False):
login_counter.labels(guest=is_guest, auth_provider=auth_provider_id)
login_counter.labels(guest=str(is_guest), auth_provider=auth_provider_id)
for shadow_banned in (True, False):
registration_counter.labels(
guest=is_guest,
shadow_banned=shadow_banned,
guest=str(is_guest),
shadow_banned=str(shadow_banned),
auth_provider=auth_provider_id,
)

Expand Down Expand Up @@ -341,8 +341,8 @@ async def register_user(
fail_count += 1

registration_counter.labels(
guest=make_guest,
shadow_banned=shadow_banned,
guest=str(make_guest),
shadow_banned=str(shadow_banned),
auth_provider=(auth_provider_id or ""),
).inc()

Expand Down Expand Up @@ -775,7 +775,7 @@ async def register_device(
)

login_counter.labels(
guest=is_guest,
guest=str(is_guest),
auth_provider=(auth_provider_id or ""),
).inc()

Expand Down
4 changes: 2 additions & 2 deletions synapse/metrics/_gc.py
Original file line number Diff line number Diff line change
Expand Up @@ -123,8 +123,8 @@ def _maybe_gc() -> None:

_last_gc[i] = end

gc_time.labels(i).observe(end - start)
gc_unreachable.labels(i).set(unreachable)
gc_time.labels(str(i)).observe(end - start)
gc_unreachable.labels(str(i)).set(unreachable)

gc_task = task.LoopingCall(_maybe_gc)
gc_task.start(0.1)
Expand Down
4 changes: 2 additions & 2 deletions synapse/replication/http/_base.py
Original file line number Diff line number Diff line change
Expand Up @@ -257,13 +257,13 @@ async def send_request(*, instance_name="master", **kwargs):
# We convert to SynapseError as we know that it was a SynapseError
# on the main process that we should send to the client. (And
# importantly, not stack traces everywhere)
_outgoing_request_counter.labels(cls.NAME, e.code).inc()
_outgoing_request_counter.labels(cls.NAME, str(e.code)).inc()
raise e.to_synapse_error()
except Exception as e:
_outgoing_request_counter.labels(cls.NAME, "ERR").inc()
raise SynapseError(502, "Failed to talk to main process") from e

_outgoing_request_counter.labels(cls.NAME, 200).inc()
_outgoing_request_counter.labels(cls.NAME, "200").inc()
return result

return send_request
Expand Down
2 changes: 1 addition & 1 deletion synapse/replication/tcp/external_cache.py
Original file line number Diff line number Diff line change
Expand Up @@ -115,7 +115,7 @@ async def get(self, cache_name: str, key: str) -> Optional[Any]:

logger.debug("Got cache result %s %s: %r", cache_name, key, result)

get_counter.labels(cache_name, result is not None).inc()
get_counter.labels(cache_name, str(result is not None)).inc()

if not result:
return None
Expand Down

0 comments on commit 676ea6d

Please sign in to comment.