mirror of https://github.com/knative/pkg.git
when recording the admission/conversion duration use the attributes from the labeler
This commit is contained in:
parent
48df033c70
commit
d9f7cd3c29
|
|
@ -33,7 +33,6 @@ import (
|
|||
"knative.dev/pkg/logging/logkey"
|
||||
|
||||
"go.opentelemetry.io/contrib/instrumentation/net/http/otelhttp"
|
||||
"go.opentelemetry.io/otel/attribute"
|
||||
"go.opentelemetry.io/otel/metric"
|
||||
)
|
||||
|
||||
|
|
@ -106,16 +105,14 @@ func admissionHandler(wh *Webhook, c AdmissionController, synced <-chan struct{}
|
|||
|
||||
labeler, _ := otelhttp.LabelerFromContext(r.Context())
|
||||
|
||||
attrs := []attribute.KeyValue{
|
||||
labeler.Add(
|
||||
AdmissionKind.With(review.Request.Kind.Kind),
|
||||
AdmissionGroup.With(review.Request.Kind.Group),
|
||||
AdmissionVersion.With(review.Request.Kind.Version),
|
||||
AdmissionOperation.With(string(review.Request.Operation)),
|
||||
AdmissionSubresource.With(review.Request.SubResource),
|
||||
webhookTypeAttr,
|
||||
}
|
||||
|
||||
labeler.Add(attrs...)
|
||||
)
|
||||
|
||||
logger = logger.With(
|
||||
logkey.Kind, review.Request.Kind.String(),
|
||||
|
|
@ -146,12 +143,11 @@ func admissionHandler(wh *Webhook, c AdmissionController, synced <-chan struct{}
|
|||
}
|
||||
|
||||
allowedAttr := AdmissionAllowed.With(reviewResponse.Allowed)
|
||||
attrs = append(attrs, allowedAttr)
|
||||
labeler.Add(allowedAttr)
|
||||
|
||||
wh.metrics.recordHandlerDuration(ctx,
|
||||
time.Since(ttStart),
|
||||
metric.WithAttributes(attrs...),
|
||||
metric.WithAttributes(labeler.Get()...),
|
||||
)
|
||||
|
||||
if !reviewResponse.Allowed || reviewResponse.PatchType != nil || response.Response == nil {
|
||||
|
|
|
|||
|
|
@ -54,10 +54,11 @@ func conversionHandler(wh *Webhook, c ConversionController) http.HandlerFunc {
|
|||
return
|
||||
}
|
||||
|
||||
versionAttr := ConversionDesiredAPIVersion.With(review.Request.DesiredAPIVersion)
|
||||
|
||||
labeler, _ := otelhttp.LabelerFromContext(r.Context())
|
||||
labeler.Add(webhookTypeAttr, versionAttr)
|
||||
labeler.Add(
|
||||
webhookTypeAttr,
|
||||
ConversionDesiredAPIVersion.With(review.Request.DesiredAPIVersion),
|
||||
)
|
||||
|
||||
logger = logger.With(
|
||||
zap.String("uid", string(review.Request.UID)),
|
||||
|
|
@ -76,18 +77,14 @@ func conversionHandler(wh *Webhook, c ConversionController) http.HandlerFunc {
|
|||
Response: c.Convert(ctx, review.Request),
|
||||
}
|
||||
|
||||
wh.metrics.recordHandlerDuration(ctx, time.Since(ttStart),
|
||||
metric.WithAttributes(
|
||||
versionAttr,
|
||||
webhookTypeAttr,
|
||||
ConversionResultStatus.With(strings.ToLower(response.Response.Result.Status)),
|
||||
),
|
||||
)
|
||||
|
||||
labeler.Add(
|
||||
ConversionResultStatus.With(strings.ToLower(response.Response.Result.Status)),
|
||||
)
|
||||
|
||||
wh.metrics.recordHandlerDuration(ctx, time.Since(ttStart),
|
||||
metric.WithAttributes(labeler.Get()...),
|
||||
)
|
||||
|
||||
if err := json.NewEncoder(w).Encode(response); err != nil {
|
||||
http.Error(w, fmt.Sprint("could not encode response:", err), http.StatusInternalServerError)
|
||||
return
|
||||
|
|
|
|||
Loading…
Reference in New Issue