From 7d83087a9a2afa3c47b3736f4f61bf7148654409 Mon Sep 17 00:00:00 2001 From: Thomas Leonard Date: Tue, 26 Apr 2022 09:48:33 +0100 Subject: [PATCH 1/4] Update example to new cmdliner --- examples/example.ml | 8 +++----- 1 file changed, 3 insertions(+), 5 deletions(-) diff --git a/examples/example.ml b/examples/example.ml index f00a047..d56baec 100644 --- a/examples/example.ml +++ b/examples/example.ml @@ -41,8 +41,6 @@ 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"; - let spec = Term.(const main $ Prometheus_unix.opts) in - let info = Term.info "example" in - match Term.eval (spec, info) with - | `Error _ -> exit 1 - | _ -> exit 0 + let info = Cmd.info "example" in + let cmd = Cmd.v info Term.(const main $ Prometheus_unix.opts) in + exit @@ Cmd.eval cmd From 2350cdfba6416924aefa65cd4cff3c90ff5f71a5 Mon Sep 17 00:00:00 2001 From: Thomas Leonard Date: Tue, 26 Apr 2022 09:32:16 +0100 Subject: [PATCH 2/4] Remove fmt dependency from core package This forces a newer version of OCaml for very little benefit. --- prometheus.opam | 1 - src/dune | 2 +- src/prometheus.ml | 8 ++++---- src/prometheus.mli | 2 +- 4 files changed, 6 insertions(+), 7 deletions(-) diff --git a/prometheus.opam b/prometheus.opam index edb7d4b..dd5d95d 100644 --- a/prometheus.opam +++ b/prometheus.opam @@ -11,7 +11,6 @@ depends: [ "dune" "astring" "asetmap" - "fmt" {>= "0.8.7"} "re" "lwt" {>= "2.5.0"} "alcotest" {with-test} diff --git a/src/dune b/src/dune index fca559c..8ae5ebe 100644 --- a/src/dune +++ b/src/dune @@ -1,4 +1,4 @@ (library (name prometheus) (public_name prometheus) - (libraries lwt astring asetmap fmt re)) + (libraries lwt astring asetmap re)) diff --git a/src/prometheus.ml b/src/prometheus.ml index 4a09f2b..f05730a 100644 --- a/src/prometheus.ml +++ b/src/prometheus.ml @@ -8,7 +8,7 @@ end module type NAME = sig type t = private string val v : string -> t - val pp : t Fmt.t + val pp : Format.formatter -> t -> unit val compare : t -> t -> int end @@ -17,12 +17,12 @@ module Name(N : NAME_SPEC) : NAME = struct let v name = if not (Re.execp N.valid name) then - failwith (Fmt.str "Invalid name %S" name); + failwith (Format.asprintf "Invalid name %S" name); name let compare = String.compare - let pp = Fmt.string + let pp = Format.pp_print_string end let alphabet = Re.(alt [ rg 'a' 'z'; rg 'A' 'Z' ]) @@ -108,7 +108,7 @@ module CollectorRegistry = struct let register t info collector = if MetricFamilyMap.mem info t.metrics - then failwith (Fmt.str "%a already registered" MetricName.pp info.MetricInfo.name); + then failwith (Format.asprintf "%a already registered" MetricName.pp info.MetricInfo.name); t.metrics <- MetricFamilyMap.add info collector t.metrics let collect t = diff --git a/src/prometheus.mli b/src/prometheus.mli index 53f5935..66d38d7 100644 --- a/src/prometheus.mli +++ b/src/prometheus.mli @@ -22,7 +22,7 @@ module type NAME = sig val v : string -> t (** Raises an exception if the name is not valid. *) - val pp : t Fmt.t + val pp : Format.formatter -> t -> unit val compare : t -> t -> int end From 5b56c6a467b5a1450f84f2cd3166b9b7163fe0a9 Mon Sep 17 00:00:00 2001 From: Thomas Leonard Date: Tue, 26 Apr 2022 10:35:30 +0100 Subject: [PATCH 3/4] Remove unused alcotest dependency Update to dune 2, allowing the tests to be attached only to the prometheus-app package. --- dune-project | 3 ++- prometheus-app.opam | 2 +- prometheus.opam | 3 +-- tests/dune | 13 +++---------- 4 files changed, 7 insertions(+), 14 deletions(-) diff --git a/dune-project b/dune-project index 82d407b..665cdaf 100644 --- a/dune-project +++ b/dune-project @@ -1,2 +1,3 @@ -(lang dune 1.0) +(lang dune 2.0) (name prometheus) +(formatting disabled) diff --git a/prometheus-app.opam b/prometheus-app.opam index 35554df..4717bdf 100644 --- a/prometheus-app.opam +++ b/prometheus-app.opam @@ -26,7 +26,7 @@ doc: "https://mirage.github.io/prometheus/" bug-reports: "https://github.com/mirage/prometheus/issues" depends: [ "ocaml" {>= "4.02.3"} - "dune" {>= "1.0"} + "dune" {>= "2.0"} "prometheus" {= version} "fmt" {>= "0.8.7"} "re" diff --git a/prometheus.opam b/prometheus.opam index dd5d95d..47c423f 100644 --- a/prometheus.opam +++ b/prometheus.opam @@ -8,12 +8,11 @@ doc: "https://mirage.github.io/prometheus/" bug-reports: "https://github.com/mirage/prometheus/issues" depends: [ "ocaml" {>= "4.01.0"} - "dune" + "dune" {>= "2.0"} "astring" "asetmap" "re" "lwt" {>= "2.5.0"} - "alcotest" {with-test} ] build: [ ["dune" "build" "-p" name "-j" jobs] diff --git a/tests/dune b/tests/dune index 7a27956..6b92551 100644 --- a/tests/dune +++ b/tests/dune @@ -1,11 +1,4 @@ -(executables - (names test) - (libraries prometheus prometheus-app alcotest)) - -(alias - (name runtest) +(test + (name test) (package prometheus-app) - (deps - (:< test.exe)) - (action - (run %{<} -e -v))) + (libraries prometheus prometheus-app alcotest)) From 076ee4408d3519f80cb32f3b1e80f02427805a77 Mon Sep 17 00:00:00 2001 From: Thomas Leonard Date: Tue, 26 Apr 2022 09:15:57 +0100 Subject: [PATCH 4/4] Update minimum OCaml version for prometheus-app Cohttp requires OCaml >= 4.08, so be explicit that we do too. --- prometheus-app.opam | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/prometheus-app.opam b/prometheus-app.opam index 4717bdf..cfc073d 100644 --- a/prometheus-app.opam +++ b/prometheus-app.opam @@ -25,7 +25,7 @@ homepage: "https://github.com/mirage/prometheus" doc: "https://mirage.github.io/prometheus/" bug-reports: "https://github.com/mirage/prometheus/issues" depends: [ - "ocaml" {>= "4.02.3"} + "ocaml" {>= "4.08"} "dune" {>= "2.0"} "prometheus" {= version} "fmt" {>= "0.8.7"}