mirror of
https://github.com/rancher/steve.git
synced 2025-08-17 13:56:28 +00:00
Add support for configuring the QPS and Burst from the environment.
This commit is contained in:
parent
6de55df701
commit
148a22d3eb
@ -2,7 +2,10 @@ package client
|
|||||||
|
|
||||||
import (
|
import (
|
||||||
"fmt"
|
"fmt"
|
||||||
|
"log"
|
||||||
"net/http"
|
"net/http"
|
||||||
|
"os"
|
||||||
|
"strconv"
|
||||||
"time"
|
"time"
|
||||||
|
|
||||||
"github.com/rancher/apiserver/pkg/types"
|
"github.com/rancher/apiserver/pkg/types"
|
||||||
@ -49,8 +52,7 @@ func (a *addQuery) WrappedRoundTripper() http.RoundTripper {
|
|||||||
|
|
||||||
func NewFactory(cfg *rest.Config, impersonate bool) (*Factory, error) {
|
func NewFactory(cfg *rest.Config, impersonate bool) (*Factory, error) {
|
||||||
clientCfg := rest.CopyConfig(cfg)
|
clientCfg := rest.CopyConfig(cfg)
|
||||||
clientCfg.QPS = 10000
|
updateConfigFromEnvironment(clientCfg)
|
||||||
clientCfg.Burst = 100
|
|
||||||
|
|
||||||
watchClientCfg := rest.CopyConfig(clientCfg)
|
watchClientCfg := rest.CopyConfig(clientCfg)
|
||||||
watchClientCfg.Timeout = 30 * time.Minute
|
watchClientCfg.Timeout = 30 * time.Minute
|
||||||
@ -199,3 +201,27 @@ func newClient(ctx *types.APIRequest, cfg *rest.Config, s *types.APISchema, name
|
|||||||
gvr := attributes.GVR(s)
|
gvr := attributes.GVR(s)
|
||||||
return client.Resource(gvr).Namespace(namespace), nil
|
return client.Resource(gvr).Namespace(namespace), nil
|
||||||
}
|
}
|
||||||
|
|
||||||
|
func updateConfigFromEnvironment(cfg *rest.Config) {
|
||||||
|
cfg.QPS = 10000
|
||||||
|
if v := os.Getenv("RANCHER_CLIENT_QPS"); v != "" {
|
||||||
|
qps, err := strconv.ParseFloat(v, 32)
|
||||||
|
if err != nil {
|
||||||
|
log.Printf("steve: configuring client failed to parse RANCHER_CLIENT_QPS: %s", err)
|
||||||
|
} else {
|
||||||
|
log.Printf("steve: configuring client.QPS = %v", qps)
|
||||||
|
cfg.QPS = float32(qps)
|
||||||
|
}
|
||||||
|
}
|
||||||
|
|
||||||
|
cfg.Burst = 100
|
||||||
|
if v := os.Getenv("RANCHER_CLIENT_BURST"); v != "" {
|
||||||
|
burst, err := strconv.Atoi(v)
|
||||||
|
if err != nil {
|
||||||
|
log.Printf("steve: configuring client failed to parse RANCHER_CLIENT_QPS: %s", err)
|
||||||
|
} else {
|
||||||
|
log.Printf("steve: configuring client.Burst = %v", burst)
|
||||||
|
cfg.Burst = burst
|
||||||
|
}
|
||||||
|
}
|
||||||
|
}
|
||||||
|
Loading…
Reference in New Issue
Block a user