From 17dcc9441821c544672bd2d41dd104f7c69442bc Mon Sep 17 00:00:00 2001 From: googs1025 Date: Sun, 27 Oct 2024 21:58:45 +0800 Subject: [PATCH] feature: add QPS Burst flags --- cmd/options/options.go | 6 ++++++ pkg/exporters/k8sexporter/problemclient/problem_client.go | 3 ++- 2 files changed, 8 insertions(+), 1 deletion(-) diff --git a/cmd/options/options.go b/cmd/options/options.go index f0de27c79..a7d581135 100644 --- a/cmd/options/options.go +++ b/cmd/options/options.go @@ -43,6 +43,10 @@ type NodeProblemDetectorOptions struct { ServerPort int // ServerAddress is the address to bind the node problem detector server. ServerAddress string + // QPS is the maximum QPS to the master from client. + QPS float64 + // Burst is the maximum burst for throttle. + Burst int // exporter options @@ -125,6 +129,8 @@ func (npdo *NodeProblemDetectorOptions) AddFlags(fs *pflag.FlagSet) { 20257, "The port to bind the Prometheus scrape endpoint. Prometheus exporter is enabled by default at port 20257. Use 0 to disable.") fs.StringVar(&npdo.PrometheusServerAddress, "prometheus-address", "127.0.0.1", "The address to bind the Prometheus scrape endpoint.") + flag.Float64Var(&npdo.QPS, "kube-api-qps", 500, "Maximum QPS to use while talking with Kubernetes API") + flag.IntVar(&npdo.Burst, "kube-api-burst", 500, "Maximum burst for throttle while talking with Kubernetes API") for _, exporterName := range exporters.GetExporterNames() { exporterHandler := exporters.GetExporterHandlerOrDie(exporterName) exporterHandler.Options.SetFlags(fs) diff --git a/pkg/exporters/k8sexporter/problemclient/problem_client.go b/pkg/exporters/k8sexporter/problemclient/problem_client.go index 9127617d7..6d92df652 100644 --- a/pkg/exporters/k8sexporter/problemclient/problem_client.go +++ b/pkg/exporters/k8sexporter/problemclient/problem_client.go @@ -74,7 +74,8 @@ func NewClientOrDie(npdo *options.NodeProblemDetectorOptions) Client { } cfg.UserAgent = fmt.Sprintf("%s/%s", filepath.Base(os.Args[0]), version.Version()) - // TODO(random-liu): Set QPS Limit + cfg.QPS = float32(npdo.QPS) + cfg.Burst = npdo.Burst c.client = clientset.NewForConfigOrDie(cfg).CoreV1() c.nodeName = npdo.NodeName c.eventNamespace = npdo.EventNamespace