Skip to content
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

Use correct signatures for Celery Task Hooks #791

Merged
merged 1 commit into from
Oct 21, 2024
Merged

Conversation

Swatinem
Copy link
Contributor

This explicitly declares and forwards all the arguments to the on_success/retry/failure task hooks, as they are documented on https://docs.celeryq.dev/en/main/_modules/celery/app/task.html#Task.on_success

The reason being that the Sentry tags set via the MetricContext constructor are not making their way to Sentry, possibly because the kwargs were misused in the previous hooks, and were overwriting those tag values with None.

So this should ideally solve that mystery.

As a driveby change, I also took the liberty of removing all the deprecated statsd metrics calls. All of the relevant metrics also have prometheus equivalents.

@Swatinem Swatinem requested a review from a team October 16, 2024 09:37
@Swatinem Swatinem self-assigned this Oct 16, 2024
Copy link

codecov bot commented Oct 16, 2024

Codecov Report

Attention: Patch coverage is 96.96970% with 1 line in your changes missing coverage. Please review.

Project coverage is 98.01%. Comparing base (112592f) to head (8c66f91).
Report is 7 commits behind head on main.

✅ All tests successful. No failed tests found.

Files with missing lines Patch % Lines
helpers/telemetry.py 50.00% 1 Missing ⚠️
Additional details and impacted files

Impacted file tree graph

@@           Coverage Diff           @@
##             main     #791   +/-   ##
=======================================
  Coverage   98.01%   98.01%           
=======================================
  Files         442      443    +1     
  Lines       36597    36533   -64     
=======================================
- Hits        35869    35808   -61     
+ Misses        728      725    -3     
Flag Coverage Δ
integration 98.01% <96.96%> (+<0.01%) ⬆️
unit 98.01% <96.96%> (+<0.01%) ⬆️

Flags with carried forward coverage won't be shown. Click here to find out more.

Components Coverage Δ
NonTestCode 95.89% <96.42%> (+0.01%) ⬆️
OutsideTasks 98.00% <50.00%> (+0.01%) ⬆️
Files with missing lines Coverage Δ
tasks/base.py 95.90% <100.00%> (-0.84%) ⬇️
tasks/tests/unit/test_base.py 98.30% <100.00%> (-0.07%) ⬇️
helpers/telemetry.py 91.04% <50.00%> (+4.20%) ⬆️

... and 4 files with indirect coverage changes

@codecov-notifications
Copy link

codecov-notifications bot commented Oct 16, 2024

Codecov Report

Attention: Patch coverage is 96.96970% with 1 line in your changes missing coverage. Please review.

✅ All tests successful. No failed tests found.

Files with missing lines Patch % Lines
helpers/telemetry.py 50.00% 1 Missing ⚠️

Impacted file tree graph

@@           Coverage Diff           @@
##             main     #791   +/-   ##
=======================================
  Coverage   98.01%   98.01%           
=======================================
  Files         442      443    +1     
  Lines       36597    36533   -64     
=======================================
- Hits        35869    35808   -61     
+ Misses        728      725    -3     
Flag Coverage Δ
integration 98.01% <96.96%> (+<0.01%) ⬆️
unit 98.01% <96.96%> (+<0.01%) ⬆️

Flags with carried forward coverage won't be shown. Click here to find out more.

Components Coverage Δ
NonTestCode 95.89% <96.42%> (+0.01%) ⬆️
OutsideTasks 98.00% <50.00%> (+0.01%) ⬆️
Files with missing lines Coverage Δ
tasks/base.py 95.90% <100.00%> (-0.84%) ⬇️
tasks/tests/unit/test_base.py 98.30% <100.00%> (-0.07%) ⬇️
helpers/telemetry.py 91.04% <50.00%> (+4.20%) ⬆️

... and 4 files with indirect coverage changes

@codecov-qa
Copy link

codecov-qa bot commented Oct 16, 2024

Codecov Report

Attention: Patch coverage is 96.96970% with 1 line in your changes missing coverage. Please review.

Project coverage is 98.01%. Comparing base (112592f) to head (8c66f91).
Report is 7 commits behind head on main.

✅ All tests successful. No failed tests found.

Files with missing lines Patch % Lines
helpers/telemetry.py 50.00% 1 Missing ⚠️

Impacted file tree graph

@@           Coverage Diff           @@
##             main     #791   +/-   ##
=======================================
  Coverage   98.01%   98.01%           
=======================================
  Files         442      443    +1     
  Lines       36597    36533   -64     
=======================================
- Hits        35869    35808   -61     
+ Misses        728      725    -3     
Flag Coverage Δ
integration 98.01% <96.96%> (+<0.01%) ⬆️
unit 98.01% <96.96%> (+<0.01%) ⬆️

Flags with carried forward coverage won't be shown. Click here to find out more.

Components Coverage Δ
NonTestCode 95.89% <96.42%> (+0.01%) ⬆️
OutsideTasks 98.00% <50.00%> (+0.01%) ⬆️
Files with missing lines Coverage Δ
tasks/base.py 95.90% <100.00%> (-0.84%) ⬇️
tasks/tests/unit/test_base.py 98.30% <100.00%> (-0.07%) ⬇️
helpers/telemetry.py 91.04% <50.00%> (+4.20%) ⬆️

... and 4 files with indirect coverage changes

Copy link

codecov-public-qa bot commented Oct 16, 2024

Codecov Report

Attention: Patch coverage is 96.96970% with 1 line in your changes missing coverage. Please review.

Project coverage is 98.01%. Comparing base (112592f) to head (8c66f91).
Report is 6 commits behind head on main.

✅ All tests successful. No failed tests found.

Impacted file tree graph

@@           Coverage Diff           @@
##             main     #791   +/-   ##
=======================================
  Coverage   98.01%   98.01%           
=======================================
  Files         442      443    +1     
  Lines       36597    36533   -64     
=======================================
- Hits        35869    35808   -61     
+ Misses        728      725    -3     
Flag Coverage Δ
integration 98.01% <96.96%> (+<0.01%) ⬆️
unit 98.01% <96.96%> (+<0.01%) ⬆️

Flags with carried forward coverage won't be shown. Click here to find out more.

Components Coverage Δ
NonTestCode 95.89% <96.42%> (+0.01%) ⬆️
OutsideTasks 98.00% <50.00%> (+0.01%) ⬆️
Files Coverage Δ
tasks/base.py 95.90% <100.00%> (-0.84%) ⬇️
tasks/tests/unit/test_base.py 98.30% <100.00%> (-0.07%) ⬇️
helpers/telemetry.py 91.04% <50.00%> (+4.20%) ⬆️

... and 4 files with indirect coverage changes

Copy link
Contributor

@matt-codecov matt-codecov left a comment

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

did you observe that this behaves differently? it's a little surprising to me

tasks/base.py Outdated Show resolved Hide resolved
Copy link
Contributor

@matt-codecov matt-codecov left a comment

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

self.metrics_prefix might also be dead code now too

EDIT nvm it's referenced in task subclasses still

This explicitly declares and forwards all the arguments to the `on_success/retry/failure` task hooks, as they are documented on https://docs.celeryq.dev/en/main/_modules/celery/app/task.html#Task.on_success

The reason being that the Sentry tags set via the `MetricContext` constructor are not making their way to Sentry, possibly because the `kwargs` were misused in the previous hooks, and were overwriting those tag values with `None`.

So this should ideally solve that mystery.

As a driveby change, I also took the liberty of removing all the deprecated statsd `metrics` calls. All of the relevant metrics also have prometheus equivalents.
@Swatinem Swatinem added this pull request to the merge queue Oct 21, 2024
Merged via the queue into main with commit e7432b4 Oct 21, 2024
24 of 27 checks passed
@Swatinem Swatinem deleted the swatinem/task-hooks branch October 21, 2024 09:00
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
None yet
Projects
None yet
Development

Successfully merging this pull request may close these issues.

2 participants