From eb55e2b980dafdb81608bdc0f851f8639e12a3af Mon Sep 17 00:00:00 2001 From: Richa Banker Date: Mon, 9 Jan 2023 17:33:44 -0800 Subject: [PATCH] Add e2e test for checking /metrics/slis endpoint for API server --- .../framework/metrics/api_server_metrics.go | 8 ++++++++ test/e2e/framework/metrics/metrics_grabber.go | 18 ++++++++++++++++++ .../monitoring/metrics_grabber.go | 10 ++++++++++ 3 files changed, 36 insertions(+) diff --git a/test/e2e/framework/metrics/api_server_metrics.go b/test/e2e/framework/metrics/api_server_metrics.go index c22c5c45a00..5d9e1bb5743 100644 --- a/test/e2e/framework/metrics/api_server_metrics.go +++ b/test/e2e/framework/metrics/api_server_metrics.go @@ -50,3 +50,11 @@ func (g *Grabber) getMetricsFromAPIServer(ctx context.Context) (string, error) { } return string(rawOutput), nil } + +func (g *Grabber) getMetricsSLIsFromAPIServer(ctx context.Context) (string, error) { + rawOutput, err := g.client.CoreV1().RESTClient().Get().RequestURI("/metrics/slis").Do(ctx).Raw() + if err != nil { + return "", err + } + return string(rawOutput), nil +} diff --git a/test/e2e/framework/metrics/metrics_grabber.go b/test/e2e/framework/metrics/metrics_grabber.go index f7c34d8ec77..87e1bbaec8d 100644 --- a/test/e2e/framework/metrics/metrics_grabber.go +++ b/test/e2e/framework/metrics/metrics_grabber.go @@ -54,6 +54,7 @@ var MetricsGrabbingDisabledError = errors.New("metrics grabbing disabled") // Collection is metrics collection of components type Collection struct { APIServerMetrics APIServerMetrics + APIServerMetricsSLIs APIServerMetrics ControllerManagerMetrics ControllerManagerMetrics SnapshotControllerMetrics SnapshotControllerMetrics KubeletMetrics map[string]KubeletMetrics @@ -323,6 +324,15 @@ func (g *Grabber) GrabFromAPIServer(ctx context.Context) (APIServerMetrics, erro return parseAPIServerMetrics(output) } +// GrabMetricsSLIsFromAPIServer returns metrics from API server +func (g *Grabber) GrabMetricsSLIsFromAPIServer(ctx context.Context) (APIServerMetrics, error) { + output, err := g.getMetricsSLIsFromAPIServer(ctx) + if err != nil { + return APIServerMetrics{}, err + } + return parseAPIServerMetrics(output) +} + // Grab returns metrics from corresponding component func (g *Grabber) Grab(ctx context.Context) (Collection, error) { result := Collection{} @@ -383,6 +393,14 @@ func (g *Grabber) Grab(ctx context.Context) (Collection, error) { } } } + if g.grabFromAPIServer { + metrics, err := g.GrabMetricsSLIsFromAPIServer(ctx) + if err != nil { + errs = append(errs, err) + } else { + result.APIServerMetricsSLIs = metrics + } + } if len(errs) > 0 { return result, fmt.Errorf("Errors while grabbing metrics: %v", errs) } diff --git a/test/e2e/instrumentation/monitoring/metrics_grabber.go b/test/e2e/instrumentation/monitoring/metrics_grabber.go index 4d2df772a05..e7e7c4f7a72 100644 --- a/test/e2e/instrumentation/monitoring/metrics_grabber.go +++ b/test/e2e/instrumentation/monitoring/metrics_grabber.go @@ -93,4 +93,14 @@ var _ = instrumentation.SIGDescribe("MetricsGrabber", func() { framework.ExpectNoError(err) gomega.Expect(response).NotTo(gomega.BeEmpty()) }) + + ginkgo.It("should grab all metrics slis from API server.", func(ctx context.Context) { + ginkgo.By("Connecting to /metrics/slis endpoint") + response, err := grabber.GrabMetricsSLIsFromAPIServer(ctx) + if errors.Is(err, e2emetrics.MetricsGrabbingDisabledError) { + e2eskipper.Skipf("%v", err) + } + framework.ExpectNoError(err) + gomega.Expect(response).NotTo(gomega.BeEmpty()) + }) })