mirror of
https://github.com/k3s-io/kubernetes.git
synced 2025-08-21 09:34:40 +00:00
Add group to apiserver tracing
This commit is contained in:
parent
751058c0a4
commit
8c34208a62
@ -77,6 +77,24 @@ func (lazy *lazyAccept) String() string {
|
||||
return "unknown"
|
||||
}
|
||||
|
||||
// lazyAPIGroup implements String() string and it will
|
||||
// lazily get Group from request info.
|
||||
type lazyAPIGroup struct {
|
||||
req *http.Request
|
||||
}
|
||||
|
||||
func (lazy *lazyAPIGroup) String() string {
|
||||
if lazy.req != nil {
|
||||
ctx := lazy.req.Context()
|
||||
requestInfo, ok := apirequest.RequestInfoFrom(ctx)
|
||||
if ok {
|
||||
return requestInfo.APIGroup
|
||||
}
|
||||
}
|
||||
|
||||
return "unknown"
|
||||
}
|
||||
|
||||
// lazyAuditID implements Stringer interface to lazily retrieve
|
||||
// the audit ID associated with the request.
|
||||
type lazyAuditID struct {
|
||||
|
@ -85,6 +85,18 @@ func TestLazyVerb(t *testing.T) {
|
||||
assert.Equal(t, "WATCH", fmt.Sprintf("%v", verbWithReq))
|
||||
}
|
||||
|
||||
func TestLazyApiGroup(t *testing.T) {
|
||||
assert.Equal(t, "unknown", fmt.Sprintf("%v", &lazyAPIGroup{}))
|
||||
|
||||
scopeWithEmptyReq := &lazyAPIGroup{&http.Request{}}
|
||||
assert.Equal(t, "unknown", fmt.Sprintf("%v", scopeWithEmptyReq))
|
||||
|
||||
req := &http.Request{}
|
||||
ctx := request.WithRequestInfo(context.TODO(), &request.RequestInfo{APIGroup: "apps"})
|
||||
scopeWithReq := &lazyAPIGroup{req: req.WithContext(ctx)}
|
||||
assert.Equal(t, "apps", fmt.Sprintf("%v", scopeWithReq))
|
||||
}
|
||||
|
||||
func TestLazyResource(t *testing.T) {
|
||||
assert.Equal(t, "unknown", fmt.Sprintf("%v", &lazyResource{}))
|
||||
|
||||
|
@ -27,6 +27,7 @@ func traceFields(req *http.Request) []attribute.KeyValue {
|
||||
attribute.Stringer("accept", &lazyAccept{req: req}),
|
||||
attribute.Stringer("audit-id", &lazyAuditID{req: req}),
|
||||
attribute.Stringer("client", &lazyClientIP{req: req}),
|
||||
attribute.Stringer("api-group", &lazyAPIGroup{req: req}),
|
||||
attribute.String("protocol", req.Proto),
|
||||
attribute.Stringer("resource", &lazyResource{req: req}),
|
||||
attribute.Stringer("scope", &lazyScope{req: req}),
|
||||
|
Loading…
Reference in New Issue
Block a user