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

fix: Set a maximum retries for Docker driver to avoid deadlock. #15026

Draft
wants to merge 1 commit into
base: main
Choose a base branch
from
Draft
Show file tree
Hide file tree
Changes from all 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
52 changes: 38 additions & 14 deletions clients/cmd/docker-driver/config.go
Original file line number Diff line number Diff line change
Expand Up @@ -66,18 +66,16 @@ const (
defaultHostLabelName = model.LabelName("host")
)

var (
defaultClientConfig = client.Config{
BatchWait: client.BatchWait,
BatchSize: client.BatchSize,
BackoffConfig: backoff.Config{
MinBackoff: client.MinBackoff,
MaxBackoff: client.MaxBackoff,
MaxRetries: client.MaxRetries,
},
Timeout: client.Timeout,
}
)
var defaultClientConfig = client.Config{
BatchWait: client.BatchWait,
BatchSize: client.BatchSize,
BackoffConfig: backoff.Config{
MinBackoff: client.MinBackoff,
MaxBackoff: client.MaxBackoff,
MaxRetries: client.MaxRetries,
Copy link
Contributor

Choose a reason for hiding this comment

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

I mean here

Copy link
Contributor Author

Choose a reason for hiding this comment

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

Interesting. The default is 10 so the driver should not deadlock it can just take almost an hour until the client gives up. For production use this should be fine.

},
Timeout: client.Timeout,
}

type config struct {
labels model.LabelSet
Expand Down Expand Up @@ -153,7 +151,7 @@ func parseConfig(logCtx logger.Info) (*config, error) {
clientConfig.URL = flagext.URLValue{URL: url}

// parse timeout
if err := parseDuration(cfgTimeoutKey, logCtx, func(d time.Duration) { clientConfig.Timeout = d }); err != nil {
if err := parseDurationWithDefault(cfgTimeoutKey, logCtx, func(d time.Duration) { clientConfig.Timeout = d }, 10*time.Second); err != nil {
Copy link
Contributor

Choose a reason for hiding this comment

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

why not just set the default on the config struct ?

Copy link
Contributor Author

Choose a reason for hiding this comment

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

You mean here? That's also used by Promtail.

Copy link
Contributor

Choose a reason for hiding this comment

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

return nil, err
}

Expand All @@ -172,7 +170,7 @@ func parseConfig(logCtx logger.Info) (*config, error) {
if err := parseDuration(cfgMaxBackoffKey, logCtx, func(d time.Duration) { clientConfig.BackoffConfig.MaxBackoff = d }); err != nil {
return nil, err
}
if err := parseInt(cfgMaxRetriesKey, logCtx, func(i int) { clientConfig.BackoffConfig.MaxRetries = i }); err != nil {
if err := parseIntWithDefault(cfgMaxRetriesKey, logCtx, func(i int) { clientConfig.BackoffConfig.MaxRetries = i }, 2); err != nil {
return nil, err
}

Expand Down Expand Up @@ -350,6 +348,19 @@ func parseDuration(key string, logCtx logger.Info, set func(d time.Duration)) er
return nil
}

func parseDurationWithDefault(key string, logCtx logger.Info, set func(d time.Duration), defaultValue time.Duration) error {
if raw, ok := logCtx.Config[key]; ok {
val, err := time.ParseDuration(raw)
if err != nil {
return fmt.Errorf("%s: invalid option %s format: %s", driverName, key, raw)
}
set(val)
} else {
set(defaultValue)
}
return nil
}

func parseInt(key string, logCtx logger.Info, set func(i int)) error {
if raw, ok := logCtx.Config[key]; ok {
val, err := strconv.Atoi(raw)
Expand All @@ -361,6 +372,19 @@ func parseInt(key string, logCtx logger.Info, set func(i int)) error {
return nil
}

func parseIntWithDefault(key string, logCtx logger.Info, set func(i int), defaultValue int) error {
if raw, ok := logCtx.Config[key]; ok {
val, err := strconv.Atoi(raw)
if err != nil {
return fmt.Errorf("%s: invalid option %s format: %s", driverName, key, raw)
}
set(val)
} else {
set(defaultValue)
}
return nil
}

func relabelConfig(config string, lbs model.LabelSet) (model.LabelSet, error) {
relabelConfig := make([]*relabel.Config, 0)
if err := yaml.UnmarshalStrict([]byte(config), &relabelConfig); err != nil {
Expand Down
6 changes: 3 additions & 3 deletions clients/cmd/docker-driver/driver.go
Original file line number Diff line number Diff line change
Expand Up @@ -81,14 +81,14 @@ func (d *driver) StartLogging(file string, logCtx logger.Info) error {
return err
}

keepFile, err := parseBoolean(cfgKeepFile, logCtx, false)
keepFile, err := parseBoolean(cfgKeepFile, logCtx, true)
if err != nil {
return err
}

var jsonl logger.Logger
if !noFile {
if err := os.MkdirAll(folder, 0755); err != nil {
if err := os.MkdirAll(folder, 0o755); err != nil {
return errors.Wrap(err, "error setting up logger dir")
}

Expand All @@ -102,7 +102,7 @@ func (d *driver) StartLogging(file string, logCtx logger.Info) error {
if err != nil {
return errors.Wrap(err, "error creating loki logger")
}
f, err := fifo.OpenFifo(context.Background(), file, syscall.O_RDONLY, 0700)
f, err := fifo.OpenFifo(context.Background(), file, syscall.O_RDONLY, 0o700)
if err != nil {
return errors.Wrapf(err, "error opening logger fifo: %q", file)
}
Expand Down
Loading