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
Open
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension


Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
6 changes: 3 additions & 3 deletions README.md
Original file line number Diff line number Diff line change
Expand Up @@ -43,9 +43,9 @@ func main() {
MemThreshold: 0.8, // Default: 0.75.
Reporter: report.NewSlackReporter(
&report.SlackReporterOption{
App: "YOUR_APP_NAME",
Token: "YOUR_TOKEN_HERE",
Channel: "#REPORT_CHANNEL",
App: "YOUR_APP_NAME",
Token: "YOUR_TOKEN_HERE",
ChannelID: "REPORT_CHANNEL_ID",
},
),
})
Expand Down
11 changes: 7 additions & 4 deletions autopprof.go
Original file line number Diff line number Diff line change
Expand Up @@ -7,10 +7,10 @@ import (
"bytes"
"context"
"fmt"
"github.com/daangn/autopprof/queryer"
"log"
"time"

"github.com/daangn/autopprof/queryer"
"github.com/daangn/autopprof/report"
)

Expand Down Expand Up @@ -245,7 +245,8 @@ func (ap *autoPprof) reportCPUProfile(cpuUsage float64) error {
UsagePercentage: cpuUsage * 100,
}
bReader := bytes.NewReader(b)
if err := ap.reporter.ReportCPUProfile(ctx, bReader, ci); err != nil {
bSize := len(b)
if err := ap.reporter.ReportCPUProfile(ctx, bReader, bSize, ci); err != nil {
return err
}
return nil
Expand Down Expand Up @@ -331,7 +332,8 @@ func (ap *autoPprof) reportHeapProfile(memUsage float64) error {
UsagePercentage: memUsage * 100,
}
bReader := bytes.NewReader(b)
if err := ap.reporter.ReportHeapProfile(ctx, bReader, mi); err != nil {
bSize := len(b)
if err := ap.reporter.ReportHeapProfile(ctx, bReader, bSize, mi); err != nil {
return err
}
return nil
Expand Down Expand Up @@ -419,7 +421,8 @@ func (ap *autoPprof) reportGoroutineProfile(goroutineCount int) error {
Count: goroutineCount,
}
bReader := bytes.NewReader(b)
if err := ap.reporter.ReportGoroutineProfile(ctx, bReader, gi); err != nil {
bSize := len(b)
if err := ap.reporter.ReportGoroutineProfile(ctx, bReader, bSize, gi); err != nil {
return err
}
return nil
Expand Down
78 changes: 39 additions & 39 deletions autopprof_test.go
Original file line number Diff line number Diff line change
Expand Up @@ -79,9 +79,9 @@ func TestStart(t *testing.T) {
opt: Option{
Reporter: report.NewSlackReporter(
&report.SlackReporterOption{
App: "appname",
Token: "token",
Channel: "channel",
App: "appname",
Token: "token",
ChannelID: "channel_id",
},
),
},
Expand All @@ -93,9 +93,9 @@ func TestStart(t *testing.T) {
MemThreshold: 0.5,
Reporter: report.NewSlackReporter(
&report.SlackReporterOption{
App: "appname",
Token: "token",
Channel: "channel",
App: "appname",
Token: "token",
ChannelID: "channel_id",
},
),
},
Expand Down Expand Up @@ -144,9 +144,9 @@ func TestStop(t *testing.T) {
MemThreshold: 0.5,
Reporter: report.NewSlackReporter(
&report.SlackReporterOption{
App: "appname",
Token: "token",
Channel: "channel",
App: "appname",
Token: "token",
ChannelID: "channel_id",
},
),
})
Expand Down Expand Up @@ -266,10 +266,10 @@ func TestAutoPprof_watchCPUUsage(t *testing.T) {

mockReporter := report.NewMockReporter(ctrl)
mockReporter.EXPECT().
ReportCPUProfile(gomock.Any(), gomock.Any(), gomock.Any()).
ReportCPUProfile(gomock.Any(), gomock.Any(), gomock.Any(), gomock.Any()).
AnyTimes().
DoAndReturn(
func(_ context.Context, _ io.Reader, _ report.CPUInfo) error {
func(_ context.Context, _ io.Reader, _ int, _ report.CPUInfo) error {
reported = true
return nil
},
Expand Down Expand Up @@ -329,10 +329,10 @@ func TestAutoPprof_watchCPUUsage_consecutive(t *testing.T) {

mockReporter := report.NewMockReporter(ctrl)
mockReporter.EXPECT().
ReportCPUProfile(gomock.Any(), gomock.Any(), gomock.Any()).
ReportCPUProfile(gomock.Any(), gomock.Any(), gomock.Any(), gomock.Any()).
AnyTimes().
DoAndReturn(
func(_ context.Context, _ io.Reader, _ report.CPUInfo) error {
func(_ context.Context, _ io.Reader, _ int, _ report.CPUInfo) error {
reportedCnt++
return nil
},
Expand Down Expand Up @@ -426,7 +426,7 @@ func TestAutoPprof_watchCPUUsage_reportAll(t *testing.T) {
Return([]byte("cpu_prof"), nil),

mockReporter.EXPECT().
ReportCPUProfile(gomock.Any(), gomock.Any(), report.CPUInfo{
ReportCPUProfile(gomock.Any(), gomock.Any(), gomock.Any(), report.CPUInfo{
ThresholdPercentage: 0.5 * 100,
UsagePercentage: 0.6 * 100,
}).
Expand All @@ -444,7 +444,7 @@ func TestAutoPprof_watchCPUUsage_reportAll(t *testing.T) {
Return([]byte("mem_prof"), nil),

mockReporter.EXPECT().
ReportHeapProfile(gomock.Any(), gomock.Any(), report.MemInfo{
ReportHeapProfile(gomock.Any(), gomock.Any(), gomock.Any(), report.MemInfo{
ThresholdPercentage: 0.5 * 100,
UsagePercentage: 0.2 * 100,
}).
Expand All @@ -462,7 +462,7 @@ func TestAutoPprof_watchCPUUsage_reportAll(t *testing.T) {
Return([]byte("goroutine_prof"), nil),

mockReporter.EXPECT().
ReportGoroutineProfile(gomock.Any(), gomock.Any(), report.GoroutineInfo{
ReportGoroutineProfile(gomock.Any(), gomock.Any(), gomock.Any(), report.GoroutineInfo{
ThresholdCount: 500,
Count: 200,
}).
Expand Down Expand Up @@ -494,7 +494,7 @@ func TestAutoPprof_watchCPUUsage_reportAll(t *testing.T) {
Return([]byte("cpu_prof"), nil),

mockReporter.EXPECT().
ReportCPUProfile(gomock.Any(), gomock.Any(), report.CPUInfo{
ReportCPUProfile(gomock.Any(), gomock.Any(), gomock.Any(), report.CPUInfo{
ThresholdPercentage: 0.5 * 100,
UsagePercentage: 0.6 * 100,
}).
Expand All @@ -512,7 +512,7 @@ func TestAutoPprof_watchCPUUsage_reportAll(t *testing.T) {
Return([]byte("goroutine_prof"), nil),

mockReporter.EXPECT().
ReportGoroutineProfile(gomock.Any(), gomock.Any(), report.GoroutineInfo{
ReportGoroutineProfile(gomock.Any(), gomock.Any(), gomock.Any(), report.GoroutineInfo{
ThresholdCount: 500,
Count: 200,
}).
Expand Down Expand Up @@ -543,7 +543,7 @@ func TestAutoPprof_watchCPUUsage_reportAll(t *testing.T) {
Return([]byte("cpu_prof"), nil),

mockReporter.EXPECT().
ReportCPUProfile(gomock.Any(), gomock.Any(), report.CPUInfo{
ReportCPUProfile(gomock.Any(), gomock.Any(), gomock.Any(), report.CPUInfo{
ThresholdPercentage: 0.5 * 100,
UsagePercentage: 0.6 * 100,
}).
Expand Down Expand Up @@ -617,9 +617,9 @@ func TestAutoPprof_watchMemUsage(t *testing.T) {

mockReporter := report.NewMockReporter(ctrl)
mockReporter.EXPECT().
ReportHeapProfile(gomock.Any(), gomock.Any(), gomock.Any()).
ReportHeapProfile(gomock.Any(), gomock.Any(), gomock.Any(), gomock.Any()).
DoAndReturn(
func(_ context.Context, _ io.Reader, _ report.MemInfo) error {
func(_ context.Context, _ io.Reader, _ int, _ report.MemInfo) error {
reported = true
return nil
},
Expand Down Expand Up @@ -679,10 +679,10 @@ func TestAutoPprof_watchMemUsage_consecutive(t *testing.T) {

mockReporter := report.NewMockReporter(ctrl)
mockReporter.EXPECT().
ReportHeapProfile(gomock.Any(), gomock.Any(), gomock.Any()).
ReportHeapProfile(gomock.Any(), gomock.Any(), gomock.Any(), gomock.Any()).
AnyTimes().
DoAndReturn(
func(_ context.Context, _ io.Reader, _ report.MemInfo) error {
func(_ context.Context, _ io.Reader, _ int, _ report.MemInfo) error {
reportedCnt++
return nil
},
Expand Down Expand Up @@ -776,7 +776,7 @@ func TestAutoPprof_watchMemUsage_reportAll(t *testing.T) {
Return([]byte("mem_prof"), nil),

mockReporter.EXPECT().
ReportHeapProfile(gomock.Any(), gomock.Any(), report.MemInfo{
ReportHeapProfile(gomock.Any(), gomock.Any(), gomock.Any(), report.MemInfo{
ThresholdPercentage: 0.5 * 100,
UsagePercentage: 0.6 * 100,
}).
Expand All @@ -794,7 +794,7 @@ func TestAutoPprof_watchMemUsage_reportAll(t *testing.T) {
Return([]byte("cpu_prof"), nil),

mockReporter.EXPECT().
ReportCPUProfile(gomock.Any(), gomock.Any(), report.CPUInfo{
ReportCPUProfile(gomock.Any(), gomock.Any(), gomock.Any(), report.CPUInfo{
ThresholdPercentage: 0.5 * 100,
UsagePercentage: 0.2 * 100,
}).
Expand All @@ -812,7 +812,7 @@ func TestAutoPprof_watchMemUsage_reportAll(t *testing.T) {
Return([]byte("goroutine_prof"), nil),

mockReporter.EXPECT().
ReportGoroutineProfile(gomock.Any(), gomock.Any(), report.GoroutineInfo{
ReportGoroutineProfile(gomock.Any(), gomock.Any(), gomock.Any(), report.GoroutineInfo{
ThresholdCount: 500,
Count: 200,
}).
Expand Down Expand Up @@ -844,7 +844,7 @@ func TestAutoPprof_watchMemUsage_reportAll(t *testing.T) {
Return([]byte("mem_prof"), nil),

mockReporter.EXPECT().
ReportHeapProfile(gomock.Any(), gomock.Any(), report.MemInfo{
ReportHeapProfile(gomock.Any(), gomock.Any(), gomock.Any(), report.MemInfo{
ThresholdPercentage: 0.5 * 100,
UsagePercentage: 0.6 * 100,
}).
Expand All @@ -862,7 +862,7 @@ func TestAutoPprof_watchMemUsage_reportAll(t *testing.T) {
Return([]byte("goroutine_prof"), nil),

mockReporter.EXPECT().
ReportGoroutineProfile(gomock.Any(), gomock.Any(), report.GoroutineInfo{
ReportGoroutineProfile(gomock.Any(), gomock.Any(), gomock.Any(), report.GoroutineInfo{
ThresholdCount: 500,
Count: 200,
}).
Expand Down Expand Up @@ -894,7 +894,7 @@ func TestAutoPprof_watchMemUsage_reportAll(t *testing.T) {
Return([]byte("mem_prof"), nil),

mockReporter.EXPECT().
ReportHeapProfile(gomock.Any(), gomock.Any(), report.MemInfo{
ReportHeapProfile(gomock.Any(), gomock.Any(), gomock.Any(), report.MemInfo{
ThresholdPercentage: 0.5 * 100,
UsagePercentage: 0.6 * 100,
}).
Expand Down Expand Up @@ -968,9 +968,9 @@ func TestAutoPprof_watchGoroutineCount(t *testing.T) {

mockReporter := report.NewMockReporter(ctrl)
mockReporter.EXPECT().
ReportGoroutineProfile(gomock.Any(), gomock.Any(), gomock.Any()).
ReportGoroutineProfile(gomock.Any(), gomock.Any(), gomock.Any(), gomock.Any()).
DoAndReturn(
func(_ context.Context, _ io.Reader, _ report.GoroutineInfo) error {
func(_ context.Context, _ io.Reader, _ int, _ report.GoroutineInfo) error {
reported = true
return nil
},
Expand Down Expand Up @@ -1031,10 +1031,10 @@ func TestAutoPprof_watchGoroutineCount_consecutive(t *testing.T) {

mockReporter := report.NewMockReporter(ctrl)
mockReporter.EXPECT().
ReportGoroutineProfile(gomock.Any(), gomock.Any(), gomock.Any()).
ReportGoroutineProfile(gomock.Any(), gomock.Any(), gomock.Any(), gomock.Any()).
AnyTimes().
DoAndReturn(
func(_ context.Context, _ io.Reader, _ report.GoroutineInfo) error {
func(_ context.Context, _ io.Reader, _ int, _ report.GoroutineInfo) error {
reportedCnt++
return nil
},
Expand Down Expand Up @@ -1129,7 +1129,7 @@ func TestAutoPprof_watchGoroutineCount_reportAll(t *testing.T) {
Return([]byte("goroutine_prof"), nil),

mockReporter.EXPECT().
ReportGoroutineProfile(gomock.Any(), gomock.Any(), report.GoroutineInfo{
ReportGoroutineProfile(gomock.Any(), gomock.Any(), gomock.Any(), report.GoroutineInfo{
ThresholdCount: 100,
Count: 200,
}).
Expand All @@ -1147,7 +1147,7 @@ func TestAutoPprof_watchGoroutineCount_reportAll(t *testing.T) {
Return([]byte("cpu_prof"), nil),

mockReporter.EXPECT().
ReportCPUProfile(gomock.Any(), gomock.Any(), report.CPUInfo{
ReportCPUProfile(gomock.Any(), gomock.Any(), gomock.Any(), report.CPUInfo{
ThresholdPercentage: 0.5 * 100,
UsagePercentage: 0.2 * 100,
}).
Expand All @@ -1165,7 +1165,7 @@ func TestAutoPprof_watchGoroutineCount_reportAll(t *testing.T) {
Return([]byte("mem_prof"), nil),

mockReporter.EXPECT().
ReportHeapProfile(gomock.Any(), gomock.Any(), report.MemInfo{
ReportHeapProfile(gomock.Any(), gomock.Any(), gomock.Any(), report.MemInfo{
ThresholdPercentage: 0.5 * 100,
UsagePercentage: 0.2 * 100,
}).
Expand Down Expand Up @@ -1197,7 +1197,7 @@ func TestAutoPprof_watchGoroutineCount_reportAll(t *testing.T) {
Return([]byte("goroutine_prof"), nil),

mockReporter.EXPECT().
ReportGoroutineProfile(gomock.Any(), gomock.Any(), report.GoroutineInfo{
ReportGoroutineProfile(gomock.Any(), gomock.Any(), gomock.Any(), report.GoroutineInfo{
ThresholdCount: 100,
Count: 200,
}).
Expand All @@ -1215,7 +1215,7 @@ func TestAutoPprof_watchGoroutineCount_reportAll(t *testing.T) {
Return([]byte("mem_prof"), nil),

mockReporter.EXPECT().
ReportHeapProfile(gomock.Any(), gomock.Any(), report.MemInfo{
ReportHeapProfile(gomock.Any(), gomock.Any(), gomock.Any(), report.MemInfo{
ThresholdPercentage: 0.5 * 100,
UsagePercentage: 0.2 * 100,
}).
Expand Down Expand Up @@ -1247,7 +1247,7 @@ func TestAutoPprof_watchGoroutineCount_reportAll(t *testing.T) {
Return([]byte("goroutine_prof"), nil),

mockReporter.EXPECT().
ReportGoroutineProfile(gomock.Any(), gomock.Any(), report.GoroutineInfo{
ReportGoroutineProfile(gomock.Any(), gomock.Any(), gomock.Any(), report.GoroutineInfo{
ThresholdCount: 100,
Count: 200,
}).
Expand Down
8 changes: 5 additions & 3 deletions examples/example.go
Original file line number Diff line number Diff line change
Expand Up @@ -18,11 +18,13 @@ type mm struct {

func main() {
err := autopprof.Start(autopprof.Option{
CPUThreshold: 0.8, // Default: 0.75.
MemThreshold: 0.8, // Default: 0.75.
Reporter: report.NewSlackReporter(
&report.SlackReporterOption{
App: "YOUR_APP_NAME",
Token: "YOUR_TOKEN_HERE",
Channel: "#REPORT_CHANNEL",
App: "YOUR_APP_NAME",
Token: "YOUR_TOKEN_HERE",
ChannelID: "REPORT_CHANNEL_ID",
},
),
})
Expand Down
4 changes: 2 additions & 2 deletions go.mod
Original file line number Diff line number Diff line change
Expand Up @@ -5,7 +5,7 @@ go 1.19
require (
github.com/containerd/cgroups v1.0.4
github.com/golang/mock v1.6.0
github.com/slack-go/slack v0.11.3
github.com/slack-go/slack v0.14.0
)

require (
Expand All @@ -14,7 +14,7 @@ require (
github.com/docker/go-units v0.4.0 // indirect
github.com/godbus/dbus/v5 v5.0.4 // indirect
github.com/gogo/protobuf v1.3.2 // indirect
github.com/gorilla/websocket v1.4.2 // indirect
github.com/gorilla/websocket v1.5.3 // indirect
github.com/opencontainers/runtime-spec v1.0.2 // indirect
github.com/sirupsen/logrus v1.8.1 // indirect
golang.org/x/sys v0.0.0-20210510120138-977fb7262007 // indirect
Expand Down
9 changes: 5 additions & 4 deletions go.sum
Original file line number Diff line number Diff line change
Expand Up @@ -22,8 +22,9 @@ github.com/golang/mock v1.6.0/go.mod h1:p6yTPP+5HYm5mzsMV8JkE6ZKdX+/wYM6Hr+Licev
github.com/google/go-cmp v0.5.4/go.mod h1:v8dTdLbMG2kIc/vJvl+f65V22dbkXbowE6jgT/gNBxE=
github.com/google/go-cmp v0.5.7 h1:81/ik6ipDQS2aGcBfIN5dHDB36BwrStyeAQquSYCV4o=
github.com/google/go-cmp v0.5.7/go.mod h1:n+brtR0CgQNWTVd5ZUFpTBC8YFBDLK/h/bpaJ8/DtOE=
github.com/gorilla/websocket v1.4.2 h1:+/TMaTYc4QFitKJxsQ7Yye35DkWvkdLcvGKqM+x0Ufc=
github.com/gorilla/websocket v1.4.2/go.mod h1:YR8l580nyteQvAITg2hZ9XVh4b55+EU/adAjf1fMHhE=
github.com/gorilla/websocket v1.5.3 h1:saDtZ6Pbx/0u+bgYQ3q96pZgCzfhKXGPqt7kZ72aNNg=
github.com/gorilla/websocket v1.5.3/go.mod h1:YR8l580nyteQvAITg2hZ9XVh4b55+EU/adAjf1fMHhE=
github.com/kisielk/errcheck v1.5.0/go.mod h1:pFxgyoBC7bSaBwPgfKdkLd5X25qrDl4LWUI2bnpBCr8=
github.com/kisielk/gotool v1.0.0/go.mod h1:XhKaO+MFFWcvkIS/tQcRk01m1F5IRFswLeQ+oQHNcck=
github.com/kr/pretty v0.1.0/go.mod h1:dAy3ld7l9f0ibDNOQOHHMYYIIbhfbHSm3C4ZsoJORNo=
Expand All @@ -38,12 +39,12 @@ github.com/pmezard/go-difflib v1.0.0 h1:4DBwDE0NGyQoBHbLQYPwSUPoCMWR5BEzIk/f1lZb
github.com/pmezard/go-difflib v1.0.0/go.mod h1:iKH77koFhYxTK1pcRnkKkqfTogsbg7gZNVY4sRDYZ/4=
github.com/sirupsen/logrus v1.8.1 h1:dJKuHgqk1NNQlqoA6BTlM1Wf9DOH3NBjQyu0h9+AZZE=
github.com/sirupsen/logrus v1.8.1/go.mod h1:yWOB1SBYBC5VeMP7gHvWumXLIWorT60ONWic61uBYv0=
github.com/slack-go/slack v0.11.3 h1:GN7revxEMax4amCc3El9a+9SGnjmBvSUobs0QnO6ZO8=
github.com/slack-go/slack v0.11.3/go.mod h1:hlGi5oXA+Gt+yWTPP0plCdRKmjsDxecdHxYQdlMQKOw=
github.com/stretchr/objx v0.1.0/go.mod h1:HFkY916IF+rwdDfMAkV7OtwuqBVzrE8GR6GFx+wExME=
github.com/slack-go/slack v0.14.0 h1:6c0UTfbRnvRssZUsZ2qe0Iu07VAMPjRqOa6oX8ewF4k=
github.com/slack-go/slack v0.14.0/go.mod h1:hlGi5oXA+Gt+yWTPP0plCdRKmjsDxecdHxYQdlMQKOw=
github.com/stretchr/testify v1.2.2/go.mod h1:a8OnRcib4nhh0OaRAV+Yts87kKdq0PP7pXfy6kDkUVs=
github.com/stretchr/testify v1.7.0 h1:nwc3DEeHmmLAfoZucVR881uASk0Mfjw8xYJ99tb5CcY=
github.com/stretchr/testify v1.7.0/go.mod h1:6Fq8oRcR53rry900zMqJjRRixrwX3KX962/h/Wwjteg=
github.com/stretchr/objx v0.1.0/go.mod h1:HFkY916IF+rwdDfMAkV7OtwuqBVzrE8GR6GFx+wExME=
github.com/yuin/goldmark v1.1.27/go.mod h1:3hX8gzYuyVAZsxl0MRgGTJEmQBFcNTphYh9decYSb74=
github.com/yuin/goldmark v1.2.1/go.mod h1:3hX8gzYuyVAZsxl0MRgGTJEmQBFcNTphYh9decYSb74=
github.com/yuin/goldmark v1.3.5/go.mod h1:mwnBkeHKe2W/ZEtQ+71ViKU8L12m81fl3OWwC1Zlc8k=
Expand Down
Loading
Loading