Skip to content

Commit

Permalink
Merge 423812a into fb3723f
Browse files Browse the repository at this point in the history
  • Loading branch information
kzys authored Dec 19, 2024
2 parents fb3723f + 423812a commit 04add7a
Show file tree
Hide file tree
Showing 8 changed files with 31 additions and 221 deletions.
2 changes: 1 addition & 1 deletion go.mod
Original file line number Diff line number Diff line change
Expand Up @@ -21,7 +21,7 @@ require (
github.com/briandowns/spinner v1.23.1
github.com/buildpacks/pack v0.36.1
github.com/cavaliergopher/grab/v3 v3.0.1
github.com/cenkalti/backoff v2.2.1+incompatible
github.com/cenkalti/backoff/v5 v5.0.0
github.com/chzyer/readline v1.5.1
github.com/cli/safeexec v1.0.1
github.com/coder/websocket v1.8.12
Expand Down
4 changes: 2 additions & 2 deletions go.sum
Original file line number Diff line number Diff line change
Expand Up @@ -166,10 +166,10 @@ github.com/buildpacks/pack v0.36.1/go.mod h1:oM4TCRUir43xU8bwiapa6VPHs29HuznNxPg
github.com/bwesterb/go-ristretto v1.2.3/go.mod h1:fUIoIZaG73pV5biE2Blr2xEzDoMj7NFEuV9ekS419A0=
github.com/cavaliergopher/grab/v3 v3.0.1 h1:4z7TkBfmPjmLAAmkkAZNX/6QJ1nNFdv3SdIHXju0Fr4=
github.com/cavaliergopher/grab/v3 v3.0.1/go.mod h1:1U/KNnD+Ft6JJiYoYBAimKH2XrYptb8Kl3DFGmsjpq4=
github.com/cenkalti/backoff v2.2.1+incompatible h1:tNowT99t7UNflLxfYYSlKYsBpXdEet03Pg2g16Swow4=
github.com/cenkalti/backoff v2.2.1+incompatible/go.mod h1:90ReRw6GdpyfrHakVjL/QHaoyV4aDUVVkXQJJJ3NXXM=
github.com/cenkalti/backoff/v4 v4.3.0 h1:MyRJ/UdXutAwSAT+s3wNd7MfTIcy71VQueUuFK343L8=
github.com/cenkalti/backoff/v4 v4.3.0/go.mod h1:Y3VNntkOUPxTVeUxJ/G5vcM//AlwfmyYozVcomhLiZE=
github.com/cenkalti/backoff/v5 v5.0.0 h1:4ziwFuaVJicDO1ah1Nz1aXXV1caM28PFgf1V5TTFXew=
github.com/cenkalti/backoff/v5 v5.0.0/go.mod h1:rkhZdG3JZukswDf7f0cwqPNk4K0sa+F97BxZthm/crw=
github.com/cespare/xxhash/v2 v2.3.0 h1:UL815xU9SqsFlibzuggzjXhog7bL6oX9BbNZnL2UFvs=
github.com/cespare/xxhash/v2 v2.3.0/go.mod h1:VGX0DQ3Q6kWi7AoAeZDth3/j3BFtOZR5XLFGgcrjCOs=
github.com/chrismellard/docker-credential-acr-env v0.0.0-20230304212654-82a0ddb27589 h1:krfRl01rzPzxSxyLyrChD+U+MzsBXbm0OwYYB67uF+4=
Expand Down
18 changes: 8 additions & 10 deletions internal/build/imgsrc/depot.go
Original file line number Diff line number Diff line change
Expand Up @@ -10,6 +10,7 @@ import (
"path/filepath"
"time"

"github.com/cenkalti/backoff/v5"
depotbuild "github.com/depot/depot-go/build"
depotmachine "github.com/depot/depot-go/machine"
"github.com/moby/buildkit/client"
Expand All @@ -25,7 +26,6 @@ import (
"github.com/superfly/flyctl/internal/render"
"github.com/superfly/flyctl/internal/tracing"
"github.com/superfly/flyctl/iostreams"
"github.com/superfly/flyctl/retry"
"github.com/superfly/flyctl/terminal"
"go.opentelemetry.io/otel/attribute"
"go.opentelemetry.io/otel/trace"
Expand Down Expand Up @@ -208,24 +208,22 @@ func initBuilder(ctx context.Context, buildState *build, appName string, streams
}

// Set the buildErr to any error that represents the build failing.
var buildErr error
var finalBuildErr error

span.AddEvent("Acquiring Depot machine")
var buildkit *depotmachine.Machine

timeoutCtx, cancel := context.WithTimeout(ctx, 25*time.Second)
defer cancel()

finalBuildErr = retry.Retry(timeoutCtx, func() error {
buildkit, buildErr = depotmachine.Acquire(ctx, build.ID, build.Token, "amd64")
if buildErr != nil {
span.RecordError(buildErr)
return buildErr
buildkit, finalBuildErr := backoff.Retry(timeoutCtx, func() (*depotmachine.Machine, error) {
machine, err := depotmachine.Acquire(ctx, build.ID, build.Token, "amd64")
if err != nil {
span.RecordError(err)
return nil, err
}

return nil
}, 2)
return machine, nil
}, backoff.WithMaxTries(2))

if finalBuildErr != nil {
streams.StopProgressIndicator()
Expand Down
8 changes: 4 additions & 4 deletions internal/build/imgsrc/resolver.go
Original file line number Diff line number Diff line change
Expand Up @@ -12,6 +12,7 @@ import (
"sync"
"time"

"github.com/cenkalti/backoff/v5"
"github.com/pkg/errors"
"github.com/vektah/gqlparser/v2/gqlerror"
"go.opentelemetry.io/otel/attribute"
Expand All @@ -27,7 +28,6 @@ import (
"github.com/superfly/flyctl/internal/sentry"
"github.com/superfly/flyctl/internal/tracing"
"github.com/superfly/flyctl/iostreams"
"github.com/superfly/flyctl/retry"

"github.com/superfly/flyctl/terminal"
)
Expand Down Expand Up @@ -675,9 +675,9 @@ func (r *Resolver) StartHeartbeat(ctx context.Context) (*StopSignal, error) {
terminal.Debugf("Sending remote builder heartbeat pulse to %s...\n", heartbeatUrl)

span.AddEvent("sending first heartbeat")
err = retry.Retry(ctx, func() error {
return r.heartbeatFn(ctx, dockerClient, heartbeatReq)
}, 3)
_, err = backoff.Retry(ctx, func() (any, error) {
return nil, r.heartbeatFn(ctx, dockerClient, heartbeatReq)
}, backoff.WithMaxTries(3))
if err != nil {
var h *httpError
if errors.As(err, &h) {
Expand Down
14 changes: 7 additions & 7 deletions internal/command/deploy/machinebasedtest.go
Original file line number Diff line number Diff line change
Expand Up @@ -5,7 +5,7 @@ import (
"fmt"
"time"

"github.com/cenkalti/backoff"
"github.com/cenkalti/backoff/v5"
"github.com/samber/lo"
fly "github.com/superfly/fly-go"
"github.com/superfly/flyctl/internal/appconfig"
Expand Down Expand Up @@ -153,19 +153,19 @@ func (md *machineDeployment) waitForLogs(ctx context.Context, mach *fly.Machine,
b := backoff.NewExponentialBackOff()
b.InitialInterval = 1 * time.Second
b.MaxInterval = 10 * time.Second
b.MaxElapsedTime = timeout

return backoff.Retry(func() error {
_, err := backoff.Retry(ctx, func() ([]fly.LogEntry, error) {
logs, _, err := md.apiClient.GetAppLogs(ctx, md.app.Name, "", md.appConfig.PrimaryRegion, mach.ID)
if err != nil {
return err
return nil, err
}
if len(logs) == 0 {
return fmt.Errorf(ErrNoLogsFound)
return nil, fmt.Errorf(ErrNoLogsFound)
}

return nil
}, backoff.WithContext(b, ctx))
return logs, nil
}, backoff.WithBackOff(b), backoff.WithMaxElapsedTime(timeout))
return err
}

func (md *machineDeployment) createTestMachine(ctx context.Context, svc *appconfig.ServiceMachineCheck, machineToTest *fly.Machine, sl statuslogger.StatusLine) (*fly.Machine, error) {
Expand Down
19 changes: 9 additions & 10 deletions internal/command/deploy/machines_deploymachinesapp.go
Original file line number Diff line number Diff line change
Expand Up @@ -12,7 +12,7 @@ import (
"strings"
"time"

"github.com/cenkalti/backoff"
"github.com/cenkalti/backoff/v5"
"github.com/miekg/dns"
"github.com/samber/lo"
"github.com/sourcegraph/conc/pool"
Expand Down Expand Up @@ -1367,9 +1367,8 @@ func (md *machineDeployment) checkDNS(ctx context.Context) error {
b := backoff.NewExponentialBackOff()
b.InitialInterval = 1 * time.Second
b.MaxInterval = 5 * time.Second
b.MaxElapsedTime = 60 * time.Second

return backoff.Retry(func() error {
_, err = backoff.Retry(ctx, func() (any, error) {
m := new(dns.Msg)

var numIPv4, numIPv6 int
Expand All @@ -1389,28 +1388,28 @@ func (md *machineDeployment) checkDNS(ctx context.Context) error {
answerv4, _, err := c.Exchange(m, "8.8.8.8:53")
if err != nil {
tracing.RecordError(span, err, "failed to exchange v4")
return err
return nil, err
} else if len(answerv4.Answer) != numIPv4 {
span.SetAttributes(attribute.String("v4_answer", answerv4.String()))
tracing.RecordError(span, errors.New("v4 response count mismatch"), "v4 response count mismatch")
return fmt.Errorf("expected %d A records for %s, got %d", numIPv4, fqdn, len(answerv4.Answer))
return nil, fmt.Errorf("expected %d A records for %s, got %d", numIPv4, fqdn, len(answerv4.Answer))
}

m.SetQuestion(fqdn, dns.TypeAAAA)
span.SetAttributes(attribute.String("v6_question", m.String()))
answerv6, _, err := c.Exchange(m, "8.8.8.8:53")
if err != nil {
tracing.RecordError(span, err, "failed to exchange v4")
return err
return nil, err
} else if len(answerv6.Answer) != numIPv6 {
span.SetAttributes(attribute.String("v6_answer", answerv6.String()))
tracing.RecordError(span, errors.New("v6 response count mismatch"), "v6 response count mismatch")
return fmt.Errorf("expected %d AAAA records for %s, got %d", numIPv6, fqdn, len(answerv6.Answer))
return nil, fmt.Errorf("expected %d AAAA records for %s, got %d", numIPv6, fqdn, len(answerv6.Answer))
}

return nil
}, backoff.WithContext(b, ctx))

return nil, nil
}, backoff.WithBackOff(b), backoff.WithMaxElapsedTime(60*time.Second))
return err
} else {
return nil
}
Expand Down
49 changes: 0 additions & 49 deletions retry/retry.go

This file was deleted.

138 changes: 0 additions & 138 deletions retry/retry_test.go

This file was deleted.

0 comments on commit 04add7a

Please sign in to comment.