From ce915ec07220c5b0f52aca8c03ab1f7f14580bbf Mon Sep 17 00:00:00 2001 From: Zach Zhu Date: Thu, 14 Dec 2023 15:06:54 +0800 Subject: [PATCH 1/2] introduce kube api qps & burst flags Signed-off-by: Zach Zhu --- main.go | 19 +++++++++++++++++++ 1 file changed, 19 insertions(+) diff --git a/main.go b/main.go index 0a89a6e..ddf275f 100644 --- a/main.go +++ b/main.go @@ -72,6 +72,11 @@ import ( //+kubebuilder:scaffold:imports ) +const ( + defaultQPS = float64(20) + defaultBurst = 30 +) + var ( scheme = runtime.NewScheme() setupLog = ctrl.Log.WithName("setup") @@ -110,6 +115,8 @@ func main() { metricsAddr string probeAddr string enableLeaderElection bool + kubeAPIQPS float64 + kubeAPIBurst int reconcileConcurrency int objectLabelSelector string objectFieldSelector string @@ -131,6 +138,10 @@ func main() { flag.BoolVar(&enableLeaderElection, "leader-elect", false, "Enable leader election for controller manager. "+ "Enabling this will ensure there is only one active controller manager.") + flag.Float64Var(&kubeAPIQPS, "kube-api-qps", defaultQPS, "QPS to use while talking with kubernetes apiserver."+ + fmt.Sprintf("The number must be >= 0. If 0 will use defaultQPS: %f.", defaultQPS)) + flag.IntVar(&kubeAPIBurst, "kube-api-burst", defaultBurst, "Burst to use while talking with kubernetes apiserver."+ + fmt.Sprintf("The number must be >= 0. If 0 will use defaultBurst: %d.", defaultBurst)) flag.IntVar(&reconcileConcurrency, "reconcile-concurrency", 1, "The reconciliation concurrency of each controller.") flag.StringVar(&objectLabelSelector, "object-label-selector", "", "The label selector to restrict controllers' list watch for objects.") flag.StringVar(&objectFieldSelector, "object-field-selector", "", "The field selector to restrict controllers' list watch for objects.") @@ -186,6 +197,14 @@ func main() { cfg := ctrl.GetConfigOrDie() rest.AddUserAgent(cfg, util.UserAgent) + if kubeAPIQPS <= 0 { + kubeAPIQPS = defaultQPS + } + cfg.QPS = float32(kubeAPIQPS) + if kubeAPIBurst <= 0 { + kubeAPIBurst = defaultBurst + } + cfg.Burst = kubeAPIBurst var ( cacheObjectSelector = cache.ObjectSelector{} From 61c2d9fbe0c769087b90c52ce5586e81d3958585 Mon Sep 17 00:00:00 2001 From: Zach Zhu Date: Thu, 14 Dec 2023 15:07:33 +0800 Subject: [PATCH 2/2] make prom metrics lister log more verbose Signed-off-by: Zach Zhu --- pkg/metric/provider/prometheus/runnable.go | 3 ++- 1 file changed, 2 insertions(+), 1 deletion(-) diff --git a/pkg/metric/provider/prometheus/runnable.go b/pkg/metric/provider/prometheus/runnable.go index f98107a..16c3f44 100644 --- a/pkg/metric/provider/prometheus/runnable.go +++ b/pkg/metric/provider/prometheus/runnable.go @@ -49,7 +49,7 @@ func (p *MetricProvider) Start(ctx context.Context) error { Steps: math.MaxInt32, Cap: p.metricsRelistInterval, }, func(ctx context.Context) (bool, error) { - metricsListerLog.V(2).Info("start to relist metrics") + metricsListerLog.V(1).Info("start to relist metrics") if err := p.updateObjectSeries(ctx); err != nil { metricsListerLog.Error(err, "failed to update object series") return false, nil @@ -58,6 +58,7 @@ func (p *MetricProvider) Start(ctx context.Context) error { metricsListerLog.Error(err, "failed to update external series") return false, nil } + metricsListerLog.V(1).Info("metrics relisted successfully") return true, nil }); err != nil { metricsListerLog.Error(err, "backoff stopped with unexpected error")