Commit 3e353f5
* fix(router): clear stale Prometheus endpoint health metrics (fixes #888)
Endpoint health gauges retained stale server= labels indefinitely when
a backend was removed from service discovery, causing Prometheus to
keep exporting the last known value for dead endpoints.
Changes:
- Add EndpointInfo.healthy field (default True) to carry health state
from service discovery into the metrics handler
- Introduce _LABEL_GAUGES list and _clear_label_gauges() helper in
metrics_router.py; call it at the start of every /metrics scrape so
only currently-active endpoints appear in the output
- Update healthy_pods_total to use ep.healthy instead of a hardcoded 1
- Add test_stale_metrics.py covering: EndpointInfo.healthy default/
override, stale label removal, full endpoint removal, unlabeled gauge
preservation, _LABEL_GAUGES completeness, and post-clear repopulation
- Remove redundant inline comments and section headers throughout
Signed-off-by: prashansapkota <prashan.sapkota3456@gmail.com>
* fix(router): address review feedback on PR #936
- Add num_requests_waiting to _LABEL_GAUGES and import it so stale
waiting-request series are cleared along with all other server labels
- Restore the metrics() endpoint docstring
- Expand test imports and expected set in
test_label_gauges_list_contains_all_expected_gauges to cover all
server-labeled gauges including num_requests_waiting
Signed-off-by: prashansapkota <prashan.sapkota3456@gmail.com>
* fix: remove unused CollectorRegistry import in test_stale_metrics.py
Signed-off-by: prashansapkota <prashan.sapkota3456@gmail.com>
---------
Signed-off-by: prashansapkota <prashan.sapkota3456@gmail.com>
Co-authored-by: Rui Zhang <51696593+ruizhang0101@users.noreply.github.com>
1 parent 72c2b7f commit 3e353f5
3 files changed
Lines changed: 160 additions & 32 deletions
| Original file line number | Diff line number | Diff line change | |
|---|---|---|---|
| |||
| 1 | + | |
| 2 | + | |
| 3 | + | |
| 4 | + | |
| 5 | + | |
| 6 | + | |
| 7 | + | |
| 8 | + | |
| 9 | + | |
| 10 | + | |
| 11 | + | |
| 12 | + | |
| 13 | + | |
| 14 | + | |
| 15 | + | |
| 16 | + | |
| 17 | + | |
| 18 | + | |
| 19 | + | |
| 20 | + | |
| 21 | + | |
| 22 | + | |
| 23 | + | |
| 24 | + | |
| 25 | + | |
| 26 | + | |
| 27 | + | |
| 28 | + | |
| 29 | + | |
| 30 | + | |
| 31 | + | |
| 32 | + | |
| 33 | + | |
| 34 | + | |
| 35 | + | |
| 36 | + | |
| 37 | + | |
| 38 | + | |
| 39 | + | |
| 40 | + | |
| 41 | + | |
| 42 | + | |
| 43 | + | |
| 44 | + | |
| 45 | + | |
| 46 | + | |
| 47 | + | |
| 48 | + | |
| 49 | + | |
| 50 | + | |
| 51 | + | |
| 52 | + | |
| 53 | + | |
| 54 | + | |
| 55 | + | |
| 56 | + | |
| 57 | + | |
| 58 | + | |
| 59 | + | |
| 60 | + | |
| 61 | + | |
| 62 | + | |
| 63 | + | |
| 64 | + | |
| 65 | + | |
| 66 | + | |
| 67 | + | |
| 68 | + | |
| 69 | + | |
| 70 | + | |
| 71 | + | |
| 72 | + | |
| 73 | + | |
| 74 | + | |
| 75 | + | |
| 76 | + | |
| 77 | + | |
| 78 | + | |
| 79 | + | |
| 80 | + | |
| 81 | + | |
| 82 | + | |
| 83 | + | |
| 84 | + | |
| 85 | + | |
| 86 | + | |
| 87 | + | |
| 88 | + | |
| 89 | + | |
| 90 | + | |
| 91 | + | |
| 92 | + | |
| 93 | + | |
| 94 | + | |
| 95 | + | |
| 96 | + | |
| 97 | + | |
| 98 | + | |
| 99 | + | |
| 100 | + | |
| 101 | + | |
| 102 | + | |
| 103 | + | |
| 104 | + | |
| 105 | + | |
| 106 | + | |
| 107 | + | |
| 108 | + | |
| 109 | + | |
| 110 | + | |
| 111 | + | |
| 112 | + | |
| 113 | + | |
| 114 | + | |
| 115 | + | |
| 116 | + | |
| 117 | + | |
| 118 | + | |
| 119 | + | |
| 120 | + | |
| 121 | + | |
| 122 | + | |
| 123 | + | |
| 124 | + | |
| 125 | + | |
| 126 | + | |
| 127 | + | |
| 128 | + | |
| 129 | + | |
| 130 | + | |
| 131 | + | |
| Original file line number | Diff line number | Diff line change | |
|---|---|---|---|
| |||
18 | 18 | | |
19 | 19 | | |
20 | 20 | | |
| 21 | + | |
21 | 22 | | |
22 | 23 | | |
23 | 24 | | |
| |||
32 | 33 | | |
33 | 34 | | |
34 | 35 | | |
| 36 | + | |
35 | 37 | | |
36 | 38 | | |
37 | 39 | | |
38 | 40 | | |
| 41 | + | |
| 42 | + | |
39 | 43 | | |
40 | 44 | | |
41 | | - | |
42 | 45 | | |
43 | 46 | | |
44 | 47 | | |
| |||
53 | 56 | | |
54 | 57 | | |
55 | 58 | | |
56 | | - | |
| 59 | + | |
| 60 | + | |
| 61 | + | |
| 62 | + | |
| 63 | + | |
| 64 | + | |
| 65 | + | |
| 66 | + | |
| 67 | + | |
| 68 | + | |
| 69 | + | |
| 70 | + | |
| 71 | + | |
| 72 | + | |
| 73 | + | |
| 74 | + | |
| 75 | + | |
| 76 | + | |
| 77 | + | |
| 78 | + | |
| 79 | + | |
| 80 | + | |
57 | 81 | | |
58 | 82 | | |
59 | | - | |
60 | 83 | | |
61 | 84 | | |
62 | 85 | | |
| |||
72 | 95 | | |
73 | 96 | | |
74 | 97 | | |
| 98 | + | |
75 | 99 | | |
76 | | - | |
77 | 100 | | |
78 | 101 | | |
79 | 102 | | |
80 | | - | |
81 | 103 | | |
82 | 104 | | |
83 | 105 | | |
84 | | - | |
85 | 106 | | |
86 | 107 | | |
87 | 108 | | |
88 | | - | |
89 | 109 | | |
90 | 110 | | |
91 | 111 | | |
| |||
99 | 119 | | |
100 | 120 | | |
101 | 121 | | |
102 | | - | |
103 | 122 | | |
104 | 123 | | |
105 | 124 | | |
| |||
112 | 131 | | |
113 | 132 | | |
114 | 133 | | |
115 | | - | |
116 | 134 | | |
117 | 135 | | |
118 | | - | |
119 | | - | |
120 | | - | |
| 136 | + | |
121 | 137 | | |
122 | | - | |
123 | 138 | | |
| Original file line number | Diff line number | Diff line change | |
|---|---|---|---|
| |||
96 | 96 | | |
97 | 97 | | |
98 | 98 | | |
99 | | - | |
100 | 99 | | |
101 | | - | |
102 | | - | |
103 | 100 | | |
104 | | - | |
105 | | - | |
106 | 101 | | |
107 | | - | |
108 | | - | |
109 | 102 | | |
110 | | - | |
111 | | - | |
112 | 103 | | |
113 | | - | |
114 | | - | |
115 | 104 | | |
116 | | - | |
117 | | - | |
| 105 | + | |
118 | 106 | | |
119 | | - | |
120 | | - | |
121 | 107 | | |
122 | | - | |
123 | | - | |
124 | 108 | | |
125 | | - | |
126 | | - | |
127 | 109 | | |
128 | 110 | | |
129 | 111 | | |
| |||
0 commit comments