prometheus-engine icon indicating copy to clipboard operation
prometheus-engine copied to clipboard

Documentation or examples could demonstrate TargetLabels FromPod

Open strideynet opened this issue 1 year ago • 1 comments

None of the examples or documentation beyond the API reference demonstrate how to scrape the pod labels as metric labels. This makes it harder than necessary to get going.

For my future reference, and the reference of anyone else:

spec:
  endpoints:
  - interval: 1m
    port: my-port
  selector:
    matchLabels:
      app.kubernetes.io/name: my-app
  targetLabels:
    fromPod:
    - from: foo
    - from: foo/bar
      to: foo_bar
    metadata:
    - pod
    - container

Specify from as the name of the pod label you wish to have added to the metric labels. You may also need to specify to to provide the name the label should be on the metric - this is necessary if the pod label is not compatible with the metric labels (e.g contains characters such as /)

strideynet avatar Feb 27 '24 12:02 strideynet

Thanks! Some of it is explained in field comment (e.g. readable via kubectl explain), but that nuance when to is useful and what remap means can be improved. Thanks, we will add more context to the commentary plus examples.

kubectl explain podmonitoring.spec.targetLabels.fromPod
GROUP:      monitoring.googleapis.com
KIND:       PodMonitoring
VERSION:    v1

FIELD: fromPod <[]Object>

DESCRIPTION:
    Labels to transfer from the Kubernetes Pod to Prometheus target labels.
    Mappings are applied in order.
    LabelMapping specifies how to transfer a label from a Kubernetes resource
    onto a Prometheus target.
    
FIELDS:
  from	<string> -required-
    Kubernetes resource label to remap.

  to	<string>
    Remapped Prometheus target label.
    Defaults to the same name as `From`.

bwplotka avatar Apr 08 '24 10:04 bwplotka