1
0
Fork 0
mirror of https://github.com/kyverno/kyverno.git synced 2025-03-28 10:28:36 +00:00

fix: context propagation in tracing (#8104)

Signed-off-by: Charles-Edouard Brétéché <charles.edouard@nirmata.com>
This commit is contained in:
Charles-Edouard Brétéché 2023-08-24 08:45:58 +02:00 committed by GitHub
parent da3531a0c0
commit 3c09d902fd
No known key found for this signature in database
GPG key ID: 4AEE18F83AFDEB23
4 changed files with 15 additions and 13 deletions

View file

@ -77,7 +77,7 @@ func NewServer(
WithSubResourceFilter().
WithMetrics(policyLogger, metricsConfig.Config(), metrics.WebhookValidating).
WithAdmission(policyLogger.WithName("validate")).
ToHandlerFunc(),
ToHandlerFunc("VALIDATE"),
)
mux.HandlerFunc(
"POST",
@ -87,7 +87,7 @@ func NewServer(
WithSubResourceFilter().
WithMetrics(labelLogger, metricsConfig.Config(), metrics.WebhookValidating).
WithAdmission(labelLogger.WithName("validate")).
ToHandlerFunc(),
ToHandlerFunc("VALIDATE"),
)
mux.HandlerFunc(
"GET",
@ -95,7 +95,7 @@ func NewServer(
handlers.HttpHandler(cleanupHandlerFunc).
WithMetrics(policyLogger).
WithTrace("CLEANUP").
ToHandlerFunc(),
ToHandlerFunc("CLEANUP"),
)
mux.HandlerFunc("GET", config.LivenessServicePath, handlers.Probe(probes.IsLive))
mux.HandlerFunc("GET", config.ReadinessServicePath, handlers.Probe(probes.IsReady))

View file

@ -63,8 +63,8 @@ func NewTraceConfig(log logr.Logger, tracerName, address, certs string, kubeClie
sdktrace.WithResource(res),
)
// set global propagator to tracecontext (the default is no-op).
otel.SetTextMapPropagator(propagation.TraceContext{})
otel.SetTracerProvider(tp)
otel.SetTextMapPropagator(propagation.NewCompositeTextMapPropagator(propagation.TraceContext{}, propagation.Baggage{}))
return func() {
ctx, cancel := context.WithTimeout(context.Background(), 20*time.Second)
defer cancel()

View file

@ -6,6 +6,7 @@ import (
"time"
"github.com/go-logr/logr"
"go.opentelemetry.io/contrib/instrumentation/net/http/otelhttp"
admissionv1 "k8s.io/api/admission/v1"
"k8s.io/apimachinery/pkg/runtime/schema"
)
@ -35,6 +36,7 @@ func FromAdmissionFunc(name string, h AdmissionHandler) AdmissionHandler {
return h.WithTrace(name)
}
func (h HttpHandler) ToHandlerFunc() http.HandlerFunc {
return http.HandlerFunc(h)
func (h HttpHandler) ToHandlerFunc(operation string) http.HandlerFunc {
handler := otelhttp.NewHandler(http.HandlerFunc(h), operation)
return handler.ServeHTTP
}

View file

@ -128,7 +128,7 @@ func NewServer(
WithDump(debugModeOpts.DumpPayload).
WithMetrics(policyLogger, metricsConfig.Config(), metrics.WebhookMutating).
WithAdmission(policyLogger.WithName("mutate")).
ToHandlerFunc(),
ToHandlerFunc("MUTATE"),
)
mux.HandlerFunc(
"POST",
@ -138,7 +138,7 @@ func NewServer(
WithSubResourceFilter().
WithMetrics(policyLogger, metricsConfig.Config(), metrics.WebhookValidating).
WithAdmission(policyLogger.WithName("validate")).
ToHandlerFunc(),
ToHandlerFunc("VALIDATE"),
)
mux.HandlerFunc(
"POST",
@ -148,14 +148,14 @@ func NewServer(
WithSubResourceFilter().
WithMetrics(exceptionLogger, metricsConfig.Config(), metrics.WebhookValidating).
WithAdmission(exceptionLogger.WithName("validate")).
ToHandlerFunc(),
ToHandlerFunc("VALIDATE"),
)
mux.HandlerFunc(
"POST",
config.VerifyMutatingWebhookServicePath,
handlers.FromAdmissionFunc("VERIFY", handlers.Verify).
WithAdmission(verifyLogger.WithName("mutate")).
ToHandlerFunc(),
ToHandlerFunc("VERIFY"),
)
mux.HandlerFunc("GET", config.LivenessServicePath, handlers.Probe(runtime.IsLive))
mux.HandlerFunc("GET", config.ReadinessServicePath, handlers.Probe(runtime.IsReady))
@ -280,7 +280,7 @@ func registerWebhookHandlers(
return handlerFunc(ctx, logger, request, "fail", startTime)
},
)
mux.HandlerFunc("POST", basePath, builder(all).ToHandlerFunc())
mux.HandlerFunc("POST", basePath+"/ignore", builder(ignore).ToHandlerFunc())
mux.HandlerFunc("POST", basePath+"/fail", builder(fail).ToHandlerFunc())
mux.HandlerFunc("POST", basePath, builder(all).ToHandlerFunc(name))
mux.HandlerFunc("POST", basePath+"/ignore", builder(ignore).ToHandlerFunc(name))
mux.HandlerFunc("POST", basePath+"/fail", builder(fail).ToHandlerFunc(name))
}