Skip to content

Commit 291660d

Browse files
authored
feat(inject): Populate proxy tracing values from annotations (#14592)
* feat: Add label for root parent object Signed-off-by: Scott Fleener <[email protected]> * fix: Use correct format for API resource The GroupVersionResource requires the resource to be both lowercase and plural. Signed-off-by: Scott Fleener <[email protected]> * chore(docs): Add godoc for RootOwnerRetrieverFunc Signed-off-by: Scott Fleener <[email protected]> * chore(inject): Add group label for root parent Signed-off-by: Scott Fleener <[email protected]> * feat(inject): Populate proxy tracing values from annotations This adds functionality to the proxy injector that parses tracing semantic convention annotations and labels, and populates those into the trace labels provided to the proxy. This also updates the set of extra labels (pod IP, pod ID, etc.) to be part of the control plane values, which both allows user customization and the proxy injector to modify those values directly. Signed-off-by: Scott Fleener <[email protected]> * test(inject): Update webhook tests for root owner annotations Signed-off-by: Scott Fleener <[email protected]> * chore(inject): Fix test failures Signed-off-by: Scott Fleener <[email protected]> --------- Signed-off-by: Scott Fleener <[email protected]>
1 parent 7746264 commit 291660d

28 files changed

+2511
-7
lines changed

charts/linkerd-control-plane/values.yaml

Lines changed: 7 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -286,6 +286,13 @@ proxy:
286286
# -- Enables trace collection and export in the proxy
287287
enabled: false
288288
traceServiceName: linkerd-proxy
289+
# -- Additional labels to add to the traces emitted by the proxy.
290+
# These should generally not be set globally, and instead overridden on
291+
# individual workloads via `resource.opentelemetry.io/<label>` annotations.
292+
labels:
293+
k8s.pod.ip: "$(_pod_ip)"
294+
k8s.pod.uid: "$(_pod_uid)"
295+
k8s.container.name: "$(_pod_containerName)"
289296
collector:
290297
# -- The collector endpoint to send traces to.
291298
endpoint: ""

charts/partials/templates/_proxy.tpl

Lines changed: 3 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -172,9 +172,9 @@ env:
172172
value: {{ .Values.proxy.tracing.collector.meshIdentity.serviceAccountName }}.{{ .Values.proxy.tracing.collector.meshIdentity.namespace }}.serviceaccount.identity.{{.Release.Namespace}}.{{ .Values.clusterDomain }}
173173
- name: LINKERD2_PROXY_TRACE_EXTRA_ATTRIBUTES
174174
value: |
175-
k8s.pod.ip=$(_pod_ip)
176-
k8s.pod.uid=$(_pod_uid)
177-
k8s.container.name=$(_pod_containerName)
175+
{{- range $k, $v := .Values.proxy.tracing.labels }}
176+
{{ $k }}={{ $v }}
177+
{{- end }}
178178
{{ end -}}
179179
{{/* Configure inbound and outbound parameters, e.g. for HTTP/2 servers. */ -}}
180180
{{ range $proxyK, $proxyV := (dict "inbound" .Values.proxy.inbound "outbound" .Values.proxy.outbound) -}}

cli/cmd/install_test.go

Lines changed: 17 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -126,7 +126,12 @@ func TestRender(t *testing.T) {
126126
HostnameLabels: false,
127127
},
128128
Tracing: &charts.Tracing{
129-
Enabled: false,
129+
Enabled: false,
130+
Labels: map[string]string{
131+
"k8s.pod.ip": "$(_pod_ip)",
132+
"k8s.pod.uid": "$(_pod_uid)",
133+
"k8s.container.name": "$(_pod_containerName)",
134+
},
130135
TraceServiceName: "linkerd-proxy",
131136
Collector: &charts.TracingCollector{
132137
Endpoint: "",
@@ -263,6 +268,16 @@ func TestRender(t *testing.T) {
263268
withCustomDestinationGetNetsValues.ClusterNetworks = "10.0.0.0/8,100.64.0.0/10,172.0.0.0/8"
264269
addFakeTLSSecrets(withCustomDestinationGetNetsValues)
265270

271+
tracingValues, err := testInstallOptions()
272+
if err != nil {
273+
t.Fatalf("Unexpected error: %v\n", err)
274+
}
275+
tracingValues.Proxy.Tracing.Enabled = true
276+
tracingValues.Proxy.Tracing.Collector.Endpoint = "tracing.foo:4317"
277+
tracingValues.Proxy.Tracing.Collector.MeshIdentity.ServiceAccountName = "default"
278+
tracingValues.Proxy.Tracing.Collector.MeshIdentity.Namespace = "foo"
279+
addFakeTLSSecrets(tracingValues)
280+
266281
testCases := []struct {
267282
values *charts.Values
268283
goldenFileName string
@@ -282,6 +297,7 @@ func TestRender(t *testing.T) {
282297
{defaultValues, "install_values_file.golden", values.Options{ValueFiles: []string{filepath.Join("testdata", "install_config.yaml")}}},
283298
{defaultValues, "install_default_token.golden", values.Options{Values: []string{"identity.serviceAccountTokenProjection=false"}}},
284299
{gidValues, "install_gid_output.golden", values.Options{}},
300+
{tracingValues, "install_tracing.golden", values.Options{}},
285301
}
286302

287303
for i, tc := range testCases {

cli/cmd/testdata/install_controlplane_tracing_output.golden

Lines changed: 5 additions & 0 deletions
Some generated files are not rendered by default. Learn more about customizing how changed files appear on GitHub.

cli/cmd/testdata/install_custom_domain.golden

Lines changed: 5 additions & 0 deletions
Some generated files are not rendered by default. Learn more about customizing how changed files appear on GitHub.

cli/cmd/testdata/install_custom_registry.golden

Lines changed: 5 additions & 0 deletions
Some generated files are not rendered by default. Learn more about customizing how changed files appear on GitHub.

cli/cmd/testdata/install_default.golden

Lines changed: 5 additions & 0 deletions
Some generated files are not rendered by default. Learn more about customizing how changed files appear on GitHub.

cli/cmd/testdata/install_default_override_dst_get_nets.golden

Lines changed: 5 additions & 0 deletions
Some generated files are not rendered by default. Learn more about customizing how changed files appear on GitHub.

cli/cmd/testdata/install_default_token.golden

Lines changed: 5 additions & 0 deletions
Some generated files are not rendered by default. Learn more about customizing how changed files appear on GitHub.

cli/cmd/testdata/install_gid_output.golden

Lines changed: 5 additions & 0 deletions
Some generated files are not rendered by default. Learn more about customizing how changed files appear on GitHub.

0 commit comments

Comments
 (0)