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

Nested env variables not resolved, unable to use downward API #3022

Open
tiithansen opened this issue Jun 10, 2024 · 4 comments
Open

Nested env variables not resolved, unable to use downward API #3022

tiithansen opened this issue Jun 10, 2024 · 4 comments
Labels
area:auto-instrumentation Issues for auto-instrumentation bug Something isn't working needs triage

Comments

@tiithansen
Copy link

tiithansen commented Jun 10, 2024

Component(s)

auto-instrumentation

What happened?

Description

We want traces to be exporter to OTEL collector running on the same host/node. For that purpose we use downward API to get status.hostIP and reference it in OTEL_EXPORTER_OTLP_ENDPOINT end, but OTEL operator does not resolve it and exporter gets invalid IP.

Steps to Reproduce

apiVersion: opentelemetry.io/v1alpha1
kind: Instrumentation
metadata:
  name: instrumentation
spec:
  propagators:
  - tracecontext
  - baggage
  sampler:
    type: parentbased_traceidratio
    argument: {{ .Values.instrumentation.sampler.parentbased_traceidratio | quote }}
  env:
  - name: OTEL_BSP_MAX_EXPORT_BATCH_SIZE
    value: "512"
  - name: OTEL_EXPORTER_HOST_IP
    valueFrom:
      fieldRef:
        fieldPath: status.hostIP
  nodejs:
    env:
    - name: OTEL_EXPORTER_OTLP_ENDPOINT
      value: "http://$(OTEL_EXPORTER_HOST_IP):4317"

Expected Result

Env OTEL_EXPORTER_OTLP_ENDPOINT should contain correct address with host ip.

Actual Result

Env OTEL_EXPORTER_OTLP_ENDPOINT contains string as http://$(OTEL_EXPORTER_HOST_IP):4317 instead which is not resolved.

Kubernetes Version

1.28

Operator version

version: 0.47.0 appVersion: 0.93.0

Collector version

Custom

Environment information

No response

Log output

No response

Additional context

No response

@tiithansen tiithansen added bug Something isn't working needs triage labels Jun 10, 2024
@pavolloffay pavolloffay added the area:auto-instrumentation Issues for auto-instrumentation label Jun 10, 2024
@pavolloffay
Copy link
Member

instrumentation: Instrumentation now automatically add node and pod ips as env vars OTEL_NODE_IP and OTEL_POD_IP to instrumented containers. (#2769)

The env vars with the IPs are already injected

@pavolloffay
Copy link
Member

Could you please paste here the pod spec after the instrumentation is injected?

@pavolloffay
Copy link
Member

This is the code for setting the exporter endpoint

if otelinst.Spec.Exporter.Endpoint != "" {

I am not sure why it should not work

@fyuan1316
Copy link
Contributor

Expected Result
Env OTEL_EXPORTER_OTLP_ENDPOINT should contain correct address with host ip.

pod = i.injectCommonEnvVar(otelinst, pod, index)
pod = i.injectCommonSDKConfig(ctx, otelinst, ns, pod, index, index)
pod = i.setInitContainerSecurityContext(pod, pod.Spec.Containers[index].SecurityContext, javaInitContainerName)
}

After looking at the source code implementation, I think there might be some misunderstanding here.

By design both nodejs.env and Instrumentation spec.env end up injecting pod container[0].env. No string substitution occurs during the injection process. Therefore, the value of OTEL_EXPORTER_OTLP_ENDPOINT will always be "http://$(OTEL_EXPORTER_HOST_IP):4317".

So this could be a potential requirement rather than a bug? @pavolloffay @tiithansen

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
area:auto-instrumentation Issues for auto-instrumentation bug Something isn't working needs triage
Projects
None yet
Development

No branches or pull requests

3 participants