containers / prometheus-podman-exporter

Prometheus exporter for podman environments exposing containers, pods, images, volumes and networks information.

Geek Repo:Geek Repo

Github PK Tool:Github PK Tool

Exporter crashes when attempting to export metrics for a pod with no namespace

PJDuszynski opened this issue · comments

Describe the bug
The exporter will crash as soon as the metrics endpoint is accessed if the --collector.pod tag is enabled, if a pod is created without an infrastructure container and namespace.

These are the default configurations used in the podman-compose up and podman-compose systemd commands in the podman compose package.

To Reproduce

Create at least one pod with no infrastructure container.

podman pod create --infra=false --share="" <pod_name>
podman pod ls -ns
POD ID        NAME           STATUS      CREATED       INFRA ID               CGROUP      NAMESPACES  # OF CONTAINERS
5e76f99ca  <pod_with_infra>     Running     44 hours ago  997264653234c603  user.slice          2
1f3fb57f3  <pod_with_no_infra>  Running     5 days ago                          user.slice              1
prometheus-podman-exporter -o -d

Expected behavior
The metrics endpoints are displayed.

Error Logs

prometheus-podman-exporter -o -d
ts=2022-10-20T16:31:34.408Z caller=exporter.go:57 level=info msg="Starting podman-prometheus-exporter" version="(version=1.0.0, branch=, revision=1)"
ts=2022-10-20T16:31:34.408Z caller=handler.go:93 level=info msg="enabled collectors"
ts=2022-10-20T16:31:34.408Z caller=handler.go:104 level=info collector=container
ts=2022-10-20T16:31:34.408Z caller=handler.go:104 level=info collector=pod
ts=2022-10-20T16:31:34.408Z caller=exporter.go:68 level=info msg="Listening on" address=:9882
ts=2022-10-20T16:31:34.409Z caller=tls_config.go:195 level=info msg="TLS is disabled." http2=false
ts=2022-10-20T16:31:51.484Z caller=handler.go:34 level=debug msg="collect query:" filters="unsupported value type"
panic: runtime error: slice bounds out of range [:12] with length 0

goroutine 48 [running]:
github.com/containers/prometheus-podman-exporter/pdcs.Pods()
        /builddir/build/BUILD/prometheus-podman-exporter/pdcs/pod.go:30 +0x396
github.com/containers/prometheus-podman-exporter/collector.(*podCollector).Update(0xc00026b0e0, 0x0)
        /builddir/build/BUILD/prometheus-podman-exporter/collector/pod.go:58 +0x38
github.com/containers/prometheus-podman-exporter/collector.execute({0x14bfd51, 0x0}, {0x16ddc60, 0xc00026b0e0}, 0x0, {0x16ddee0, 0xc000269780})
        /builddir/build/BUILD/prometheus-podman-exporter/collector/collector.go:115 +0x9c
github.com/containers/prometheus-podman-exporter/collector.PodmanCollector.Collect.func1({0x14bfd51, 0x0}, {0x16ddc60, 0xc00026b0e0})
        /builddir/build/BUILD/prometheus-podman-exporter/collector/collector.go:103 +0x3d
created by github.com/containers/prometheus-podman-exporter/collector.PodmanCollector.Collect
        /builddir/build/BUILD/prometheus-podman-exporter/collector/collector.go:102 +0xd5

Desktop (please complete the following information):

  • OS RHEL 9.0
  • Podman Version 4.1.1

Hi @PJDuszynski
Thanks, following PR #44 will fix the issue.

@navidys Awesome. Thank you!