mirror of
https://github.com/k3s-io/kubernetes.git
synced 2025-07-20 10:20:51 +00:00
Carefully compute request path for metrics
Preserve the previx before "api/v1".
This commit is contained in:
parent
724497cda4
commit
1d199db03e
@ -23,6 +23,7 @@ import (
|
||||
"fmt"
|
||||
"io"
|
||||
"net/http"
|
||||
"strings"
|
||||
"sync"
|
||||
"sync/atomic"
|
||||
"time"
|
||||
@ -274,9 +275,17 @@ func createPriorityLevel(ctx context.Context, f *framework.Framework, priorityLe
|
||||
}
|
||||
|
||||
func getPriorityLevelNominalConcurrency(ctx context.Context, c clientset.Interface, priorityLevelName string) (int32, error) {
|
||||
resp, err := c.CoreV1().RESTClient().Get().RequestURI("/metrics").DoRaw(ctx)
|
||||
req := c.CoreV1().RESTClient().Get()
|
||||
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)
|
||||
if err != nil {
|
||||
return 0, err
|
||||
return 0, fmt.Errorf("error requesting metrics; request=%#+v, request.URL()=%s: %w", req, req.URL(), err)
|
||||
}
|
||||
sampleDecoder := expfmt.SampleDecoder{
|
||||
Dec: expfmt.NewDecoder(bytes.NewBuffer(resp), expfmt.FmtText),
|
||||
|
Loading…
Reference in New Issue
Block a user