Skip to content

Commit

Permalink
fixup metrics stats usage
Browse files Browse the repository at this point in the history
  • Loading branch information
libretto committed Jan 10, 2024
1 parent c785e1a commit 5da8ca8
Showing 1 changed file with 7 additions and 3 deletions.
10 changes: 7 additions & 3 deletions karapace/metrics.py
Original file line number Diff line number Diff line change
Expand Up @@ -40,6 +40,8 @@ def __init__(
) -> None:
self.is_ready = False
self.lock = threading.Lock()
self.request_size_total = 0
self.request_count = 0

def setup(self, config: Config) -> None:
with self.lock:
Expand All @@ -62,14 +64,16 @@ def request(self, size: int) -> None:
return
if not isinstance(self.stats_client, StatsClient):
raise RuntimeError("no StatsClient available")
self.stats_client.gauge("request-size", size)
self.stats_client.increase("request-size-total", size)
self.stats_client.increase("request-count", 1)

def response(self, size: int) -> None:
if not self.is_ready or self.stats_client is None:
return
if not isinstance(self.stats_client, StatsClient):
raise RuntimeError("no StatsClient available")
self.stats_client.gauge("response-size", size)
self.stats_client.increase("response-size-total", size)
self.stats_client.increase("response-count", 1)

def are_we_master(self, is_master: bool) -> None:
if not self.is_ready or self.stats_client is None:
Expand All @@ -90,7 +94,7 @@ def error(self) -> None:
return
if not isinstance(self.stats_client, StatsClient):
raise RuntimeError("no StatsClient available")
self.stats_client.increase("error_total", 1)
self.stats_client.increase("error-total", 1)

def cleanup(self) -> None:
if self.stats_client:
Expand Down

0 comments on commit 5da8ca8

Please sign in to comment.