Skip to content

Commit

Permalink
get deploy-retries from launchdarkly by default
Browse files Browse the repository at this point in the history
Users can still set deploy-retries to whatever value they'd like, however.
  • Loading branch information
billyb2 committed Jul 22, 2024
1 parent a717b49 commit f5b3330
Show file tree
Hide file tree
Showing 2 changed files with 32 additions and 3 deletions.
28 changes: 25 additions & 3 deletions internal/command/deploy/deploy.go
Original file line number Diff line number Diff line change
Expand Up @@ -167,10 +167,10 @@ var CommonFlags = flag.Set{
Shorthand: "s",
Description: "Signal to stop the machine with for bluegreen strategy (default: SIGINT)",
},
flag.Int{
flag.String{
Name: "deploy-retries",
Description: "Number of times to retry a deployment if it fails",
Default: 0,
Default: "auto",
},
}

Expand Down Expand Up @@ -486,6 +486,28 @@ func deployToMachines(

status.FlyctlVersion = buildinfo.Info().Version.String()

retriesFlag := flag.GetString(ctx, "deploy-retries")
deployRetries := 0

switch retriesFlag {
case "auto":
ldClient := launchdarkly.ClientFromContext(ctx)
retries := ldClient.GetFeatureFlagValue("deploy-retries", 0.0).(float64)
deployRetries = int(retries)

default:
var invalidRetriesErr error = fmt.Errorf("--deploy-retries must be set to a positive integer, 0, or 'auto'")
retries, err := strconv.Atoi(retriesFlag)
if err != nil {
return invalidRetriesErr
}
if retries < 0 {
return invalidRetriesErr
}

deployRetries = retries
}

md, err := NewMachineDeployment(ctx, MachineDeploymentArgs{
AppCompact: app,
DeploymentImage: img.Tag,
Expand Down Expand Up @@ -513,7 +535,7 @@ func deployToMachines(
MaxConcurrent: maxConcurrent,
VolumeInitialSize: flag.GetInt(ctx, "volume-initial-size"),
ProcessGroups: processGroups,
DeployRetries: flag.GetInt(ctx, "deploy-retries"),
DeployRetries: deployRetries,
})
if err != nil {
sentry.CaptureExceptionWithAppInfo(ctx, err, "deploy", app)
Expand Down
7 changes: 7 additions & 0 deletions internal/launchdarkly/launchdarkly.go
Original file line number Diff line number Diff line change
Expand Up @@ -13,6 +13,7 @@ import (
"github.com/launchdarkly/go-sdk-common/v3/ldcontext"
"github.com/superfly/flyctl/internal/logger"
"github.com/superfly/flyctl/internal/tracing"
"go.opentelemetry.io/otel/attribute"
)

const clientSideID string = "6557a71bbffb5f134b84b15c"
Expand Down Expand Up @@ -84,12 +85,18 @@ func (ldClient *Client) monitor(ctx context.Context) {
}

func (ldClient *Client) GetFeatureFlagValue(key string, defaultValue any) any {
_, span := tracing.GetTracer().Start(context.Background(), "get_feature_flag_value")
defer span.End()

span.SetAttributes(attribute.String("flag", key))

ldClient.flagsMutex.Lock()
defer ldClient.flagsMutex.Unlock()

if flag, ok := ldClient.flags[key]; ok {
return flag.Value
}
span.SetAttributes(attribute.Bool("default_flag", true))
return defaultValue

}
Expand Down

0 comments on commit f5b3330

Please sign in to comment.