Skip to content

[Metricbeat] [kubernetes] Ensure label updates are reflected in metadata enrichment #47397

@b-deam

Description

@b-deam

Describe the enhancement:

The Metricbeat Kubernetes module should ensure that label updates on Kubernetes resources are reflected in the metadata that enriches documents, even when the resource state (such as phase or status) has not changed. Currently, metadata enrichment is only refreshed when resource state transitions occur, which means resources that are already in a stable state miss label updates that happen after their initial metadata collection.

The module should detect when labels on any Kubernetes resource have changed and trigger a metadata refresh for the affected resource and all related resources that inherit or reference those labels, regardless of whether their state has changed. This will ensure that documents are consistently enriched with the most up-to-date label information across all resource types.

Describe a specific use case for the enhancement or feature:

This issue manifests across multiple Kubernetes resource types. For example, when a node starts up, there is a race condition where labels (such as node_kubernetes_io/instance-type) may be added or updated after resources are already running. As a concrete example with pods:

  1. Node starts up
  2. System pods begin running and their first metrics are collected without node labels (because labels aren't set yet)
  3. Node labels are then added (e.g., node_kubernetes_io/instance-type)
  4. On the next collection cycle, only resources that experience state changes (e.g., pods transitioning from "waiting" → "running") get their metadata refreshed with the new labels
  5. Resources that were already in their final state during the first collection never get updated with the new labels, resulting in documents missing this label

This same pattern affects nodes themselves, where node labels may be added or modified after the initial metadata collection, and these updates are not reflected in documents if the node's overall status hasn't changed.

This creates inconsistent metadata in Elasticsearch documents across all resource types, where some resources have current labels and others don't, even when they should share the same label values. This affects filtering, aggregation, and analysis of metrics by any label-based dimension, leading to incomplete or incorrect insights.

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