prometheus / prometheus/client_python

Add public, read-only access to label names, label values of any metric

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

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ả

Hi,

I am currently working on Prometheus metrics for Celery workers in Flower project and we use this wonderful library :) - thx for your work on it!

One issue I came across is lack of direct access to metric's labelnames and labelvalues.

I think easiest is to give you an example how it is used/why it is needed.

We have multiple celery workers in a kubernetes cluster, they are monitored by Flower which generates Prometheus metrics.
Now the pods in k8s can die or be replaced if a new release of our software is deployed.

The problem with that then is that the final reading for each metric for that pod is retained forever and it shows in grafana forever.

We want to remove any tuples of label values which contain a celery worker name that is deemed offline/dead.

I used a semi-hack (https://github.com/mher/flower/pull/1135) and get those label values through metric.collect(), and from that iterate over samples and the labels in them and then if they contain an offline worker I remove the whole tuple from a given metric by calling metric.remove(*labelvalues_containg_dead_worker)

There could be a better way - access metric._metric.keys() in a thread safe and read-only way.

So I propose to add to MetricWrapperBase a read only property, say all_label_values (name to be improved, suggestions welcome :))

@property
def all_label_values(self) -> List[Tuple[str, ...]]:
    with self._lock:
        all_label_values = list(self._metric.keys().copy())

   return all_label_values

I think I am also badly missing access to actual labelnames set for the given metric to know at which position a label with a given name will be in the labelvalues.

Could kill 2 birds with one stone then and add:

@property
def labelnames(self) -> Tuple[str, ...]:
    return self._labelnames

Please let me know if such a change is acceptable and if I am missing any nuances.

If you think you would be ok merging it I will make a PR with tests soon.

Cheers,

Tom

Hướng dẫn đóng góp

Mở hướng dẫn đóng góp

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.

Hướng nghiên cứu

Bắt đầu với MetricWrapperBase và kiểm tra hành vi hiện có của _metric, _labelnames, _lock, collect() và remove() được mô tả trong issue. Xác định quyền truy cập công khai chỉ-đọc đối với tên label và các tuple label-giá trị, sau đó thêm các bài kiểm thử xác nhận các giá trị được cung cấp và hành vi đọc thread-safe.

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

Đánh giá

Công nghệ
prometheus, python
Lĩnh vực
observability
Loại issue
Tính năng
Độ khó
3/5
Thời gian dự kiến
1-2 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
38/100

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.