Skip to content

Commit 617017c

Browse files
authored
fix(deps): Update module github.com/avast/retry-go/v4 to v5 (#591)
#### Summary Instead of #590 so I can get a proper review, as it required a few changes. ---
1 parent f695a0e commit 617017c

4 files changed

Lines changed: 72 additions & 54 deletions

File tree

go.mod

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -7,7 +7,7 @@ toolchain go1.24.6
77
require (
88
github.com/Masterminds/semver v1.5.0
99
github.com/apache/arrow-go/v18 v18.5.0
10-
github.com/avast/retry-go/v4 v4.7.0
10+
github.com/avast/retry-go/v5 v5.0.0
1111
github.com/cloudquery/cloudquery-api-go v1.14.7
1212
github.com/distribution/reference v0.6.0
1313
github.com/docker/docker v28.5.2+incompatible

go.sum

Lines changed: 2 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -13,8 +13,8 @@ github.com/apache/thrift v0.22.0 h1:r7mTJdj51TMDe6RtcmNdQxgn9XcyfGDOzegMDRg47uc=
1313
github.com/apache/thrift v0.22.0/go.mod h1:1e7J/O1Ae6ZQMTYdy9xa3w9k+XHWPfRvdPyJeynQ+/g=
1414
github.com/apapsch/go-jsonmerge/v2 v2.0.0 h1:axGnT1gRIfimI7gJifB699GoE/oq+F2MU7Dml6nw9rQ=
1515
github.com/apapsch/go-jsonmerge/v2 v2.0.0/go.mod h1:lvDnEdqiQrp0O42VQGgmlKpxL1AP2+08jFMw88y4klk=
16-
github.com/avast/retry-go/v4 v4.7.0 h1:yjDs35SlGvKwRNSykujfjdMxMhMQQM0TnIjJaHB+Zio=
17-
github.com/avast/retry-go/v4 v4.7.0/go.mod h1:ZMPDa3sY2bKgpLtap9JRUgk2yTAba7cgiFhqxY2Sg6Q=
16+
github.com/avast/retry-go/v5 v5.0.0 h1:kf1Qc2UsTZ4qq8elDymqfbISvkyMuhgRxuJqX2NHP7k=
17+
github.com/avast/retry-go/v5 v5.0.0/go.mod h1://d+usmKWio1agtZfS1H/ltTqwtIfBnRq9zEwjc3eH8=
1818
github.com/bmatcuk/doublestar v1.1.1/go.mod h1:UD6OnuiIn0yFxxA2le/rnRU1G4RaI4UvFv1sNto9p6w=
1919
github.com/cenkalti/backoff/v4 v4.2.1 h1:y4OZtCnogmCPw98Zjyt5a6+QwPLGkiQsYW5oUqylYbM=
2020
github.com/cenkalti/backoff/v4 v4.2.1/go.mod h1:Y3VNntkOUPxTVeUxJ/G5vcM//AlwfmyYozVcomhLiZE=

managedplugin/download.go

Lines changed: 24 additions & 18 deletions
Original file line numberDiff line numberDiff line change
@@ -15,7 +15,7 @@ import (
1515
"strings"
1616
"time"
1717

18-
"github.com/avast/retry-go/v4"
18+
"github.com/avast/retry-go/v5"
1919
cloudquery_api "github.com/cloudquery/cloudquery-api-go"
2020
"github.com/rs/zerolog"
2121
"github.com/schollz/progressbar/v3"
@@ -74,8 +74,18 @@ func getURLLocation(ctx context.Context, org string, name string, version string
7474
err429 = errors.New("429")
7575
)
7676

77+
options := []retry.Option{
78+
retry.RetryIf(func(err error) bool {
79+
return err == err401 || err == err429
80+
}),
81+
retry.Context(ctx),
82+
retry.Attempts(RetryAttempts),
83+
retry.Delay(RetryWaitTime),
84+
retry.LastErrorOnly(true),
85+
}
86+
retrier := retry.New(options...)
7787
for _, downloadURL := range urls {
78-
err := retry.Do(func() error {
88+
err := retrier.Do(func() error {
7989
req, err := http.NewRequestWithContext(ctx, http.MethodGet, downloadURL, nil)
8090
if err != nil {
8191
return fmt.Errorf("failed create request %s: %w", downloadURL, err)
@@ -101,14 +111,7 @@ func getURLLocation(ctx context.Context, org string, name string, version string
101111
fmt.Printf("Failed downloading %s with status code %d\n", downloadURL, resp.StatusCode)
102112
return fmt.Errorf("statusCode %d", resp.StatusCode)
103113
}
104-
}, retry.RetryIf(func(err error) bool {
105-
return err == err401 || err == err429
106-
}),
107-
retry.Context(ctx),
108-
retry.Attempts(RetryAttempts),
109-
retry.Delay(RetryWaitTime),
110-
retry.LastErrorOnly(true),
111-
)
114+
})
112115
if err == err404 {
113116
continue
114117
}
@@ -338,7 +341,16 @@ func downloadFile(ctx context.Context, localPath string, downloadURL string, dop
338341
defer out.Close()
339342

340343
checksum := ""
341-
err = retry.Do(func() error {
344+
options := []retry.Option{
345+
retry.RetryIf(func(err error) bool {
346+
return err.Error() == "statusCode != 200"
347+
}),
348+
retry.Context(ctx),
349+
retry.Attempts(RetryAttempts),
350+
retry.Delay(RetryWaitTime),
351+
}
352+
retrier := retry.New(options...)
353+
err = retrier.Do(func() error {
342354
checksum = ""
343355
// Get the data
344356
req, err := http.NewRequestWithContext(ctx, http.MethodGet, downloadURL, nil)
@@ -384,13 +396,7 @@ func downloadFile(ctx context.Context, localPath string, downloadURL string, dop
384396
}
385397
checksum = fmt.Sprintf("%x", s.Sum(nil))
386398
return nil
387-
}, retry.RetryIf(func(err error) bool {
388-
return err.Error() == "statusCode != 200"
389-
}),
390-
retry.Context(ctx),
391-
retry.Attempts(RetryAttempts),
392-
retry.Delay(RetryWaitTime),
393-
)
399+
})
394400
if err != nil {
395401
for _, e := range err.(retry.Error) {
396402
if e.Error() == "not found" {

managedplugin/plugin.go

Lines changed: 45 additions & 33 deletions
Original file line numberDiff line numberDiff line change
@@ -16,7 +16,7 @@ import (
1616
"sync/atomic"
1717
"time"
1818

19-
"github.com/avast/retry-go/v4"
19+
"github.com/avast/retry-go/v5"
2020
"github.com/cloudquery/plugin-pb-go/internal/env"
2121
pbBase "github.com/cloudquery/plugin-pb-go/pb/base/v0"
2222
pbDiscovery "github.com/cloudquery/plugin-pb-go/pb/discovery/v0"
@@ -337,20 +337,23 @@ func (c *Client) startDockerPlugin(ctx context.Context, configPath string) error
337337
}
338338

339339
var hostConnection string
340-
err = retry.Do(func() error {
341-
hostConnection, err = getHostConnection(ctx, cli, resp.ID, portMapping.Port)
342-
return err
343-
}, retry.RetryIf(func(err error) bool {
344-
return err.Error() == "failed to get port mapping for container"
345-
}),
340+
options := []retry.Option{
341+
retry.RetryIf(func(err error) bool {
342+
return err.Error() == "failed to get port mapping for container"
343+
}),
346344
// this should generally succeed on first or second try, because we're only waiting for the container to start
347345
// to get the port mapping, not the plugin to start. The plugin will be waited for when we establish the tcp
348346
// connection.
349347
retry.Attempts(containerPortMappingRetries),
350348
retry.Delay(containerPortMappingInitialRetryDelay),
351349
retry.DelayType(retry.BackOffDelay),
352-
retry.MaxDelay(1*time.Second),
353-
)
350+
retry.MaxDelay(1 * time.Second),
351+
}
352+
retrier := retry.New(options...)
353+
err = retrier.Do(func() error {
354+
hostConnection, err = getHostConnection(ctx, cli, resp.ID, portMapping.Port)
355+
return err
356+
})
354357
if err != nil {
355358
return fmt.Errorf("failed to get host connection: %w", err)
356359
}
@@ -390,7 +393,17 @@ func getHostConnection(ctx context.Context, cli *dockerClient.Client, containerI
390393
}
391394

392395
func waitForContainerRunning(ctx context.Context, cli *dockerClient.Client, containerID string) error {
393-
err := retry.Do(func() error {
396+
options := []retry.Option{
397+
retry.RetryIf(func(err error) bool {
398+
return err != nil
399+
}),
400+
retry.Attempts(containerRunningRetries),
401+
retry.Delay(containerRunningInitialRetryDelay),
402+
retry.DelayType(retry.BackOffDelay),
403+
retry.MaxDelay(1 * time.Second),
404+
}
405+
retrier := retry.New(options...)
406+
err := retrier.Do(func() error {
394407
containerJSON, err := cli.ContainerInspect(ctx, containerID)
395408
if err != nil {
396409
return fmt.Errorf("failed to inspect container: %w", err)
@@ -404,14 +417,7 @@ func waitForContainerRunning(ctx context.Context, cli *dockerClient.Client, cont
404417
}
405418
}
406419
return errors.New("container not running")
407-
}, retry.RetryIf(func(err error) bool {
408-
return err != nil
409-
}),
410-
retry.Attempts(containerRunningRetries),
411-
retry.Delay(containerRunningInitialRetryDelay),
412-
retry.DelayType(retry.BackOffDelay),
413-
retry.MaxDelay(1*time.Second),
414-
)
420+
})
415421
return err
416422
}
417423

@@ -432,7 +438,16 @@ func getFreeTCPAddr() (string, error) {
432438

433439
func (c *Client) startLocal(ctx context.Context, path string) error {
434440
attempt := 0
435-
return retry.Do(
441+
options := []retry.Option{
442+
retry.Attempts(3),
443+
retry.Delay(1 * time.Second),
444+
retry.LastErrorOnly(true),
445+
retry.OnRetry(func(n uint, err error) {
446+
c.logger.Debug().Err(err).Int("attempt", int(n)).Msg("failed to start plugin, retrying")
447+
}),
448+
}
449+
retrier := retry.New(options...)
450+
return retrier.Do(
436451
func() error {
437452
attempt++
438453
c.logger.Debug().Str("path", path).Int("attempt", attempt).Msg("starting plugin")
@@ -454,12 +469,6 @@ func (c *Client) startLocal(ctx context.Context, path string) error {
454469
}
455470
return err
456471
},
457-
retry.Attempts(3),
458-
retry.Delay(1*time.Second),
459-
retry.LastErrorOnly(true),
460-
retry.OnRetry(func(n uint, err error) {
461-
c.logger.Debug().Err(err).Int("attempt", int(n)).Msg("failed to start plugin, retrying")
462-
}),
463472
)
464473
}
465474

@@ -601,7 +610,17 @@ func (c *Client) connectUsingTCP(ctx context.Context, path string) error {
601610
return fmt.Errorf("failed to dial grpc %s plugin at %s: %w", c.typ.String(), path, err)
602611
}
603612

604-
return retry.Do(
613+
options := []retry.Option{
614+
retry.RetryIf(func(err error) bool {
615+
return err.Error() == "connection not ready"
616+
}),
617+
retry.Delay(containerServerHealthyInitialRetryDelay),
618+
retry.Attempts(containerServerHealthyRetries),
619+
retry.DelayType(retry.BackOffDelay),
620+
retry.MaxDelay(1 * time.Second),
621+
}
622+
retrier := retry.New(options...)
623+
return retrier.Do(
605624
func() error {
606625
state := c.Conn.GetState()
607626
if state == connectivity.Idle || state == connectivity.Ready {
@@ -612,13 +631,6 @@ func (c *Client) connectUsingTCP(ctx context.Context, path string) error {
612631
}
613632
return errors.New("connection not ready")
614633
},
615-
retry.RetryIf(func(err error) bool {
616-
return err.Error() == "connection not ready"
617-
}),
618-
retry.Delay(containerServerHealthyInitialRetryDelay),
619-
retry.Attempts(containerServerHealthyRetries),
620-
retry.DelayType(retry.BackOffDelay),
621-
retry.MaxDelay(1*time.Second),
622634
)
623635
}
624636

0 commit comments

Comments
 (0)