prometheus / prometheus/client_python
write_to_textfile: tmp file is left behind if generator code fails
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ả
In the write_to_textfile function, the code to run the collector registry is in the temp file creation block: https://github.com/prometheus/client_python/blob/master/prometheus_client/exposition.py#L202-L203
In my case, I had an error in my collector code (run by generate_latest(registry)). This resulted in many tmp files left over from the errors.
I'm wondering if it would be preferable to run the code before the temp file block, e.g.:
tmppath = '%s.%s.%s' % (path, os.getpid(), threading.current_thread().ident)
out = generate_latest(registry)
with open(tmppath, 'wb') as f:
f.write(out)
# rename(2) is atomic.
os.rename(tmppath, path)
Unless leaving temp files behind is the desired/intended behavior.
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 trong prometheus_client/exposition.py, tại phần triển khai write_to_textfile quanh các dòng 202-203, nơi generate_latest(registry) chạy trong quá trình tạo tệp tạm thời. Theo dõi đường đi của lỗi khi mã collector phát sinh ngoại lệ và xác minh rằng hành vi hoàn tất không để lại tệp tạm thời nào, đồng thời vẫn giữ nguyên quy trình đổi tên nguyên tử.
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
- backend
- Loại issue
- Lỗi
- Độ khó
- 2/5
- Thời gian dự kiến
- 1-3 giờ
- Mức độ hoạt động
- Đình trệ
- Độ rõ ràng
- Đặc tả rõ ràng
- Mức phù hợp với người mới
- 45/100