prometheus / prometheus/client_python
gauge.set_function() doesn't work in multiprocess mode
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ả
Multiprocess mode's collect() reads the registry files and aggregates metrics that have been written to prometheus_multiproc_dir.
This doesn't work with gauge.set_function() which does not record its value. The provided function is just called during collection.
That means with the following code:
registry = CollectorRegistry()
Gauge("test", "test", registry=self._registry).set_function(lambda: 100)
multiprocess.MultiProcessCollector(registry)
The output will be:
# HELP test test
# TYPE test gauge
test 100.0
# HELP test Multiprocess metric
# TYPE test gauge
test{pid="10705"} 0.0
Current side effects:
- If any mode other than
allorliveallis used, thepidtag won't be included. This results in duplicate metrics being reported to Prometheus. Prometheus currently only uses the first metric it reads, which is non-deterministic due to iteration over the registry's dictionary. - If
registry=Noneto avoid double reporting, only the default value of0.0is reported. - Current way to work around it is to use the mode
alland to ignore gauges in Prometheus and with the tagpid.
Proposal:
I'm not sure how you could incorporate set_function into the multiprocess registry and I'm not convinced how useful of a feature it would be. Is it reasonable to add a new multiprocess_mode: exclude which would prevent the incorrect 0.0 value being reported? Or would it be better to just add documentation to recommend using two independent registries?
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
Tái hiện sự khác biệt bằng cách sử dụng entry point collect() của multiprocess.py và hành vi set_function() của registry.py, với prometheus_multiproc_dir được cấu hình. So sánh các giá trị được báo cáo giữa các chế độ multiprocess và xác định hành vi mong đợi cho set_function(); công việc được xem là hoàn tất khi hành vi được chọn đã được ghi lại và việc báo cáo trùng lặp hoặc không chính xác giá trị 0.0 đã được khắc phục.
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
- Cần làm rõ
- Mức phù hợp với người mới
- 35/100