open-telemetry / opentelemetry-helm-charts

OpenTelemetry Helm Charts
https://opentelemetry.io
Apache License 2.0
399 stars 488 forks source link

Unable to expose health_check port from the container #1418

Open perry-mitchell opened 5 days ago

perry-mitchell commented 5 days ago

I can't seem to get the healthcheck port exposed for some reason. I'm creating the release in terraform:

locals {
  collector_version = "0.104.0"
}

resource "helm_release" "opentelemetry-collector" {
  name       = "opentelemetry-collector"
  repository = "https://open-telemetry.github.io/opentelemetry-helm-charts"
  chart      = "opentelemetry-collector"
  version    = local.collector_version
  namespace  = var.namespace
  timeout    = 180
  wait       = true

  values = [yamlencode({
    mode = "deployment"

    replicaCount = 1

    image = {
      repository = "otel/opentelemetry-collector-contrib"
    }

    command = {
      extraArgs = [
        "--feature-gates=-component.UseLocalHostAsDefaultHost"
      ]
    }

    livenessProbe = {
      httpGet = {
        port = 13133
        path = "/health"
      }
    }

    readinessProbe = {
      httpGet = {
        port = 13133
        path = "/health"
      }
    }

    service = {
      enabled = true
    }

    serviceAccount = {
      create = true
      annotations = {
        "eks.amazonaws.com/role-arn" = aws_iam_role.otel_collector.arn
      }
    }

    presets = {}

    config = local.otel_config
  })]
}

Current config:

        health_check         = {
          endpoint = "$${env:MY_POD_IP}:13133"
          path = "/health"
          response_body = {
            healthy = "OK"
          }
        }

(Though I've tried it with no options as well).

Yet it won't expose port 13133:

Controlled By:  ReplicaSet/opentelemetry-collector-57bbcb5fc8
Containers:
  opentelemetry-collector:
    Container ID:  containerd://9307ee70b33a5f1a4d3a5d96b99df99b870edc1c59d196d3e95a5375da9a3ae0
    Image:         otel/opentelemetry-collector-contrib:0.108.0
    Image ID:      docker.io/otel/opentelemetry-collector-contrib@sha256:923eb1cfae32fe09676cfd74762b2b237349f2273888529594f6c6ffe1fb3d7e
    Ports:         6831/UDP, 14250/TCP, 14268/TCP, 4317/TCP, 4318/TCP, 9411/TCP
    Host Ports:    0/UDP, 0/TCP, 0/TCP, 0/TCP, 0/TCP, 0/TCP
    Args:
      --config=/conf/relay.yaml
      --feature-gates=-component.UseLocalHostAsDefaultHost
    State:          Running
      Started:      Mon, 18 Nov 2024 15:31:34 +0200

Looking at the ports configuration in the chart values, there doesn't even seem to be an entry for the healthcheck.

Additionally, the created service for the collector, when enabled, does not expose such a port either.

TylerHelmuth commented 2 days ago

@perry-mitchell by default the chart doesn't not expose the port on the container. You can see a simple example here: https://github.com/open-telemetry/opentelemetry-helm-charts/blob/main/charts/opentelemetry-collector/examples/daemonset-only/rendered/daemonset.yaml.

If you need to add a port to the container you can use .Values.ports: https://github.com/open-telemetry/opentelemetry-helm-charts/blob/6f674b102585a158dbacccecfc2c12a3bbc5a120/charts/opentelemetry-collector/values.yaml#L268

perry-mitchell commented 1 day ago

by default the chart doesn't not expose the port on the container.

Wouldn't it make sense to expose it, even by default, so it could be used as a healthcheck downstream?

.Values.ports

This doesn't work, and the helm chart throws an exception when I add a new port name that isn't listed there. I don't have the error on-hand anymore, unfortunately.

TylerHelmuth commented 1 day ago

This configuration worked for me:

ports:
  healthcheck:
    enabled: true
    containerPort: 13133
    servicePort: 13133
    protocol: TCP