prometheus / prometheus/client_python
Metric without `labelnames` causes issues in when MULTIPROC is enabled
Chưa có ai nhận issue này.
- Ngôn ngữ chính
- Python
- Star
- 4.4k
- Fork
- 876
- Merge trung bình
- 8 ngày 4 giờ
- Pull request đã merge (30 ngày)
- 1
Mô tả
Hello,
I noticed (see https://github.com/prometheus/client_python/issues/902#issuecomment-3013566209 for example ) that when
- having a metric defined without a label
- multiprocess mode is enabled (i.e.
PROMETHEUS_MULTIPROC_DIRis set ) - an app has a single process
then this causes issues, and some metrics will not be reported.
It's not exactly clear to me what is happening, but an indication that something is wrong is that a prometheus db file is created at load time (i.e. when metrics are defined, before they are set).
Here's what I have in more details:
Observations in a prod application:
- Some histogram metrics set in a threaded celery worker where
PROMETHEUS_MULTIPROC_DIRare not reported - No such issue in pre-fork workers
- The issue was resolved by adding the
labelnamesargument to a metric where it was missing (which was an histogram as well)
Other observations:
- When starting the app, a prom db file is created for the metric that was missing labelnames (before any measurement is made)
Hypothesis:
- in a celery worker in pre-fork mode, the process creating the first db file is not the same process were metrics are set afterwards, so there is no "collision" (because of the pid suffix)
- in a celery worker in threaded mode, there is a single process creating the first db file and setting the metrics, and somehow collisions happens and some metrics are not reported
Values set at startup:
$ curl localhost:8000
# HELP test_histogram_no_label test Histogram
# TYPE test_histogram_no_label histogram
test_histogram_no_label_sum 0.0
test_histogram_no_label_bucket{le="1.0"} 0.0
test_histogram_no_label_bucket{le="2.0"} 0.0
test_histogram_no_label_bucket{le="+Inf"} 0.0
test_histogram_no_label_count 0.0
It seems to me that a simple way to address this would be to raise when a metric is defined without labelnames, as labelnames are mandatory anyway.
Hướng dẫn đóng góp
Bắt đầu từ đâu
- Đọc hết issue, rồi đọc hướng dẫn đóng góp của dự án.
- 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.
- Fork repository và làm thay đổi trên một nhánh.
- Mở pull request có tham chiếu số hiệu của issue.
Hướng nghiên cứu
Bắt đầu bằng cách tái hiện thiết lập một tiến trình với các thread và PROMETHEUS_MULTIPROC_DIR được bật, đồng thời so sánh các metric được định nghĩa có và không có labelnames. Quan sát quá trình khởi tạo metric, các tệp cơ sở dữ liệu được tạo và đầu ra exposition, sau đó lần theo phần xử lý multiprocess liên quan. Công việc được xem là hoàn tất khi đã hiểu hành vi, các metric được báo cáo nhất quán và có quyết định rõ ràng về việc có xác thực labelnames bị thiếu hay không.
Do mô hình lập chỉ mục viết ra từ nội dung của issue.
Đánh giá
- Công nghệ
- python
- Lĩnh vực
- observability-sre
- Loại issue
- Lỗi
- Độ khó
- 4/5
- Thời gian dự kiến
- 3-5 ngày
- Mức độ hoạt động
- Đình trệ
- Độ rõ ràng
- Khá rõ ràng
- Mức phù hợp với người mới
- 45/100