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

retry change detection #598

Merged
merged 26 commits into from
Mar 7, 2023
Merged
Show file tree
Hide file tree
Changes from 14 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
1 change: 1 addition & 0 deletions Makefile
1 change: 1 addition & 0 deletions agents/go.mod
Original file line number Diff line number Diff line change
Expand Up @@ -14,6 +14,7 @@ require (
github.com/coinbase/rosetta-sdk-go v0.8.1
github.com/davecgh/go-spew v1.1.1
github.com/ethereum/go-ethereum v1.10.26
github.com/hedzr/log v1.6.3
Copy link
Contributor

Choose a reason for hiding this comment

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

I spent so much time on this :-)

github.com/ipfs/go-log v1.0.5
github.com/jftuga/ellipsis v1.0.0
github.com/jftuga/termsize v1.0.2
Expand Down
3 changes: 3 additions & 0 deletions agents/go.sum
Original file line number Diff line number Diff line change
Expand Up @@ -650,6 +650,8 @@ github.com/hashicorp/memberlist v0.3.0/go.mod h1:MS2lj3INKhZjWNqd3N0m3J+Jxf3DAOn
github.com/hashicorp/serf v0.9.5/go.mod h1:UWDWwZeL5cuWDJdl0C6wrvrUwEqtQ4ZKBKKENpqIUyk=
github.com/hashicorp/serf v0.9.6/go.mod h1:TXZNMjZQijwlDvp+r0b63xZ45H7JmCmgg4gpTwn9UV4=
github.com/hdevalence/ed25519consensus v0.0.0-20201207055737-7fde80a9d5ff/go.mod h1:Feit0l8NcNO4g69XNjwvsR0LGcwMMfzI1TF253rOIlQ=
github.com/hedzr/log v1.6.3 h1:qCdnDUpeQ+E9vmfDKk+IHjA0QipnWNds2mr4hh6iGxA=
github.com/hedzr/log v1.6.3/go.mod h1:goMXeVWLSKZYxNs+10viGe2O1fbzBNnnLpdx0MoCRkA=
github.com/holiman/bloomfilter/v2 v2.0.3 h1:73e0e/V0tCydx14a0SCYS/EWCxgwLZ18CZcZKVu0fao=
github.com/holiman/bloomfilter/v2 v2.0.3/go.mod h1:zpoh+gs7qcpqrHr3dB55AMiJwo0iURXE7ZOP9L9hSkA=
github.com/holiman/uint256 v1.2.0/go.mod h1:y4ga/t+u+Xwd7CpDgZESaRcWy0I7XMlTMA25ApIH5Jw=
Expand Down Expand Up @@ -1901,6 +1903,7 @@ gopkg.in/check.v1 v1.0.0-20201130134442-10cb98267c6c h1:Hei/4ADfdWqJk1ZMxUNpqntN
gopkg.in/check.v1 v1.0.0-20201130134442-10cb98267c6c/go.mod h1:JHkPIbrfpd72SG/EVd6muEfDQjcINNoR0C8j2r3qZ4Q=
gopkg.in/errgo.v2 v2.1.0/go.mod h1:hNsd1EY+bozCKY1Ytp96fpM3vjJbqLJn88ws8XvfDNI=
gopkg.in/fsnotify.v1 v1.4.7/go.mod h1:Tz8NjZHkW78fSQdbUxIjBTcgA1z1m8ZHf0WmKUhAMys=
gopkg.in/hedzr/errors.v3 v3.1.1/go.mod h1:UwtyepqtGTIAmdZGSc7wxXT5Gfd/BjcfRMhPpxwkJM4=
gopkg.in/inconshreveable/log15.v2 v2.0.0-20180818164646-67afb5ed74ec/go.mod h1:aPpfJ7XW+gOuirDoZ8gHhLh3kZ1B08FtV2bbmy7Jv3s=
gopkg.in/ini.v1 v1.66.2/go.mod h1:pNLf8WUiyNEtQjuu5G5vTm06TEv9tsIgeAvK8hOrP4k=
gopkg.in/ini.v1 v1.66.6 h1:LATuAqN/shcYAOkv3wl2L4rkaKqkcgTBQjOyYDvcPKI=
Expand Down
26 changes: 20 additions & 6 deletions contrib/git-changes-action/detector/ref.go
Original file line number Diff line number Diff line change
Expand Up @@ -4,13 +4,15 @@ import (
"context"
"encoding/json"
"fmt"
"github.com/avast/retry-go"
"github.com/google/go-github/v41/github"
"github.com/synapsecns/sanguine/contrib/git-changes-action/detector/actionscore"
"github.com/synapsecns/sanguine/contrib/git-changes-action/detector/tree"
"golang.org/x/exp/slices"
"golang.org/x/oauth2"
"os"
"strings"
"time"
)

// GetChangeTree returns the ref for the given event name.
Expand Down Expand Up @@ -63,13 +65,25 @@ func getChangedFilesFromAPI(ctx context.Context, ghContext *actionscore.Context,
ct = tree.NewTree()

page := 1
const retryCount = 10
for {
files, res, err := client.PullRequests.ListFiles(ctx, repoOwner, repoName, prNumber, &github.ListOptions{
Page: page,
PerPage: 100,
})
var files []*github.CommitFile
var res *github.Response
err = retry.Do(func() error {
reqCtx, cancel := context.WithTimeout(ctx, 15*time.Second)
defer cancel()

files, res, err = client.PullRequests.ListFiles(reqCtx, repoOwner, repoName, prNumber, &github.ListOptions{
Page: page,
PerPage: 100,
Copy link
Contributor

Choose a reason for hiding this comment

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

In master, I now changed this to PerPage: 20 and it worked after not working for a long time. Not sure if I just ended up getting lucky with that, but maybe just use 20 since that worked for me?

Copy link
Contributor Author

Choose a reason for hiding this comment

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

so max is 100, 20 will cause rate limit hits during high commit times

Copy link
Contributor

Choose a reason for hiding this comment

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

Yeah, just slacked you before seeing this.
My thing failed getting page 2. Definitely leave at 100.

})
if err != nil {
return fmt.Errorf("could not get files: %w", err)
}
return nil
}, retry.Context(ctx), retry.Attempts(retryCount))
if err != nil {
return nil, fmt.Errorf("could not get files: %w", err)
return nil, fmt.Errorf("could not get files after %d retries: %w", retryCount, err)
Copy link
Contributor

Choose a reason for hiding this comment

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

Maybe include the information I had in my log about the page number and repoName and prNumber and repoOwner?

Copy link
Contributor Author

Choose a reason for hiding this comment

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

done and wrapped above

}

for _, file := range files {
Expand All @@ -81,7 +95,7 @@ func getChangedFilesFromAPI(ctx context.Context, ghContext *actionscore.Context,
}
}

if page == res.LastPage {
if res.NextPage == 0 {
Copy link
Contributor

Choose a reason for hiding this comment

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

I am not sure this will work? Keeping it res.LastPage worked for me in the messaging branch that had multiple pages.

Copy link
Contributor Author

@trajan0x trajan0x Mar 7, 2023

Choose a reason for hiding this comment

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

image

I ran it w/ a fmt.Println and you can see the last page detection not working here https://github.com/synapsecns/sanguine/actions/runs/4309209034/jobs/7516328981

It'd get to 12 and then reset to 1. res.LastPage can be 0 when the cursor is lost

break
}

Expand Down
1 change: 1 addition & 0 deletions contrib/git-changes-action/go.mod
Original file line number Diff line number Diff line change
Expand Up @@ -9,6 +9,7 @@ replace (

require (
github.com/Flaque/filet v0.0.0-20201012163910-45f684403088
github.com/avast/retry-go v3.0.0+incompatible
github.com/brianvoe/gofakeit/v6 v6.20.1
github.com/ethereum/go-ethereum v1.10.26
github.com/go-git/go-git/v5 v5.5.2
Expand Down
2 changes: 2 additions & 0 deletions contrib/git-changes-action/go.sum
Original file line number Diff line number Diff line change
Expand Up @@ -51,6 +51,8 @@ github.com/anmitsu/go-shlex v0.0.0-20200514113438-38f4b401e2be h1:9AeTilPcZAjCFI
github.com/anmitsu/go-shlex v0.0.0-20200514113438-38f4b401e2be/go.mod h1:ySMOLuWl6zY27l47sB3qLNK6tF2fkHG55UZxx8oIVo4=
github.com/armon/go-socks5 v0.0.0-20160902184237-e75332964ef5 h1:0CwZNZbxp69SHPdPJAN/hZIm0C4OItdklCFmMRWYpio=
github.com/armon/go-socks5 v0.0.0-20160902184237-e75332964ef5/go.mod h1:wHh0iHkYZB8zMSxRWpUBQtwG5a7fFgvEO+odwuTv2gs=
github.com/avast/retry-go v3.0.0+incompatible h1:4SOWQ7Qs+oroOTQOYnAHqelpCO0biHSxpiH9JdtuBj0=
github.com/avast/retry-go v3.0.0+incompatible/go.mod h1:XtSnn+n/sHqQIpZ10K1qAevBhOOCWBLXXy3hyiqqBrY=
github.com/benbjohnson/clock v1.1.0 h1:Q92kusRqC1XV2MjkWETPvjJVqKetz1OzxZB7mHJLju8=
github.com/brianvoe/gofakeit/v6 v6.20.1 h1:8ihJ60OvPnPJ2W6wZR7M+TTeaZ9bml0z6oy4gvyJ/ek=
github.com/brianvoe/gofakeit/v6 v6.20.1/go.mod h1:Ow6qC71xtwm79anlwKRlWZW6zVq9D2XHE4QSSMP/rU8=
Expand Down
Loading