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

[query] Add ability to set default query timeout by config #2226

Merged
merged 7 commits into from
Apr 9, 2020
Merged
Show file tree
Hide file tree
Changes from 1 commit
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
18 changes: 18 additions & 0 deletions src/cmd/services/m3query/config/config.go
Original file line number Diff line number Diff line change
Expand Up @@ -57,6 +57,8 @@ const (
errNoIDGenerationScheme = "error: a recent breaking change means that an ID " +
"generation scheme is required in coordinator configuration settings. " +
"More information is available here: %s"

defaultQueryTimeout = 30 * time.Duration
)

var (
Expand Down Expand Up @@ -124,6 +126,9 @@ type Configuration struct {
// Carbon is the carbon configuration.
Carbon *CarbonConfiguration `yaml:"carbon"`

// Query is the query configuration.
Query QueryConfiguration `yaml:"query"`

// Limits specifies limits on per-query resource usage.
Limits LimitsConfiguration `yaml:"limits"`

Expand Down Expand Up @@ -190,6 +195,19 @@ type ResultOptions struct {
KeepNans bool `yaml:"keepNans"`
}

// QueryConfiguration is the query configuration.
type QueryConfiguration struct {
Timeout *time.Duration `yaml:"timeout"`
}

// TimeoutOrDefault returns the configured timeout or default value.
func (c QueryConfiguration) TimeoutOrDefault() time.Duration {
if v := c.Timeout; v != nil {
return *v
}
return defaultQueryTimeout
}

// LimitsConfiguration represents limitations on resource usage in the query
// instance. Limits are split between per-query and global limits.
type LimitsConfiguration struct {
Expand Down
20 changes: 8 additions & 12 deletions src/query/api/v1/options/handler.go
Original file line number Diff line number Diff line change
Expand Up @@ -190,17 +190,11 @@ func NewHandlerOptions(
placementServiceNames []string,
serviceOptionDefaults []handleroptions.ServiceOptionsDefault,
) (HandlerOptions, error) {
var timeoutOpts = &prometheus.TimeoutOpts{}
if embeddedDbCfg == nil || embeddedDbCfg.Client.FetchTimeout == nil {
timeoutOpts.FetchTimeout = defaultTimeout
} else {
timeout := *embeddedDbCfg.Client.FetchTimeout
if timeout <= 0 {
return nil,
fmt.Errorf("m3db client fetch timeout should be > 0, is %d", timeout)
}

timeoutOpts.FetchTimeout = timeout
timeout := cfg.Query.TimeoutOrDefault()
if embeddedDbCfg != nil
&& embeddedDbCfg.Client.FetchTimeout != nil
&& *embeddedDbCfg.Client.FetchTimeout > timeout {
timeout = *embeddedDbCfg.Client.FetchTimeout
}

return &handlerOptions{
Expand All @@ -213,7 +207,6 @@ func NewHandlerOptions(
embeddedDbCfg: embeddedDbCfg,
createdAt: time.Now(),
tagOptions: tagOptions,
timeoutOpts: timeoutOpts,
enforcer: enforcer,
fetchOptionsBuilder: fetchOptionsBuilder,
queryContextOptions: queryContextOptions,
Expand All @@ -222,6 +215,9 @@ func NewHandlerOptions(
placementServiceNames: placementServiceNames,
serviceOptionDefaults: serviceOptionDefaults,
nowFn: time.Now,
timeoutOpts: &prometheus.TimeoutOpts{
FetchTimeout: timeout,
},
}, nil
}

Expand Down