Skip to content

Commit 28dbd26

Browse files
committed
Create variables for default values of new flags
1 parent b4f032e commit 28dbd26

File tree

1 file changed

+14
-4
lines changed

1 file changed

+14
-4
lines changed

pkg/options/options.go

Lines changed: 14 additions & 4 deletions
Original file line numberDiff line numberDiff line change
@@ -28,6 +28,16 @@ import (
2828
"k8s.io/klog/v2"
2929
)
3030

31+
var (
32+
// Align with the default scrape interval from Prometheus: https://prometheus.io/docs/prometheus/latest/configuration/configuration/#scrape_config
33+
defaultServerReadTimeout = 60 * time.Second
34+
defaultServerWriteTimeout = 60 * time.Second
35+
// ServerIdleTimeout is set to 5 minutes to match the default idle timeout of Prometheus scrape clients
36+
// https://github.com/prometheus/common/blob/318309999517402ad522877ac7e55fa650a11114/config/http_config.go#L55
37+
defaultServerIdleTimeout = 5 * time.Minute
38+
defaultServerReadHeaderTimeout = 5 * time.Second
39+
)
40+
3141
// Options are the configurable parameters for kube-state-metrics.
3242
type Options struct {
3343
AnnotationsAllowList LabelsAllowList `yaml:"annotations_allow_list"`
@@ -152,10 +162,10 @@ func (o *Options) AddFlags(cmd *cobra.Command) {
152162
o.cmd.Flags().Var(&o.NamespacesDenylist, "namespaces-denylist", "Comma-separated list of namespaces not to be enabled. If namespaces and namespaces-denylist are both set, only namespaces that are excluded in namespaces-denylist will be used.")
153163
o.cmd.Flags().Var(&o.Resources, "resources", fmt.Sprintf("Comma-separated list of Resources to be enabled. Defaults to %q", &DefaultResources))
154164

155-
o.cmd.Flags().DurationVar(&o.ServerReadTimeout, "server-read-timeout", 30*time.Second, "The maximum duration for reading the entire request, including the body.")
156-
o.cmd.Flags().DurationVar(&o.ServerWriteTimeout, "server-write-timeout", 60*time.Second, "The maximum duration before timing out writes of the response.")
157-
o.cmd.Flags().DurationVar(&o.ServerIdleTimeout, "server-idle-timeout", 5*time.Minute, "The maximum amount of time to wait for the next request when keep-alives are enabled.")
158-
o.cmd.Flags().DurationVar(&o.ServerReadHeaderTimeout, "server-read-header-timeout", 5*time.Second, "The maximum duration for reading the header of requests.")
165+
o.cmd.Flags().DurationVar(&o.ServerReadTimeout, "server-read-timeout", defaultServerReadTimeout, "The maximum duration for reading the entire request, including the body. Align with the scrape interval or timeout of scraping clients. ")
166+
o.cmd.Flags().DurationVar(&o.ServerWriteTimeout, "server-write-timeout", defaultServerWriteTimeout, "The maximum duration before timing out writes of the response. Align with the scrape interval or timeout of scraping clients..")
167+
o.cmd.Flags().DurationVar(&o.ServerIdleTimeout, "server-idle-timeout", defaultServerIdleTimeout, "The maximum amount of time to wait for the next request when keep-alives are enabled. Align with the idletimeout of your scrape clients.")
168+
o.cmd.Flags().DurationVar(&o.ServerReadHeaderTimeout, "server-read-header-timeout", defaultServerReadHeaderTimeout, "The maximum duration for reading the header of requests.")
159169
}
160170

161171
// Parse parses the flag definitions from the argument list.

0 commit comments

Comments
 (0)