mirror of
https://github.com/k3s-io/kubernetes.git
synced 2025-07-21 19:01:49 +00:00
Add e2e test for checking /metrics/slis endpoint for API server
This commit is contained in:
parent
301fa8f633
commit
eb55e2b980
@ -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
|
||||
}
|
||||
|
@ -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)
|
||||
}
|
||||
|
@ -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())
|
||||
})
|
||||
})
|
||||
|
Loading…
Reference in New Issue
Block a user