Skip to content

fix(taskworker) Remove pickle usage from sentryapps task #91372

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 2 commits into from
May 9, 2025

Conversation

markstory
Copy link
Member

The event parameter of process_service_hook requires pickle. By generating the payload before spawning a task, we don't have to use pickle.

Refs SENTRY-3V47

The `event` parameter of process_service_hook requires pickle. By
generating the payload before spawning a task, we don't have to
use pickle.

Refs SENTRY-3V47
@markstory markstory requested a review from a team May 9, 2025 18:55
@markstory markstory requested review from a team as code owners May 9, 2025 18:55
@github-actions github-actions bot added the Scope: Backend Automatically applied to PRs that change backend components label May 9, 2025
Comment on lines +1197 to +1202
process_service_hook.delay(
servicehook_id=servicehook_id,
project_id=event.project_id,
event=event,
payload=payload,
)
Copy link
Member Author

Choose a reason for hiding this comment

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

Because process_service_hook already supports kwargs we can provide the new args at the same time as expanding the signature.

Comment on lines +57 to +61
if not payload:
if servicehook.version == 0:
payload = json.dumps(get_payload_v0(event))
else:
raise NotImplementedError
Copy link
Member Author

Choose a reason for hiding this comment

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

Passing in the serialized payload as a string saves us pickle + two json.dumps calls here 🚀

Copy link

codecov bot commented May 9, 2025

Codecov Report

Attention: Patch coverage is 92.59259% with 2 lines in your changes missing coverage. Please review.

✅ All tests successful. No failed tests found.

Files with missing lines Patch % Lines
src/sentry/sentry_apps/tasks/service_hooks.py 75.00% 2 Missing ⚠️
Additional details and impacted files
@@            Coverage Diff             @@
##           master   #91372      +/-   ##
==========================================
- Coverage   87.64%   87.63%   -0.01%     
==========================================
  Files       10328    10330       +2     
  Lines      586134   586295     +161     
  Branches    22628    22628              
==========================================
+ Hits       513713   513826     +113     
- Misses      71994    72042      +48     
  Partials      427      427              

Copy link
Contributor

@Christinarlong Christinarlong left a comment

Choose a reason for hiding this comment

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

Makes sense to me, we're replacing the event parameter/var with the serialized payload.

@markstory markstory merged commit 81d0180 into master May 9, 2025
60 checks passed
@markstory markstory deleted the fix-sentryapp-param branch May 9, 2025 21:34
Copy link

sentry-io bot commented May 9, 2025

Suspect Issues

This pull request was deployed and Sentry observed the following issues:

  • ‼️ RateLimitExceeded: Query on could not be run due to allocation policies, info: {'details': {'ReferrerGuardRailPolicy': {'can_run': False, 'max_threads': 0, 'explanation': {'reason': 'concurrent policy 58 exceeds limit of 50', 'policy': 'referrer_guard_rail_policy', 'refer... sentry.tasks.post_process.post_process_group View Issue
  • ‼️ RateLimitExceeded: Query on could not be run due to allocation policies, info: {'details': {'ConcurrentRateLimitAllocationPolicy': {'can_run': False, 'max_threads': 0, 'explanation': {'reason': 'concurrent policy 17 exceeds limit of 16', 'overrides': {}, 'storage_key': 'S... sentry.tasks.post_process.post_process_group View Issue
  • ‼️ SnubaError: HTTPConnectionPool(host='snuba-api', port=80): Read timed out. (read timeout=30) sentry.tasks.post_process.post_process_group View Issue
  • ‼️ SnubaError: Failed to parse snuba error response sentry.tasks.post_process.post_process_group View Issue

Did you find this useful? React with a 👍 or 👎

@markstory markstory added the Trigger: Revert Add to a merged PR to revert it (skips CI) label May 10, 2025
@getsentry-bot
Copy link
Contributor

PR reverted: dfe6a25

getsentry-bot added a commit that referenced this pull request May 10, 2025
)"

This reverts commit 81d0180.

Co-authored-by: markstory <24086+markstory@users.noreply.github.com>
markstory added a commit that referenced this pull request May 12, 2025
Redo of #91372 which was reverted because of rate limiting.
This time around, use an option to control task variants,
and only generate a payload when a hook is going to be sent.
For projects with multiple service hooks, this should result in fewer
snuba calls as events are only serialized once.
andrewshie-sentry pushed a commit that referenced this pull request May 12, 2025
The `event` parameter of process_service_hook requires pickle. By
generating the payload before spawning a task, we don't have to use
pickle.

Refs SENTRY-3V47
andrewshie-sentry pushed a commit that referenced this pull request May 12, 2025
)"

This reverts commit 81d0180.

Co-authored-by: markstory <24086+markstory@users.noreply.github.com>
markstory added a commit that referenced this pull request May 12, 2025
Redo of #91372 which was reverted because of rate limiting. This time
around, use an option to control task variants, and only generate a
payload when a hook is going to be sent. For projects with multiple
service hooks, this should result in fewer snuba calls as events are
only serialized once.
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
Scope: Backend Automatically applied to PRs that change backend components Trigger: Revert Add to a merged PR to revert it (skips CI)
Projects
None yet
Development

Successfully merging this pull request may close these issues.

3 participants