From b2c062888bd09b5c5f69d85a0d5a09f8031d1f4c Mon Sep 17 00:00:00 2001 From: David Heredero Date: Tue, 10 Dec 2024 15:12:05 +0100 Subject: [PATCH] feat(Traefik Proxy): add `tracing`parameters to helm chart values --- traefik/templates/_podtemplate.tpl | 27 +++++++++++++++++ traefik/templates/requirements.yaml | 4 +++ traefik/tests/requirements-config_test.yaml | 10 +++++++ traefik/tests/tracing-config_test.yaml | 33 +++++++++++++++++++++ traefik/values.schema.json | 27 +++++++++++++++++ traefik/values.yaml | 12 ++++++++ 6 files changed, 113 insertions(+) diff --git a/traefik/templates/_podtemplate.tpl b/traefik/templates/_podtemplate.tpl index 51e1c4e2e..34f7e0850 100644 --- a/traefik/templates/_podtemplate.tpl +++ b/traefik/templates/_podtemplate.tpl @@ -383,6 +383,33 @@ - "--tracing.addinternals" {{- end }} + {{- with .Values.tracing }} + {{- with .sampleRate }} + - "--tracing.sampleRate={{ . }}" + {{- end }} + + {{- with .serviceName }} + - "--tracing.serviceName={{ . }}" + {{- end }} + + {{- range $name, $value := .globalAttributes }} + - "--tracing.globalAttributes.{{ $name }}={{ $value }}" + {{- end }} + + {{- range $index, $value := .capturedRequestHeaders }} + - "--tracing.capturedRequestHeaders[{{ $index }}]={{ $value }}" + {{- end }} + + {{- range $index, $value := .capturedResponseHeaders }} + - "--tracing.capturedResponseHeaders[{{ $index }}]={{ $value }}" + {{- end }} + + {{- if .safeQueryParams }} + - "--tracing.safeQueryParams={{- .safeQueryParams | join "," -}}" + {{- end }} + + {{- end }} + {{- with .Values.tracing.otlp }} {{- if .enabled }} - "--tracing.otlp=true" diff --git a/traefik/templates/requirements.yaml b/traefik/templates/requirements.yaml index e2387008b..f21296f37 100644 --- a/traefik/templates/requirements.yaml +++ b/traefik/templates/requirements.yaml @@ -39,3 +39,7 @@ {{- if and (semverCompare "<3.2.0-0" $version) (.Values.providers.kubernetesGateway.nativeLBByDefault)}} {{- fail "ERROR: nativeLBByDefault has been introduced in Kubernetes Gateway provider in v3.2.0" }} {{- end }} + +{{- if and (semverCompare "= v3.1.0."}} +{{- end }} \ No newline at end of file diff --git a/traefik/tests/requirements-config_test.yaml b/traefik/tests/requirements-config_test.yaml index 2133870df..7747d6b74 100644 --- a/traefik/tests/requirements-config_test.yaml +++ b/traefik/tests/requirements-config_test.yaml @@ -119,3 +119,13 @@ tests: asserts: - failedTemplate: errorMessage: "ERROR: abortOnPluginFailure is an experimental feature only available for traefik >= v3.3.0." + - it: shouldn't have safeQueryParams, when enabled on traefik < 3.1.0 + set: + image: + tag: v3.0.0 + tracing: + safeQueryParams: + - foo + asserts: + - failedTemplate: + errorMessage: "ERROR: safeQueryParams is a feature only available for traefik >= v3.1.0." diff --git a/traefik/tests/tracing-config_test.yaml b/traefik/tests/tracing-config_test.yaml index f48851865..c83260754 100644 --- a/traefik/tests/tracing-config_test.yaml +++ b/traefik/tests/tracing-config_test.yaml @@ -9,6 +9,18 @@ tests: set: tracing: addInternals: true + sampleRate: 0.5 + serviceName: my-service-name + globalAttributes: + attr1: foo + attr2: bar + capturedRequestHeaders: + - X-CustomHeader + capturedResponseHeaders: + - X-CustomHeader + safeQueryParams: + - bar + - buz otlp: enabled: true http: @@ -38,6 +50,27 @@ tests: - contains: path: spec.template.spec.containers[0].args content: "--tracing.addinternals" + - contains: + path: spec.template.spec.containers[0].args + content: "--tracing.sampleRate=0.5" + - contains: + path: spec.template.spec.containers[0].args + content: "--tracing.serviceName=my-service-name" + - contains: + path: spec.template.spec.containers[0].args + content: "--tracing.globalAttributes.attr1=foo" + - contains: + path: spec.template.spec.containers[0].args + content: "--tracing.globalAttributes.attr2=bar" + - contains: + path: spec.template.spec.containers[0].args + content: "--tracing.capturedRequestHeaders[0]=X-CustomHeader" + - contains: + path: spec.template.spec.containers[0].args + content: "--tracing.capturedResponseHeaders[0]=X-CustomHeader" + - contains: + path: spec.template.spec.containers[0].args + content: "--tracing.safeQueryParams=bar,buz" - contains: path: spec.template.spec.containers[0].args content: "--tracing.otlp.http=true" diff --git a/traefik/values.schema.json b/traefik/values.schema.json index b3c233ca8..aa76667a7 100644 --- a/traefik/values.schema.json +++ b/traefik/values.schema.json @@ -1571,6 +1571,16 @@ "addInternals": { "type": "boolean" }, + "capturedRequestHeaders": { + "type": "array" + }, + "capturedResponseHeaders": { + "type": "array" + }, + "globalAttributes": { + "properties": {}, + "type": "object" + }, "otlp": { "properties": { "enabled": { @@ -1641,6 +1651,23 @@ } }, "type": "object" + }, + "safeQueryParams": { + "type": "array" + }, + "sampleRate": { + "maximum": 1, + "minimum": 0, + "type": [ + "number", + "null" + ] + }, + "serviceName": { + "type": [ + "string", + "null" + ] } }, "type": "object" diff --git a/traefik/values.yaml b/traefik/values.yaml index d9794b18b..78c8ea4f4 100644 --- a/traefik/values.yaml +++ b/traefik/values.yaml @@ -535,6 +535,18 @@ metrics: tracing: # @schema additionalProperties: false # -- Enables tracing for internal resources. Default: false. addInternals: false + # -- Service name used in selected backend. Default: traefik. + serviceName: # @schema type:[string, null] + # -- Applies a list of shared key:value attributes on all spans. + globalAttributes: {} + # -- Defines the list of request headers to add as attributes. It applies to client and server kind spans. + capturedRequestHeaders: [] + # -- Defines the list of response headers to add as attributes. It applies to client and server kind spans. + capturedResponseHeaders: [] + # -- By default, all query parameters are redacted. Defines the list of query parameters to not redact. + safeQueryParams: [] + # -- The proportion of requests to trace, specified between 0.0 and 1.0. Default: 1.0. + sampleRate: # @schema type:[number, null]; minimum:0; maximum:1 otlp: # -- See https://doc.traefik.io/traefik/v3.0/observability/tracing/opentelemetry/ enabled: false