-
-
Notifications
You must be signed in to change notification settings - Fork 4.4k
ref(replay): delete seer data on replay deletes #97279
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
Merged
Merged
Changes from all commits
Commits
Show all changes
28 commits
Select commit
Hold shift + click to select a range
6d82529
ref(replay): delete seer data on replay deletes
aliu39 e9d5e74
Use settings default timeout
aliu39 d266671
Update success check
aliu39 f3a8987
Update timeout default
aliu39 e68507c
rewrite w no org query
aliu39 839fc03
Add delete coverage
aliu39 d5b49ad
api req tests
aliu39 bcaedad
Add bulk del endpoint test
aliu39 c30b83e
Fix bulk task tests
aliu39 ea2a4f7
Merge branch 'master' into aliu/del-summaries
aliu39 106a2dd
Add chained bulk tests
aliu39 88bed44
Type fix
aliu39 b1544f5
Add trace
aliu39 b6f4260
Use const in delete fx
aliu39 42af1f0
Exclude org proj id from request
aliu39 8547d89
Fix comment
aliu39 53099af
Update util docstr
aliu39 a4fbe3b
Dont raise for status
aliu39 6c82321
del comment
aliu39 2dcb435
Review
aliu39 ef6e9aa
Merge branch 'master' of github.com:getsentry/sentry into aliu/del-su…
aliu39 5d7827f
Rename task and metric
aliu39 f2a60ec
Rm util
aliu39 9256626
Del unused const
aliu39 cf7f970
Fix
aliu39 dbe8ceb
Merge branch 'master' into aliu/del-summaries
aliu39 597ac20
:hammer_and_wrench: apply pre-commit fixes
getsantry[bot] 3baf1d2
timeout param
aliu39 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 hidden or 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 hidden or 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 hidden or 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 |
---|---|---|
|
@@ -15,7 +15,11 @@ | |
storage_kv, | ||
) | ||
from sentry.replays.models import DeletionJobStatus, ReplayDeletionJobModel, ReplayRecordingSegment | ||
from sentry.replays.usecases.delete import delete_matched_rows, fetch_rows_matching_pattern | ||
from sentry.replays.usecases.delete import ( | ||
delete_matched_rows, | ||
delete_seer_replay_data, | ||
fetch_rows_matching_pattern, | ||
) | ||
from sentry.replays.usecases.events import archive_event | ||
from sentry.replays.usecases.reader import fetch_segments_metadata | ||
from sentry.silo.base import SiloMode | ||
|
@@ -30,7 +34,7 @@ | |
|
||
|
||
@instrumented_task( | ||
name="sentry.replays.tasks.delete_recording_segments", | ||
name="sentry.replays.tasks.delete_replay", | ||
queue="replays.delete_replay", | ||
default_retry_delay=5, | ||
max_retries=5, | ||
|
@@ -43,32 +47,17 @@ | |
), | ||
), | ||
) | ||
def delete_recording_segments(project_id: int, replay_id: str, **kwargs: Any) -> None: | ||
def delete_replay( | ||
project_id: int, replay_id: str, has_seer_data: bool = False, **kwargs: Any | ||
) -> None: | ||
"""Asynchronously delete a replay.""" | ||
metrics.incr("replays.delete_recording_segments", amount=1, tags={"status": "started"}) | ||
metrics.incr("replays.delete_replay", amount=1, tags={"status": "started"}) | ||
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. Not sure if we're using this metric anywhere, I can restore if needed |
||
publisher = initialize_replays_publisher(is_async=False) | ||
archive_replay(publisher, project_id, replay_id) | ||
delete_replay_recording(project_id, replay_id) | ||
metrics.incr("replays.delete_recording_segments", amount=1, tags={"status": "finished"}) | ||
|
||
|
||
@instrumented_task( | ||
name="sentry.replays.tasks.delete_replay_recording_async", | ||
queue="replays.delete_replay", | ||
default_retry_delay=5, | ||
max_retries=5, | ||
silo_mode=SiloMode.REGION, | ||
taskworker_config=TaskworkerConfig( | ||
namespace=replays_tasks, | ||
processing_deadline_duration=120, | ||
retry=Retry( | ||
times=5, | ||
delay=5, | ||
), | ||
), | ||
) | ||
def delete_replay_recording_async(project_id: int, replay_id: str) -> None: | ||
delete_replay_recording(project_id, replay_id) | ||
if has_seer_data: | ||
delete_seer_replay_data(project_id, [replay_id]) | ||
metrics.incr("replays.delete_replay", amount=1, tags={"status": "finished"}) | ||
|
||
|
||
@instrumented_task( | ||
|
@@ -117,6 +106,25 @@ def delete_replays_script_async( | |
segment_model.delete() | ||
|
||
|
||
@instrumented_task( | ||
name="sentry.replays.tasks.delete_replay_recording_async", | ||
queue="replays.delete_replay", | ||
default_retry_delay=5, | ||
max_retries=5, | ||
silo_mode=SiloMode.REGION, | ||
taskworker_config=TaskworkerConfig( | ||
namespace=replays_tasks, | ||
processing_deadline_duration=120, | ||
retry=Retry( | ||
times=5, | ||
delay=5, | ||
), | ||
), | ||
) | ||
def delete_replay_recording_async(project_id: int, replay_id: str) -> None: | ||
delete_replay_recording(project_id, replay_id) | ||
|
||
|
||
def delete_replay_recording(project_id: int, replay_id: str) -> None: | ||
"""Delete all recording-segments associated with a Replay.""" | ||
segments_from_metadata = fetch_segments_metadata(project_id, replay_id, offset=0, limit=10000) | ||
|
@@ -178,7 +186,9 @@ def _delete_if_exists(filename: str) -> None: | |
namespace=replays_tasks, retry=Retry(times=5), processing_deadline_duration=300 | ||
), | ||
) | ||
def run_bulk_replay_delete_job(replay_delete_job_id: int, offset: int, limit: int = 100) -> None: | ||
def run_bulk_replay_delete_job( | ||
replay_delete_job_id: int, offset: int, limit: int = 100, has_seer_data: bool = False | ||
) -> None: | ||
"""Replay bulk deletion task. | ||
|
||
We specify retry behavior in the task definition. However, if the task fails more than 5 times | ||
|
@@ -213,6 +223,10 @@ def run_bulk_replay_delete_job(replay_delete_job_id: int, offset: int, limit: in | |
# Delete the matched rows if any rows were returned. | ||
if len(results["rows"]) > 0: | ||
delete_matched_rows(job.project_id, results["rows"]) | ||
if has_seer_data: | ||
delete_seer_replay_data( | ||
job.project_id, [row["replay_id"] for row in results["rows"]] | ||
) | ||
except Exception: | ||
logger.exception("Bulk delete replays failed.") | ||
|
||
|
@@ -228,8 +242,9 @@ def run_bulk_replay_delete_job(replay_delete_job_id: int, offset: int, limit: in | |
# Checkpoint before continuing. | ||
job.offset = next_offset | ||
job.save() | ||
|
||
run_bulk_replay_delete_job.delay(job.id, next_offset, limit=limit) | ||
run_bulk_replay_delete_job.delay( | ||
job.id, next_offset, limit=limit, has_seer_data=has_seer_data | ||
) | ||
return None | ||
else: | ||
# If we've finished deleting all the replays for the selection. We can move the status to | ||
|
This file contains hidden or 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 hidden or 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 hidden or 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
Oops, something went wrong.
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.
Renamed this to match its purpose of deleting a single replay - archive event, del recording segments, and request seer. Maybe this can later be replaced by this task I removed recently, since they seem to be very similar?