-
Notifications
You must be signed in to change notification settings - Fork 3.5k
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
base: main
Are you sure you want to change the base?
Changes from all commits
File filter
Filter by extension
Conversations
Jump to
Diff view
Diff view
There are no files selected for viewing
Original file line number | Diff line number | Diff line change |
---|---|---|
|
@@ -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, | ||
}, | ||
Timeout: client.Timeout, | ||
} | ||
|
||
type config struct { | ||
labels model.LabelSet | ||
|
@@ -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 { | ||
There was a problem hiding this comment. Choose a reason for hiding this commentThe reason will be displayed to describe this comment to others. Learn more. why not just set the default on the config struct ? There was a problem hiding this comment. Choose a reason for hiding this commentThe reason will be displayed to describe this comment to others. Learn more. You mean here? That's also used by Promtail. There was a problem hiding this comment. Choose a reason for hiding this commentThe reason will be displayed to describe this comment to others. Learn more. |
||
return nil, err | ||
} | ||
|
||
|
@@ -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 | ||
} | ||
|
||
|
@@ -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) | ||
|
@@ -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 { | ||
|
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
I mean here
There was a problem hiding this comment.
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.