From 6f57effda40a707de783e521f79f42193aba2047 Mon Sep 17 00:00:00 2001 From: =?UTF-8?q?Manuel=20R=C3=BCger?= Date: Wed, 6 Nov 2024 09:10:20 +0100 Subject: [PATCH] fix: Remove log output from benchmark Without this change Info logs appear in the benchmark ok k8s.io/kube-state-metrics/v2/pkg/allowdenylist 0.005s I1106 08:50:22.006480 144965 builder.go:280] "Active resources" activeStoreNames="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" goos: linux goarch: amd64 pkg: k8s.io/kube-state-metrics/v2/pkg/app cpu: Intel(R) Core(TM) i7-1065G7 CPU @ 1.30GHz BenchmarkKubeStateMetrics/GenerateMetrics-8 1 1001291639 ns/op 67578008 B/op 582810 allocs/op --- pkg/app/server_test.go | 6 ++++++ 1 file changed, 6 insertions(+) diff --git a/pkg/app/server_test.go b/pkg/app/server_test.go index 9f6c0be97..6738785d1 100644 --- a/pkg/app/server_test.go +++ b/pkg/app/server_test.go @@ -19,6 +19,7 @@ package app import ( "bytes" "context" + "flag" "fmt" "io" "net/http/httptest" @@ -45,6 +46,7 @@ import ( basemetrics "k8s.io/component-base/metrics" + "k8s.io/klog/v2" "k8s.io/kube-state-metrics/v2/internal/store" "k8s.io/kube-state-metrics/v2/pkg/allowdenylist" "k8s.io/kube-state-metrics/v2/pkg/customresource" @@ -70,6 +72,10 @@ func BenchmarkKubeStateMetrics(b *testing.B) { b.Errorf("error injecting resources: %v", err) } ctx, cancel := context.WithCancel(context.Background()) + + klogFlags := flag.NewFlagSet("klog", flag.ExitOnError) + klog.InitFlags(klogFlags) + klogFlags.Set("logtostderr", "false") defer cancel() reg := prometheus.NewRegistry()