Skip to content

Commit

Permalink
Merge pull request #113698 from dashpole/missing_apiserver_migration
Browse files Browse the repository at this point in the history
Migrate another usage of utiltrace to component base tracing
  • Loading branch information
k8s-ci-robot committed Nov 8, 2022
2 parents 3a99a59 + 788b3c3 commit e361272
Showing 1 changed file with 9 additions and 6 deletions.
15 changes: 9 additions & 6 deletions staging/src/k8s.io/apiserver/plugin/pkg/audit/webhook/webhook.go
Original file line number Diff line number Diff line change
Expand Up @@ -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"
Expand All @@ -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 (
Expand Down Expand Up @@ -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()
}

Expand Down

0 comments on commit e361272

Please sign in to comment.