From da7a27552a5215b075ba0a600961c81a79bee7c0 Mon Sep 17 00:00:00 2001 From: Simon Cruanes Date: Thu, 18 Jan 2024 21:11:58 -0500 Subject: [PATCH] wip: tests for prometheus --- tests/prometheus/dune | 4 ++++ tests/prometheus/t_prom.expected | 22 ++++++++++++++++++++++ tests/prometheus/t_prom.ml | 23 +++++++++++++++++++++++ 3 files changed, 49 insertions(+) create mode 100644 tests/prometheus/dune create mode 100644 tests/prometheus/t_prom.expected create mode 100644 tests/prometheus/t_prom.ml diff --git a/tests/prometheus/dune b/tests/prometheus/dune new file mode 100644 index 00000000..da921019 --- /dev/null +++ b/tests/prometheus/dune @@ -0,0 +1,4 @@ + +(test + (name t_prom) + (libraries tiny_httpd.prometheus)) diff --git a/tests/prometheus/t_prom.expected b/tests/prometheus/t_prom.expected new file mode 100644 index 00000000..590b6c82 --- /dev/null +++ b/tests/prometheus/t_prom.expected @@ -0,0 +1,22 @@ +==== first try ==== +``` +# TYPE yolo_gauge gauge +yolo_gauge{level="max"} 2525 +# HELP t_c2 more awesome than c1 +# TYPE t_c2 counter +t_c2 1 +# TYPE t_c1 counter +t_c1 42 + +``` +==== second try==== +``` +# TYPE yolo_gauge gauge +yolo_gauge{level="max"} 42000 +# HELP t_c2 more awesome than c1 +# TYPE t_c2 counter +t_c2 2 +# TYPE t_c1 counter +t_c1 53 + +``` diff --git a/tests/prometheus/t_prom.ml b/tests/prometheus/t_prom.ml new file mode 100644 index 00000000..8e9fe8b5 --- /dev/null +++ b/tests/prometheus/t_prom.ml @@ -0,0 +1,23 @@ +module P = Tiny_httpd_prometheus + +let pf = Printf.printf +let reg = P.Registry.create () +let c1 = P.Counter.create reg "t_c1" +let c2 = P.Counter.create reg "t_c2" ~descr:"more awesome than c1" +let g1 = P.Gauge.create reg ~tags:[ "level", "max" ] "yolo_gauge" + +let () = + print_endline "==== first try ===="; + P.Counter.inc_by c1 42; + P.Counter.inc c2; + P.Gauge.set g1 2525; + + pf "```\n%s\n```\n" @@ P.Registry.emit_str reg + +let () = + print_endline "==== second try===="; + P.Counter.inc_by c1 11; + P.Counter.inc c2; + P.Gauge.set g1 42_000; + + pf "```\n%s\n```\n" @@ P.Registry.emit_str reg