-
Notifications
You must be signed in to change notification settings - Fork 92
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
feat(metrics): Forward received_at field to Kafka #3561
Changes from all commits
96b2afa
19215e1
298c9fa
187d1b5
7572a51
0d18245
c865cd4
ee9b3f7
def59a0
d5b88d8
9bc8367
cd8cc42
b5ecdb9
bdf8a03
a78b197
27e48d7
74990f5
de8bbd5
c2eaeb3
bdadda5
06736db
ad14b6b
bb4a0a2
342da97
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,3 @@ | ||
from .time import time_after, time_within, time_within_delta | ||
|
||
__all__ = ["time_after", "time_within", "time_within_delta"] |
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,35 @@ | ||
from datetime import timedelta, datetime, timezone | ||
|
||
|
||
class _WithinBounds: | ||
|
||
def __init__(self, lower_bound, upper_bound): | ||
self._lower_bound = lower_bound | ||
self._upper_bound = upper_bound | ||
|
||
def __eq__(self, other): | ||
assert isinstance(other, int) | ||
return self._lower_bound <= other <= self._upper_bound | ||
|
||
def __str__(self): | ||
return f"{self._lower_bound} <= x <= {self._upper_bound}" | ||
|
||
|
||
def time_after(lower_bound): | ||
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. This doesn't assert after, but after until now. I think making the upper bound on 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. Yeah, I was indeed thinking about a better name. |
||
upper_bound = int(datetime.now(tz=timezone.utc).timestamp()) | ||
return time_within(lower_bound, upper_bound) | ||
|
||
|
||
def time_within(lower_bound, upper_bound): | ||
assert lower_bound <= upper_bound | ||
return _WithinBounds(lower_bound, upper_bound) | ||
|
||
|
||
def time_within_delta(timestamp, delta=None): | ||
if delta is None: | ||
delta = timedelta(seconds=5) | ||
|
||
lower_bound = (datetime.fromtimestamp(timestamp) - delta).timestamp() | ||
upper_bound = (datetime.fromtimestamp(timestamp) + delta).timestamp() | ||
|
||
return _WithinBounds(lower_bound, upper_bound) |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
Surprised the formatter doesn't complain about this newline