From 794114bf98774d0ab8a4894abf570b6ebf9beafe Mon Sep 17 00:00:00 2001 From: Gabriel Moise Date: Tue, 2 Jul 2024 12:27:41 +0100 Subject: [PATCH 1/5] Manifest: Remove prometheus from data only dirs --- dune | 2 +- manifest/main.ml | 2 -- 2 files changed, 1 insertion(+), 3 deletions(-) diff --git a/dune b/dune index bf853fa18147..c3c7d8e6c601 100644 --- a/dune +++ b/dune @@ -1,6 +1,6 @@ (vendored_dirs vendors) -(data_only_dirs _opam-repo-for-release prometheus) +(data_only_dirs _opam-repo-for-release) (env (_ diff --git a/manifest/main.ml b/manifest/main.ml index ba88add8f878..d67806a132c0 100644 --- a/manifest/main.ml +++ b/manifest/main.ml @@ -72,8 +72,6 @@ let exclude filename = | ["opam"; "mandatory-for-make.opam"] -> true (* opam-repository is used by scripts/opam-release.sh *) | "opam-repository" :: _ -> true - (* prometheus is imported as data-only for now to ease review of its monorepotisation. *) - | "prometheus" :: _ -> true (* We need to tell Dune about excluding directories without defining targets in those directories. Therefore we hand write some Dune in these. *) | "src" :: "riscv" :: _ -> true -- GitLab From 0c444753507dd2815d6fffc789c2857d0cf84aff Mon Sep 17 00:00:00 2001 From: Gabriel Moise Date: Wed, 3 Jul 2024 10:02:23 +0100 Subject: [PATCH 2/5] Prometheus: Formatting --- prometheus/app/prometheus_app.ml | 174 ++++++++------ prometheus/app/prometheus_app.mli | 7 +- prometheus/app/prometheus_unix.ml | 104 +++++---- prometheus/app/prometheus_unix.mli | 17 +- prometheus/examples/example.ml | 20 +- prometheus/src/prometheus.ml | 355 +++++++++++++++++------------ prometheus/src/prometheus.mli | 130 ++++++----- prometheus/tests/test.ml | 195 ++++++++-------- 8 files changed, 587 insertions(+), 415 deletions(-) diff --git a/prometheus/app/prometheus_app.ml b/prometheus/app/prometheus_app.ml index 6707b2dc7117..37a261126908 100644 --- a/prometheus/app/prometheus_app.ml +++ b/prometheus/app/prometheus_app.ml @@ -1,10 +1,10 @@ open Prometheus -let failf fmt = - Fmt.kstr failwith fmt +let failf fmt = Fmt.kstr failwith fmt module TextFormat_0_0_4 = struct let re_unquoted_escapes = Re.compile @@ Re.set "\\\n" + let re_quoted_escapes = Re.compile @@ Re.set "\"\\\n" let quote g = @@ -15,9 +15,9 @@ module TextFormat_0_0_4 = struct | x -> failf "Unexpected match %S" x let output_metric_type f = function - | Counter -> Fmt.string f "counter" - | Gauge -> Fmt.string f "gauge" - | Summary -> Fmt.string f "summary" + | Counter -> Fmt.string f "counter" + | Gauge -> Fmt.string f "gauge" + | Summary -> Fmt.string f "summary" | Histogram -> Fmt.string f "histogram" let output_unquoted f s = @@ -29,8 +29,7 @@ module TextFormat_0_0_4 = struct (* Fmt.float by default prints floats using scientific exponential * notation, which loses significant data on e.g. timestamp: * Fmt.str "%a" Fmt.float 1575363850.57 --> 1.57536e+09 *) - let float_fmt f = - Fmt.pf f "%f" + let float_fmt f = Fmt.pf f "%f" let output_value f v = match classify_float v with @@ -42,8 +41,7 @@ module TextFormat_0_0_4 = struct let output_pairs f (label_names, label_values) = let cont = ref false in let output_pair name value = - if !cont then Fmt.string f ", " - else cont := true; + if !cont then Fmt.string f ", " else cont := true ; Fmt.pf f "%a=\"%a\"" LabelName.pp name output_quoted value in List.iter2 output_pair label_names label_values @@ -52,17 +50,25 @@ module TextFormat_0_0_4 = struct | [] -> () | label_values -> Fmt.pf f "{%a}" output_pairs (label_names, label_values) - let output_sample ~base ~label_names ~label_values f { Sample_set.ext; value; bucket } = - let label_names, label_values = match bucket with - | None -> label_names, label_values + let output_sample ~base ~label_names ~label_values f + {Sample_set.ext; value; bucket} = + let label_names, label_values = + match bucket with + | None -> (label_names, label_values) | Some (label_name, label_value) -> - let label_value_str = Fmt.str "%a" output_value label_value in - label_name :: label_names, label_value_str :: label_values + let label_value_str = Fmt.str "%a" output_value label_value in + (label_name :: label_names, label_value_str :: label_values) in - Fmt.pf f "%a%s%a %a@." - MetricName.pp base ext - (output_labels ~label_names) label_values - output_value value + Fmt.pf + f + "%a%s%a %a@." + MetricName.pp + base + ext + (output_labels ~label_names) + label_values + output_value + value let output_metric ~name ~label_names f (label_values, samples) = List.iter (output_sample ~base:name ~label_names ~label_values f) samples @@ -70,96 +76,128 @@ module TextFormat_0_0_4 = struct let output f = MetricFamilyMap.iter (fun metric samples -> let {MetricInfo.name; metric_type; help; label_names} = metric in - Fmt.pf f - "#HELP %a %a@.\ - #TYPE %a %a@.\ - %a" - MetricName.pp name output_unquoted help - MetricName.pp name output_metric_type metric_type - (LabelSetMap.pp ~sep:Fmt.nop (output_metric ~name ~label_names)) samples - ) + Fmt.pf + f + "#HELP %a %a@.#TYPE %a %a@.%a" + MetricName.pp + name + output_unquoted + help + MetricName.pp + name + output_metric_type + metric_type + (LabelSetMap.pp ~sep:Fmt.nop (output_metric ~name ~label_names)) + samples) end module Runtime = struct let current = ref (Gc.quick_stat ()) - let update () = - current := Gc.quick_stat () + + let update () = current := Gc.quick_stat () let simple_metric ~metric_type ~help name fn = - let info = { - MetricInfo. - name = MetricName.v name; - help; - metric_type; - label_names = []; - } - in - let collect () = - LabelSetMap.singleton [] [Sample_set.sample (fn ())] + let info = + {MetricInfo.name = MetricName.v name; help; metric_type; label_names = []} in - info, collect + let collect () = LabelSetMap.singleton [] [Sample_set.sample (fn ())] in + (info, collect) let ocaml_gc_allocated_bytes = - simple_metric ~metric_type:Counter "ocaml_gc_allocated_bytes" Gc.allocated_bytes + simple_metric + ~metric_type:Counter + "ocaml_gc_allocated_bytes" + Gc.allocated_bytes ~help:"Total number of bytes allocated since the program was started." let ocaml_gc_major_words = - simple_metric ~metric_type:Counter "ocaml_gc_major_words" (fun () -> (!current).Gc.major_words) - ~help:"Number of words allocated in the major heap since the program was started." + simple_metric + ~metric_type:Counter + "ocaml_gc_major_words" + (fun () -> !current.Gc.major_words) + ~help: + "Number of words allocated in the major heap since the program was \ + started." let ocaml_gc_minor_collections = - simple_metric ~metric_type:Counter "ocaml_gc_minor_collections" (fun () -> float_of_int (!current).Gc.minor_collections) - ~help:"Number of minor collection cycles completed since the program was started." + simple_metric + ~metric_type:Counter + "ocaml_gc_minor_collections" + (fun () -> float_of_int !current.Gc.minor_collections) + ~help: + "Number of minor collection cycles completed since the program was \ + started." let ocaml_gc_major_collections = - simple_metric ~metric_type:Counter "ocaml_gc_major_collections" (fun () -> float_of_int (!current).Gc.major_collections) - ~help:"Number of major collection cycles completed since the program was started." + simple_metric + ~metric_type:Counter + "ocaml_gc_major_collections" + (fun () -> float_of_int !current.Gc.major_collections) + ~help: + "Number of major collection cycles completed since the program was \ + started." let ocaml_gc_heap_words = - simple_metric ~metric_type:Gauge "ocaml_gc_heap_words" (fun () -> float_of_int (!current).Gc.heap_words) + simple_metric + ~metric_type:Gauge + "ocaml_gc_heap_words" + (fun () -> float_of_int !current.Gc.heap_words) ~help:"Total size of the major heap, in words." let ocaml_gc_compactions = - simple_metric ~metric_type:Counter "ocaml_gc_compactions" (fun () -> float_of_int (!current).Gc.compactions) + simple_metric + ~metric_type:Counter + "ocaml_gc_compactions" + (fun () -> float_of_int !current.Gc.compactions) ~help:"Number of heap compactions since the program was started." let ocaml_gc_top_heap_words = - simple_metric ~metric_type:Counter "ocaml_gc_top_heap_words" (fun () -> float_of_int (!current).Gc.top_heap_words) + simple_metric + ~metric_type:Counter + "ocaml_gc_top_heap_words" + (fun () -> float_of_int !current.Gc.top_heap_words) ~help:"Maximum size reached by the major heap, in words." let process_cpu_seconds_total = - simple_metric ~metric_type:Counter "process_cpu_seconds_total" Sys.time + simple_metric + ~metric_type:Counter + "process_cpu_seconds_total" + Sys.time ~help:"Total user and system CPU time spent in seconds." - let metrics = [ - ocaml_gc_allocated_bytes; - ocaml_gc_major_words; - ocaml_gc_minor_collections; - ocaml_gc_major_collections; - ocaml_gc_heap_words; - ocaml_gc_compactions; - ocaml_gc_top_heap_words; - process_cpu_seconds_total; - ] + let metrics = + [ + ocaml_gc_allocated_bytes; + ocaml_gc_major_words; + ocaml_gc_minor_collections; + ocaml_gc_major_collections; + ocaml_gc_heap_words; + ocaml_gc_compactions; + ocaml_gc_top_heap_words; + process_cpu_seconds_total; + ] end open Lwt.Infix -module Cohttp(Server : Cohttp_lwt.S.Server) = struct +module Cohttp (Server : Cohttp_lwt.S.Server) = struct let callback _conn req _body = let open Cohttp in let uri = Request.uri req in - match Request.meth req, Uri.path uri with + match (Request.meth req, Uri.path uri) with | `GET, "/metrics" -> - Prometheus.CollectorRegistry.(collect default) >>= fun data -> - let body = Fmt.to_to_string TextFormat_0_0_4.output data in - let headers = Header.init_with "Content-Type" "text/plain; version=0.0.4" in - Server.respond_string ~status:`OK ~headers ~body () + Prometheus.CollectorRegistry.(collect default) >>= fun data -> + let body = Fmt.to_to_string TextFormat_0_0_4.output data in + let headers = + Header.init_with "Content-Type" "text/plain; version=0.0.4" + in + Server.respond_string ~status:`OK ~headers ~body () | _ -> Server.respond_error ~status:`Bad_request ~body:"Bad request" () end let () = - CollectorRegistry.(register_pre_collect default) Runtime.update; + CollectorRegistry.(register_pre_collect default) Runtime.update ; let add (info, collector) = - CollectorRegistry.(register default) info collector in + CollectorRegistry.(register default) info collector + in List.iter add Runtime.metrics diff --git a/prometheus/app/prometheus_app.mli b/prometheus/app/prometheus_app.mli index f9c3c71df3e5..708047d8bf43 100644 --- a/prometheus/app/prometheus_app.mli +++ b/prometheus/app/prometheus_app.mli @@ -12,15 +12,16 @@ - This module does not depend on [Unix], and so can be used in unikernels. *) +(** Format a snapshot in Prometheus's text format, version 0.0.4. *) module TextFormat_0_0_4 : sig val output : Prometheus.CollectorRegistry.snapshot Fmt.t end -(** Format a snapshot in Prometheus's text format, version 0.0.4. *) +(** A Cohttp callback for a web-server that exposes the Prometheus metrics. *) module Cohttp (S : Cohttp_lwt.S.Server) : sig val callback : S.conn -> Cohttp.Request.t -> - Cohttp_lwt.Body.t -> (Cohttp.Response.t * Cohttp_lwt.Body.t) Lwt.t + Cohttp_lwt.Body.t -> + (Cohttp.Response.t * Cohttp_lwt.Body.t) Lwt.t end -(** A Cohttp callback for a web-server that exposes the Prometheus metrics. *) diff --git a/prometheus/app/prometheus_unix.ml b/prometheus/app/prometheus_unix.ml index eeecab929ccf..d594e7e23129 100644 --- a/prometheus/app/prometheus_unix.ml +++ b/prometheus/app/prometheus_unix.ml @@ -8,57 +8,61 @@ module Metrics = struct let inc_messages = let help = "Total number of messages logged" in let c = - Counter.v_labels ~label_names:[ "level"; "src" ] ~help ~namespace - ~subsystem "messages_total" + Counter.v_labels + ~label_names:["level"; "src"] + ~help + ~namespace + ~subsystem + "messages_total" in fun lvl src -> let lvl = Logs.level_to_string (Some lvl) in - Counter.inc_one @@ Counter.labels c [ lvl; src ] + Counter.inc_one @@ Counter.labels c [lvl; src] end module Unix_runtime = struct let start_time = Unix.gettimeofday () let simple_metric ~metric_type ~help name fn = - let info = { - MetricInfo. - name = MetricName.v name; - help; - metric_type; - label_names = []; - } + let info = + {MetricInfo.name = MetricName.v name; help; metric_type; label_names = []} in - let collect () = - LabelSetMap.singleton [] [Sample_set.sample (fn ())] - in - info, collect + let collect () = LabelSetMap.singleton [] [Sample_set.sample (fn ())] in + (info, collect) let process_start_time_seconds = - simple_metric ~metric_type:Counter "process_start_time_seconds" (fun () -> start_time) + simple_metric + ~metric_type:Counter + "process_start_time_seconds" + (fun () -> start_time) ~help:"Start time of the process since unix epoch in seconds." - let metrics = [ - process_start_time_seconds; - ] + let metrics = [process_start_time_seconds] end type config = int option -module Server = Prometheus_app.Cohttp(Cohttp_lwt_unix.Server) +module Server = Prometheus_app.Cohttp (Cohttp_lwt_unix.Server) let serve = function | None -> [] | Some port -> - let mode = `TCP (`Port port) in - let callback = Server.callback in - let thread = Cohttp_lwt_unix.Server.create ~mode (Cohttp_lwt_unix.Server.make ~callback ()) in - [thread] + let mode = `TCP (`Port port) in + let callback = Server.callback in + let thread = + Cohttp_lwt_unix.Server.create + ~mode + (Cohttp_lwt_unix.Server.make ~callback ()) + in + [thread] let listen_prometheus = let open! Cmdliner in let doc = - Arg.info ~docs:"MONITORING OPTIONS" ~docv:"PORT" ~doc: - "Port on which to provide Prometheus metrics over HTTP." + Arg.info + ~docs:"MONITORING OPTIONS" + ~docv:"PORT" + ~doc:"Port on which to provide Prometheus metrics over HTTP." ["listen-prometheus"] in Arg.(value @@ opt (some int) None doc) @@ -67,7 +71,8 @@ let opts = listen_prometheus let () = let add (info, collector) = - CollectorRegistry.(register default) info collector in + CollectorRegistry.(register default) info collector + in List.iter add Unix_runtime.metrics module Logging = struct @@ -76,33 +81,52 @@ module Logging = struct let pp_timestamp f x = let open Unix in let tm = localtime x in - Fmt.pf f "%04d-%02d-%02d %02d:%02d.%02d" (tm.tm_year + 1900) (tm.tm_mon + 1) - tm.tm_mday tm.tm_hour tm.tm_min tm.tm_sec + Fmt.pf + f + "%04d-%02d-%02d %02d:%02d.%02d" + (tm.tm_year + 1900) + (tm.tm_mon + 1) + tm.tm_mday + tm.tm_hour + tm.tm_min + tm.tm_sec let reporter formatter = let report src level ~over k msgf = - let k _ = over (); k () in + let k _ = + over () ; + k () + in let src = Logs.Src.name src in - Metrics.inc_messages level src; + Metrics.inc_messages level src ; msgf @@ fun ?header ?tags:_ fmt -> - Fmt.kpf k formatter ("%a %a %a @[" ^^ fmt ^^ "@]@.") - pp_timestamp (Unix.gettimeofday ()) - Fmt.(styled `Magenta string) (Printf.sprintf "%14s" src) - Logs_fmt.pp_header (level, header) + Fmt.kpf + k + formatter + ("%a %a %a @[" ^^ fmt ^^ "@]@.") + pp_timestamp + (Unix.gettimeofday ()) + Fmt.(styled `Magenta string) + (Printf.sprintf "%14s" src) + Logs_fmt.pp_header + (level, header) in - { Logs.report = report } + {Logs.report} let set_level (src, level) = let rec aux = function - | [] -> Logs.warn (fun f -> f "set_level: logger %S not registered; ignoring" src) + | [] -> + Logs.warn (fun f -> + f "set_level: logger %S not registered; ignoring" src) | x :: _ when Logs.Src.name x = src -> Logs.Src.set_level x (Some level) | _ :: xs -> aux xs in aux (Logs.Src.list ()) - let init ?(default_level=Logs.Info) ?(levels=[]) ?(formatter=Fmt.stderr) () = - Fmt_tty.setup_std_outputs (); - Logs.set_reporter (reporter formatter); - Logs.set_level (Some default_level); + let init ?(default_level = Logs.Info) ?(levels = []) ?(formatter = Fmt.stderr) + () = + Fmt_tty.setup_std_outputs () ; + Logs.set_reporter (reporter formatter) ; + Logs.set_level (Some default_level) ; List.iter set_level levels end diff --git a/prometheus/app/prometheus_unix.mli b/prometheus/app/prometheus_unix.mli index 69131e60b20f..b55ad8f41433 100644 --- a/prometheus/app/prometheus_unix.mli +++ b/prometheus/app/prometheus_unix.mli @@ -15,22 +15,17 @@ type config -val serve : config -> unit Lwt.t list (** [serve config] starts a Cohttp server according to config. It returns a singleton list containing the thread to monitor, or an empty list if no server is configured. *) +val serve : config -> unit Lwt.t list -val opts : config Cmdliner.Term.t (** [opts] is the extra command-line options to offer Prometheus monitoring. *) +val opts : config Cmdliner.Term.t (** Report metrics for messages logged. *) module Logging : sig - val init : - ?default_level:Logs.level -> - ?levels:(string * Logs.level) list -> - ?formatter:Format.formatter -> - unit -> unit (** Initialise the Logs library with a reporter that reports prometheus metrics too. The reporter is configured to log to stderr and the log messages include a timestamp and the event's source. @@ -52,9 +47,15 @@ module Logging : sig @param default_level The default log-level to use (default {!Logs.Info}). @param levels Provides levels for specific log sources. @param formatter A custom formatter (default {!Fmt.stderr}). *) + val init : + ?default_level:Logs.level -> + ?levels:(string * Logs.level) list -> + ?formatter:Format.formatter -> + unit -> + unit - val inc_counter : Logs.level -> string -> unit (** [inc_counter level src] increments the count of messages logged by [src] at [level]. The reporter installed by [init] calls this automatically, but you might want to use this if you use your own reporter instead. *) + val inc_counter : Logs.level -> string -> unit end diff --git a/prometheus/examples/example.ml b/prometheus/examples/example.ml index d56baecc1d4d..de6959bc6c93 100644 --- a/prometheus/examples/example.ml +++ b/prometheus/examples/example.ml @@ -10,6 +10,7 @@ module Metrics = struct open Prometheus let namespace = "MyProg" + let subsystem = "main" let ticks_counted_total = @@ -19,8 +20,8 @@ end let rec counter () = Lwt_unix.sleep 1.0 >>= fun () -> - print_endline "Tick!"; - Prometheus.Counter.inc_one Metrics.ticks_counted_total; + print_endline "Tick!" ; + Prometheus.Counter.inc_one Metrics.ticks_counted_total ; counter () let main prometheus_config = @@ -31,16 +32,17 @@ open Cmdliner (* Optional: configure logging *) let () = - Prometheus_unix.Logging.init () + Prometheus_unix.Logging.init + () ~default_level:Logs.Debug - ~levels:[ - "cohttp.lwt.io", Logs.Info; - ] + ~levels:[("cohttp.lwt.io", Logs.Info)] let () = - Logs.info (fun f -> f "Logging initialised."); - print_endline "If run with the option --listen-prometheus=9090, this program serves metrics at\n\ - http://localhost:9090/metrics"; + Logs.info (fun f -> f "Logging initialised.") ; + print_endline + "If run with the option --listen-prometheus=9090, this program serves \ + metrics at\n\ + http://localhost:9090/metrics" ; let info = Cmd.info "example" in let cmd = Cmd.v info Term.(const main $ Prometheus_unix.opts) in exit @@ Cmd.eval cmd diff --git a/prometheus/src/prometheus.ml b/prometheus/src/prometheus.ml index 7077824022e6..6e37b0ec68f7 100644 --- a/prometheus/src/prometheus.ml +++ b/prometheus/src/prometheus.ml @@ -7,17 +7,20 @@ end module type NAME = sig type t = private string + val v : string -> t + val pp : Format.formatter -> t -> unit + val compare : t -> t -> int end -module Name(N : NAME_SPEC) : NAME = struct +module Name (N : NAME_SPEC) : NAME = struct type t = string let v name = if not (Re.execp N.valid name) then - failwith (Format.asprintf "Invalid name %S" name); + failwith (Format.asprintf "Invalid name %S" name) ; name let compare = String.compare @@ -25,31 +28,39 @@ module Name(N : NAME_SPEC) : NAME = struct let pp = Format.pp_print_string end -let alphabet = Re.(alt [ rg 'a' 'z'; rg 'A' 'Z' ]) +let alphabet = Re.(alt [rg 'a' 'z'; rg 'A' 'Z']) + module LabelName = struct (* "^[a-zA-Z_][a-zA-Z0-9_]*$" *) - let start = Re.alt [ alphabet; Re.char '_' ] - let rest = Re.alt [ start; Re.digit ] - include Name(struct let valid = Re.compile @@ Re.seq [ Re.bos; start; Re.rep rest; Re.eos] end) + let start = Re.alt [alphabet; Re.char '_'] + + let rest = Re.alt [start; Re.digit] + + include Name (struct + let valid = Re.compile @@ Re.seq [Re.bos; start; Re.rep rest; Re.eos] + end) end + module MetricName = struct (* "^[a-zA-Z_:][a-zA-Z0-9_:]*$" *) - let start = Re.alt [ LabelName.start; Re.char ':' ] - let rest = Re.alt [ start; Re.digit ] - include Name(struct let valid = Re.compile @@ Re.seq [ Re.bos; start; Re.rep rest; Re.eos] end) + let start = Re.alt [LabelName.start; Re.char ':'] + + let rest = Re.alt [start; Re.digit] + + include Name (struct + let valid = Re.compile @@ Re.seq [Re.bos; start; Re.rep rest; Re.eos] + end) end -type metric_type = - | Counter - | Gauge - | Summary - | Histogram +type metric_type = Counter | Gauge | Summary | Histogram module LabelSet = struct type t = string list - let compare (a:t) (b:t) = compare a b + + let compare (a : t) (b : t) = compare a b end -module LabelSetMap = Map.Make(LabelSet) + +module LabelSetMap = Map.Make (LabelSet) module MetricInfo = struct type t = { @@ -59,23 +70,16 @@ module MetricInfo = struct label_names : LabelName.t list; } - let pp_opt () = function - | None -> "" - | Some v -> v ^ "_" + let pp_opt () = function None -> "" | Some v -> v ^ "_" - let v ~help ?(label_names=[]) ~metric_type ?namespace ?subsystem name = + let v ~help ?(label_names = []) ~metric_type ?namespace ?subsystem name = let name = Printf.sprintf "%a%a%s" pp_opt namespace pp_opt subsystem name in - { - name = MetricName.v name; - metric_type; - help; - label_names; - } + {name = MetricName.v name; metric_type; help; label_names} let compare a b = MetricName.compare a.name b.name end -module MetricFamilyMap = Map.Make(MetricInfo) +module MetricFamilyMap = Map.Make (MetricInfo) module Sample_set = struct type sample = { @@ -86,25 +90,27 @@ module Sample_set = struct type t = sample list - let sample ?(ext="") ?bucket value = { ext; value; bucket } + let sample ?(ext = "") ?bucket value = {ext; value; bucket} end module CollectorRegistry = struct type t = { - mutable metrics : (unit -> Sample_set.t LabelSetMap.t ) MetricFamilyMap.t; - mutable metrics_lwt : (unit -> Sample_set.t LabelSetMap.t Lwt.t) MetricFamilyMap.t; - mutable pre_collect : (unit -> unit ) list; + mutable metrics : (unit -> Sample_set.t LabelSetMap.t) MetricFamilyMap.t; + mutable metrics_lwt : + (unit -> Sample_set.t LabelSetMap.t Lwt.t) MetricFamilyMap.t; + mutable pre_collect : (unit -> unit) list; mutable pre_collect_lwt : (unit -> unit Lwt.t) list; } type snapshot = Sample_set.t LabelSetMap.t MetricFamilyMap.t - let create () = { - metrics = MetricFamilyMap.empty; - metrics_lwt = MetricFamilyMap.empty; - pre_collect = []; - pre_collect_lwt = []; - } + let create () = + { + metrics = MetricFamilyMap.empty; + metrics_lwt = MetricFamilyMap.empty; + pre_collect = []; + pre_collect_lwt = []; + } let default = create () @@ -113,16 +119,22 @@ module CollectorRegistry = struct let register_pre_collect_lwt t f = t.pre_collect_lwt <- f :: t.pre_collect_lwt let ensure_not_registered t info = - if MetricFamilyMap.mem info t.metrics || - MetricFamilyMap.mem info t.metrics_lwt - then failwith (Format.asprintf "%a already registered" MetricName.pp info.MetricInfo.name) + if + MetricFamilyMap.mem info t.metrics + || MetricFamilyMap.mem info t.metrics_lwt + then + failwith + (Format.asprintf + "%a already registered" + MetricName.pp + info.MetricInfo.name) let register t info collector = - ensure_not_registered t info; + ensure_not_registered t info ; t.metrics <- MetricFamilyMap.add info collector t.metrics let register_lwt t info collector = - ensure_not_registered t info; + ensure_not_registered t info ; t.metrics_lwt <- MetricFamilyMap.add info collector t.metrics_lwt open Lwt.Infix @@ -130,41 +142,68 @@ module CollectorRegistry = struct let map_p m = MetricFamilyMap.fold (fun k f acc -> (k, f ()) :: acc) m [] |> Lwt_list.fold_left_s - (fun acc (k, v) -> v >|= fun v -> MetricFamilyMap.add k v acc) - MetricFamilyMap.empty + (fun acc (k, v) -> v >|= fun v -> MetricFamilyMap.add k v acc) + MetricFamilyMap.empty let collect t = - List.iter (fun f -> f ()) t.pre_collect; + List.iter (fun f -> f ()) t.pre_collect ; Lwt_list.iter_p (fun f -> f ()) t.pre_collect_lwt >>= fun () -> let metrics = MetricFamilyMap.map (fun f -> f ()) t.metrics in map_p t.metrics_lwt >|= fun metrics_lwt -> MetricFamilyMap.merge - (fun _ v1 v2 -> - match v1 with - | Some v1 -> Some v1 - | None -> v2) - metrics metrics_lwt - + (fun _ v1 v2 -> match v1 with Some v1 -> Some v1 | None -> v2) + metrics + metrics_lwt end module type METRIC = sig type family + type t - val v_labels : label_names:string list -> ?registry:CollectorRegistry.t -> help:string -> ?namespace:string -> ?subsystem:string -> string -> family + + val v_labels : + label_names:string list -> + ?registry:CollectorRegistry.t -> + help:string -> + ?namespace:string -> + ?subsystem:string -> + string -> + family + val labels : family -> string list -> t - val v_label : label_name:string -> ?registry:CollectorRegistry.t -> help:string -> ?namespace:string -> ?subsystem:string -> string -> (string -> t) - val v : ?registry:CollectorRegistry.t -> help:string -> ?namespace:string -> ?subsystem:string -> string -> t + + val v_label : + label_name:string -> + ?registry:CollectorRegistry.t -> + help:string -> + ?namespace:string -> + ?subsystem:string -> + string -> + string -> + t + + val v : + ?registry:CollectorRegistry.t -> + help:string -> + ?namespace:string -> + ?subsystem:string -> + string -> + t end module type CHILD = sig type t + val create : unit -> t + val values : t -> Sample_set.t + val metric_type : metric_type + val validate_label : string -> unit end -module Metric(Child : CHILD) : sig +module Metric (Child : CHILD) : sig include METRIC with type t = Child.t end = struct type family = { @@ -174,133 +213,150 @@ end = struct type t = Child.t - let collect t = - LabelSetMap.map Child.values t.children + let collect t = LabelSetMap.map Child.values t.children - let v_labels ~label_names ?(registry=CollectorRegistry.default) ~help ?namespace ?subsystem name = - List.iter Child.validate_label label_names; + let v_labels ~label_names ?(registry = CollectorRegistry.default) ~help + ?namespace ?subsystem name = + List.iter Child.validate_label label_names ; let label_names = List.map LabelName.v label_names in - let metric = MetricInfo.v ~metric_type:Child.metric_type ~help ~label_names ?namespace ?subsystem name in - let t = { - metric; - children = LabelSetMap.empty; - } in - CollectorRegistry.register registry metric (fun () -> collect t); + let metric = + MetricInfo.v + ~metric_type:Child.metric_type + ~help + ~label_names + ?namespace + ?subsystem + name + in + let t = {metric; children = LabelSetMap.empty} in + CollectorRegistry.register registry metric (fun () -> collect t) ; t let labels t label_values = - assert (List.length t.metric.MetricInfo.label_names = List.length label_values); + assert ( + List.length t.metric.MetricInfo.label_names = List.length label_values) ; match LabelSetMap.find label_values t.children with | Some child -> child | None -> - let child = Child.create () in - t.children <- LabelSetMap.add label_values child t.children; - child + let child = Child.create () in + t.children <- LabelSetMap.add label_values child t.children ; + child let v_label ~label_name ?registry ~help ?namespace ?subsystem name = - let family = v_labels ~label_names:[label_name] ?registry ~help ?namespace ?subsystem name in + let family = + v_labels + ~label_names:[label_name] + ?registry + ~help + ?namespace + ?subsystem + name + in fun x -> labels family [x] let v ?registry ~help ?namespace ?subsystem name = - let family = v_labels ~help ?registry ?namespace ?subsystem name ~label_names:[] in + let family = + v_labels ~help ?registry ?namespace ?subsystem name ~label_names:[] + in labels family [] end module Counter = struct - include Metric(struct - type t = float ref - let create () = ref 0.0 - let values t = [Sample_set.sample !t] - let metric_type = Counter - let validate_label _ = () - end) + include Metric (struct + type t = float ref + + let create () = ref 0.0 + + let values t = [Sample_set.sample !t] + + let metric_type = Counter + + let validate_label _ = () + end) - let inc_one t = - t := !t +. 1.0 + let inc_one t = t := !t +. 1.0 let inc t v = - assert (v >= 0.0); + assert (v >= 0.0) ; t := !t +. v end module Gauge = struct - include Metric(struct - type t = float ref - let create () = ref 0.0 - let values t = [Sample_set.sample !t] - let metric_type = Gauge - let validate_label _ = () - end) + include Metric (struct + type t = float ref + + let create () = ref 0.0 + + let values t = [Sample_set.sample !t] + + let metric_type = Gauge + + let validate_label _ = () + end) + + let inc t v = t := !t +. v - let inc t v = - t := !t +. v let inc_one t = inc t 1.0 - let dec t x = inc t (-. x) + let dec t x = inc t (-.x) + let dec_one t = dec t 1.0 - let set t v = - t := v + let set t v = t := v let track_inprogress t fn = - inc_one t; - Lwt.finalize fn (fun () -> dec_one t; Lwt.return_unit) + inc_one t ; + Lwt.finalize fn (fun () -> + dec_one t ; + Lwt.return_unit) let time t gettimeofday fn = let start = gettimeofday () in - Lwt.finalize fn - (fun () -> - let finish = gettimeofday () in - inc t (finish -. start); - Lwt.return_unit - ) + Lwt.finalize fn (fun () -> + let finish = gettimeofday () in + inc t (finish -. start) ; + Lwt.return_unit) end module Summary = struct module Child = struct - type t = { - mutable count : float; - mutable sum : float; - } - let create () = { count = 0.0; sum = 0.0 } + type t = {mutable count : float; mutable sum : float} + + let create () = {count = 0.0; sum = 0.0} + let values t = [ Sample_set.sample ~ext:"_sum" t.sum; Sample_set.sample ~ext:"_count" t.count; ] + let metric_type = Summary let validate_label = function | "quantile" -> failwith "Can't use special label 'quantile' in summary" | _ -> () end - include Metric(Child) + + include Metric (Child) let observe t v = let open Child in - t.count <- t.count +. 1.0; + t.count <- t.count +. 1.0 ; t.sum <- t.sum +. v let time t gettimeofday fn = let start = gettimeofday () in - Lwt.finalize fn - (fun () -> - let finish = gettimeofday () in - observe t (finish -. start); - Lwt.return_unit - ) + Lwt.finalize fn (fun () -> + let finish = gettimeofday () in + observe t (finish -. start) ; + Lwt.return_unit) end module Histogram_spec = struct type t = float array (* Upper bounds *) let make at_index_f count = - let real_at_index i = - if i >= count then - infinity - else - at_index_f i - in + let real_at_index i = if i >= count then infinity else at_index_f i in Array.init (count + 1) real_at_index let of_linear start interval count = @@ -312,7 +368,7 @@ module Histogram_spec = struct let of_exponential start factor count = let at_index i = - let multiplier = factor ** (float_of_int i) in + let multiplier = factor ** float_of_int i in start *. multiplier in make at_index count @@ -323,10 +379,7 @@ module Histogram_spec = struct (* The index at which to record a value [v]. *) let index t v = - let rec aux index = - if v <= t.(index) then index - else aux (index + 1) - in + let rec aux index = if v <= t.(index) then index else aux (index + 1) in aux 0 end @@ -336,7 +389,9 @@ end module type HISTOGRAM = sig include METRIC + val observe : t -> float -> unit + val time : t -> (unit -> float) -> (unit -> 'a Lwt.t) -> 'a Lwt.t end @@ -353,15 +408,15 @@ module Histogram (Buckets : BUCKETS) = struct let create () = let count = Array.length Buckets.spec in let counts = Array.make count 0. in - { upper_bounds = Buckets.spec; counts; sum = 0. } + {upper_bounds = Buckets.spec; counts; sum = 0.} let values t = let count = Array.length t.counts in let rec fold val_acc acc index = if index = count then - Sample_set.sample ~ext:"_sum" t.sum :: - Sample_set.sample ~ext:"_count" val_acc :: - acc + Sample_set.sample ~ext:"_sum" t.sum + :: Sample_set.sample ~ext:"_count" val_acc + :: acc else let val_acc = t.counts.(index) +. val_acc in let bucket = (bucket_label, t.upper_bounds.(index)) in @@ -377,29 +432,39 @@ module Histogram (Buckets : BUCKETS) = struct | _ -> () end - include Metric(Child) + include Metric (Child) let observe t v = let open Child in let index = Histogram_spec.index t.upper_bounds v in - t.counts.(index) <- t.counts.(index) +. 1.; + t.counts.(index) <- t.counts.(index) +. 1. ; t.sum <- t.sum +. v let time t gettimeofday fn = let start = gettimeofday () in - Lwt.finalize fn - (fun () -> - let finish = gettimeofday () in - observe t (finish -. start); - Lwt.return_unit - ) + Lwt.finalize fn (fun () -> + let finish = gettimeofday () in + observe t (finish -. start) ; + Lwt.return_unit) end -module DefaultHistogram = Histogram ( - struct - let spec = - Histogram_spec.of_list [0.005; 0.01; 0.025; 0.05; - 0.075; 0.1 ; 0.25 ; 0.5; - 0.75 ; 1. ; 2.5 ; 5.; - 7.5 ; 10. ] - end) +module DefaultHistogram = Histogram (struct + let spec = + Histogram_spec.of_list + [ + 0.005; + 0.01; + 0.025; + 0.05; + 0.075; + 0.1; + 0.25; + 0.5; + 0.75; + 1.; + 2.5; + 5.; + 7.5; + 10.; + ] +end) diff --git a/prometheus/src/prometheus.mli b/prometheus/src/prometheus.mli index e053680af1a9..588a12ab99d6 100644 --- a/prometheus/src/prometheus.mli +++ b/prometheus/src/prometheus.mli @@ -10,30 +10,27 @@ even though many applications will not enable it. Therefore it should have minimal dependencies. *) -type metric_type = - | Counter - | Gauge - | Summary - | Histogram +type metric_type = Counter | Gauge | Summary | Histogram +(** A string that meets some additional requirements. *) module type NAME = sig type t = private string - val v : string -> t (** Raises an exception if the name is not valid. *) + val v : string -> t val pp : Format.formatter -> t -> unit val compare : t -> t -> int end -(** A string that meets some additional requirements. *) -module MetricName : NAME (** A valid name for a metric. *) +module MetricName : NAME -module LabelName : NAME (** A valid name for a label. *) +module LabelName : NAME +(** Metadata about a metric. *) module MetricInfo : sig type t = { name : MetricName.t; @@ -42,172 +39,201 @@ module MetricInfo : sig label_names : LabelName.t list; } end -(** Metadata about a metric. *) -module LabelSetMap : Asetmap.Map.S with type key = string list (** A map indexed by a set of labels. *) +module LabelSetMap : Asetmap.Map.S with type key = string list -module MetricFamilyMap : Asetmap.Map.S with type key = MetricInfo.t (** A map indexed by metric families. *) +module MetricFamilyMap : Asetmap.Map.S with type key = MetricInfo.t module Sample_set : sig type sample = { - ext : string; (** An extension to append to the base metric name. *) + ext : string; (** An extension to append to the base metric name. *) value : float; - bucket : (LabelName.t * float) option; (** The "le" or "quantile" label and value, if any. *) + bucket : (LabelName.t * float) option; + (** The "le" or "quantile" label and value, if any. *) } - type t = sample list (** A collection of values that together represent a single sample. For a counter, each reading is just a single value, but more complex types require multiple values. For example, a "summary" sample set contains "_sum" and "_count" values. *) + type t = sample list - val sample : ?ext:string -> ?bucket:(LabelName.t * float) -> float -> sample + val sample : ?ext:string -> ?bucket:LabelName.t * float -> float -> sample end +(** A collection of metric reporters. Usually, only {!CollectorRegistry.default} is used. *) module CollectorRegistry : sig - type t (** A collection of metrics to be monitored. *) + type t - type snapshot = Sample_set.t LabelSetMap.t MetricFamilyMap.t (** The result of reading a set of metrics. *) + type snapshot = Sample_set.t LabelSetMap.t MetricFamilyMap.t - val create : unit -> t (** [create ()] is a fresh registry. This is mostly useful for testing. *) + val create : unit -> t - val default : t (** The default registry. *) + val default : t - val collect : t -> snapshot Lwt.t (** Read the current value of each metric. *) + val collect : t -> snapshot Lwt.t - val register : t -> MetricInfo.t -> (unit -> Sample_set.t LabelSetMap.t) -> unit (** [register t metric collector] adds [metric] to the set of metrics being collected. It will call [collector ()] to collect the values each time [collect] is called. *) + val register : + t -> MetricInfo.t -> (unit -> Sample_set.t LabelSetMap.t) -> unit - val register_lwt : t -> MetricInfo.t -> (unit -> Sample_set.t LabelSetMap.t Lwt.t) -> unit (** [register_lwt t metric collector] is the same as [register t metrics collector] but [collector] returns [Sample_set.t LabelSetMap.t Lwt.t]. *) + val register_lwt : + t -> MetricInfo.t -> (unit -> Sample_set.t LabelSetMap.t Lwt.t) -> unit - val register_pre_collect : t -> (unit -> unit) -> unit (** [register_pre_collect t fn] arranges for [fn ()] to be called at the start of each collection. This is useful if one expensive call provides information about multiple metrics. *) + val register_pre_collect : t -> (unit -> unit) -> unit - val register_pre_collect_lwt : t -> (unit -> unit Lwt.t) -> unit (** [register_pre_collect t fn] same as [register_pre_collect] but [fn] returns [unit Lwt.t]. *) + val register_pre_collect_lwt : t -> (unit -> unit Lwt.t) -> unit end -(** A collection of metric reporters. Usually, only {!CollectorRegistry.default} is used. *) +(** Operations common to all types of metric. *) module type METRIC = sig - type family (** A collection of metrics that are the same except for their labels. e.g. "Number of HTTP responses" *) + type family - type t (** A particular metric. e.g. "Number of HTTP responses with code=404" *) + type t - val v_labels : label_names:string list -> ?registry:CollectorRegistry.t -> help:string -> ?namespace:string -> ?subsystem:string -> string -> family (** [v_labels ~label_names ~help ~namespace ~subsystem name] is a family of metrics with full name [namespace_subsystem_name] and documentation string [help]. Each metric in the family will provide a value for each of the labels. The new family is registered with [registry] (default: {!CollectorRegistry.default}). *) + val v_labels : + label_names:string list -> + ?registry:CollectorRegistry.t -> + help:string -> + ?namespace:string -> + ?subsystem:string -> + string -> + family - val labels : family -> string list -> t (** [labels family label_values] is the metric in [family] with these values for the labels. The order of the values must be the same as the order of the [label_names] passed to [v_labels]; you may wish to write a wrapper function with labelled arguments to avoid mistakes. If this is called multiple times with the same set of values, the existing metric will be returned. *) + val labels : family -> string list -> t - val v_label : label_name:string -> ?registry:CollectorRegistry.t -> help:string -> ?namespace:string -> ?subsystem:string -> string -> (string -> t) (** [v_label] is a convenience wrapper around [v_labels] for the case where there is a single label. The result is a function from the single label's value to the metric. *) + val v_label : + label_name:string -> + ?registry:CollectorRegistry.t -> + help:string -> + ?namespace:string -> + ?subsystem:string -> + string -> + string -> + t - val v : ?registry:CollectorRegistry.t -> help:string -> ?namespace:string -> ?subsystem:string -> string -> t (** [v] is a convenience wrapper around [v_labels] for the case where there are no labels. *) + val v : + ?registry:CollectorRegistry.t -> + help:string -> + ?namespace:string -> + ?subsystem:string -> + string -> + t end -(** Operations common to all types of metric. *) +(** A counter is a cumulative metric that represents a single numerical value that only ever goes up. *) module Counter : sig include METRIC + val inc_one : t -> unit - val inc : t -> float -> unit + (** [inc t v] increases [t] by [v], which must be non-negative. *) + val inc : t -> float -> unit end -(** A counter is a cumulative metric that represents a single numerical value that only ever goes up. *) +(** A gauge is a metric that represents a single numerical value that can arbitrarily go up and down. *) module Gauge : sig include METRIC val inc_one : t -> unit - val inc : t -> float -> unit + (** [inc t v] increases the current value of the guage by [v]. *) + val inc : t -> float -> unit val dec_one : t -> unit - val dec : t -> float -> unit + (** [dec t v] decreases the current value of the guage by [v]. *) + val dec : t -> float -> unit - val set : t -> float -> unit (** [set t v] sets the current value of the guage to [v]. *) + val set : t -> float -> unit - val track_inprogress : t -> (unit -> 'a Lwt.t) -> 'a Lwt.t (** [track_inprogress t f] increases the value of the gauge by one while [f ()] is running. *) + val track_inprogress : t -> (unit -> 'a Lwt.t) -> 'a Lwt.t - val time : t -> (unit -> float) -> (unit -> 'a Lwt.t) -> 'a Lwt.t (** [time t gettime f] calls [gettime ()] before and after executing [f ()] and increases the metric by the difference. *) + val time : t -> (unit -> float) -> (unit -> 'a Lwt.t) -> 'a Lwt.t end -(** A gauge is a metric that represents a single numerical value that can arbitrarily go up and down. *) +(** A summary is a metric that records both the number of readings and their total. + This allows calculating the average. *) module Summary : sig include METRIC - val observe : t -> float -> unit (** [observe t v] increases the total by [v] and the count by one. *) + val observe : t -> float -> unit - val time : t -> (unit -> float) -> (unit -> 'a Lwt.t) -> 'a Lwt.t (** [time t gettime f] calls [gettime ()] before and after executing [f ()] and observes the difference. *) + val time : t -> (unit -> float) -> (unit -> 'a Lwt.t) -> 'a Lwt.t end -(** A summary is a metric that records both the number of readings and their total. - This allows calculating the average. *) module Histogram_spec : sig type t - val of_linear : float -> float -> int -> t (** [of_linear start interval count] will return a histogram type with [count] buckets with values starting at [start] and [interval] apart: [(start, start+interval, start + (2 * interval), ... start + ((count-1) * interval), infinity)]. [count] does not include the infinity bucket. *) + val of_linear : float -> float -> int -> t - val of_exponential : float -> float -> int -> t (** [of_exponential start factor count] will return a histogram type with [count] buckets with values starting at [start] and every next item [previous*factor]. [count] does not include the infinity bucket. *) + val of_exponential : float -> float -> int -> t - val of_list : float list -> t (** [of_list [0.5; 1.]] will return a histogram with buckets [0.5;1.;infinity]. *) + val of_list : float list -> t end module type HISTOGRAM = sig include METRIC - val observe : t -> float -> unit (** [observe t v] adds one to the appropriate bucket for v and adds v to the sum. *) + val observe : t -> float -> unit - val time : t -> (unit -> float) -> (unit -> 'a Lwt.t) -> 'a Lwt.t (** [time t gettime f] calls [gettime ()] before and after executing [f ()] and observes the difference. *) + val time : t -> (unit -> float) -> (unit -> 'a Lwt.t) -> 'a Lwt.t end -module Histogram (Buckets : sig val spec : Histogram_spec.t end) : HISTOGRAM +module Histogram (Buckets : sig + val spec : Histogram_spec.t +end) : HISTOGRAM -module DefaultHistogram : HISTOGRAM (** A histogram configured with reasonable defaults for measuring network request times in seconds. *) +module DefaultHistogram : HISTOGRAM diff --git a/prometheus/tests/test.ml b/prometheus/tests/test.ml index c4d2467c4770..12b045c241c1 100644 --- a/prometheus/tests/test.ml +++ b/prometheus/tests/test.ml @@ -1,44 +1,51 @@ open! Astring open Prometheus open Prometheus_app - open Lwt.Infix let test_metrics () = let registry = CollectorRegistry.create () in let requests = let label_names = ["method"; "path"] in - Counter.v_labels ~label_names ~registry ~help:"Requests" ~namespace:"dkci" ~subsystem:"tests" "requests" in + Counter.v_labels + ~label_names + ~registry + ~help:"Requests" + ~namespace:"dkci" + ~subsystem:"tests" + "requests" + in let m = Counter.v ~registry ~help:"Test \\counter:\n1" "tests" in - Counter.inc_one m; + Counter.inc_one m ; let get_index = Counter.labels requests ["GET"; "\"\\-\n"] in let post_login = Counter.labels requests ["POST"; "/login"] in - Counter.inc get_index 5.; - Counter.inc post_login 2.; + Counter.inc get_index 5. ; + Counter.inc post_login 2. ; let post_login2 = Counter.labels requests ["POST"; "/login"] in - Counter.inc_one post_login2; + Counter.inc_one post_login2 ; CollectorRegistry.collect registry >|= fun collected -> let output = Fmt.to_to_string TextFormat_0_0_4.output collected in - Alcotest.(check string) "Text output" + Alcotest.(check string) + "Text output" "#HELP dkci_tests_requests Requests\n\ #TYPE dkci_tests_requests counter\n\ dkci_tests_requests{method=\"GET\", path=\"\\\"\\\\-\\n\"} 5.000000\n\ dkci_tests_requests{method=\"POST\", path=\"/login\"} 3.000000\n\ #HELP tests Test \\\\counter:\\n1\n\ #TYPE tests counter\n\ - tests 1.000000\n\ - " + tests 1.000000\n" output let test_lwt_collectors () = let registry = CollectorRegistry.create () in let register_counter ~name ~help value = - let metric_info = { - MetricInfo.name = MetricName.v name; - metric_type = Counter; - help; - label_names = [] - } + let metric_info = + { + MetricInfo.name = MetricName.v name; + metric_type = Counter; + help; + label_names = []; + } in let collector () = Lwt.pause () >|= fun () -> @@ -47,11 +54,12 @@ let test_lwt_collectors () = CollectorRegistry.register_lwt registry metric_info collector in (* Test register_lwt *) - register_counter ~name:"counter_1" ~help:"The first counter" 1.0; - register_counter ~name:"counter_2" ~help:"The second counter" 2.0; + register_counter ~name:"counter_1" ~help:"The first counter" 1.0 ; + register_counter ~name:"counter_2" ~help:"The second counter" 2.0 ; CollectorRegistry.collect registry >|= fun collected -> let output = Fmt.to_to_string TextFormat_0_0_4.output collected in - Alcotest.(check string) "Text output" + Alcotest.(check string) + "Text output" "#HELP counter_1 The first counter\n\ #TYPE counter_1 counter\n\ counter_1 1.000000\n\ @@ -70,110 +78,117 @@ let test_histogram () = let registry = CollectorRegistry.create () in let requests = let label_names = ["method"; "path"] in - H.v_labels ~label_names ~registry ~help:"Requests" ~namespace:"dkci" ~subsystem:"tests" "requests" in + H.v_labels + ~label_names + ~registry + ~help:"Requests" + ~namespace:"dkci" + ~subsystem:"tests" + "requests" + in let foo = H.labels requests ["GET"; "/foo"] in let bar = H.labels requests ["PUT"; "/bar"] in - H.observe foo 0.12; - H.observe bar 0.33; + H.observe foo 0.12 ; + H.observe bar 0.33 ; CollectorRegistry.collect registry >|= fun collected -> let output = Fmt.to_to_string TextFormat_0_0_4.output collected in - Alcotest.(check string) "Text output" + Alcotest.(check string) + "Text output" "#HELP dkci_tests_requests Requests\n\ #TYPE dkci_tests_requests histogram\n\ dkci_tests_requests_sum{method=\"GET\", path=\"/foo\"} 0.120000\n\ dkci_tests_requests_count{method=\"GET\", path=\"/foo\"} 1.000000\n\ - dkci_tests_requests_bucket{le=\"+Inf\", method=\"GET\", path=\"/foo\"} 1.000000\n\ - dkci_tests_requests_bucket{le=\"0.500000\", method=\"GET\", path=\"/foo\"} 1.000000\n\ - dkci_tests_requests_bucket{le=\"0.250000\", method=\"GET\", path=\"/foo\"} 1.000000\n\ + dkci_tests_requests_bucket{le=\"+Inf\", method=\"GET\", path=\"/foo\"} \ + 1.000000\n\ + dkci_tests_requests_bucket{le=\"0.500000\", method=\"GET\", \ + path=\"/foo\"} 1.000000\n\ + dkci_tests_requests_bucket{le=\"0.250000\", method=\"GET\", \ + path=\"/foo\"} 1.000000\n\ dkci_tests_requests_sum{method=\"PUT\", path=\"/bar\"} 0.330000\n\ dkci_tests_requests_count{method=\"PUT\", path=\"/bar\"} 1.000000\n\ - dkci_tests_requests_bucket{le=\"+Inf\", method=\"PUT\", path=\"/bar\"} 1.000000\n\ - dkci_tests_requests_bucket{le=\"0.500000\", method=\"PUT\", path=\"/bar\"} 1.000000\n\ - dkci_tests_requests_bucket{le=\"0.250000\", method=\"PUT\", path=\"/bar\"} 0.000000\n\ - " + dkci_tests_requests_bucket{le=\"+Inf\", method=\"PUT\", path=\"/bar\"} \ + 1.000000\n\ + dkci_tests_requests_bucket{le=\"0.500000\", method=\"PUT\", \ + path=\"/bar\"} 1.000000\n\ + dkci_tests_requests_bucket{le=\"0.250000\", method=\"PUT\", \ + path=\"/bar\"} 0.000000\n" output (* "^[a-zA-Z_][a-zA-Z0-9_]*$" *) -let valid_labels = [ - "_"; - "a"; - "aA0b1B9c8C7z6Z5y4Y3x2X1"; - "_______"; -] - -let invalid_labels = [ - ""; - "1"; - "a bad label"; -] +let valid_labels = ["_"; "a"; "aA0b1B9c8C7z6Z5y4Y3x2X1"; "_______"] + +let invalid_labels = [""; "1"; "a bad label"] let check_valid_label label () = - let _l: LabelName.t = LabelName.v label in + let _l : LabelName.t = LabelName.v label in () let check_invalid_label label () = let valid = try - let _l: LabelName.t = LabelName.v label in + let _l : LabelName.t = LabelName.v label in true - with _ -> false in - if valid then - failwith (label ^ " should be an invalid label") + with _ -> false + in + if valid then failwith (label ^ " should be an invalid label") -let test_valid_labels_set = List.map (fun label -> - label, `Quick, fun () -> Lwt.return @@ check_valid_label label () -) valid_labels +let test_valid_labels_set = + List.map + (fun label -> + (label, `Quick, fun () -> Lwt.return @@ check_valid_label label ())) + valid_labels -let test_invalid_labels_set = List.map (fun label -> - label, `Quick, fun () -> Lwt.return @@ check_invalid_label label () -) invalid_labels +let test_invalid_labels_set = + List.map + (fun label -> + (label, `Quick, fun () -> Lwt.return @@ check_invalid_label label ())) + invalid_labels let check_valid_metric metric () = - let _m: MetricName.t = MetricName.v metric in + let _m : MetricName.t = MetricName.v metric in () let check_invalid_metric metric () = let valid = try - let _m: MetricName.t = MetricName.v metric in + let _m : MetricName.t = MetricName.v metric in true - with _ -> false in - if valid then - failwith (metric ^ " should be an invalid metric") + with _ -> false + in + if valid then failwith (metric ^ " should be an invalid metric") (* "^[a-zA-Z_:][a-zA-Z0-9_:]*$" *) -let valid_metrics = [ - "_"; - ":"; - "aA0b1B9c8C7z6Z5y4Y3x:2X1"; - ":::::::"; -] - -let invalid_metrics = [ - ""; - "1"; - "a bad metric"; -] - -let test_valid_metrics_set = List.map (fun metric -> - metric, `Quick, fun () -> Lwt.return @@ check_valid_metric metric () -) valid_metrics - -let test_invalid_metrics_set = List.map (fun metric -> - metric, `Quick, fun () -> Lwt.return @@ check_invalid_metric metric () -) invalid_metrics - -let test_set = [ - "Metrics", `Quick, test_metrics; - "Lwt collectors",`Quick, test_lwt_collectors; - "Histogram", `Quick, test_histogram; -] +let valid_metrics = ["_"; ":"; "aA0b1B9c8C7z6Z5y4Y3x:2X1"; ":::::::"] + +let invalid_metrics = [""; "1"; "a bad metric"] + +let test_valid_metrics_set = + List.map + (fun metric -> + (metric, `Quick, fun () -> Lwt.return @@ check_valid_metric metric ())) + valid_metrics + +let test_invalid_metrics_set = + List.map + (fun metric -> + (metric, `Quick, fun () -> Lwt.return @@ check_invalid_metric metric ())) + invalid_metrics + +let test_set = + [ + ("Metrics", `Quick, test_metrics); + ("Lwt collectors", `Quick, test_lwt_collectors); + ("Histogram", `Quick, test_histogram); + ] let () = - Lwt_main.run @@ Alcotest_lwt.run "prometheus" [ - "main", test_set; - "valid_labels", test_valid_labels_set; - "invalid_labels", test_invalid_labels_set; - "valid_metrics", test_valid_metrics_set; - "invalid_metrics", test_invalid_metrics_set; - ] + Lwt_main.run + @@ Alcotest_lwt.run + "prometheus" + [ + ("main", test_set); + ("valid_labels", test_valid_labels_set); + ("invalid_labels", test_invalid_labels_set); + ("valid_metrics", test_valid_metrics_set); + ("invalid_metrics", test_invalid_metrics_set); + ] -- GitLab From 1ca440d86cd4c62684e9b5cffe94d210a676c450 Mon Sep 17 00:00:00 2001 From: Gabriel Moise Date: Tue, 2 Jul 2024 20:13:43 +0100 Subject: [PATCH 3/5] Prometheus: Use prometheus inside tezos --- etherlink/bin_node/lib_dev/dune | 2 +- manifest/externals.ml | 2 + manifest/product_octez.ml | 11 +++- manifest/product_prometheus.ml | 75 ++++++++++++++++++++++++--- manifest/product_prometheus.mli | 2 + opam/octez-dal-node.opam | 2 - opam/octez-evm-node-libs.opam | 1 - opam/octez-libs.opam | 15 +++--- opam/octez-node.opam | 1 - opam/octez-rpc-process.opam | 1 - opam/octez-shell-libs.opam | 1 - opam/octez-smart-rollup-node-lib.opam | 1 - opam/virtual/octez-deps.opam | 5 +- opam/virtual/octez-deps.opam.locked | 4 +- prometheus/app/dune | 35 ++++++++++--- prometheus/examples/dune | 14 +++-- prometheus/src/dune | 12 ++++- prometheus/tests/dune | 14 +++-- script-inputs/octez-source-content | 1 + src/bin_dal_node/dune | 4 +- src/bin_node/dune | 2 +- src/lib_base/index.mld | 1 + src/lib_p2p/dune | 2 +- src/lib_rpc_process/dune | 2 +- src/lib_shell/dune | 2 +- src/lib_smart_rollup_node/dune | 2 +- src/lib_store/unix/dune | 2 +- 27 files changed, 166 insertions(+), 50 deletions(-) diff --git a/etherlink/bin_node/lib_dev/dune b/etherlink/bin_node/lib_dev/dune index 17f9e46d1da8..cbcbc1dae99f 100644 --- a/etherlink/bin_node/lib_dev/dune +++ b/etherlink/bin_node/lib_dev/dune @@ -31,7 +31,7 @@ octez-l2-libs.layer2_store octez-l2-libs.smart-rollup octez-evm-node-libs.evm_node_migrations - prometheus-app) + octez-libs.prometheus-app) (flags (:standard) -open Tezos_base.TzPervasives diff --git a/manifest/externals.ml b/manifest/externals.ml index 69147b64ec55..65baa9b03a55 100644 --- a/manifest/externals.ml +++ b/manifest/externals.ml @@ -34,6 +34,8 @@ let alcotest = external_lib "alcotest" V.(at_least "1.5.0") let alcotest_lwt = external_lib "alcotest-lwt" V.(at_least "1.5.0") +let asetmap = external_lib "asetmap" V.(at_least "0.8.1") + let astring = external_lib "astring" V.True let bheap = external_lib "bheap" V.(at_least "2.0.0") diff --git a/manifest/product_octez.ml b/manifest/product_octez.ml index 8d9cc2d10998..1ffbbe0c3e62 100644 --- a/manifest/product_octez.ml +++ b/manifest/product_octez.ml @@ -39,7 +39,8 @@ include Product (struct "brassaia/"; "rust-toolchain"; ] - @ Product_data_encoding.product_source @ Product_resto.product_source + @ Product_data_encoding.product_source @ Product_prometheus.product_source + @ Product_resto.product_source end) module String_set = Set.Make (String) @@ -110,6 +111,14 @@ let () = ~target:"!module-Data_encoding" ~text:"Data_encoding" +(* Back-register the prometheus library which is currently maintained as its + own product but still attached to octez-libs. *) +let () = + Sub_lib.add_doc_link + registered_octez_libs + ~target:"!module-Prometheus" + ~text:"Prometheus" + (* Back-register the resto library which is currently maintained as its own product but still attached to octez-libs. *) let () = diff --git a/manifest/product_prometheus.ml b/manifest/product_prometheus.ml index 93c12b6a03ac..314f9ceea55a 100644 --- a/manifest/product_prometheus.ml +++ b/manifest/product_prometheus.ml @@ -8,12 +8,73 @@ open Manifest open Externals -(* Ultimately, prometheus will use the local sources from `prometheus/`. - For now we still use the opam package (see below, uses of - `external_lib`). This temporary state is to minimise disruptions - for other developers and reducing the size of MRs. *) -let prometheus = external_lib "prometheus" V.(exactly "1.2") +let product_source = ["prometheus/"] -let prometheus_app = external_lib "prometheus-app" V.(exactly "1.2") +include Product (struct + let name = "octez" -let prometheus_app_unix = external_sublib prometheus_app "prometheus-app.unix" + let source = product_source +end) + +let conflicts = + [external_lib "prometheus" V.True; external_lib "prometheus-app" V.True] + +let prometheus = + public_lib + "octez-libs.prometheus" + ~internal_name:"prometheus" + ~path:"prometheus/src" + ~deps:[lwt; astring; asetmap; re] + ~conflicts + +let prometheus_app = + public_lib + "octez-libs.prometheus-app" + ~internal_name:"prometheus_app" + ~path:"prometheus/app" + ~wrapped:false + ~modules:["Prometheus_app"] + ~deps:[prometheus; lwt; cohttp_lwt; astring; asetmap; fmt; re] + ~conflicts + +let conflicts = + conflicts + @ [ + external_sublib + (external_lib "prometheus-app" V.True) + "prometheus-app.unix"; + ] + +let prometheus_app_unix = + public_lib + "octez-libs.prometheus-app.unix" + ~internal_name:"prometheus_app_unix" + ~path:"prometheus/app" + ~wrapped:false + ~modules:["Prometheus_unix"] + ~deps: + [ + prometheus; + prometheus_app; + cmdliner; + cohttp_lwt; + cohttp_lwt_unix; + logs_fmt; + fmt_tty; + ] + ~conflicts + +let _prometheus_example = + private_exe + "example" + ~path:"prometheus/examples" + ~opam:"octez-libs" + ~deps: + [prometheus; prometheus_app_unix; cmdliner; cohttp_lwt; cohttp_lwt_unix] + +let _prometheus_test = + test + "test" + ~opam:"octez-libs" + ~path:"prometheus/tests" + ~deps:[prometheus; prometheus_app; alcotest; alcotest_lwt] diff --git a/manifest/product_prometheus.mli b/manifest/product_prometheus.mli index c5eba6742f92..1fef15deec20 100644 --- a/manifest/product_prometheus.mli +++ b/manifest/product_prometheus.mli @@ -5,6 +5,8 @@ (* *) (*****************************************************************************) +val product_source : string list + val prometheus : Manifest.target val prometheus_app : Manifest.target diff --git a/opam/octez-dal-node.opam b/opam/octez-dal-node.opam index 45d6bbeee45c..acdadaadd72f 100644 --- a/opam/octez-dal-node.opam +++ b/opam/octez-dal-node.opam @@ -16,8 +16,6 @@ depends: [ "tezos-dal-node-lib" { = version } "tezos-dal-node-services" { = version } "octez-l2-libs" { = version } - "prometheus-app" { = "1.2" } - "prometheus" { = "1.2" } "octez-crawler" { = version } "octez-protocol-020-PsParisC-libs" { = version } ] diff --git a/opam/octez-evm-node-libs.opam b/opam/octez-evm-node-libs.opam index aa576282a9d6..69a0f2af2245 100644 --- a/opam/octez-evm-node-libs.opam +++ b/opam/octez-evm-node-libs.opam @@ -23,7 +23,6 @@ depends: [ "caqti-driver-sqlite3" { >= "2.0.1" } "octez-l2-libs" "octez-smart-rollup-wasm-debugger-lib" - "prometheus-app" { = "1.2" } ] build: [ ["rm" "-r" "vendors" "contrib"] diff --git a/opam/octez-libs.opam b/opam/octez-libs.opam index 98d1b61a3892..3b74f533b5d7 100644 --- a/opam/octez-libs.opam +++ b/opam/octez-libs.opam @@ -20,13 +20,17 @@ depends: [ "zarith" { >= "1.13" & < "1.14" } "bigstringaf" { >= "0.5.0" } "ppx_expect" - "logs" - "fmt" { >= "0.8.7" } "lwt" { >= "5.7.0" } + "astring" + "asetmap" { >= "0.8.1" } + "re" { >= "1.10.0" } "cohttp-lwt" { >= "5.2.0" } + "fmt" { >= "0.8.7" } + "cmdliner" { >= "1.1.0" } "cohttp-lwt-unix" { >= "5.2.0" } - "conduit-lwt-unix" { = "6.2.2" } + "logs" "alcotest-lwt" { >= "1.5.0" } + "conduit-lwt-unix" { = "6.2.2" } "tezt" { >= "4.1.0" & < "5.0.0" } "qcheck-core" "qcheck-alcotest" { >= "0.20" } @@ -41,7 +45,6 @@ depends: [ "bigarray-compat" "eqaf" "ppx_repr" { >= "0.6.0" } - "cmdliner" { >= "1.1.0" } "base-unix" "ppx_deriving" "repr" @@ -50,7 +53,6 @@ depends: [ "octez-alcotezt" { = version } "aches-lwt" { >= "1.0.0" } "ipaddr" { >= "5.3.0" & < "6.0.0" } - "re" { >= "1.10.0" } "ptime" { >= "1.1.0" } "mtime" { >= "2.0.0" } "conf-libev" @@ -58,7 +60,6 @@ depends: [ "uutf" "lwt-exit" "ppxlib" - "astring" "bheap" { >= "2.0.0" } "digestif" "jsonm" @@ -89,6 +90,8 @@ conflicts: [ "json_data_encoding" "json_data_encoding_browser" "json_data_encoding_bson" + "prometheus" + "prometheus-app" "resto" "resto-acl" "resto-cohttp" diff --git a/opam/octez-node.opam b/opam/octez-node.opam index 1790d7eb7ea2..36ffe01091bd 100644 --- a/opam/octez-node.opam +++ b/opam/octez-node.opam @@ -18,7 +18,6 @@ depends: [ "cmdliner" { >= "1.1.0" } "fmt" { >= "0.8.7" } "tls-lwt" { >= "0.16.0" } - "prometheus-app" { = "1.2" } "lwt-exit" "uri" { >= "3.1.0" } "tezos-protocol-000-Ps9mPmXa" { = version } diff --git a/opam/octez-rpc-process.opam b/opam/octez-rpc-process.opam index 77b9a47c6ca4..581f09a04b42 100644 --- a/opam/octez-rpc-process.opam +++ b/opam/octez-rpc-process.opam @@ -15,7 +15,6 @@ depends: [ "octez-node-config" { = version } "lwt" { >= "5.7.0" } "lwt-exit" - "prometheus-app" { = "1.2" } ] build: [ ["rm" "-r" "vendors" "contrib"] diff --git a/opam/octez-shell-libs.opam b/opam/octez-shell-libs.opam index 58c0bd425902..9ee4b6ccb997 100644 --- a/opam/octez-shell-libs.opam +++ b/opam/octez-shell-libs.opam @@ -15,7 +15,6 @@ depends: [ "lwt-canceler" { >= "0.3" & < "0.4" } "ringo" { >= "1.0.0" } "aches" { >= "1.0.0" } - "prometheus" { = "1.2" } "tezt" { >= "4.1.0" & < "5.0.0" } "tezt-tezos" { with-test & = version } "octez-alcotezt" { with-test & = version } diff --git a/opam/octez-smart-rollup-node-lib.opam b/opam/octez-smart-rollup-node-lib.opam index 70a171aa184f..cbf286c21b4e 100644 --- a/opam/octez-smart-rollup-node-lib.opam +++ b/opam/octez-smart-rollup-node-lib.opam @@ -15,7 +15,6 @@ depends: [ "cohttp-lwt-unix" { >= "5.2.0" } "tezos-openapi" { = version } "octez-node-config" { = version } - "prometheus-app" { = "1.2" } "camlzip" { >= "1.11" & < "1.12" } "tar" "tar-unix" { >= "2.0.1" & < "3.0.0" } diff --git a/opam/virtual/octez-deps.opam b/opam/virtual/octez-deps.opam index 11099608b95a..eaf1f50bf6a9 100644 --- a/opam/virtual/octez-deps.opam +++ b/opam/virtual/octez-deps.opam @@ -13,6 +13,7 @@ depends: [ "aches-lwt" { >= "1.0.0" } "alcotest" { >= "1.5.0" } "alcotest-lwt" { >= "1.5.0" } + "asetmap" { >= "0.8.1" } "astring" "base-unix" "bheap" { >= "2.0.0" } @@ -80,8 +81,6 @@ depends: [ "prbnmcn-stats" { = "0.0.6" } "pringo" { >= "1.3" & < "1.4" } "progress" { >= "0.1.0" } - "prometheus" { = "1.2" } - "prometheus-app" { = "1.2" } "ptime" { >= "1.1.0" } "pure-splitmix" { = "0.3" } "pyml" { >= "20220905" } @@ -114,6 +113,8 @@ conflicts: [ "json_data_encoding" "json_data_encoding_browser" "json_data_encoding_bson" + "prometheus" + "prometheus-app" "resto" "resto-acl" "resto-cohttp" diff --git a/opam/virtual/octez-deps.opam.locked b/opam/virtual/octez-deps.opam.locked index 2759b1f6e26a..ba4cc75ac5fa 100644 --- a/opam/virtual/octez-deps.opam.locked +++ b/opam/virtual/octez-deps.opam.locked @@ -174,8 +174,6 @@ depends: [ "prbnmcn-stats" {= "0.0.6"} "pringo" {= "1.3"} "progress" {= "0.3.0"} - "prometheus" {= "1.2"} - "prometheus-app" {= "1.2"} "psq" {= "0.2.1"} "ptime" {= "1.1.0"} "pure-splitmix" {= "0.3"} @@ -231,6 +229,8 @@ conflicts: [ "json_data_encoding" "json_data_encoding_browser" "json_data_encoding_bson" + "prometheus" + "prometheus-app" "resto" "resto-acl" "resto-cohttp" diff --git a/prometheus/app/dune b/prometheus/app/dune index debed4ddeb58..39204876c6e4 100644 --- a/prometheus/app/dune +++ b/prometheus/app/dune @@ -1,13 +1,32 @@ +; This file was automatically generated, do not edit. +; Edit file manifest/main.ml instead. + (library (name prometheus_app) - (public_name prometheus-app) - (libraries prometheus lwt cohttp-lwt astring asetmap fmt re) - (modules Prometheus_app) - (wrapped false)) + (public_name octez-libs.prometheus-app) + (instrumentation (backend bisect_ppx)) + (libraries + octez-libs.prometheus + lwt + cohttp-lwt + astring + asetmap + fmt + re) + (wrapped false) + (modules Prometheus_app)) (library (name prometheus_app_unix) - (public_name prometheus-app.unix) - (libraries prometheus prometheus-app cmdliner cohttp-lwt cohttp-lwt-unix logs.fmt fmt.tty) - (modules Prometheus_unix) - (wrapped false)) + (public_name octez-libs.prometheus-app.unix) + (instrumentation (backend bisect_ppx)) + (libraries + octez-libs.prometheus + octez-libs.prometheus-app + cmdliner + cohttp-lwt + cohttp-lwt-unix + logs.fmt + fmt.tty) + (wrapped false) + (modules Prometheus_unix)) diff --git a/prometheus/examples/dune b/prometheus/examples/dune index dffb6824a90a..9d7fde9a29b9 100644 --- a/prometheus/examples/dune +++ b/prometheus/examples/dune @@ -1,4 +1,12 @@ +; This file was automatically generated, do not edit. +; Edit file manifest/main.ml instead. + (executable - (name example) - (enabled_if (>= %{ocaml_version} 4.08)) ; Work-around for dune bug #5621 - (libraries prometheus prometheus-app.unix cmdliner cohttp-lwt cohttp-lwt-unix)) + (name example) + (instrumentation (backend bisect_ppx)) + (libraries + octez-libs.prometheus + octez-libs.prometheus-app.unix + cmdliner + cohttp-lwt + cohttp-lwt-unix)) diff --git a/prometheus/src/dune b/prometheus/src/dune index 8ae5ebee23d1..08f692cac277 100644 --- a/prometheus/src/dune +++ b/prometheus/src/dune @@ -1,4 +1,12 @@ +; This file was automatically generated, do not edit. +; Edit file manifest/main.ml instead. + (library (name prometheus) - (public_name prometheus) - (libraries lwt astring asetmap re)) + (public_name octez-libs.prometheus) + (instrumentation (backend bisect_ppx)) + (libraries + lwt + astring + asetmap + re)) diff --git a/prometheus/tests/dune b/prometheus/tests/dune index 8a23e948f900..3a233e4fcd50 100644 --- a/prometheus/tests/dune +++ b/prometheus/tests/dune @@ -1,4 +1,12 @@ -(test +; This file was automatically generated, do not edit. +; Edit file manifest/main.ml instead. + +(executable (name test) - (package prometheus-app) - (libraries prometheus prometheus-app alcotest alcotest-lwt)) + (libraries + octez-libs.prometheus + octez-libs.prometheus-app + alcotest + alcotest-lwt)) + +(rule (alias runtest) (package octez-libs) (action (run %{dep:./test.exe}))) diff --git a/script-inputs/octez-source-content b/script-inputs/octez-source-content index 0d3e135c3e30..ceb97341967e 100644 --- a/script-inputs/octez-source-content +++ b/script-inputs/octez-source-content @@ -13,4 +13,5 @@ irmin brassaia rust-toolchain data-encoding +prometheus resto diff --git a/src/bin_dal_node/dune b/src/bin_dal_node/dune index 8dbfeedaa22e..42ab456e47fe 100644 --- a/src/bin_dal_node/dune +++ b/src/bin_dal_node/dune @@ -33,8 +33,8 @@ octez-libs.crypto octez-libs.base.p2p-identity-file octez-shell-libs.shell-services - prometheus-app - prometheus + octez-libs.prometheus-app + octez-libs.prometheus octez-crawler octez-protocol-020-PsParisC-libs.dal (select void_for_linking-octez-protocol-alpha-libs-dal from diff --git a/src/bin_node/dune b/src/bin_node/dune index d4c6c57ea78c..ea9e0aa52231 100644 --- a/src/bin_node/dune +++ b/src/bin_node/dune @@ -29,7 +29,7 @@ fmt.cli fmt.tty tls-lwt - prometheus-app.unix + octez-libs.prometheus-app.unix lwt-exit uri octez-libs.base.p2p-identity-file diff --git a/src/lib_base/index.mld b/src/lib_base/index.mld index fb0800666e45..058ace959260 100644 --- a/src/lib_base/index.mld +++ b/src/lib_base/index.mld @@ -55,4 +55,5 @@ It contains the following libraries: - {{!page-tezos_workers}Tezos_workers}: Worker library - {{!module-Tezt_wrapper}Tezt_wrapper} - {{!module-Data_encoding}Data_encoding} +- {{!module-Prometheus}Prometheus} - {{!module-Resto}Resto} diff --git a/src/lib_p2p/dune b/src/lib_p2p/dune index 21ae2d40cdc3..c14b0f49d4ee 100644 --- a/src/lib_p2p/dune +++ b/src/lib_p2p/dune @@ -16,7 +16,7 @@ octez-libs.stdlib octez-libs.tezos-p2p-services octez-libs.version - prometheus + octez-libs.prometheus octez-libs.base.p2p-identity-file) (flags (:standard) diff --git a/src/lib_rpc_process/dune b/src/lib_rpc_process/dune index a00988a7ec0c..efb5b3b790f6 100644 --- a/src/lib_rpc_process/dune +++ b/src/lib_rpc_process/dune @@ -21,7 +21,7 @@ octez-shell-libs.store.shared lwt.unix lwt-exit - prometheus-app) + octez-libs.prometheus-app) (flags (:standard) -open Tezos_base.TzPervasives diff --git a/src/lib_shell/dune b/src/lib_shell/dune index 2af271ee3877..df3b0bfffc7d 100644 --- a/src/lib_shell/dune +++ b/src/lib_shell/dune @@ -8,7 +8,7 @@ (libraries lwt-watcher lwt-canceler - prometheus + octez-libs.prometheus octez-libs.base octez-libs.base.unix octez-libs.rpc diff --git a/src/lib_smart_rollup_node/dune b/src/lib_smart_rollup_node/dune index 82e516f8ded8..f7b757fa02cb 100644 --- a/src/lib_smart_rollup_node/dune +++ b/src/lib_smart_rollup_node/dune @@ -15,7 +15,7 @@ cohttp-lwt-unix tezos-openapi octez-node-config - prometheus-app + octez-libs.prometheus-app camlzip tar tar-unix diff --git a/src/lib_store/unix/dune b/src/lib_store/unix/dune index 467289b25a7f..36f0dfa8661f 100644 --- a/src/lib_store/unix/dune +++ b/src/lib_store/unix/dune @@ -24,7 +24,7 @@ camlzip tar tar-unix - prometheus) + octez-libs.prometheus) (flags (:standard) -open Tezos_shell_services -- GitLab From 331614174d340c04e618637c869bcfd6d4ce2da6 Mon Sep 17 00:00:00 2001 From: Gabriel Moise Date: Tue, 2 Jul 2024 13:03:16 +0100 Subject: [PATCH 4/5] Docs: include prometheus --- docs/Makefile | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/docs/Makefile b/docs/Makefile index 5ee013aa544c..1dcbe037cf3b 100644 --- a/docs/Makefile +++ b/docs/Makefile @@ -87,7 +87,7 @@ odoc-lite: rm -rf $(TMPDOCDIR)/ mkdir -p $(TMPDOCDIR)/ rsync --recursive --links --perms --exclude=target \ - ../scripts ../script-inputs ../src ../tezt ../irmin ../brassaia ../vendors ../dune ../dune-project ../dune-workspace ../data-encoding ../rust-toolchain ../resto $(TMPDOCDIR)/ + ../scripts ../script-inputs ../src ../tezt ../irmin ../brassaia ../vendors ../dune ../dune-project ../dune-workspace ../data-encoding ../rust-toolchain ../resto ../prometheus $(TMPDOCDIR)/ cd $(TMPDOCDIR)/ && ./scripts/slim-mode.sh on @echo "Running odoc in $(TMPDOCDIR), with build directory $(TOPBUILDDIR_ABS) and outputs in odoc.log" ODOC_WARN_ERROR=true dune build @doc --build-dir=$(TOPBUILDDIR_ABS) --root=$(TMPDOCDIR) >$(CURDIR)/odoc.log 2>&1; \ -- GitLab From b4a1dc7848cd62db6364a5c47fde7d11b97afd8a Mon Sep 17 00:00:00 2001 From: Gabriel Moise Date: Thu, 18 Jul 2024 12:02:14 +0100 Subject: [PATCH 5/5] Docker: Add prometheus to build file for docker --- build.Dockerfile | 1 + 1 file changed, 1 insertion(+) diff --git a/build.Dockerfile b/build.Dockerfile index fae9e9f38e44..e0d07bfa1b3f 100644 --- a/build.Dockerfile +++ b/build.Dockerfile @@ -38,6 +38,7 @@ COPY --chown=tezos:nogroup dune-project tezos/dune-project COPY --chown=tezos:nogroup vendors tezos/vendors COPY --chown=tezos:nogroup rust-toolchain tezos/rust-toolchain COPY --chown=tezos:nogroup resto tezos/resto +COPY --chown=tezos:nogroup prometheus tezos/prometheus ENV GIT_SHORTREF=${GIT_SHORTREF} ENV GIT_DATETIME=${GIT_DATETIME} ENV GIT_VERSION=${GIT_VERSION} -- GitLab