Skip to content

Commit

Permalink
add back hardcoding retries
Browse files Browse the repository at this point in the history
  • Loading branch information
Kristina Pathak committed Apr 10, 2024
1 parent 58bfd61 commit 5c43c8a
Show file tree
Hide file tree
Showing 2 changed files with 6 additions and 24 deletions.
23 changes: 2 additions & 21 deletions cmd/builder/internal/builder/config.go
Original file line number Diff line number Diff line change
Expand Up @@ -10,7 +10,6 @@ import (
"os/exec"
"path/filepath"
"strings"
"time"

"github.com/hashicorp/go-version"
"go.uber.org/multierr"
Expand All @@ -19,12 +18,8 @@ import (

const defaultOtelColVersion = "0.97.0"

var (
// ErrInvalidGoMod indicates an invalid gomod
ErrInvalidGoMod = errors.New("invalid gomod specification for module")
// ErrIncompatibleConfigurationValues indicates that there is configuration that cannot be combined
ErrIncompatibleConfigurationValues = errors.New("cannot combine configuration values")
)
// ErrInvalidGoMod indicates an invalid gomod
var ErrInvalidGoMod = errors.New("invalid gomod specification for module")

// Config holds the builder's configuration
type Config struct {
Expand All @@ -44,8 +39,6 @@ type Config struct {
Connectors []Module `mapstructure:"connectors"`
Replaces []string `mapstructure:"replaces"`
Excludes []string `mapstructure:"excludes"`

downloadModules retry `mapstructure:"-"`
}

// Distribution holds the parameters for the final binary
Expand All @@ -70,12 +63,6 @@ type Module struct {
Path string `mapstructure:"path"` // an optional path to the local version of this module
}

// retry dictates how many times to retry and how long to wait between attempts.
type retry struct {
numRetries int
wait time.Duration
}

// NewDefaultConfig creates a new config, with default values
func NewDefaultConfig() Config {
log, err := zap.NewDevelopment()
Expand All @@ -95,12 +82,6 @@ func NewDefaultConfig() Config {
OtelColVersion: defaultOtelColVersion,
Module: "go.opentelemetry.io/collector/cmd/builder",
},
// basic retry if error from go mod command (in case of transient network error). This could be improved
// retry 3 times with 5 second spacing interval
downloadModules: retry{
numRetries: 3,
wait: 5 * time.Second,
},
}
}

Expand Down
7 changes: 4 additions & 3 deletions cmd/builder/internal/builder/main.go
Original file line number Diff line number Diff line change
Expand Up @@ -225,12 +225,13 @@ func processAndWrite(cfg Config, tmpl *template.Template, outFile string, tmplPa
func downloadModules(cfg Config) error {
cfg.Logger.Info("Getting go modules")

retries := 3
failReason := "unknown"
for i := 1; i <= cfg.downloadModules.numRetries; i++ {
for i := 1; i <= retries; i++ {
if err := runGoCommand(cfg, "mod", "download"); err != nil {
failReason = err.Error()
cfg.Logger.Info("Failed modules download", zap.String("retry", fmt.Sprintf("%d/%d", i, cfg.downloadModules.numRetries)))
time.Sleep(cfg.downloadModules.wait)
cfg.Logger.Info("Failed modules download", zap.String("retry", fmt.Sprintf("%d/%d", i, retries)))
time.Sleep(5 * time.Second)
continue
}
return nil
Expand Down

0 comments on commit 5c43c8a

Please sign in to comment.