add basic test that emits fake data

This commit is contained in:
Simon Cruanes 2022-03-16 16:48:43 -04:00
parent b05d64a025
commit a6b0a2134b
No known key found for this signature in database
GPG key ID: EBFFF6F283F3A2B4
3 changed files with 32 additions and 0 deletions

2
emit1.sh Executable file
View file

@ -0,0 +1,2 @@
#!/bin/sh
exec dune exec --profile=release tests/emit1.exe -- $@

4
tests/dune Normal file
View file

@ -0,0 +1,4 @@
(executable
(name emit1)
(libraries unix opentelemetry opentelemetry-client-ocurl))

26
tests/emit1.ml Normal file
View file

@ -0,0 +1,26 @@
module T = Opentelemetry
let run () =
Printf.printf "collector is on %S\n%!" (Opentelemetry_client_ocurl.get_url());
let i = ref 0 in
while true do
Unix.sleepf 2.;
let gc = Gc.stat() in
T.Metrics.(
emit [
gauge ~name:"i" [int !i];
gauge ~name:"major-heap-words" [int gc.Gc.heap_words];
sum ~name:"minor-allocated" [float gc.Gc.minor_words];
]);
incr i;
(* allocate some stuff *)
let _arr = Sys.opaque_identity @@ Array.make (25 * 25551) 42.0 in
ignore _arr;
done
let () =
Opentelemetry_client_ocurl.with_setup run