mirror of
https://github.com/k3s-io/kubernetes.git
synced 2025-08-10 04:27:54 +00:00
Add name to apiserver tracing
This commit is contained in:
parent
646053d73d
commit
bcb59a03eb
@ -113,6 +113,24 @@ func (lazy *lazyAPIVersion) String() string {
|
|||||||
return "unknown"
|
return "unknown"
|
||||||
}
|
}
|
||||||
|
|
||||||
|
// lazyName implements String() string and it will
|
||||||
|
// lazily get Group from request info.
|
||||||
|
type lazyName struct {
|
||||||
|
req *http.Request
|
||||||
|
}
|
||||||
|
|
||||||
|
func (lazy *lazyName) String() string {
|
||||||
|
if lazy.req != nil {
|
||||||
|
ctx := lazy.req.Context()
|
||||||
|
requestInfo, ok := apirequest.RequestInfoFrom(ctx)
|
||||||
|
if ok {
|
||||||
|
return requestInfo.Name
|
||||||
|
}
|
||||||
|
}
|
||||||
|
|
||||||
|
return "unknown"
|
||||||
|
}
|
||||||
|
|
||||||
// lazyAuditID implements Stringer interface to lazily retrieve
|
// lazyAuditID implements Stringer interface to lazily retrieve
|
||||||
// the audit ID associated with the request.
|
// the audit ID associated with the request.
|
||||||
type lazyAuditID struct {
|
type lazyAuditID struct {
|
||||||
|
@ -109,6 +109,18 @@ func TestLazyApiVersion(t *testing.T) {
|
|||||||
assert.Equal(t, "v1", fmt.Sprintf("%v", scopeWithReq))
|
assert.Equal(t, "v1", fmt.Sprintf("%v", scopeWithReq))
|
||||||
}
|
}
|
||||||
|
|
||||||
|
func TestLazyName(t *testing.T) {
|
||||||
|
assert.Equal(t, "unknown", fmt.Sprintf("%v", &lazyName{}))
|
||||||
|
|
||||||
|
scopeWithEmptyReq := &lazyName{&http.Request{}}
|
||||||
|
assert.Equal(t, "unknown", fmt.Sprintf("%v", scopeWithEmptyReq))
|
||||||
|
|
||||||
|
req := &http.Request{}
|
||||||
|
ctx := request.WithRequestInfo(context.TODO(), &request.RequestInfo{Name: "jaeger-76d45d6876-vqp8t"})
|
||||||
|
scopeWithReq := &lazyName{req: req.WithContext(ctx)}
|
||||||
|
assert.Equal(t, "jaeger-76d45d6876-vqp8t", fmt.Sprintf("%v", scopeWithReq))
|
||||||
|
}
|
||||||
|
|
||||||
func TestLazyResource(t *testing.T) {
|
func TestLazyResource(t *testing.T) {
|
||||||
assert.Equal(t, "unknown", fmt.Sprintf("%v", &lazyResource{}))
|
assert.Equal(t, "unknown", fmt.Sprintf("%v", &lazyResource{}))
|
||||||
|
|
||||||
|
@ -29,6 +29,7 @@ func traceFields(req *http.Request) []attribute.KeyValue {
|
|||||||
attribute.Stringer("client", &lazyClientIP{req: req}),
|
attribute.Stringer("client", &lazyClientIP{req: req}),
|
||||||
attribute.Stringer("api-group", &lazyAPIGroup{req: req}),
|
attribute.Stringer("api-group", &lazyAPIGroup{req: req}),
|
||||||
attribute.Stringer("api-version", &lazyAPIVersion{req: req}),
|
attribute.Stringer("api-version", &lazyAPIVersion{req: req}),
|
||||||
|
attribute.Stringer("name", &lazyName{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.Stringer("scope", &lazyScope{req: req}),
|
||||||
|
Loading…
Reference in New Issue
Block a user