mirror of
https://github.com/ocaml-tracing/ocaml-opentelemetry.git
synced 2026-03-10 04:35:46 -04:00
test(emit1): knobs to change sleep, batch size, collector config etc.
This commit is contained in:
parent
124ba09b2b
commit
396ef4c366
1 changed files with 45 additions and 12 deletions
|
|
@ -3,11 +3,30 @@ module T = Opentelemetry
|
||||||
let spf = Printf.sprintf
|
let spf = Printf.sprintf
|
||||||
let (let@) f x = f x
|
let (let@) f x = f x
|
||||||
|
|
||||||
|
let sleep_inner = ref 0.1
|
||||||
|
let sleep_outer = ref 2.0
|
||||||
|
|
||||||
let run () =
|
let run () =
|
||||||
Printf.printf "collector is on %S\n%!" (Opentelemetry_client_ocurl.get_url());
|
Printf.printf "collector is on %S\n%!" (Opentelemetry_client_ocurl.get_url());
|
||||||
|
|
||||||
|
(* regularly emit some metrics *)
|
||||||
|
let emit_gc() =
|
||||||
|
let gc = Gc.stat() in
|
||||||
|
T.Metrics.(
|
||||||
|
emit [
|
||||||
|
gauge ~name:"ocaml_opentracing.test.major_heap_words" [int gc.Gc.heap_words];
|
||||||
|
sum ~name:"ocaml_opentracing.test.minor_allocated" [float gc.Gc.minor_words];
|
||||||
|
]);
|
||||||
|
in
|
||||||
|
let _al = Gc.create_alarm emit_gc in
|
||||||
|
|
||||||
|
let@ scope = T.Trace.with_ "run" in
|
||||||
|
|
||||||
let i = ref 0 in
|
let i = ref 0 in
|
||||||
while true do
|
while true do
|
||||||
let@ scope = T.Trace.with_ ~kind:T.Span.Span_kind_producer
|
let@ scope =
|
||||||
|
T.Trace.with_ ~trace_id:scope.trace_id ~parent:scope.span_id
|
||||||
|
~kind:T.Span.Span_kind_producer
|
||||||
"loop.outer" ~attrs:["i", `Int !i] in
|
"loop.outer" ~attrs:["i", `Int !i] in
|
||||||
|
|
||||||
for j=0 to 4 do
|
for j=0 to 4 do
|
||||||
|
|
@ -16,15 +35,7 @@ let run () =
|
||||||
~trace_id:scope.trace_id ~parent:scope.span_id
|
~trace_id:scope.trace_id ~parent:scope.span_id
|
||||||
~attrs:["j", `Int j]
|
~attrs:["j", `Int j]
|
||||||
"loop.inner" in
|
"loop.inner" in
|
||||||
Unix.sleepf 2.;
|
Unix.sleepf !sleep_outer;
|
||||||
|
|
||||||
let gc = Gc.stat() in
|
|
||||||
T.Metrics.(
|
|
||||||
emit [
|
|
||||||
gauge ~name:"ocaml_opentracing.test.i" [int !i];
|
|
||||||
gauge ~name:"ocaml_opentracing.test.major_heap_words" [int gc.Gc.heap_words];
|
|
||||||
sum ~name:"ocaml_opentracing.test.minor_allocated" [float gc.Gc.minor_words];
|
|
||||||
]);
|
|
||||||
|
|
||||||
incr i;
|
incr i;
|
||||||
|
|
||||||
|
|
@ -36,7 +47,7 @@ let run () =
|
||||||
(* allocate some stuff *)
|
(* allocate some stuff *)
|
||||||
let _arr = Sys.opaque_identity @@ Array.make (25 * 25551) 42.0 in
|
let _arr = Sys.opaque_identity @@ Array.make (25 * 25551) 42.0 in
|
||||||
ignore _arr;
|
ignore _arr;
|
||||||
Unix.sleepf 0.1;
|
Unix.sleepf !sleep_inner;
|
||||||
if j=4 && !i mod 13 = 0 then failwith "oh no"; (* simulate a failure *)
|
if j=4 && !i mod 13 = 0 then failwith "oh no"; (* simulate a failure *)
|
||||||
|
|
||||||
T.Trace.add_event scope (fun()->T.Event.make "done with alloc");
|
T.Trace.add_event scope (fun()->T.Event.make "done with alloc");
|
||||||
|
|
@ -49,4 +60,26 @@ let () =
|
||||||
Sys.catch_break true;
|
Sys.catch_break true;
|
||||||
T.Globals.service_name := "t1";
|
T.Globals.service_name := "t1";
|
||||||
T.Globals.service_namespace := Some "ocaml-otel.test";
|
T.Globals.service_namespace := Some "ocaml-otel.test";
|
||||||
Opentelemetry_client_ocurl.with_setup run
|
|
||||||
|
let thread = ref true in
|
||||||
|
let batch_traces = ref 400 in
|
||||||
|
let batch_metrics = ref 3 in
|
||||||
|
let opts = [
|
||||||
|
"--thread", Arg.Bool ((:=) thread), " use a background thread";
|
||||||
|
"--batch-traces", Arg.Int ((:=) batch_traces), " size of traces batch";
|
||||||
|
"--batch-metrics", Arg.Int ((:=) batch_metrics), " size of metrics batch";
|
||||||
|
"--sleep-inner", Arg.Set_float sleep_inner, " sleep (in s) in inner loop";
|
||||||
|
"--sleep-outer", Arg.Set_float sleep_outer, " sleep (in s) in outer loop";
|
||||||
|
] |> Arg.align in
|
||||||
|
|
||||||
|
Arg.parse opts (fun _ -> ()) "emit1 [opt]*";
|
||||||
|
|
||||||
|
let some_if_nzero r = if !r > 0 then Some !r else None in
|
||||||
|
let config = Opentelemetry_client_ocurl.Config.make
|
||||||
|
~batch_traces:(some_if_nzero batch_traces)
|
||||||
|
~batch_metrics:(some_if_nzero batch_metrics)
|
||||||
|
~thread:!thread () in
|
||||||
|
Format.printf "@[<2>sleep outer: %.3fs,@ sleep inner: %.3fs,@ config: %a@]@."
|
||||||
|
!sleep_outer !sleep_inner Opentelemetry_client_ocurl.Config.pp config;
|
||||||
|
|
||||||
|
Opentelemetry_client_ocurl.with_setup ~config run
|
||||||
|
|
|
||||||
Loading…
Add table
Reference in a new issue