Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

feat: ✨ add hub tracing capabilities #1322

Merged
merged 4 commits into from
Jan 28, 2025
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
5 changes: 5 additions & 0 deletions traefik/VALUES.md
Original file line number Diff line number Diff line change
Expand Up @@ -102,6 +102,11 @@ Kubernetes: `>=1.22.0-0`
| hub.redis.username | string | `""` | The username to use when connecting to Redis endpoints. Default: "". |
| hub.sendlogs | string | `nil` | |
| hub.token | string | `""` | Name of `Secret` with key 'token' set to a valid license token. It enables API Gateway. |
| hub.tracing.additionalTraceHeaders | object | `{"enabled":false,"traceContext":{"parentId":"","traceId":"","traceParent":"","traceState":""}}` | Tracing headers to duplicate. To configure the following, tracing.otlp.enabled needs to be set to true. |
| hub.tracing.additionalTraceHeaders.traceContext.parentId | string | `""` | Name of the header that will contain the parent-id header copy. |
| hub.tracing.additionalTraceHeaders.traceContext.traceId | string | `""` | Name of the header that will contain the trace-id copy. |
| hub.tracing.additionalTraceHeaders.traceContext.traceParent | string | `""` | Name of the header that will contain the traceparent copy. |
| hub.tracing.additionalTraceHeaders.traceContext.traceState | string | `""` | Name of the header that will contain the tracestate copy. |
| image.pullPolicy | string | `"IfNotPresent"` | Traefik image pull policy |
| image.registry | string | `"docker.io"` | Traefik image host registry |
| image.repository | string | `"traefik"` | Traefik image repository |
Expand Down
2 changes: 2 additions & 0 deletions traefik/templates/_helpers.tpl
Original file line number Diff line number Diff line change
Expand Up @@ -170,7 +170,9 @@ Key: {{ $cert.Key | b64enc }}
{{- if kindIs "map" $value }}
{{- include "traefik.yaml2CommandLineArgsRec" (dict "path" (printf "%s.%s" $path $key) "content" $value) -}}
{{- else }}
{{- with $value }}
--{{ join "." (list $path $key)}}={{ join "," $value }}
{{- end -}}
{{- end -}}
{{- end -}}
{{- end -}}
Expand Down
3 changes: 3 additions & 0 deletions traefik/templates/_podtemplate.tpl
Original file line number Diff line number Diff line change
Expand Up @@ -812,6 +812,9 @@
{{- with .sendlogs }}
- "--hub.sendlogs={{ . }}"
{{- end }}
{{- if and $.Values.tracing.otlp.enabled .tracing.additionalTraceHeaders.enabled }}
{{- include "traefik.yaml2CommandLineArgs" (dict "path" "hub.tracing.additionalTraceHeaders.traceContext" "content" $.Values.hub.tracing.additionalTraceHeaders.traceContext) | nindent 10 }}
{{- end }}
{{- end }}
{{- end }}
env:
Expand Down
17 changes: 17 additions & 0 deletions traefik/templates/requirements.yaml
Original file line number Diff line number Diff line change
Expand Up @@ -47,3 +47,20 @@
{{- if and (semverCompare "<v3.1.0-0" $version) .Values.tracing.safeQueryParams }}
{{ fail "ERROR: safeQueryParams is a feature only available for traefik >= v3.1.0."}}
{{- end }}


{{- if $.Values.hub.token -}}
{{ if not $.Values.image.tag }}
{{ fail "When using Traefik Hub image tag needs to be specified !" }}
{{- end -}}

{{ $hubVersion := (split "@" (default "v3" $.Values.image.tag))._0 | replace "latest-" "" }}

{{- if and (semverCompare "<v3.9.0" $hubVersion) .Values.hub.tracing.additionalTraceHeaders.enabled }}
{{ fail "ERROR: additionalTraceHeaders is a feature only available for traefik-hub >= v3.9.0."}}
{{- end }}

{{- if and (not $.Values.tracing.otlp.enabled) .Values.hub.tracing.additionalTraceHeaders.enabled }}
{{ fail "ERROR: additionalTraceHeaders needs tracing.otlp to be enabled."}}
{{- end }}
{{- end }}
39 changes: 39 additions & 0 deletions traefik/tests/requirements-config_test.yaml
Original file line number Diff line number Diff line change
Expand Up @@ -65,6 +65,10 @@ tests:
- notFailedTemplate: {}
- it: should fail when using traefik-hub API management with namespaced RBACs
set:
image:
registry: "ghcr.io"
repository: "traefik/traefik-hub"
tag: "v3"
hub:
token: xxx
apimanagement:
Expand Down Expand Up @@ -141,3 +145,38 @@ tests:
asserts:
- failedTemplate:
errorMessage: "ERROR: safeQueryParams is a feature only available for traefik >= v3.1.0."
- it: should fail when using Traefik Hub without image registry and repository specified.
set:
hub:
token: "xxx"
asserts:
- failedTemplate:
errorMessage: "When using Traefik Hub image tag needs to be specified !"
- it: should fail when using hub.tracing.additionalTraceHeaders on Traefik Hub < 3.9.0
set:
image:
registry: "ghcr.io"
repository: "traefik/traefik-hub"
tag: v3.8.0
hub:
token: "xxx"
tracing:
additionalTraceHeaders:
enabled: true
asserts:
- failedTemplate:
errorMessage: "ERROR: additionalTraceHeaders is a feature only available for traefik-hub >= v3.9.0."
- it: should fail when using hub.tracing.additionalTraceHeaders without tracing.otlp enabled
set:
image:
registry: "ghcr.io"
repository: "traefik/traefik-hub"
tag: v3.9.0
hub:
token: "xxx"
tracing:
additionalTraceHeaders:
enabled: true
asserts:
- failedTemplate:
errorMessage: "ERROR: additionalTraceHeaders needs tracing.otlp to be enabled."
32 changes: 32 additions & 0 deletions traefik/tests/traefik-config_test.yaml
Original file line number Diff line number Diff line change
Expand Up @@ -780,3 +780,35 @@ tests:
asserts:
- failedTemplate:
errorMessage: "ERROR: allowACMEByPass has been introduced with Traefik v3.1.3+"
- it: should be possible to configure Traefik Hub additionalTraceHeaders
set:
image:
registry: "ghcr.io"
repository: "traefik/traefik-hub"
tag: v3.9.0
tracing:
otlp:
enabled: true
hub:
token: "xxx"
tracing:
additionalTraceHeaders:
enabled: true
traceContext:
parentId: "parentId"
traceId: "traceId"
traceParent: "traceParent"
traceState: "traceState"
asserts:
- contains:
path: spec.template.spec.containers[0].args
content: "--hub.tracing.additionalTraceHeaders.traceContext.parentId=parentId"
- contains:
path: spec.template.spec.containers[0].args
content: "--hub.tracing.additionalTraceHeaders.traceContext.traceId=traceId"
- contains:
path: spec.template.spec.containers[0].args
content: "--hub.tracing.additionalTraceHeaders.traceContext.traceParent=traceParent"
- contains:
path: spec.template.spec.containers[0].args
content: "--hub.tracing.additionalTraceHeaders.traceContext.traceState=traceState"
30 changes: 30 additions & 0 deletions traefik/values.schema.json
Original file line number Diff line number Diff line change
Expand Up @@ -358,6 +358,36 @@
},
"token": {
"type": "string"
},
"tracing": {
"properties": {
"additionalTraceHeaders": {
"properties": {
"enabled": {
"type": "boolean"
},
"traceContext": {
"properties": {
"parentId": {
"type": "string"
},
"traceId": {
"type": "string"
},
"traceParent": {
"type": "string"
},
"traceState": {
"type": "string"
}
},
"type": "object"
}
},
"type": "object"
}
},
"type": "object"
}
},
"type": "object"
Expand Down
14 changes: 14 additions & 0 deletions traefik/values.yaml
Original file line number Diff line number Diff line change
Expand Up @@ -979,3 +979,17 @@ hub:
insecureSkipVerify: false
# Enable export of errors logs to the platform. Default: true.
sendlogs: # @schema type:[boolean, null]
tracing:
# -- Tracing headers to duplicate.
# To configure the following, tracing.otlp.enabled needs to be set to true.
additionalTraceHeaders:
enabled: false
traceContext:
# -- Name of the header that will contain the parent-id header copy.
parentId: ""
# -- Name of the header that will contain the trace-id copy.
traceId: ""
# -- Name of the header that will contain the traceparent copy.
traceParent: ""
# -- Name of the header that will contain the tracestate copy.
traceState: ""
Loading