Skip to content

Commit a4c47a4

Browse files
Dav1ddeandrewshie-sentry
authored andcommitted
Revert "fix(taskworker) Remove countdown from relay tasks" (#92610)
Reverts #88819 Metrics show increased load since this PR was merged, which leads to increased calculation times overall.
1 parent 3d61e1d commit a4c47a4

File tree

5 files changed

+19
-6
lines changed

5 files changed

+19
-6
lines changed

bin/invalidate-project-configs

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -37,7 +37,7 @@ def invalidate_project_configs(percentage):
3737
for org_id in RangeQuerySetWrapperWithProgressBar(queryset, result_value_getter=lambda x: x):
3838
if (org_id % 100) < percentage:
3939
schedule_invalidate_project_config(
40-
trigger="invalidate-all-orgs", organization_id=org_id
40+
trigger="invalidate-all-orgs", organization_id=org_id, countdown=0
4141
)
4242

4343

src/sentry/killswitches.py

Lines changed: 3 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -48,7 +48,9 @@ def _update_project_configs(
4848
for org_id in (
4949
Organization.objects.values_list("id", flat=True).all().iterator(chunk_size=50_000)
5050
):
51-
schedule_invalidate_project_config(trigger="invalidate-all", organization_id=org_id)
51+
schedule_invalidate_project_config(
52+
trigger="invalidate-all", organization_id=org_id, countdown=0
53+
)
5254
bar.update(1)
5355
else:
5456
with click.progressbar(changed_project_ids) as ids:

src/sentry/tasks/relay.py

Lines changed: 8 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -262,6 +262,7 @@ def schedule_invalidate_project_config(
262262
organization_id=None,
263263
project_id=None,
264264
public_key=None,
265+
countdown=5,
265266
transaction_db=None,
266267
):
267268
"""Schedules the :func:`invalidate_project_config` task.
@@ -287,12 +288,15 @@ def schedule_invalidate_project_config(
287288
>>> )
288289
289290
If there is no active database transaction open for the provided ``transaction_db``,
290-
the project config task is scheduled immediately.
291+
the project config task is executed immediately.
291292
292293
:param trigger: The reason for the invalidation. This is used to tag metrics.
293294
:param organization_id: Invalidates all project keys for all projects in an organization.
294295
:param project_id: Invalidates all project keys for a project.
295296
:param public_key: Invalidate a single public key.
297+
:param countdown: The time to delay running this task in seconds. Normally there is a
298+
slight delay to increase the likelihood of deduplicating invalidations but you can
299+
tweak this, like e.g. the :func:`invalidate_all` task does.
296300
:param transaction_db: The database currently being used by an active transaction.
297301
This directs the on_commit handler for the task to the correct transaction.
298302
"""
@@ -316,6 +320,7 @@ def schedule_invalidate_project_config(
316320
organization_id=organization_id,
317321
project_id=project_id,
318322
public_key=public_key,
323+
countdown=countdown,
319324
),
320325
using=transaction_db,
321326
)
@@ -327,6 +332,7 @@ def _schedule_invalidate_project_config(
327332
organization_id=None,
328333
project_id=None,
329334
public_key=None,
335+
countdown=5,
330336
):
331337
"""For param docs, see :func:`schedule_invalidate_project_config`."""
332338
from sentry.models.project import Project
@@ -375,6 +381,7 @@ def _schedule_invalidate_project_config(
375381
)
376382

377383
invalidate_project_config.apply_async(
384+
countdown=countdown,
378385
kwargs={
379386
"project_id": project_id,
380387
"organization_id": organization_id,

tests/sentry/runner/commands/test_killswitches.py

Lines changed: 1 addition & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -161,5 +161,6 @@ def test_relay_drop_transaction_metrics_all(self, mock_set, mock_schedule):
161161
mock.call(
162162
trigger="invalidate-all",
163163
organization_id=mock_schedule.mock_calls[0].kwargs["organization_id"],
164+
countdown=0,
164165
)
165166
]

tests/sentry/tasks/test_relay.py

Lines changed: 6 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -465,7 +465,9 @@ def test_project_config_invalidations_after_commit(
465465
schedule_inner,
466466
default_project,
467467
):
468-
schedule_invalidate_project_config(trigger="test", project_id=default_project.id)
468+
schedule_invalidate_project_config(
469+
trigger="test", project_id=default_project.id, countdown=2
470+
)
469471

470472
assert oncommit.call_count == 1
471473
assert schedule_inner.call_count == 1
@@ -474,6 +476,7 @@ def test_project_config_invalidations_after_commit(
474476
organization_id=None,
475477
project_id=default_project.id,
476478
public_key=None,
479+
countdown=2,
477480
)
478481

479482
@mock.patch("sentry.tasks.relay._schedule_invalidate_project_config")
@@ -484,13 +487,13 @@ def test_project_config_invalidations_delayed(
484487
):
485488
with transaction.atomic(router.db_for_write(ProjectOption)):
486489
schedule_invalidate_project_config(
487-
trigger="inside-transaction", project_id=default_project
490+
trigger="inside-transaction", project_id=default_project, countdown=2
488491
)
489492
assert schedule_inner.call_count == 0
490493

491494
assert schedule_inner.call_count == 1
492495
schedule_invalidate_project_config(
493-
trigger="outside-transaction", project_id=default_project
496+
trigger="outside-transaction", project_id=default_project, countdown=2
494497
)
495498
assert schedule_inner.call_count == 2
496499

0 commit comments

Comments
 (0)