-
-
Notifications
You must be signed in to change notification settings - Fork 0
Introduce lightweight stats #305
New issue
Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.
By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.
Already on GitHub? Sign in to your account
base: main
Are you sure you want to change the base?
Changes from all commits
257bd53
15baf67
17d846b
a94272c
30dc9fc
cf3d1e4
File filter
Filter by extension
Conversations
Jump to
Diff view
Diff view
There are no files selected for viewing
| Original file line number | Diff line number | Diff line change |
|---|---|---|
| @@ -0,0 +1,59 @@ | ||
| import time | ||
| from collections import defaultdict | ||
|
|
||
| from sentry_streams.metrics import Metrics | ||
| from sentry_streams.metrics.metrics import Metric, get_raw_metrics | ||
|
|
||
| FLUSH_TIME = 10 | ||
|
|
||
|
|
||
| class PipielineStats: | ||
|
There was a problem hiding this comment. Choose a reason for hiding this commentThe reason will be displayed to describe this comment to others. Learn more. Class name
|
||
|
|
||
| def __init__(self, metrics: Metrics) -> None: | ||
| self._metrics = metrics | ||
|
|
||
| self._exec_buffer: dict[str, int] = defaultdict(int) | ||
| self._error_buffer: dict[str, int] = defaultdict(int) | ||
| self._timing_buffer: dict[str, float] = defaultdict(float) | ||
|
|
||
| self.__last_flush_time = 0.0 | ||
|
|
||
| def step_exec(self, step: str) -> None: | ||
| self._exec_buffer[step] += 1 | ||
| self._maybe_flush() | ||
|
|
||
| def step_error(self, step: str) -> None: | ||
| self._error_buffer[step] += 1 | ||
| self._maybe_flush() | ||
|
|
||
| def step_timing(self, step: str, value: float) -> None: | ||
| if self._timing_buffer[step] < value: | ||
| self._timing_buffer[step] = value | ||
| self._maybe_flush() | ||
|
|
||
| def _maybe_flush(self) -> None: | ||
| if time.time() - self.__last_flush_time >= FLUSH_TIME: | ||
| self.__last_flush_time = time.time() | ||
| for step, value in self._exec_buffer.items(): | ||
| tags = {"step": step} | ||
| self._metrics.increment(Metric.INPUT_MESSAGES, value, tags) | ||
| for step, value in self._error_buffer.items(): | ||
| tags = {"step": step} | ||
| self._metrics.increment(Metric.ERRORS, value, tags) | ||
| for step, fvalue in self._timing_buffer.items(): | ||
| tags = {"step": step} | ||
| self._metrics.timing(Metric.DURATION, fvalue, tags) | ||
|
There was a problem hiding this comment. Choose a reason for hiding this commentThe reason will be displayed to describe this comment to others. Learn more.
|
||
|
|
||
| self._exec_buffer = defaultdict(int) | ||
| self._error_buffer = defaultdict(int) | ||
| self._timing_buffer = defaultdict(float) | ||
|
sentry[bot] marked this conversation as resolved.
cursor[bot] marked this conversation as resolved.
|
||
|
|
||
|
|
||
| _stats: PipielineStats | None = None | ||
|
|
||
|
|
||
| def get_stats() -> PipielineStats: | ||
| global _stats | ||
| if _stats is None: | ||
| _stats = PipielineStats(get_raw_metrics()) | ||
| return _stats | ||
|
There was a problem hiding this comment. Choose a reason for hiding this commentThe reason will be displayed to describe this comment to others. Learn more.
|
||


Uh oh!
There was an error while loading. Please reload this page.