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

Commit

Permalink
Fix lints
Browse files Browse the repository at this point in the history
  • Loading branch information
MadLittleMods authored and David Robertson committed Aug 30, 2022
1 parent 8be5d7c commit d8ec11a
Showing 1 changed file with 19 additions and 5 deletions.
24 changes: 19 additions & 5 deletions synapse/util/ratelimitutils.py
Original file line number Diff line number Diff line change
Expand Up @@ -17,9 +17,21 @@
import logging
import threading
import typing
from typing import Any, DefaultDict, Dict, Iterator, List, Mapping, Optional, Set, Tuple
from typing import (
Any,
Callable,
DefaultDict,
Dict,
Iterator,
List,
Mapping,
Optional,
Set,
Tuple,
)

from prometheus_client.core import Counter
from typing_extensions import ContextManager

from twisted.internet import defer

Expand Down Expand Up @@ -79,7 +91,9 @@
_rate_limiter_instances_lock = threading.Lock()


def _get_counts_from_rate_limiter_instance(count_func) -> Mapping[Tuple[str, ...], int]:
def _get_counts_from_rate_limiter_instance(
count_func: Callable[["FederationRateLimiter"], int]
) -> Mapping[Tuple[str, ...], int]:
"""Returns a count of something (slept/rejected hosts) by (metrics_name)"""
# Cast to a list to prevent it changing while the Prometheus
# thread is collecting metrics
Expand Down Expand Up @@ -134,7 +148,7 @@ def __init__(
self,
clock: Clock,
config: FederationRatelimitSettings,
metrics_name: Optional[str],
metrics_name: Optional[str] = None,
):
"""
Args:
Expand Down Expand Up @@ -181,7 +195,7 @@ def __init__(
self,
clock: Clock,
config: FederationRatelimitSettings,
metrics_name: Optional[str],
metrics_name: Optional[str] = None,
):
"""
Args:
Expand Down Expand Up @@ -249,7 +263,7 @@ def should_sleep(self) -> bool:
return len(self.request_times) > self.sleep_limit

async def _on_enter_with_tracing(self, request_id: object) -> None:
maybe_metrics_cm = contextlib.nullcontext()
maybe_metrics_cm: ContextManager = contextlib.nullcontext()
if self.metrics_name:
maybe_metrics_cm = queue_wait_timer.labels(self.metrics_name).time()
with start_active_span("ratelimit wait"), maybe_metrics_cm:
Expand Down

0 comments on commit d8ec11a

Please sign in to comment.