mirror of
https://github.com/k3s-io/kubernetes.git
synced 2025-07-23 11:50:44 +00:00
Merge pull request #113728 from pawbana/add-scope-to-api-server-tracking
Added scope to api server tracing
This commit is contained in:
commit
34ca18d1d0
@ -121,3 +121,21 @@ func (lazy *lazyResource) String() string {
|
|||||||
|
|
||||||
return "unknown"
|
return "unknown"
|
||||||
}
|
}
|
||||||
|
|
||||||
|
// lazyScope implements String() string and it will
|
||||||
|
// lazily get Scope from request info
|
||||||
|
type lazyScope struct {
|
||||||
|
req *http.Request
|
||||||
|
}
|
||||||
|
|
||||||
|
func (lazy *lazyScope) String() string {
|
||||||
|
if lazy.req != nil {
|
||||||
|
ctx := lazy.req.Context()
|
||||||
|
requestInfo, ok := apirequest.RequestInfoFrom(ctx)
|
||||||
|
if ok {
|
||||||
|
return metrics.CleanScope(requestInfo)
|
||||||
|
}
|
||||||
|
}
|
||||||
|
|
||||||
|
return "unknown"
|
||||||
|
}
|
||||||
|
@ -96,3 +96,15 @@ func TestLazyResource(t *testing.T) {
|
|||||||
resourceWithReq := &lazyResource{req: req.WithContext(ctx)}
|
resourceWithReq := &lazyResource{req: req.WithContext(ctx)}
|
||||||
assert.Equal(t, "resource", fmt.Sprintf("%v", resourceWithReq))
|
assert.Equal(t, "resource", fmt.Sprintf("%v", resourceWithReq))
|
||||||
}
|
}
|
||||||
|
|
||||||
|
func TestLazyScope(t *testing.T) {
|
||||||
|
assert.Equal(t, "unknown", fmt.Sprintf("%v", &lazyScope{}))
|
||||||
|
|
||||||
|
scopeWithEmptyReq := &lazyScope{&http.Request{}}
|
||||||
|
assert.Equal(t, "unknown", fmt.Sprintf("%v", scopeWithEmptyReq))
|
||||||
|
|
||||||
|
req := &http.Request{}
|
||||||
|
ctx := request.WithRequestInfo(context.TODO(), &request.RequestInfo{Namespace: "ns"})
|
||||||
|
scopeWithReq := &lazyScope{req: req.WithContext(ctx)}
|
||||||
|
assert.Equal(t, "namespace", fmt.Sprintf("%v", scopeWithReq))
|
||||||
|
}
|
||||||
|
@ -29,6 +29,7 @@ func traceFields(req *http.Request) []attribute.KeyValue {
|
|||||||
attribute.Stringer("client", &lazyClientIP{req: req}),
|
attribute.Stringer("client", &lazyClientIP{req: req}),
|
||||||
attribute.String("protocol", req.Proto),
|
attribute.String("protocol", req.Proto),
|
||||||
attribute.Stringer("resource", &lazyResource{req: req}),
|
attribute.Stringer("resource", &lazyResource{req: req}),
|
||||||
|
attribute.Stringer("scope", &lazyScope{req: req}),
|
||||||
attribute.String("url", req.URL.Path),
|
attribute.String("url", req.URL.Path),
|
||||||
attribute.Stringer("user-agent", &lazyTruncatedUserAgent{req: req}),
|
attribute.Stringer("user-agent", &lazyTruncatedUserAgent{req: req}),
|
||||||
attribute.Stringer("verb", &lazyVerb{req: req}),
|
attribute.Stringer("verb", &lazyVerb{req: req}),
|
||||||
|
Loading…
Reference in New Issue
Block a user