Skip to content

Commit

Permalink
Merge pull request #238 from mtelvers/cache-stats
Browse files Browse the repository at this point in the history
Added basic Obuilder cache statistics to Prometheus
  • Loading branch information
tmcgilchrist authored Sep 13, 2023
2 parents a0f5e04 + 56dd4bf commit ec98613
Show file tree
Hide file tree
Showing 3 changed files with 21 additions and 0 deletions.
15 changes: 15 additions & 0 deletions worker/cluster_worker.ml
Original file line number Diff line number Diff line change
Expand Up @@ -37,6 +37,14 @@ module Metrics = struct
let unhealthy =
let help = "Number of unhealthy workers" in
Gauge.v ~help ~namespace ~subsystem "unhealthy"

let cache_hits =
let help = "Number of OBuilder cache hits" in
Gauge.v ~help ~namespace ~subsystem "cache_hits"

let cache_misses =
let help = "Number of OBuilder cache misses" in
Gauge.v ~help ~namespace ~subsystem "cache_misses"
end

let buildkit_env =
Expand Down Expand Up @@ -282,6 +290,10 @@ let check_health t ~last_healthcheck ~queue = function
aux ~active:true
)

let cache_stats = function
| None -> 0, 0 (* Not using OBuilder *)
| Some obuilder -> Obuilder_build.cache_stats obuilder

let loop ~switch ?obuilder t queue =
let last_healthcheck = ref (Unix.gettimeofday ()) in
let rec loop () =
Expand Down Expand Up @@ -336,6 +348,9 @@ let loop ~switch ?obuilder t queue =
(fun () ->
t.in_use <- t.in_use - 1;
Prometheus.Gauge.set Metrics.running_jobs (float_of_int t.in_use);
let h, m = cache_stats obuilder in
Prometheus.Gauge.set Metrics.cache_hits (float_of_int h);
Prometheus.Gauge.set Metrics.cache_misses (float_of_int m);
Lwt_switch.turn_off switch >>= fun () ->
Lwt_condition.broadcast t.cond ();
Lwt.return_unit)
Expand Down
4 changes: 4 additions & 0 deletions worker/obuilder_build.ml
Original file line number Diff line number Diff line change
Expand Up @@ -139,3 +139,7 @@ let build t ~switch ~log ~spec ~src_dir ~secrets =
let healthcheck t =
let Builder ((module Builder), builder) = t.builder in
Builder.healthcheck builder

let cache_stats t =
let Builder ((module Builder), builder) = t.builder in
Builder.cache_stats builder
2 changes: 2 additions & 0 deletions worker/obuilder_build.mli
Original file line number Diff line number Diff line change
Expand Up @@ -18,3 +18,5 @@ val build : t ->
secrets:(string * string) list -> (string, [ `Cancelled | `Msg of string ]) Lwt_result.t

val healthcheck : t -> (unit, [> `Msg of string]) Lwt_result.t

val cache_stats : t -> int * int

0 comments on commit ec98613

Please sign in to comment.