k8s.io/kubernetes@v1.29.3/test/e2e/instrumentation/monitoring/metrics_grabber.go (about) 1 /* 2 Copyright 2015 The Kubernetes Authors. 3 4 Licensed under the Apache License, Version 2.0 (the "License"); 5 you may not use this file except in compliance with the License. 6 You may obtain a copy of the License at 7 8 http://www.apache.org/licenses/LICENSE-2.0 9 10 Unless required by applicable law or agreed to in writing, software 11 distributed under the License is distributed on an "AS IS" BASIS, 12 WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. 13 See the License for the specific language governing permissions and 14 limitations under the License. 15 */ 16 17 package monitoring 18 19 import ( 20 "context" 21 "errors" 22 "fmt" 23 "time" 24 25 "github.com/onsi/ginkgo/v2" 26 "github.com/onsi/gomega" 27 clientset "k8s.io/client-go/kubernetes" 28 29 "k8s.io/kubernetes/test/e2e/framework" 30 e2emetrics "k8s.io/kubernetes/test/e2e/framework/metrics" 31 e2enode "k8s.io/kubernetes/test/e2e/framework/node" 32 e2eskipper "k8s.io/kubernetes/test/e2e/framework/skipper" 33 instrumentation "k8s.io/kubernetes/test/e2e/instrumentation/common" 34 admissionapi "k8s.io/pod-security-admission/api" 35 ) 36 37 var _ = instrumentation.SIGDescribe("MetricsGrabber", func() { 38 f := framework.NewDefaultFramework("metrics-grabber") 39 f.NamespacePodSecurityLevel = admissionapi.LevelPrivileged 40 var c, ec clientset.Interface 41 var grabber *e2emetrics.Grabber 42 ginkgo.BeforeEach(func(ctx context.Context) { 43 var err error 44 c = f.ClientSet 45 ec = f.KubemarkExternalClusterClientSet 46 gomega.Eventually(ctx, func() error { 47 grabber, err = e2emetrics.NewMetricsGrabber(ctx, c, ec, f.ClientConfig(), true, true, true, true, true, true) 48 if err != nil { 49 return fmt.Errorf("failed to create metrics grabber: %w", err) 50 } 51 return nil 52 }, 5*time.Minute, 10*time.Second).Should(gomega.BeNil()) 53 }) 54 55 ginkgo.It("should grab all metrics from API server.", func(ctx context.Context) { 56 ginkgo.By("Connecting to /metrics endpoint") 57 response, err := grabber.GrabFromAPIServer(ctx) 58 if errors.Is(err, e2emetrics.MetricsGrabbingDisabledError) { 59 e2eskipper.Skipf("%v", err) 60 } 61 framework.ExpectNoError(err) 62 gomega.Expect(response).NotTo(gomega.BeEmpty()) 63 }) 64 65 ginkgo.It("should grab all metrics from a Kubelet.", func(ctx context.Context) { 66 ginkgo.By("Proxying to Node through the API server") 67 node, err := e2enode.GetRandomReadySchedulableNode(ctx, f.ClientSet) 68 if errors.Is(err, e2emetrics.MetricsGrabbingDisabledError) { 69 e2eskipper.Skipf("%v", err) 70 } 71 framework.ExpectNoError(err) 72 response, err := grabber.GrabFromKubelet(ctx, node.Name) 73 framework.ExpectNoError(err) 74 gomega.Expect(response).NotTo(gomega.BeEmpty()) 75 }) 76 77 ginkgo.It("should grab all metrics from a Scheduler.", func(ctx context.Context) { 78 ginkgo.By("Proxying to Pod through the API server") 79 response, err := grabber.GrabFromScheduler(ctx) 80 if errors.Is(err, e2emetrics.MetricsGrabbingDisabledError) { 81 e2eskipper.Skipf("%v", err) 82 } 83 framework.ExpectNoError(err) 84 gomega.Expect(response).NotTo(gomega.BeEmpty()) 85 }) 86 87 ginkgo.It("should grab all metrics from a ControllerManager.", func(ctx context.Context) { 88 ginkgo.By("Proxying to Pod through the API server") 89 response, err := grabber.GrabFromControllerManager(ctx) 90 if errors.Is(err, e2emetrics.MetricsGrabbingDisabledError) { 91 e2eskipper.Skipf("%v", err) 92 } 93 framework.ExpectNoError(err) 94 gomega.Expect(response).NotTo(gomega.BeEmpty()) 95 }) 96 97 ginkgo.It("should grab all metrics slis from API server.", func(ctx context.Context) { 98 ginkgo.By("Connecting to /metrics/slis endpoint") 99 response, err := grabber.GrabMetricsSLIsFromAPIServer(ctx) 100 if errors.Is(err, e2emetrics.MetricsGrabbingDisabledError) { 101 e2eskipper.Skipf("%v", err) 102 } 103 framework.ExpectNoError(err) 104 gomega.Expect(response).NotTo(gomega.BeEmpty()) 105 }) 106 })