Skip to content

[extension/k8sobserver] Discovering "Ports" should populate variable container_name #41309

@ChristianCiach

Description

@ChristianCiach

Component(s)

extension/observer/k8sobserver

Is your feature request related to a problem? Please describe.

When using the k8s_observer to discover container-ports, the container-name of the discovered port is not made available as part of the endpoint details, even though the information is readily available when the results are assembled.

See relevant code:

// Create endpoint for each named container port.
for _, port := range container.Ports {
endpointID = observer.EndpointID(
fmt.Sprintf(
"%s/%s(%d)", podID, port.Name, port.ContainerPort,
),
)
endpoints = append(endpoints, observer.Endpoint{
ID: endpointID,
Target: fmt.Sprintf("%s:%d", podIP, port.ContainerPort),
Details: &observer.Port{
Pod: podDetails,
Name: port.Name,
Port: uint16(port.ContainerPort),
Transport: getTransport(port.Protocol),
},
})
}

Why do I need the container name the port belongs to?

I want to configure my receivercreator-receiver like this:

receivers:
  receiver_creator/prometheus:
    watch_observers: [k8s_observer]
    receivers:
      prometheus:
        rule: >-
          type == "port" 
          && pod.annotations["prometheus.io/scrape"] == "true"
          && (pod.annotations["prometheus.io/port"] ?? "9090") == port
        resource_attributes:
          k8s.container.name: "`container_name`"
        config: '...'

Why don't I just use type == "pod"?

When using type == "pod", there is no way to get the k8s.container.name the prometheus.io-annotation targets. I need the k8s.container.name so that the k8sattributes-processor can set service.instance.id, since this relies on the k8s.container.name as described in https://opentelemetry.io/docs/specs/semconv/non-normative/k8s-attributes/#how-serviceinstanceid-should-be-calculated

Why don't I just use type == "pod.container"?

This rule would match multiple containers against the same prometheus-annotations, as there is no way to match the discovered container against the given annotation. The only container-identifying information inside the prometheus-annotations seems to be the port-number, but the discovered ports are not available when using type == "pod.container".

Describe the solution you'd like

Please add the container_name to the discovered ports, just as it's already done when discovering containers.

The container-name is readily available when constructing the endpoint details, so the required changes seem to be minimal.

Describe alternatives you've considered

No response

Additional context

No response

Tip

React with 👍 to help prioritize this issue. Please use comments to provide useful context, avoiding +1 or me too, to help us triage it. Learn more here.

Metadata

Metadata

Assignees

No one assigned

    Type

    No type

    Projects

    No projects

    Milestone

    No milestone

    Relationships

    None yet

    Development

    No branches or pull requests

    Issue actions