mirror of
https://github.com/kyverno/kyverno.git
synced 2024-12-14 11:57:48 +00:00
fix: tracing attributes length and tracer name (#6117)
Signed-off-by: Charles-Edouard Brétéché <charles.edouard@nirmata.com> Signed-off-by: Charles-Edouard Brétéché <charles.edouard@nirmata.com>
This commit is contained in:
parent
37338be747
commit
835f5551b7
10 changed files with 51 additions and 40 deletions
|
@ -75,7 +75,7 @@ func main() {
|
||||||
// setup signals
|
// setup signals
|
||||||
// setup maxprocs
|
// setup maxprocs
|
||||||
// setup metrics
|
// setup metrics
|
||||||
ctx, logger, metricsConfig, sdown := internal.Setup()
|
ctx, logger, metricsConfig, sdown := internal.Setup("kyverno-cleanup-controller")
|
||||||
defer sdown()
|
defer sdown()
|
||||||
// create instrumented clients
|
// create instrumented clients
|
||||||
kubeClient := internal.CreateKubernetesClient(logger, kubeclient.WithMetrics(metricsConfig, metrics.KubeClient), kubeclient.WithTracing())
|
kubeClient := internal.CreateKubernetesClient(logger, kubeclient.WithMetrics(metricsConfig, metrics.KubeClient), kubeclient.WithTracing())
|
||||||
|
|
|
@ -40,7 +40,7 @@ func main() {
|
||||||
// start profiling
|
// start profiling
|
||||||
// setup signals
|
// setup signals
|
||||||
// setup maxprocs
|
// setup maxprocs
|
||||||
ctx, logger, _, sdown := internal.Setup()
|
ctx, logger, _, sdown := internal.Setup("kyverno-init-controller")
|
||||||
defer sdown()
|
defer sdown()
|
||||||
// create clients
|
// create clients
|
||||||
kubeClient := internal.CreateKubernetesClient(logger)
|
kubeClient := internal.CreateKubernetesClient(logger)
|
||||||
|
|
|
@ -18,7 +18,7 @@ func shutdown(logger logr.Logger, sdowns ...context.CancelFunc) context.CancelFu
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
func Setup() (context.Context, logr.Logger, metrics.MetricsConfigManager, context.CancelFunc) {
|
func Setup(name string) (context.Context, logr.Logger, metrics.MetricsConfigManager, context.CancelFunc) {
|
||||||
logger := SetupLogger()
|
logger := SetupLogger()
|
||||||
ShowVersion(logger)
|
ShowVersion(logger)
|
||||||
sdownMaxProcs := SetupMaxProcs(logger)
|
sdownMaxProcs := SetupMaxProcs(logger)
|
||||||
|
@ -26,6 +26,6 @@ func Setup() (context.Context, logr.Logger, metrics.MetricsConfigManager, contex
|
||||||
client := CreateKubernetesClient(logger)
|
client := CreateKubernetesClient(logger)
|
||||||
ctx, sdownSignals := SetupSignals(logger)
|
ctx, sdownSignals := SetupSignals(logger)
|
||||||
metricsManager, sdownMetrics := SetupMetrics(ctx, logger, client)
|
metricsManager, sdownMetrics := SetupMetrics(ctx, logger, client)
|
||||||
sdownTracing := SetupTracing(logger, client)
|
sdownTracing := SetupTracing(logger, name, client)
|
||||||
return ctx, logger, metricsManager, shutdown(logger.WithName("shutdown"), sdownMaxProcs, sdownMetrics, sdownTracing, sdownSignals)
|
return ctx, logger, metricsManager, shutdown(logger.WithName("shutdown"), sdownMaxProcs, sdownMetrics, sdownTracing, sdownSignals)
|
||||||
}
|
}
|
||||||
|
|
|
@ -9,12 +9,13 @@ import (
|
||||||
"k8s.io/client-go/kubernetes"
|
"k8s.io/client-go/kubernetes"
|
||||||
)
|
)
|
||||||
|
|
||||||
func SetupTracing(logger logr.Logger, kubeClient kubernetes.Interface) context.CancelFunc {
|
func SetupTracing(logger logr.Logger, name string, kubeClient kubernetes.Interface) context.CancelFunc {
|
||||||
logger = logger.WithName("tracing").WithValues("enabled", tracingEnabled, "address", tracingAddress, "port", tracingPort, "creds", tracingCreds)
|
logger = logger.WithName("tracing").WithValues("enabled", tracingEnabled, "name", name, "address", tracingAddress, "port", tracingPort, "creds", tracingCreds)
|
||||||
if tracingEnabled {
|
if tracingEnabled {
|
||||||
logger.Info("setup tracing...")
|
logger.Info("setup tracing...")
|
||||||
shutdown, err := tracing.NewTraceConfig(
|
shutdown, err := tracing.NewTraceConfig(
|
||||||
logger,
|
logger,
|
||||||
|
name,
|
||||||
net.JoinHostPort(tracingAddress, tracingPort),
|
net.JoinHostPort(tracingAddress, tracingPort),
|
||||||
tracingCreds,
|
tracingCreds,
|
||||||
kubeClient,
|
kubeClient,
|
||||||
|
|
|
@ -298,7 +298,7 @@ func main() {
|
||||||
// setup signals
|
// setup signals
|
||||||
// setup maxprocs
|
// setup maxprocs
|
||||||
// setup metrics
|
// setup metrics
|
||||||
signalCtx, logger, metricsConfig, sdown := internal.Setup()
|
signalCtx, logger, metricsConfig, sdown := internal.Setup("kyverno-admission-controller")
|
||||||
defer sdown()
|
defer sdown()
|
||||||
// show version
|
// show version
|
||||||
showWarnings(logger)
|
showWarnings(logger)
|
||||||
|
|
|
@ -228,7 +228,7 @@ func main() {
|
||||||
// setup signals
|
// setup signals
|
||||||
// setup maxprocs
|
// setup maxprocs
|
||||||
// setup metrics
|
// setup metrics
|
||||||
ctx, logger, metricsConfig, sdown := internal.Setup()
|
ctx, logger, metricsConfig, sdown := internal.Setup("kyverno-reports-controller")
|
||||||
defer sdown()
|
defer sdown()
|
||||||
// create instrumented clients
|
// create instrumented clients
|
||||||
kubeClient := internal.CreateKubernetesClient(logger, kubeclient.WithMetrics(metricsConfig, metrics.KubeClient), kubeclient.WithTracing())
|
kubeClient := internal.CreateKubernetesClient(logger, kubeclient.WithMetrics(metricsConfig, metrics.KubeClient), kubeclient.WithTracing())
|
||||||
|
|
|
@ -155,7 +155,7 @@ func main() {
|
||||||
// setup signals
|
// setup signals
|
||||||
// setup maxprocs
|
// setup maxprocs
|
||||||
// setup metrics
|
// setup metrics
|
||||||
signalCtx, logger, metricsConfig, sdown := internal.Setup()
|
signalCtx, logger, metricsConfig, sdown := internal.Setup("kyverno-updaterequest-controller")
|
||||||
defer sdown()
|
defer sdown()
|
||||||
// create instrumented clients
|
// create instrumented clients
|
||||||
kubeClient := internal.CreateKubernetesClient(logger, kubeclient.WithMetrics(metricsConfig, metrics.KubeClient), kubeclient.WithTracing())
|
kubeClient := internal.CreateKubernetesClient(logger, kubeclient.WithMetrics(metricsConfig, metrics.KubeClient), kubeclient.WithTracing())
|
||||||
|
|
|
@ -5,7 +5,7 @@ import (
|
||||||
)
|
)
|
||||||
|
|
||||||
const (
|
const (
|
||||||
TracerName = "kyverno"
|
limit = 256
|
||||||
// engine attributes
|
// engine attributes
|
||||||
PolicyGroupKey = attribute.Key("kyverno.policy.group")
|
PolicyGroupKey = attribute.Key("kyverno.policy.group")
|
||||||
PolicyVersionKey = attribute.Key("kyverno.policy.version")
|
PolicyVersionKey = attribute.Key("kyverno.policy.version")
|
||||||
|
@ -58,3 +58,13 @@ const (
|
||||||
KubeClientOperationKey = attribute.Key("kube.client.operation")
|
KubeClientOperationKey = attribute.Key("kube.client.operation")
|
||||||
KubeClientNamespaceKey = attribute.Key("kube.client.namespace")
|
KubeClientNamespaceKey = attribute.Key("kube.client.namespace")
|
||||||
)
|
)
|
||||||
|
|
||||||
|
// StringValue truncates the input value if its size is above the limit.
|
||||||
|
// Some backends impose a limit on the size of a tag value.
|
||||||
|
func StringValue(value string) string {
|
||||||
|
if len(value) > limit {
|
||||||
|
value = value[:limit-3]
|
||||||
|
value += "..."
|
||||||
|
}
|
||||||
|
return value
|
||||||
|
}
|
||||||
|
|
|
@ -18,7 +18,7 @@ import (
|
||||||
)
|
)
|
||||||
|
|
||||||
// NewTraceConfig generates the initial tracing configuration with 'address' as the endpoint to connect to the Opentelemetry Collector
|
// NewTraceConfig generates the initial tracing configuration with 'address' as the endpoint to connect to the Opentelemetry Collector
|
||||||
func NewTraceConfig(log logr.Logger, address, certs string, kubeClient kubernetes.Interface) (func(), error) {
|
func NewTraceConfig(log logr.Logger, tracerName, address, certs string, kubeClient kubernetes.Interface) (func(), error) {
|
||||||
ctx := context.Background()
|
ctx := context.Background()
|
||||||
var client otlptrace.Client
|
var client otlptrace.Client
|
||||||
if certs != "" {
|
if certs != "" {
|
||||||
|
@ -47,7 +47,7 @@ func NewTraceConfig(log logr.Logger, address, certs string, kubeClient kubernete
|
||||||
resource.Default(),
|
resource.Default(),
|
||||||
resource.NewWithAttributes(
|
resource.NewWithAttributes(
|
||||||
semconv.SchemaURL,
|
semconv.SchemaURL,
|
||||||
semconv.ServiceNameKey.String(TracerName),
|
semconv.ServiceNameKey.String(tracerName),
|
||||||
semconv.ServiceVersionKey.String(version.BuildVersion),
|
semconv.ServiceVersionKey.String(version.BuildVersion),
|
||||||
),
|
),
|
||||||
)
|
)
|
||||||
|
|
|
@ -24,9 +24,9 @@ func (inner HttpHandler) WithTrace(name string) HttpHandler {
|
||||||
},
|
},
|
||||||
trace.WithAttributes(
|
trace.WithAttributes(
|
||||||
semconv.HTTPRequestContentLengthKey.Int64(request.ContentLength),
|
semconv.HTTPRequestContentLengthKey.Int64(request.ContentLength),
|
||||||
semconv.HTTPHostKey.String(request.Host),
|
semconv.HTTPHostKey.String(tracing.StringValue(request.Host)),
|
||||||
semconv.HTTPMethodKey.String(request.Method),
|
semconv.HTTPMethodKey.String(tracing.StringValue(request.Method)),
|
||||||
semconv.HTTPURLKey.String(request.RequestURI),
|
semconv.HTTPURLKey.String(tracing.StringValue(request.RequestURI)),
|
||||||
),
|
),
|
||||||
trace.WithSpanKind(trace.SpanKindServer),
|
trace.WithSpanKind(trace.SpanKindServer),
|
||||||
)
|
)
|
||||||
|
@ -43,48 +43,48 @@ func (inner AdmissionHandler) WithTrace(name string) AdmissionHandler {
|
||||||
response := inner(ctx, logger, request, startTime)
|
response := inner(ctx, logger, request, startTime)
|
||||||
if response != nil {
|
if response != nil {
|
||||||
span.SetAttributes(
|
span.SetAttributes(
|
||||||
tracing.ResponseUidKey.String(string(response.UID)),
|
tracing.ResponseUidKey.String(tracing.StringValue(string(response.UID))),
|
||||||
tracing.ResponseAllowedKey.Bool(response.Allowed),
|
tracing.ResponseAllowedKey.Bool(response.Allowed),
|
||||||
tracing.ResponseWarningsKey.StringSlice(response.Warnings),
|
tracing.ResponseWarningsKey.StringSlice(response.Warnings),
|
||||||
)
|
)
|
||||||
if response.Result != nil {
|
if response.Result != nil {
|
||||||
span.SetAttributes(
|
span.SetAttributes(
|
||||||
tracing.ResponseResultStatusKey.String(response.Result.Status),
|
tracing.ResponseResultStatusKey.String(tracing.StringValue(response.Result.Status)),
|
||||||
tracing.ResponseResultMessageKey.String(response.Result.Message),
|
tracing.ResponseResultMessageKey.String(tracing.StringValue(response.Result.Message)),
|
||||||
tracing.ResponseResultReasonKey.String(string(response.Result.Reason)),
|
tracing.ResponseResultReasonKey.String(tracing.StringValue(string(response.Result.Reason))),
|
||||||
tracing.ResponseResultCodeKey.Int(int(response.Result.Code)),
|
tracing.ResponseResultCodeKey.Int(int(response.Result.Code)),
|
||||||
)
|
)
|
||||||
}
|
}
|
||||||
if response.PatchType != nil {
|
if response.PatchType != nil {
|
||||||
span.SetAttributes(
|
span.SetAttributes(
|
||||||
tracing.ResponsePatchTypeKey.String(string(*response.PatchType)),
|
tracing.ResponsePatchTypeKey.String(tracing.StringValue(string(*response.PatchType))),
|
||||||
)
|
)
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
return response
|
return response
|
||||||
},
|
},
|
||||||
trace.WithAttributes(
|
trace.WithAttributes(
|
||||||
tracing.RequestNameKey.String(request.Name),
|
tracing.RequestNameKey.String(tracing.StringValue(request.Name)),
|
||||||
tracing.RequestNamespaceKey.String(request.Namespace),
|
tracing.RequestNamespaceKey.String(tracing.StringValue(request.Namespace)),
|
||||||
tracing.RequestUidKey.String(string(request.UID)),
|
tracing.RequestUidKey.String(tracing.StringValue(string(request.UID))),
|
||||||
tracing.RequestOperationKey.String(string(request.Operation)),
|
tracing.RequestOperationKey.String(tracing.StringValue(string(request.Operation))),
|
||||||
tracing.RequestDryRunKey.Bool(request.DryRun != nil && *request.DryRun),
|
tracing.RequestDryRunKey.Bool(request.DryRun != nil && *request.DryRun),
|
||||||
tracing.RequestKindGroupKey.String(request.Kind.Group),
|
tracing.RequestKindGroupKey.String(tracing.StringValue(request.Kind.Group)),
|
||||||
tracing.RequestKindVersionKey.String(request.Kind.Version),
|
tracing.RequestKindVersionKey.String(tracing.StringValue(request.Kind.Version)),
|
||||||
tracing.RequestKindKindKey.String(request.Kind.Kind),
|
tracing.RequestKindKindKey.String(tracing.StringValue(request.Kind.Kind)),
|
||||||
tracing.RequestSubResourceKey.String(request.SubResource),
|
tracing.RequestSubResourceKey.String(tracing.StringValue(request.SubResource)),
|
||||||
tracing.RequestRequestKindGroupKey.String(request.RequestKind.Group),
|
tracing.RequestRequestKindGroupKey.String(tracing.StringValue(request.RequestKind.Group)),
|
||||||
tracing.RequestRequestKindVersionKey.String(request.RequestKind.Version),
|
tracing.RequestRequestKindVersionKey.String(tracing.StringValue(request.RequestKind.Version)),
|
||||||
tracing.RequestRequestKindKindKey.String(request.RequestKind.Kind),
|
tracing.RequestRequestKindKindKey.String(tracing.StringValue(request.RequestKind.Kind)),
|
||||||
tracing.RequestRequestSubResourceKey.String(request.RequestSubResource),
|
tracing.RequestRequestSubResourceKey.String(tracing.StringValue(request.RequestSubResource)),
|
||||||
tracing.RequestResourceGroupKey.String(request.Resource.Group),
|
tracing.RequestResourceGroupKey.String(tracing.StringValue(request.Resource.Group)),
|
||||||
tracing.RequestResourceVersionKey.String(request.Resource.Version),
|
tracing.RequestResourceVersionKey.String(tracing.StringValue(request.Resource.Version)),
|
||||||
tracing.RequestResourceResourceKey.String(request.Resource.Resource),
|
tracing.RequestResourceResourceKey.String(tracing.StringValue(request.Resource.Resource)),
|
||||||
tracing.RequestRequestResourceGroupKey.String(request.RequestResource.Group),
|
tracing.RequestRequestResourceGroupKey.String(tracing.StringValue(request.RequestResource.Group)),
|
||||||
tracing.RequestRequestResourceVersionKey.String(request.RequestResource.Version),
|
tracing.RequestRequestResourceVersionKey.String(tracing.StringValue(request.RequestResource.Version)),
|
||||||
tracing.RequestRequestResourceResourceKey.String(request.RequestResource.Resource),
|
tracing.RequestRequestResourceResourceKey.String(tracing.StringValue(request.RequestResource.Resource)),
|
||||||
tracing.RequestUserNameKey.String(request.UserInfo.Username),
|
tracing.RequestUserNameKey.String(tracing.StringValue(request.UserInfo.Username)),
|
||||||
tracing.RequestUserUidKey.String(request.UserInfo.UID),
|
tracing.RequestUserUidKey.String(tracing.StringValue(request.UserInfo.UID)),
|
||||||
tracing.RequestUserGroupsKey.StringSlice(request.UserInfo.Groups),
|
tracing.RequestUserGroupsKey.StringSlice(request.UserInfo.Groups),
|
||||||
),
|
),
|
||||||
)
|
)
|
||||||
|
|
Loading…
Reference in a new issue