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

ref(integrations): integration webhook endpoint ABC #82739

Draft
wants to merge 7 commits into
base: master
Choose a base branch
from

Conversation

cathteng
Copy link
Member

@cathteng cathteng commented Dec 30, 2024

Begin tying together the various integration webhook endpoints. Jira differs from the others in that it has an API for each event. It still has the same basic layout of:

  1. Authenticating the incoming event
  2. Unpacking the payload
  3. Custom logic to address the payload

So the first 2 can be encapsulated in a shared base class.

Copy link

codecov bot commented Dec 31, 2024

Codecov Report

Attention: Patch coverage is 93.49593% with 8 lines in your changes missing coverage. Please review.

✅ All tests successful. No failed tests found.

Files with missing lines Patch % Lines
src/sentry/integrations/jira_server/webhooks.py 84.00% 4 Missing ⚠️
tests/sentry/integrations/jira/test_webhooks.py 66.66% 3 Missing ⚠️
...c/sentry/integrations/jira/webhooks/uninstalled.py 90.00% 1 Missing ⚠️
Additional details and impacted files
@@            Coverage Diff             @@
##           master   #82739      +/-   ##
==========================================
+ Coverage   87.48%   87.50%   +0.01%     
==========================================
  Files        9410     9411       +1     
  Lines      536794   536847      +53     
  Branches    21049    21049              
==========================================
+ Hits       469640   469752     +112     
+ Misses      66785    66726      -59     
  Partials      369      369              

Comment on lines +80 to +83
self.add_response()

self.get_error_response(
extra_headers=dict(HTTP_AUTHORIZATION="JWT anexampletoken"),
extra_headers=dict(HTTP_AUTHORIZATION="JWT " + self.jwt_token_cdn()),
Copy link
Member Author

Choose a reason for hiding this comment

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

needed to add this because checking auth was moved before checking the body

"""
Webhook hit by Jira whenever someone uninstalls the Sentry integration from their Jira instance.
"""

def post(self, request: Request, *args, **kwargs) -> Response:
def authenticate(self, request: Request, **kwargs) -> Any:
Copy link
Member Author

@cathteng cathteng Dec 31, 2024

Choose a reason for hiding this comment

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

ideally authenticating the incoming request would be on its own (without any return value and raising exceptions if an error occurred), but the get_integration_from_jwt function decodes the token, fetches the integration, and verifies the token (possibly using information from integration.metadata), so it's not easy to decouple

@cathteng cathteng marked this pull request as ready for review December 31, 2024 16:07
@cathteng cathteng requested review from a team as code owners December 31, 2024 16:07
src/sentry/integrations/webhook.py Outdated Show resolved Hide resolved
src/sentry/integrations/webhook.py Outdated Show resolved Hide resolved
def __init__(self, **kwargs):
super().__init__(**kwargs)

self.log_extra = {}
Copy link
Member

Choose a reason for hiding this comment

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

While this is helpful for consistent logging, do we always need to log this full context, or is it ok to have the subclass methods decide what should be logged?

Copy link
Member Author

Choose a reason for hiding this comment

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

the only logs that are by default is request_method and request_path, and each subclass adds more into self.log_extra as necessary. what do you mean by full context here?

Copy link
Member

Choose a reason for hiding this comment

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

Just that we're always appending additional data into this context object. If these are the only 2 places we're logging though, it's fine.

Copy link
Member Author

Choose a reason for hiding this comment

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

oh wait i think i have to double check that this is actually being initialized each time. maybe i reinitialize when dispatch is called?

@cathteng cathteng force-pushed the cathy/integrations/webhook-endpoint-abc branch from cc43759 to 4e769d5 Compare January 2, 2025 23:22
@csrf_exempt
def dispatch(self, request, *args, **kwargs):
response = super().dispatch(request, *args, **kwargs)
self.log_extra = {"request_method": self.request.method, "request_path": self.request.path}
Copy link
Member Author

Choose a reason for hiding this comment

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

@GabeVillalobos i think i need to do this because idk if the class is initialized if we link it to the url via Endpoint.as_view()

Copy link
Member Author

Choose a reason for hiding this comment

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

i don't think the class gets re-initialized on every API call so i would need to reset the log extra manually here

@getsantry
Copy link
Contributor

getsantry bot commented Jan 25, 2025

This issue has gone three weeks without activity. In another week, I will close it.

But! If you comment or otherwise update it, I will reset the clock, and if you remove the label Waiting for: Community, I will leave it alone ... forever!


"A weed is but an unloved flower." ― Ella Wheeler Wilcox 🥀

@getsantry getsantry bot added Stale and removed Stale labels Jan 25, 2025
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
Projects
None yet
Development

Successfully merging this pull request may close these issues.

2 participants