Tracing

Tracing Kyverno engine admission requests processing

Introduction

Tracing is a method of tracking application requests as they are processed by the application software. When a software is instrumented it produces traces, traces are made of spans hierarchically organised to form a trace. Spans are defined by a start and end time, eventually a parent span, and a number of properties that define the span characteristics (client spans, server spans, etc…).

Tracing is not limited to a single application, as the tracing context can be transmitted on the wire it is possible to collect spans from multiple applications and reconcile them in a single trace.

In the context of Kyverno, requests are usually sent by the Kubernetes API server to the Kyverno service during the admission phase. Kyverno receives and processes admission requests according to the configured policies. Every step in the admission pipeline and during the engine policy processing will produce spans. All clients (Kubernetes client, registry client and cosign client) have also been instrumented to produce client spans and transmit the tracing context on the wire.

Trace example

Below is a trace for a validating admission request.

Installation and Setup

Tracing requires a backend where Kyverno will send traces. Kyverno uses OpenTelemetry for instrumentation and supports various backends like Jaeger, Grafana Tempo or Datadog to name a few.

When you install Kyverno via Helm, you need to set a couple of values to enable tracing.

 1$ values.yaml
 2
 3...
 4extraArgs:
 5  # enable tracing
 6  - --enableTracing
 7  # configure tracing endpoint
 8  - --tracingAddress=<backend url>
 9  # configure tracing port
10  - --tracingPort=4317
11...

Tracing is disabled by default and depending on the backend the associated cost can be significant.

Currently, Kyverno tracing is configured to sample all incoming requests, there’s no way to configure the tracing sampler directly in Kyverno. OpenTelemetry Collector can be used to take better sampling decision at the cost of a more advanced setup.

Additional docs and tutorials


Tracing Tutorial with Grafana Tempo

A short proof-of-concept tutorial of tracing using Grafana Tempo.

Tracing Tutorial with Jaeger

A short proof-of-concept tutorial of tracing using Jaeger.

Last modified January 17, 2023 at 8:34 PM PST: feat: tracing docs (#744) (aaefe2d)