-
Notifications
You must be signed in to change notification settings - Fork 16
Expand file tree
/
Copy path_statistics.py
More file actions
29 lines (20 loc) · 903 Bytes
/
_statistics.py
File metadata and controls
29 lines (20 loc) · 903 Bytes
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
from __future__ import annotations
from collections import defaultdict
from dataclasses import dataclass, field
@dataclass
class ClientStatistics:
"""Statistics about API client usage and rate limit errors."""
calls: int = 0
"""Total number of API method calls made by the client."""
requests: int = 0
"""Total number of HTTP requests sent, including retries."""
rate_limit_errors: defaultdict[int, int] = field(default_factory=lambda: defaultdict(int))
"""List tracking which retry attempts encountered rate limit (429) errors."""
def add_rate_limit_error(self, attempt: int) -> None:
"""Add rate limit error for specific attempt.
Args:
attempt: The attempt number (1-based indexing).
"""
if attempt < 1:
raise ValueError('Attempt must be greater than 0')
self.rate_limit_errors[attempt - 1] += 1