Simplify construction of /metrics request

This commit is contained in:
Mike Spreitzer 2023-02-06 16:20:34 -05:00
parent daf0d8d14f
commit e9973979d0

View File

@ -23,7 +23,6 @@ import (
"fmt" "fmt"
"io" "io"
"net/http" "net/http"
"strings"
"sync" "sync"
"sync/atomic" "sync/atomic"
"time" "time"
@ -275,14 +274,7 @@ func createPriorityLevel(ctx context.Context, f *framework.Framework, priorityLe
} }
func getPriorityLevelNominalConcurrency(ctx context.Context, c clientset.Interface, priorityLevelName string) (int32, error) { func getPriorityLevelNominalConcurrency(ctx context.Context, c clientset.Interface, priorityLevelName string) (int32, error) {
req := c.CoreV1().RESTClient().Get() req := c.CoreV1().RESTClient().Get().AbsPath("/metrics")
reqURL := req.URL()
// That URL will end with "/api/v1", because we asked for CoreV1 above.
// Replace that part with "/metrics" and leave everything before that unchanged
// because that is what routes to the server.
reqPathOrig := reqURL.EscapedPath()
reqPathMetrics := strings.TrimSuffix(reqPathOrig, "api/v1") + "metrics"
req = req.RequestURI(reqPathMetrics)
resp, err := req.DoRaw(ctx) resp, err := req.DoRaw(ctx)
if err != nil { if err != nil {
return 0, fmt.Errorf("error requesting metrics; request=%#+v, request.URL()=%s: %w", req, req.URL(), err) return 0, fmt.Errorf("error requesting metrics; request=%#+v, request.URL()=%s: %w", req, req.URL(), err)