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

Prometheus pod discovery not working for monitor_kubernetes_pods=true and pod_scrape_scope=cluster since 1.18.3 #9600

Closed
gracewehner opened this issue Aug 7, 2021 · 1 comment · Fixed by #9605
Labels
bug unexpected problem or unintended behavior

Comments

@gracewehner
Copy link
Contributor

Relevant telegraf.conf:

[[inputs.prometheus]]
  metric_version = 2
  pod_scrape_scope = "cluster"

  ## Scrape Kubernetes pods for the following prometheus annotations:
  ## - prometheus.io/scrape: Enable scraping for this pod
  ## - prometheus.io/scheme: If the metrics endpoint is secured then you will need to
  ##     set this to `https` & most likely set the tls config.
  ## - prometheus.io/path: If the metrics path is not /metrics, define it with this annotation.
  ## - prometheus.io/port: If port is not 9102 use this annotation
  monitor_kubernetes_pods = true

  bearer_token = "/var/run/secrets/kubernetes.io/serviceaccount/token"
  response_timeout = "15s"

  tls_ca = "/var/run/secrets/kubernetes.io/serviceaccount/ca.crt"
  insecure_skip_verify = true

System info:

Telegraf 1.18.3 - 1.19.2
Telegraf executable run as a process in a Kubernetes container

Steps to reproduce:

  1. Deploy a pod that exposes prometheus metrics at <pod_ip>:<port>/<metrics path> with the annotations in the comment for monitor_kubernetes_pods above.
  2. Run telegraf with the prometheus input plugin and the settings monitor_kubernetes_pods = true, pod_scrape_scope = "cluster".

Expected behavior:

Telegraf will discover the pods with that have the annotations and scrape the metrics exposed by those pods.

Actual behavior:

No pods are registered in the kubernetes.go code of the prometheus input plugin. Since no pods are discovered/registered, no prometheus metrics are scraped.

Additional info:

This is different from the issues #9349 and #9408 which is for pod_scrape_scope = "node".

Looks like the issue stems from #8937 and this line in kubernetes.go where the pod struct is never populated with the event object so the pod registered will not have info about the endpoint to scrape.
Replacing that line with something like:

pod, ok := event.Object.(*corev1.Pod)
if !ok {
   return fmt.Errorf("Unexpected object when getting pods")
}

fixes the issue by getting the pod from the watch event.

I have a fork and can make a PR with this change.

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
bug unexpected problem or unintended behavior
Projects
None yet
Development

Successfully merging a pull request may close this issue.

1 participant