-
Notifications
You must be signed in to change notification settings - Fork 9
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: Use UploadFileV2Context due to files.upload API deprecation #18
base: main
Are you sure you want to change the base?
Conversation
file.upload
API
file.upload
API
I’m trying to add @mingrammer as a reviewer, but they are not showing up in the reviewer search. Could you please check and add them if you can find them? Thank you! |
This comment was marked as resolved.
This comment was marked as resolved.
I’ve updated the descrption and a comment |
|
@mung9 I'm on about a one-year leave, so I'm not a member of daangn org at the moment 😅. But, of course, I can review the changes, and I'm happy to see that this pkg is being maintained well. I will leave the comments soon. |
@@ -24,13 +24,13 @@ const ( | |||
// Reporter is responsible for reporting the profiling report to the destination. | |||
type Reporter interface { | |||
// ReportCPUProfile sends the CPU profiling data to the specific destination. | |||
ReportCPUProfile(ctx context.Context, r io.Reader, ci CPUInfo) error | |||
ReportCPUProfile(ctx context.Context, r io.Reader, size int, ci CPUInfo) error |
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.
ReportCPUProfile(ctx context.Context, r io.Reader, size int, ci CPUInfo) error | |
ReportCPUProfile(ctx context.Context, r io.Reader, fileSize int, ci CPUInfo) error |
A more explicit name is better, I think. size
leads the reader to be confused about what size is for.
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 it necessary to expose the size argument to the interface? How about just accepting an io.Reader as before, and using io.TeeReader or io.Copy to measure the size internally?
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.
How about just accepting an io.Reader as before, and using io.TeeReader or io.Copy to measure the size internally?
Sounds good.
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 originally made the file size a parameter because I was concerned about excessive memory usage with large amounts of data being read using io.Reader
. However, if we can guarantee that the data passed via io.Reader is small enough to be safely loaded into memory, it would actually be better to use the []byte
type instead.
Meanwhile, @winterjung mentioned in the office that making breaking changes to the interface could cause issues for places where Reporter is used directly. I thought providing a migration guide for those cases would be sufficient, but I’d like to know if there are any additional concerns
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.
@mingrammer Gentle reminder.
IMHO it could be better to avoid breaking changes.
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.
Profile file size is up to a couple of megabytes, so we don't have to worry about loading into memory. Keeping the interface and calculating the size in Reporter implementation would be a better choice.
report/slack.go
Outdated
channel string | ||
app string | ||
channelID string |
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.
How about leaving the channel
parameter and commenting on the deprecation with the official deprecation link? And, call the new Slack API by checking whether the channelD
is set, or call the legacy API if not.
This can prevent breaking changes and induce users to update their codes.
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.
this sounds better.
UploadFileContext is deprecated in the latest slack package, not gone.
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 like this idea too! I’ll go with this approach
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.
00db77c
I've updated params to include both Channel
and ChannelID
and added comments.
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’ve added a private function that calls the latest API based on whether ChannelID is set, so please take a look
@mingrammer You’ve been away for a long time! Thank you for taking the time to review despite that. |
Background
SlackReporter currently uploads files to Slack channels using the UploadFileContext function from slack-go/slack. This function internally calls the files.upload web API, but this API has been deprecated, leading to two key implications:
This PR updates the file upload method to support new Slack apps and addresses the upcoming deprecation.
The official documentation explains the deprecation as follows:
Changes
1. Updated to use UploadFileV2Context instead of UploadFileContext.
The function has been updated to call UploadFileV2Context, which implements the latest file upload method.
Since the old version didn’t support this, the slack-go/slack version was upgraded to 0.14.0 (Latest). This version supports Go 1.16, so there are no compatibility issues with the Go language version.
The v2 function differs from the old version in two significant ways:
These differences required some additional changes:
2. Modified the SlackReporter constructor to accept a Channel ID.
Previously, when creating a SlackReporter, you could pass either a channel name or ID. Now, the
Channel
parameter has been deprecated, and aChannelID
parameter has been added instead.3. Updated the ReportXXProfile functions in the Reporter interface to accept file size as a parameter.
Previously, to upload profile information, you only needed to pass an io.Reader. Now, you must also specify the file size.
Migration guide
Finding the Channel ID
You can find the channel ID by right-clicking the channel name and opening the details page.
Urgency
I hope to have the review completed by October 11th.