-
-
Notifications
You must be signed in to change notification settings - Fork 4.2k
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): introduce SlackClient using slack_sdk #72017
Conversation
integration = Integration.objects.filter(id=integration_id).first() | ||
|
||
if integration is None: | ||
raise ValueError(f"Integration with id {integration_id} not found") |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
we don't raise any errors if initialization fails in the existing SlackClient
. all subsequent calls are no-ops, but i think we should fail loudly so we're aware something is broken
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
+1
|
||
with pytest.raises(SlackApiError): | ||
# error raised because it's actually trying to POST | ||
client.chat_postMessage(channel="#announcements", text="hello") |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
i was having difficulty mocking responses with the Slack SDK client. it seems like we might have to do something like this slackapi/python-slack-sdk#1188 (comment)
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
ok i got something working here, please yell loudly if this is not the way to do it
08df208
to
894a64f
Compare
Codecov ReportAttention: Patch coverage is
Additional details and impacted files@@ Coverage Diff @@
## master #72017 +/- ##
===========================================
+ Coverage 56.86% 77.93% +21.06%
===========================================
Files 6561 6572 +11
Lines 292452 292863 +411
Branches 50480 50550 +70
===========================================
+ Hits 166309 228243 +61934
+ Misses 121415 58369 -63046
- Partials 4728 6251 +1523
|
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
I understand some of my comments are for existing code so I hope they're not too annoying 😅
if payload_blocks := blocks.get("blocks"): | ||
payload["blocks"] = orjson.dumps(payload_blocks).decode() | ||
json_blocks = orjson.dumps(payload_blocks).decode() |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
Is there a test covering this line of code? After #inc-779 I get scared whenever I see orjson.dumps
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
i added testing to this area of the code in #72066, it should be covered now
# temporarily log the payload so we can debug message failures | ||
log_params["payload"] = orjson.dumps(payload).decode() | ||
|
||
self.logger.info( |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
Why is this just info vs error? Also don't we want this in sentry?
"channel_name": self.get_option("channel"), | ||
} | ||
# temporarily log the payload so we can debug message failures | ||
log_params["payload"] = orjson.dumps(payload).decode() |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
orjson
warning! 😅 please make sure there's test coverage
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
added a test that goes through this flow no problem :)
integration = Integration.objects.filter(id=integration_id).first() | ||
|
||
if integration is None: | ||
raise ValueError(f"Integration with id {integration_id} not found") |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
+1
1cc8bd9
to
eabe176
Compare
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
Thanks for taking on this work and listening to the feedback/recommendations!!
extra = { | ||
"integration": "slack", | ||
"status_string": str(code), | ||
"error": error, | ||
} | ||
logger.info("integration.http_response", extra=extra) |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
are we going to know which method failed though? Like which API call? Any chance we can capture that as well to help us understand which method is failing?
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
i think i can pass this in the logger if i pass the method in
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
like method.__name__
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
let me do this in a followup, and move the metaclass stuff to integrations.base. currently the only API call is chat.postMessage
Suspect IssuesThis pull request was deployed and Sentry observed the following issues:
Did you find this useful? React with a 👍 or 👎 |
Added slack_sdk here #71881
This PR adds a
SlackClient
that subclassesWebClient
from the official Slack SDK. To make the usage the same as the in-houseSlackClient
, the abstraction acceptsintegration_id
and finds the access token before initializing an instance of theWebClient
.We also want to track the response outcomes for every outgoing API call to Slack, so I added a wrapper that executes right after every single API call to increment a metric.