@@ -12,6 +12,49 @@ type t = {
12
12
13
13
let ocaml = OpamPackage.Name. of_string " ocaml"
14
14
15
+ module Metrics = struct
16
+ open Prometheus
17
+
18
+ let namespace = " ocluster"
19
+ let subsystem = " worker"
20
+
21
+ let request_handling_total =
22
+ let help = " Total number of handled solve requests" in
23
+ Counter. v ~help ~namespace ~subsystem " requests_handled_total"
24
+
25
+ let request_handling =
26
+ let help = " Number of handled requests by state" in
27
+ Gauge. v_label ~label_name: " state" ~help ~namespace ~subsystem " solve_request_state"
28
+
29
+ let update_request_handling pool =
30
+ let running = Pool. running_workers pool in
31
+ let waiting = (Pool. n_workers pool) - running in
32
+ Gauge. set (request_handling " running" ) (float_of_int running);
33
+ Gauge. set (request_handling " waiting" ) (float_of_int waiting)
34
+
35
+
36
+ let request_ok =
37
+ let help = " Total number of success solve requests" in
38
+ Counter. v ~help ~namespace ~subsystem " success_solve"
39
+
40
+ let request_fail =
41
+ let help = " Total number of fail solve requests" in
42
+ Counter. v ~help ~namespace ~subsystem " fail_solve"
43
+
44
+ let request_no_solution =
45
+ let help = " Total number of no solution solve requests " in
46
+ Counter. v ~help ~namespace ~subsystem " no_solution_solve"
47
+
48
+ let request_cancelled =
49
+ let help = " Total number of cancel without running solve requests" in
50
+ Counter. v ~help ~namespace ~subsystem " cancel_without_running_solve"
51
+
52
+ let request_cancelled_after =
53
+ let help = " Total number of cancel when running solve requests" in
54
+ Counter. v ~help ~namespace ~subsystem " cancel_when_running_solve"
55
+
56
+ end
57
+
15
58
(* If a local package has a literal constraint on OCaml's version and it doesn't match
16
59
the platform, we just remove that package from the set to test, so other packages
17
60
can still be tested. *)
@@ -47,6 +90,7 @@ let solve_for_platform ?cancelled t ~log ~opam_repository_commits ~packages ~roo
47
90
) else (
48
91
let slice = { Domain_worker. vars; root_pkgs; packages; pinned_pkgs; cancelled } in
49
92
match Pool. use t.pool slice with
93
+ | Error `Cancelled -> Error `Cancelled
50
94
| Error (`Msg m ) -> Error (`Msg m)
51
95
| Ok (results , time ) ->
52
96
match results with
@@ -115,12 +159,15 @@ let solve ?cancelled t ~log request =
115
159
in
116
160
Log. info log " Solving for %a" Fmt. (list ~sep: comma string ) root_pkgs;
117
161
let serious_errors = ref [] in
162
+ let cancels_without_running = ref 0 in
118
163
let *! root_pkgs = parse_opams request.root_pkgs in
119
164
let *! pinned_pkgs = parse_opams request.pinned_pkgs in
120
165
let *! packages = Stores. packages t.stores opam_repository_commits in
121
166
let results =
122
167
platforms
123
168
|> Fiber.List. map (fun (id , vars ) ->
169
+ Prometheus.Counter. inc_one Metrics. request_handling_total;
170
+ Metrics. update_request_handling t.pool;
124
171
let result =
125
172
solve_for_platform t id
126
173
?cancelled
@@ -132,30 +179,42 @@ let solve ?cancelled t ~log request =
132
179
~pins
133
180
~vars
134
181
in
182
+ Metrics. update_request_handling t.pool;
135
183
(id, result)
136
184
)
137
185
|> List. filter_map (fun (id , result ) ->
138
186
Log. info log " = %s =" id;
139
187
match result with
140
188
| Ok result ->
189
+ Prometheus.Counter. inc_one Metrics. request_ok;
141
190
Log. info log " -> @[<hov>%a@]"
142
191
Fmt. (list ~sep: sp string )
143
192
result.Selection. packages;
144
193
Log. info log " (valid since opam-repository commit(s): @[%a@])"
145
194
Fmt. (list ~sep: semi (pair ~sep: comma string string ))
146
195
result.Selection. commits;
147
196
Some result
197
+ | Error `Cancelled ->
198
+ Prometheus.Counter. inc_one Metrics. request_cancelled;
199
+ incr cancels_without_running;
200
+ Log. info log " %s" " Cancelled" ;
201
+ None
148
202
| Error (`No_solution msg ) ->
203
+ Prometheus.Counter. inc_one Metrics. request_no_solution;
149
204
Log. info log " %s" msg;
150
205
None
151
206
| Error (`Msg msg ) ->
207
+ Prometheus.Counter. inc_one Metrics. request_fail;
152
208
Log. info log " %s" msg;
153
209
serious_errors := msg :: ! serious_errors;
154
210
None
155
211
)
156
212
in
157
213
match cancelled with
158
- | Some p when Promise. is_resolved p -> Error `Cancelled
214
+ | Some p when Promise. is_resolved p ->
215
+ let cancels = (List. length platforms) - (! cancels_without_running) in
216
+ Prometheus.Counter. inc Metrics. request_cancelled_after (float_of_int cancels);
217
+ Error `Cancelled
159
218
| _ ->
160
219
match ! serious_errors with
161
220
| [] -> Ok results
0 commit comments