Skip to content

Commit b4f032e

Browse files
committed
Add additional flags for IdleTimeouts
1 parent e97933b commit b4f032e

File tree

3 files changed

+9
-1
lines changed

3 files changed

+9
-1
lines changed

docs/developer/cli-arguments.md

Lines changed: 2 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -67,6 +67,8 @@ Flags:
6767
--pod-namespace string Name of the namespace of the pod specified by --pod. When set, it is expected that --pod and --pod-namespace are both set. Most likely this should be passed via the downward API. This is used for auto-detecting sharding. If set, this has preference over statically configured sharding. This is experimental, it may be removed without notice.
6868
--port int Port to expose metrics on. (default 8080)
6969
--resources string Comma-separated list of Resources to be enabled. Defaults to "certificatesigningrequests,configmaps,cronjobs,daemonsets,deployments,endpoints,horizontalpodautoscalers,ingresses,jobs,leases,limitranges,mutatingwebhookconfigurations,namespaces,networkpolicies,nodes,persistentvolumeclaims,persistentvolumes,poddisruptionbudgets,pods,replicasets,replicationcontrollers,resourcequotas,secrets,services,statefulsets,storageclasses,validatingwebhookconfigurations,volumeattachments"
70+
--server-idle-timeout duration The maximum amount of time to wait for the next request when keep-alives are enabled. (default 5m0s)
71+
--server-read-header-timeout duration The maximum duration for reading the header of requests. (default 5s)
7072
--server-read-timeout duration The maximum duration for reading the entire request, including the body. (default 30s)
7173
--server-write-timeout duration The maximum duration before timing out writes of the response. (default 1m0s)
7274
--shard int32 The instances shard nominal (zero indexed) within the total number of shards. (default 0)

pkg/app/server.go

Lines changed: 2 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -325,9 +325,10 @@ func RunKubeStateMetrics(ctx context.Context, opts *options.Options) error {
325325
metricsServerListenAddress := net.JoinHostPort(opts.Host, strconv.Itoa(opts.Port))
326326
metricsServer := http.Server{
327327
Handler: metricsMux,
328-
ReadHeaderTimeout: 5 * time.Second,
328+
ReadHeaderTimeout: opts.ServerReadHeaderTimeout,
329329
ReadTimeout: opts.ServerReadTimeout,
330330
WriteTimeout: opts.ServerWriteTimeout,
331+
IdleTimeout: opts.ServerIdleTimeout,
331332
}
332333
metricsFlags := web.FlagConfig{
333334
WebListenAddresses: &[]string{metricsServerListenAddress},

pkg/options/options.go

Lines changed: 5 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -58,6 +58,8 @@ type Options struct {
5858
UseAPIServerCache bool `yaml:"use_api_server_cache"`
5959
ServerReadTimeout time.Duration `yaml:"server_read_timeout"`
6060
ServerWriteTimeout time.Duration `yaml:"server_write_timeout"`
61+
ServerIdleTimeout time.Duration `yaml:"server_idle_timeout"`
62+
ServerReadHeaderTimeout time.Duration `yaml:"server_read_header_timeout"`
6163

6264
Config string
6365

@@ -149,8 +151,11 @@ func (o *Options) AddFlags(cmd *cobra.Command) {
149151
o.cmd.Flags().Var(&o.Namespaces, "namespaces", fmt.Sprintf("Comma-separated list of namespaces to be enabled. Defaults to %q", &DefaultNamespaces))
150152
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.")
151153
o.cmd.Flags().Var(&o.Resources, "resources", fmt.Sprintf("Comma-separated list of Resources to be enabled. Defaults to %q", &DefaultResources))
154+
152155
o.cmd.Flags().DurationVar(&o.ServerReadTimeout, "server-read-timeout", 30*time.Second, "The maximum duration for reading the entire request, including the body.")
153156
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.")
154159
}
155160

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

0 commit comments

Comments
 (0)