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

chore(slack): Use Slack SDK for SlackEventEndpoints #73333

Merged
merged 12 commits into from
Jul 2, 2024

Conversation

iamrajjoshi
Copy link
Member

@iamrajjoshi iamrajjoshi commented Jun 25, 2024

Updated SlackEventEndpoint to use the the SlackSdkClient.

@iamrajjoshi iamrajjoshi self-assigned this Jun 25, 2024
@github-actions github-actions bot added the Scope: Backend Automatically applied to PRs that change backend components label Jun 25, 2024
client.post("/chat.postMessage", data=payload, json=True)
except ApiError as e:
logger.error("slack.event.on-message-error", extra={"error": str(e)})
if options.get("slack.event-endpoint-sdk"):
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 am using an option here which isn't scoped to an org b/c adding an extra 1/2 RPC call will take longer and i am afraid we will start timing out.

Copy link
Member

Choose a reason for hiding this comment

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

how do you plan to LA this?

@iamrajjoshi iamrajjoshi requested a review from a team June 26, 2024 02:11
@iamrajjoshi iamrajjoshi marked this pull request as ready for review June 26, 2024 02:11
@iamrajjoshi iamrajjoshi requested a review from a team as a code owner June 26, 2024 02:11
# An unfurl may have multiple links to unfurl
for item in data.get("links", []):
try:
url = item["url"]
slack_shared_link = parse_link(url)
Copy link
Member Author

@iamrajjoshi iamrajjoshi Jun 26, 2024

Choose a reason for hiding this comment

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

deleted this b/c it created a log for every unfurl link which is expensive and we don't track this currently.

client.post("/chat.postMessage", data=payload, json=True)
except ApiError as e:
logger.error("slack.event.on-message-error", extra={"error": str(e)})
if options.get("slack.event-endpoint-sdk"):
Copy link
Member

Choose a reason for hiding this comment

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

how do you plan to LA this?

client.chat_unfurl(
channel=data["channel"],
ts=data["message_ts"],
unfurls=orjson.dumps(results).decode(),
Copy link
Member

Choose a reason for hiding this comment

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

instead of dumping twice, we could also store this in a variable

Comment on lines +107 to +127
@patch(
"sentry.integrations.slack.webhooks.event.match_link",
# match_link will be called twice, for each our links. Resolve into
# two unique links and one duplicate.
side_effect=[
(LinkType.DISCOVER, {"arg1": "value1"}),
(LinkType.DISCOVER, {"arg1", "value2"}),
(LinkType.DISCOVER, {"arg1": "value1"}),
],
)
@patch("sentry.integrations.slack.requests.event.has_discover_links", return_value=True)
@patch(
"sentry.integrations.slack.webhooks.event.link_handlers",
{
LinkType.DISCOVER: Handler(
matcher=[re.compile(r"test")],
arg_mapper=make_type_coercer({}),
fn=Mock(return_value={"link1": "unfurl", "link2": "unfurl"}),
)
},
)
Copy link
Member

Choose a reason for hiding this comment

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

if you have the same patch decorators for most functions in a test class, you can move them to the top of the class and it will apply to every function

Copy link
Member Author

Choose a reason for hiding this comment

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

ill do this when i ga and delete the old client tests

Comment on lines 68 to 70
if options.get("slack.event-endpoint-sdk") and slack_request.integration.id in options.get(
"slack.event-endpoint-sdk-integration-ids"
):
Copy link
Member

Choose a reason for hiding this comment

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

i think this should be OR
either the feature is GA'd OR the org is part of LA.

can you add a test for just the LA part?

Copy link

codecov bot commented Jul 2, 2024

Codecov Report

Attention: Patch coverage is 66.66667% with 23 lines in your changes missing coverage. Please review.

Project coverage is 78.04%. Comparing base (d724281) to head (c279eab).
Report is 57 commits behind head on master.

Additional details and impacted files
@@           Coverage Diff            @@
##           master   #73333    +/-   ##
========================================
  Coverage   78.03%   78.04%            
========================================
  Files        6640     6644     +4     
  Lines      297033   297167   +134     
  Branches    51152    51137    -15     
========================================
+ Hits       231797   231910   +113     
- Misses      58961    58985    +24     
+ Partials     6275     6272     -3     
Files Coverage Δ
src/sentry/integrations/slack/metrics.py 100.00% <100.00%> (ø)
src/sentry/options/defaults.py 100.00% <100.00%> (ø)
src/sentry/integrations/slack/webhooks/event.py 80.81% <64.61%> (-4.27%) ⬇️

... and 126 files with indirect coverage changes

@iamrajjoshi iamrajjoshi requested a review from cathteng July 2, 2024 15:36
channel=slack_request.channel_id,
user=slack_request.user_id,
text=payload["text"],
**SlackPromptLinkMessageBuilder(associate_url).as_payload(),
Copy link
Member

Choose a reason for hiding this comment

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

nit: this message builder only returns {"blocks": ...}, can we just get the blocks out of the payload instead of building them again?

@iamrajjoshi iamrajjoshi merged commit 98ddffd into master Jul 2, 2024
48 of 49 checks passed
@iamrajjoshi iamrajjoshi deleted the raj/mes-ref/slack/sdk-2.18 branch July 2, 2024 21:28
Copy link

sentry-io bot commented Jul 5, 2024

Suspect Issues

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

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

@github-actions github-actions bot locked and limited conversation to collaborators Jul 24, 2024
Sign up for free to subscribe to this conversation on GitHub. Already have an account? Sign in.
Labels
Scope: Backend Automatically applied to PRs that change backend components
Projects
None yet
Development

Successfully merging this pull request may close these issues.

3 participants