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: Use UploadFileV2Context due to files.upload API deprecation #18

Open
wants to merge 7 commits into
base: main
Choose a base branch
from

Conversation

mung9
Copy link
Member

@mung9 mung9 commented Sep 24, 2024

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:

  • From May 8, 2024, newly created Slack apps will no longer be able to use this API.
  • From March 11, 2025, all Slack apps will be unable to use this API.

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:

files.upload is deprecated and will stop functioning on March 11, 2025. Use files.getUploadURLExternal and files.completeUploadExternal for file uploads instead. Newly created apps will be unable to use files.upload starting May 8, 2024. See Uploading files for more details on the process, and check out this changelog for more on the deprecation.

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:

  1. The v2 function requires the Slack channel’s ID to upload a file. You can no longer pass the channel name.
  2. The v2 function requires the size of the file being uploaded to be specified.

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 a ChannelID 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.

image

Urgency

I hope to have the review completed by October 11th.

@mung9 mung9 changed the title WIP chore: Update SlackReporter not to call deprecated file.upload API Sep 24, 2024
@mung9 mung9 changed the title chore: Update SlackReporter not to call deprecated file.upload API chore: Use UploadFileV2Context due to files.upload API deprecation Sep 25, 2024
@mung9 mung9 self-assigned this Sep 25, 2024
@mung9 mung9 marked this pull request as ready for review September 25, 2024 13:49
@mung9 mung9 requested review from jake-shin0, suripark, MeteorSis and winterjung and removed request for jake-shin0 and suripark September 25, 2024 13:49
@mung9
Copy link
Member Author

mung9 commented Sep 25, 2024

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!

@MeteorSis

This comment was marked as resolved.

@mung9
Copy link
Member Author

mung9 commented Sep 26, 2024

hello @mung9. Is it possible to rewrite the description by English? This repo is public, so that would be nice.

I’ve updated the descrption and a comment

@MeteorSis
Copy link
Collaborator

MeteorSis commented Sep 26, 2024

I think it would be better to deprecate the old SlackReporter and separate it into SlackReporterV2.
If there's a breaking change, We'll have to update the major version with the autopprof release, and I think it would be tiring to raise the major version because of subdependencies.
Actually, github.com/slack-go/slack also created UploadFileV2Context and uploaded the minor version, not the major version.
I'm curious to see what other people think.

#18 (comment)

@mingrammer
Copy link
Contributor

@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.

@mung9 mung9 requested a review from aaron-daangn September 26, 2024 02:41
@@ -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
Copy link
Contributor

Choose a reason for hiding this comment

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

Suggested change
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.

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?

Copy link
Contributor

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.

Copy link
Member Author

@mung9 mung9 Sep 26, 2024

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

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.

Copy link
Contributor

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
Copy link
Contributor

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.

Copy link
Collaborator

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.

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 like this idea too! I’ll go with this approach

Copy link
Member Author

@mung9 mung9 Sep 26, 2024

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.

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’ve added a private function that calls the latest API based on whether ChannelID is set, so please take a look

@mung9
Copy link
Member Author

mung9 commented Sep 26, 2024

@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.

@mingrammer You’ve been away for a long time! Thank you for taking the time to review despite that.

@mung9 mung9 requested a review from mingrammer October 2, 2024 06:51
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
Projects
None yet
Development

Successfully merging this pull request may close these issues.

4 participants