@@ -3,10 +3,15 @@ open Prometheus
3
3
let namespace = " baseimages"
4
4
let subsystem = " pipeline"
5
5
6
- let family =
6
+ let platform_family =
7
7
let help = " Number of images by platform" in
8
8
Gauge. v_labels ~label_names: [" platform" ; " state" ] ~help ~namespace ~subsystem
9
- " image_state_total"
9
+ " image_platform_state_total"
10
+
11
+ let version_family =
12
+ let help = " Number of images by OCaml version" in
13
+ Gauge. v_labels ~label_names: [" version" ; " state" ] ~help ~namespace ~subsystem
14
+ " image_version_state_total"
10
15
11
16
let last_build_time =
12
17
let help = " When the images were last built, in unix time" in
@@ -19,31 +24,61 @@ let image_valid_time =
19
24
type stats = { ok : int ; failed : int ; active : int }
20
25
let stats_empty = { ok = 0 ; failed = 0 ; active = 0 }
21
26
22
- let update () =
23
- let incr_stats stats = function
24
- | Index. Ok -> { stats with ok = stats.ok + 1 }
25
- | Index. Failed -> { stats with failed = stats.failed + 1 }
26
- | Index. Active -> { stats with active = stats.active + 1 }
27
- in
27
+ open Index
28
+
29
+ let incr_stats stats = function
30
+ | Ok -> { stats with ok = stats.ok + 1 }
31
+ | Failed -> { stats with failed = stats.failed + 1 }
32
+ | Active -> { stats with active = stats.active + 1 }
33
+
34
+ let update_images_per_platform ocaml_images non_ocaml_images =
28
35
let f opam_map platform sm =
29
36
let stats =
30
- Index. Switch_map. fold
37
+ Switch_map. fold
31
38
(fun _ state stats -> incr_stats stats state)
32
39
sm stats_empty
33
40
in
34
41
let stats =
35
- Option. map (incr_stats stats) (Index. Platform_map. find_opt platform opam_map)
42
+ Option. map (incr_stats stats) (Platform_map. find_opt platform opam_map)
36
43
|> Option. value ~default: stats
37
44
in
38
- Gauge. set (Gauge. labels family [platform; " ok" ]) (float_of_int stats.ok);
39
- Gauge. set (Gauge. labels family [platform; " failed" ]) (float_of_int stats.failed);
40
- Gauge. set (Gauge. labels family [platform; " active" ]) (float_of_int stats.active)
45
+ Gauge. set (Gauge. labels platform_family [platform; " ok" ])
46
+ (float_of_int stats.ok);
47
+ Gauge. set (Gauge. labels platform_family [platform; " failed" ])
48
+ (float_of_int stats.failed);
49
+ Gauge. set (Gauge. labels platform_family [platform; " active" ])
50
+ (float_of_int stats.active)
51
+ in
52
+ Platform_map. iter (f non_ocaml_images) ocaml_images
53
+
54
+ let update_images_per_version ocaml_images =
55
+ let f v state acc =
56
+ let stats =
57
+ Option. value ~default: stats_empty @@ Switch_map. find_opt v acc
58
+ in
59
+ Switch_map. add v (incr_stats stats state) acc
41
60
in
42
- let v = Index. get_images_per_platform () in
43
- Index.Platform_map. iter (f (snd v)) (fst v)
61
+ let stats =
62
+ Platform_map. fold (fun _ sm acc -> Switch_map. fold f sm acc)
63
+ ocaml_images Switch_map. empty
64
+ in
65
+ Switch_map. iter (fun v stats ->
66
+ let version = Ocaml_version. to_string v in
67
+ Gauge. set (Gauge. labels version_family [version; " ok" ])
68
+ (float_of_int stats.ok);
69
+ Gauge. set (Gauge. labels version_family [version; " failed" ])
70
+ (float_of_int stats.failed);
71
+ Gauge. set (Gauge. labels version_family [version; " active" ])
72
+ (float_of_int stats.active))
73
+ stats
74
+
75
+ let update () =
76
+ let ocaml_images, non_ocaml_images = get_images_per_platform () in
77
+ update_images_per_platform ocaml_images non_ocaml_images;
78
+ update_images_per_version ocaml_images
44
79
45
80
let init_last_build_time () =
46
- Index. get_latest_build_time ()
81
+ get_latest_build_time ()
47
82
|> Option. iter (Gauge. set last_build_time);
48
83
Gauge. set image_valid_time
49
84
(float_of_int @@ Conf. days_between_rebuilds * 60 * 60 * 24 )
0 commit comments