-
-
Notifications
You must be signed in to change notification settings - Fork 4.2k
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(events tracking): add abstract class and logging implementation #80117
Draft
victoria-yining-huang
wants to merge
18
commits into
master
Choose a base branch
from
vic/add_logging_module
base: master
Could not load branches
Branch not found: {{ refName }}
Loading
Could not load tags
Nothing to show
Loading
Are you sure you want to change the base?
Some commits from the old base branch may be removed from the timeline,
and old review comments may become outdated.
+138
−0
Draft
Changes from 6 commits
Commits
Show all changes
18 commits
Select commit
Hold shift + click to select a range
ee51aa6
add file
victoria-yining-huang c09a7c4
add updated list of enums
victoria-yining-huang 8b5234b
add sampling
victoria-yining-huang 3143ea2
add redis put
victoria-yining-huang e6aea02
add sampling logic
victoria-yining-huang f8ba9f5
add extra
victoria-yining-huang 1964004
remove class
victoria-yining-huang 7705719
add .value
victoria-yining-huang db6d669
change enum value to int
victoria-yining-huang e21b7bc
use IntEnum
victoria-yining-huang b63ca40
add test first pass
victoria-yining-huang ec9a363
add hash sampling
victoria-yining-huang 318f241
update status enum
victoria-yining-huang d01bd37
docstring
victoria-yining-huang 6f13c83
comment
victoria-yining-huang 024fe35
add wip
victoria-yining-huang f2ea24c
wip
victoria-yining-huang bbcab56
tests pass
victoria-yining-huang File filter
Filter by extension
Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
There are no files selected for viewing
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,59 @@ | ||
import logging | ||
import random | ||
from enum import Enum | ||
|
||
|
||
class EventStageStatus(Enum): | ||
START = "start" | ||
END = "end" | ||
REDIS_PUT = "redis_put" | ||
""" | ||
i plan on adding the below enums for every step of the transactions pipeline | ||
ingest_consumer_published | ||
redis_put | ||
save_event_started | ||
save_event_finished | ||
snuba_topic_put | ||
commit_log_topic_put | ||
ppf_topic_put | ||
post_process_started | ||
post_process_finished / the same as redis_deleted | ||
""" | ||
|
||
|
||
class EventTracker: | ||
victoria-yining-huang marked this conversation as resolved.
Show resolved
Hide resolved
|
||
""" | ||
Logger-based implementation of EventTrackerBackend. The data will be saved in BigQuery using Google Log Sink | ||
""" | ||
|
||
def __init__(self, sample_rate: float = 0.01): | ||
""" | ||
Args: | ||
sample_rate (float): The probability (0.0 to 1.0) that an event is recorded. | ||
A value of 1.0 records all events, 0.1 records approximately 10% of events. | ||
""" | ||
self.logger = logging.getLogger("EventTracker") | ||
victoria-yining-huang marked this conversation as resolved.
Show resolved
Hide resolved
|
||
self.sample_rate = sample_rate | ||
|
||
def is_tracked(self) -> bool: | ||
if random.random() > self.sample_rate: | ||
return | ||
return True | ||
victoria-yining-huang marked this conversation as resolved.
Show resolved
Hide resolved
|
||
|
||
def record_event_stage_status( | ||
self, event_id: str, status: EventStageStatus, is_tracked: bool = False | ||
): | ||
""" | ||
Records how far an event has made it through the ingestion pipeline. | ||
""" | ||
if is_tracked: | ||
extra = {"event_id": event_id, "status": status} | ||
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. You need to do Alternatively you can use |
||
self.logger.info("EventTracker.recorded", extra=extra) |
Oops, something went wrong.
Add this suggestion to a batch that can be applied as a single commit.
This suggestion is invalid because no changes were made to the code.
Suggestions cannot be applied while the pull request is closed.
Suggestions cannot be applied while viewing a subset of changes.
Only one suggestion per line can be applied in a batch.
Add this suggestion to a batch that can be applied as a single commit.
Applying suggestions on deleted lines is not supported.
You must change the existing code in this line in order to create a valid suggestion.
Outdated suggestions cannot be applied.
This suggestion has been applied or marked resolved.
Suggestions cannot be applied from pending reviews.
Suggestions cannot be applied on multi-line comments.
Suggestions cannot be applied while the pull request is queued to merge.
Suggestion cannot be applied right now. Please check back later.
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.
Consider making the enum an integer. That would take a lot less memory in redis.
The galaxy brain version would be to create a bitmap. One bit per phase. Each event only needs 12 bits to encode all phases. https://redis.io/docs/latest/develop/data-types/bitmaps/
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.
not writing to redis with the logging implementation but i get the idea