[Bug]: /metrics returns a fixed short body while last_collection_error stays 0

Đang mở
#11,809 0 bình luận 1 reaction 0 người được giao Xem trên GitHub

Maintainer thường phản hồi trong vòng 1 ngày

Chưa có ai nhận issue này.

Đánh giá

Độ khó
4/5
Thời gian dự kiến
3-5 ngày
Mức phù hợp với người mới
48/100
Loại issue
Lỗi
Độ rõ ràng
Khá rõ ràng
Mức độ hoạt động
Sôi nổi
Công nghệ
go, kubernetes, postgresql, prometheus
Lĩnh vực
databases, observability

Hướng nghiên cứu

Start with pkg/management/postgres/webserver/metricserver/metrics.go, which the issue identifies as the metrics server entry point, then trace how the SQL-backed metric families are collected and how collection errors affect the exported metrics. Compare behavior during a burst of Defaulting for Cluster logs with a normal scrape. Done means a scrape includes the expected metric families or sets cnpg_collector_last_collection_error to 1 when they are missing.

Do mô hình lập chỉ mục viết ra từ nội dung của issue.

Mô tả

Is there an existing issue already for this bug?
  • I have searched for an existing issue, and could not find anything. I believe this is a new bug.
I have read the troubleshooting guide
  • I have read the troubleshooting guide and I think this is a new bug.
I am running a supported version of CloudNativePG
  • I have read the troubleshooting guide and I think this is a new bug.
Version

1.30 (latest patch) — image ghcr.io/cloudnative-pg/cloudnative-pg:1.30.1. No release is newer than v1.30.1 (published 2026-09-23).

What version of Kubernetes are you using?

1.36

What is your Kubernetes environment?

Other (self-managed Talos)

How did you install the operator?

Helm

What happened?

During a burst of Defaulting for Cluster logs, instance /metrics returns HTTP 200 with a fixed short body. cnpg_collector_up stays 1 and cnpg_collector_last_collection_error stays 0. Families that alerts need, including cnpg_pg_replication_in_recovery and cnpg_backends_total, are absent. A normal body for these instances is about 460–560 samples. The short body is 77 samples on a primary and 76 on a replica, including when the scrape finishes in a few hundred milliseconds.

This is not the Prometheus client hitting its deadline. scrape_timeout_seconds is 10. The slowest scrape in the window below is 5.63s. In v1.30.1 pkg/management/postgres/webserver/metricserver/metrics.go the metrics server sets ReadTimeout and ReadHeaderTimeout and does not set WriteTimeout. promhttp.HandlerFor is called with empty HandlerOpts. A completed 76-sample response is the registry contents for that request.

The same process logs the defaulting line. In one minute of the window below, the operator logged it 550 times and each instance's postgres container logged it tens to about 140 times. Outside the window the fleet total is about 1–8 lines per minute. cloudnative-pg/cloudnative-pg#11487 and the open pull request cloudnative-pg/cloudnative-pg#11556 cover that log volume. They do not cover the short body.

Two windows, same operator:

  1. 2026-10-18, after switchovers. Affected instances served about 77 samples instead of 480–520. cnpg_pg_replication_in_recovery and cnpg_backends_total were missing. cnpg_collector_up was 1 and cnpg_collector_last_collection_error was 0. Defaulting for Cluster ran about 90–170 times per minute in that window. Primaries that were not restarted were short as well.

  2. 2026-10-19 06:21Z–06:26Z, retained VictoriaMetrics and VictoriaLogs. Seven three-instance clusters. For job victoria-metrics/cnpg, min(scrape_samples_scraped) is 76 for each of those six minutes and about 460 outside them. Short primaries are 77, short replicas are 76. The same pod can return a full body (about 480–550) on one scrape and 76 on the next, so the exporter is not stuck. max(scrape_duration_seconds) across the six minutes is 5.63, 4.42, 4.01, 3.14, 2.75, 2.70. cnpg_collector_collection_duration_seconds{collector="Collect.cnpg"} rises to about 3.6s on some primaries; outside the window it is about 0.1–0.4s. The count of cnpg_pg_replication_in_recovery series falls from 22 to 2, and cnpg_backends_total from 42 to 3. Where cnpg_collector_up and cnpg_collector_last_collection_error are still present they are 1 and 0. Defaulting for Cluster counts per minute from 06:20Z: 625, 1843, 2012, 1965, 2122, 1895, 262, then single digits. The one single-instance cluster did not drop to 76.

Expected: a scrape either returns the full set, or cnpg_collector_last_collection_error is 1 when the body is missing the SQL-backed families.

Cluster resource

Not pasted. The affected clusters are ordinary 3-instance postgresql.cnpg.io/v1 Clusters with the chart's default monitoring queries. The short body hit primaries and replicas, including primaries whose node was not rebooted.

Relevant log output

No exporter error line. The correlated line is msg="Defaulting for Cluster", logger="cluster-resource", from both cnpg-system manager and the instance postgres container. Rate is above.

Code of Conduct
  • I agree to follow this project's Code of Conduct
Ngôn ngữ chính
Go
Star
9.7k
Fork
830
Merge trung bình
2 ngày 1 giờ
Pull request đã merge (30 ngày)
122

Chuẩn bị môi trường

Mở trong Codespaces

Khởi chạy dev container của dự án ngay trên trình duyệt, bằng tài khoản GitHub của bạn.

Bắt đầu từ đâu

  1. Đọc hết issue, rồi đọc hướng dẫn đóng góp của dự án.
  2. Bình luận trên issue rằng bạn sẽ nhận — tránh hai người làm cùng một việc.
  3. Fork repository và làm thay đổi trên một nhánh.
  4. Mở pull request có tham chiếu số hiệu của issue.

Issue khác của cloudnative-pg/cloudnative-pg

Tất cả issue của cloudnative-pg/cloudnative-pg

Issue tương tự

Thêm issue về Go

Nhận issue mới trong hộp thư của bạn

Bản tóm tắt ngắn những issue GitHub phù hợp với người mới.