-
-
Notifications
You must be signed in to change notification settings - Fork 4.5k
ref(cleanup): Minor changes #101558
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
ref(cleanup): Minor changes #101558
Changes from all commits
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 |
|---|---|---|
|
|
@@ -78,8 +78,9 @@ def multiprocess_worker(task_queue: _WorkQueue) -> None: | |
| configure() | ||
|
|
||
| from sentry import deletions, models, similarity | ||
| from sentry.utils import metrics | ||
|
|
||
| skip_models = [ | ||
| skip_child_relations_models = [ | ||
| # Handled by other parts of cleanup | ||
| models.EventAttachment, | ||
| models.UserReport, | ||
|
|
@@ -98,19 +99,25 @@ def multiprocess_worker(task_queue: _WorkQueue) -> None: | |
| return | ||
|
|
||
| model_name, chunk = j | ||
| model = import_string(model_name) | ||
|
|
||
| try: | ||
| task = deletions.get( | ||
| model=model, | ||
| query={"id__in": chunk}, | ||
| skip_models=skip_models, | ||
| transaction_id=uuid4().hex, | ||
| ) | ||
| with sentry_sdk.start_transaction( | ||
| op="cleanup", name="multiprocess_worker" | ||
| ) as transaction: | ||
| transaction.set_tag("model", model_name) | ||
| model = import_string(model_name) | ||
| task = deletions.get( | ||
| model=model, | ||
| query={"id__in": chunk}, | ||
| skip_models=skip_child_relations_models, | ||
| transaction_id=uuid4().hex, | ||
| ) | ||
|
|
||
| while True: | ||
| if not task.chunk(apply_filter=True): | ||
| break | ||
| while True: | ||
| if not task.chunk(apply_filter=True): | ||
| break | ||
| except Exception: | ||
| metrics.incr("cleanup.error", instance=model_name, sample_rate=1.0) | ||
| logger.exception("Error in multiprocess_worker.") | ||
| finally: | ||
| task_queue.task_done() | ||
|
|
@@ -137,7 +144,8 @@ def multiprocess_worker(task_queue: _WorkQueue) -> None: | |
| "-t", | ||
| default=False, | ||
| is_flag=True, | ||
| help="Send the duration of this command to internal metrics.", | ||
| hidden=True, | ||
| help="(deprecated) Send the duration of this command to internal metrics.", | ||
|
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. All scripts are passing the |
||
| ) | ||
| @log_options() | ||
| def cleanup( | ||
|
|
@@ -166,7 +174,6 @@ def cleanup( | |
| concurrency=concurrency, | ||
| silent=silent, | ||
| router=router, | ||
| timed=timed, | ||
| ) | ||
|
|
||
|
|
||
|
|
@@ -178,7 +185,6 @@ def _cleanup( | |
| concurrency: int, | ||
| silent: bool, | ||
| router: str | None, | ||
| timed: bool, | ||
| ) -> None: | ||
| _validate_and_setup_environment(concurrency, silent) | ||
| # Make sure we fork off multiprocessing pool | ||
|
|
@@ -189,18 +195,14 @@ def _cleanup( | |
| # transaction context issues in child processes. This ensures only the | ||
| # main process tracks the overall cleanup operation performance. | ||
| with sentry_sdk.start_transaction(op="cleanup", name="cleanup") as transaction: | ||
| transaction.set_tag("router", router) | ||
| transaction.set_tag("model", model) | ||
|
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. All errors are happening within the processes, thus, these taggings are useless. |
||
| try: | ||
| from sentry.runner import configure | ||
|
|
||
| configure() | ||
|
|
||
| from sentry.utils import metrics | ||
|
|
||
| start_time = None | ||
| if timed: | ||
| start_time = time.time() | ||
| start_time = time.time() | ||
|
|
||
| # list of models which this query is restricted to | ||
| model_list = {m.lower() for m in model} | ||
|
|
@@ -286,7 +288,7 @@ def is_filtered(model: type[Model]) -> bool: | |
| # Shut down our pool | ||
| _stop_pool(pool, task_queue) | ||
|
|
||
| if timed and start_time: | ||
| if start_time: | ||
| duration = int(time.time() - start_time) | ||
| metrics.timing("cleanup.duration", duration, instance=router, sample_rate=1.0) | ||
| click.echo("Clean up took %s second(s)." % duration) | ||
|
|
||
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.
This section is easier to review by hiding the white spaces:
https://github.com/getsentry/sentry/pull/101558/files?diff=split&w=1