mirror of
https://github.com/k3s-io/kubernetes.git
synced 2025-07-20 10:20:51 +00:00
Merge pull request #113698 from dashpole/missing_apiserver_migration
Migrate another usage of utiltrace to component base tracing
This commit is contained in:
commit
e361272423
@ -22,6 +22,8 @@ import (
|
||||
"fmt"
|
||||
"time"
|
||||
|
||||
"go.opentelemetry.io/otel/attribute"
|
||||
|
||||
"k8s.io/apimachinery/pkg/runtime/schema"
|
||||
utilnet "k8s.io/apimachinery/pkg/util/net"
|
||||
"k8s.io/apimachinery/pkg/util/wait"
|
||||
@ -30,7 +32,7 @@ import (
|
||||
"k8s.io/apiserver/pkg/audit"
|
||||
"k8s.io/apiserver/pkg/util/webhook"
|
||||
"k8s.io/client-go/rest"
|
||||
utiltrace "k8s.io/utils/trace"
|
||||
"k8s.io/component-base/tracing"
|
||||
)
|
||||
|
||||
const (
|
||||
@ -126,15 +128,16 @@ func (b *backend) processEvents(ev ...*auditinternal.Event) error {
|
||||
list.Items = append(list.Items, *e)
|
||||
}
|
||||
return b.w.WithExponentialBackoff(context.Background(), func() rest.Result {
|
||||
trace := utiltrace.New("Call Audit Events webhook",
|
||||
utiltrace.Field{"name", b.name},
|
||||
utiltrace.Field{"event-count", len(list.Items)})
|
||||
ctx, span := tracing.Start(context.Background(), "Call Audit Events webhook",
|
||||
attribute.String("name", b.name),
|
||||
attribute.Int("event-count", len(list.Items)),
|
||||
)
|
||||
// Only log audit webhook traces that exceed a 25ms per object limit plus a 50ms
|
||||
// request overhead allowance. The high per object limit used here is primarily to
|
||||
// allow enough time for the serialization/deserialization of audit events, which
|
||||
// contain nested request and response objects plus additional event fields.
|
||||
defer trace.LogIfLong(time.Duration(50+25*len(list.Items)) * time.Millisecond)
|
||||
return b.w.RestClient.Post().Body(&list).Do(context.Background())
|
||||
defer span.End(time.Duration(50+25*len(list.Items)) * time.Millisecond)
|
||||
return b.w.RestClient.Post().Body(&list).Do(ctx)
|
||||
}).Error()
|
||||
}
|
||||
|
||||
|
Loading…
Reference in New Issue
Block a user