mirror of
https://github.com/ocaml-tracing/ocaml-opentelemetry.git
synced 2026-03-09 12:23:32 -04:00
ocurl lwt test
This commit is contained in:
parent
cdd1289c1d
commit
ce33809446
4 changed files with 104 additions and 38 deletions
|
|
@ -11,6 +11,8 @@ let sleep_outer = ref 2.0
|
||||||
|
|
||||||
let n_jobs = ref 1
|
let n_jobs = ref 1
|
||||||
|
|
||||||
|
let iterations = ref 4
|
||||||
|
|
||||||
let n = ref max_int
|
let n = ref max_int
|
||||||
|
|
||||||
let num_sleep = Atomic.make 0
|
let num_sleep = Atomic.make 0
|
||||||
|
|
@ -34,9 +36,9 @@ let run_job () : unit Lwt.t =
|
||||||
(* Printf.printf "cnt=%d\n%!" !cnt; *)
|
(* Printf.printf "cnt=%d\n%!" !cnt; *)
|
||||||
incr cnt;
|
incr cnt;
|
||||||
|
|
||||||
for%lwt j = 0 to 4 do
|
for%lwt j = 1 to !iterations do
|
||||||
(* parent scope is found via thread local storage *)
|
(* parent scope is found via thread local storage *)
|
||||||
let@ scope =
|
let@ span =
|
||||||
Atomic.incr num_tr;
|
Atomic.incr num_tr;
|
||||||
OT.Tracer.with_ ~kind:OT.Span.Span_kind_internal ~parent:_scope
|
OT.Tracer.with_ ~kind:OT.Span.Span_kind_internal ~parent:_scope
|
||||||
~attrs:[ "j", `Int j ]
|
~attrs:[ "j", `Int j ]
|
||||||
|
|
@ -48,41 +50,40 @@ let run_job () : unit Lwt.t =
|
||||||
Atomic.incr num_sleep
|
Atomic.incr num_sleep
|
||||||
);
|
);
|
||||||
|
|
||||||
OT.Logger.logf ~trace_id:(OT.Span.trace_id scope)
|
OT.Logger.logf ~trace_id:(OT.Span.trace_id span)
|
||||||
~span_id:(OT.Span.id scope) ~severity:Severity_number_info (fun k ->
|
~span_id:(OT.Span.id span) ~severity:Severity_number_info (fun k ->
|
||||||
k "inner at %d" j);
|
k "inner at %d" j);
|
||||||
|
try%lwt
|
||||||
incr i;
|
Atomic.incr num_tr;
|
||||||
|
|
||||||
(try
|
|
||||||
(* allocate some stuff *)
|
(* allocate some stuff *)
|
||||||
|
let%lwt () =
|
||||||
if !stress_alloc_ then (
|
if !stress_alloc_ then (
|
||||||
let@ _ =
|
let@ scope =
|
||||||
OT.Tracer.with_ ~kind:OT.Span.Span_kind_internal ~parent:scope
|
OT.Tracer.with_ ~kind:OT.Span.Span_kind_internal ~parent:span
|
||||||
"alloc"
|
"alloc"
|
||||||
in
|
in
|
||||||
Atomic.incr num_tr;
|
let _arr = Sys.opaque_identity @@ Array.make (25 * 25551) 42.0 in
|
||||||
|
ignore _arr;
|
||||||
let _arr : _ array =
|
OT.Span.add_event scope (OT.Event.make "done with alloc");
|
||||||
Sys.opaque_identity @@ Array.make (25 * 25551) 42.0
|
Lwt.return ()
|
||||||
|
) else
|
||||||
|
Lwt.return ()
|
||||||
in
|
in
|
||||||
ignore _arr
|
|
||||||
);
|
|
||||||
|
|
||||||
if !sleep_inner > 0. then (
|
let%lwt () = Lwt_unix.sleep !sleep_inner in
|
||||||
Unix.sleepf !sleep_inner;
|
Atomic.incr num_sleep;
|
||||||
Atomic.incr num_sleep
|
|
||||||
);
|
|
||||||
|
|
||||||
if j = 4 && !i mod 13 = 0 then failwith "oh no";
|
|
||||||
|
|
||||||
(* simulate a failure *)
|
(* simulate a failure *)
|
||||||
OT.Span.add_event scope (OT.Event.make "done with alloc")
|
if j = 4 && !i mod 13 = 0 then
|
||||||
with Failure _ -> ());
|
Lwt.fail (Failure "oh no")
|
||||||
|
else
|
||||||
Lwt.return ()
|
Lwt.return ()
|
||||||
|
with Failure _ -> Lwt.return ()
|
||||||
done
|
done
|
||||||
done
|
done
|
||||||
|
(* >>= fun () ->
|
||||||
|
Printf.eprintf "test: job done\n%!";
|
||||||
|
Lwt.return ()*)
|
||||||
|
|
||||||
let run () : unit Lwt.t =
|
let run () : unit Lwt.t =
|
||||||
OT.Gc_metrics.setup_on_main_exporter ();
|
OT.Gc_metrics.setup_on_main_exporter ();
|
||||||
|
|
@ -119,6 +120,8 @@ let () =
|
||||||
let final_stats = ref false in
|
let final_stats = ref false in
|
||||||
|
|
||||||
let n_bg_threads = ref 0 in
|
let n_bg_threads = ref 0 in
|
||||||
|
let url = ref None in
|
||||||
|
let n_procs = ref 1 in
|
||||||
let opts =
|
let opts =
|
||||||
[
|
[
|
||||||
"--debug", Arg.Bool (( := ) debug), " enable debug output";
|
"--debug", Arg.Bool (( := ) debug), " enable debug output";
|
||||||
|
|
@ -136,13 +139,25 @@ let () =
|
||||||
"--bg-threads", Arg.Set_int n_bg_threads, " number of background threads";
|
"--bg-threads", Arg.Set_int n_bg_threads, " number of background threads";
|
||||||
"--no-self-trace", Arg.Clear self_trace, " disable self tracing";
|
"--no-self-trace", Arg.Clear self_trace, " disable self tracing";
|
||||||
"-n", Arg.Set_int n, " number of iterations (default ∞)";
|
"-n", Arg.Set_int n, " number of iterations (default ∞)";
|
||||||
|
( "--iterations",
|
||||||
|
Arg.Set_int iterations,
|
||||||
|
" the number of inner iterations to run" );
|
||||||
|
( "--url",
|
||||||
|
Arg.String (fun s -> url := Some s),
|
||||||
|
" set the url for the OTel collector" );
|
||||||
"--final-stats", Arg.Set final_stats, " display some metrics at the end";
|
"--final-stats", Arg.Set final_stats, " display some metrics at the end";
|
||||||
|
"--procs", Arg.Set_int n_procs, " number of processes (stub)";
|
||||||
]
|
]
|
||||||
|> Arg.align
|
|> Arg.align
|
||||||
in
|
in
|
||||||
|
|
||||||
Arg.parse opts (fun _ -> ()) "emit1 [opt]*";
|
Arg.parse opts (fun _ -> ()) "emit1 [opt]*";
|
||||||
|
|
||||||
|
if !n_procs > 1 then
|
||||||
|
failwith
|
||||||
|
"TODO: add support for running multiple processes to the lwt-cohttp \
|
||||||
|
emitter";
|
||||||
|
|
||||||
let some_if_nzero r =
|
let some_if_nzero r =
|
||||||
if !r > 0 then
|
if !r > 0 then
|
||||||
Some !r
|
Some !r
|
||||||
|
|
@ -151,7 +166,7 @@ let () =
|
||||||
in
|
in
|
||||||
let config =
|
let config =
|
||||||
Opentelemetry_client_ocurl_lwt.Config.make ~debug:!debug
|
Opentelemetry_client_ocurl_lwt.Config.make ~debug:!debug
|
||||||
~self_trace:!self_trace
|
~self_trace:!self_trace ?url:!url
|
||||||
?http_concurrency_level:(some_if_nzero n_bg_threads)
|
?http_concurrency_level:(some_if_nzero n_bg_threads)
|
||||||
~batch_traces:(some_if_nzero batch_traces)
|
~batch_traces:(some_if_nzero batch_traces)
|
||||||
~batch_metrics:(some_if_nzero batch_metrics)
|
~batch_metrics:(some_if_nzero batch_metrics)
|
||||||
|
|
|
||||||
|
|
@ -5,6 +5,7 @@
|
||||||
(binaries
|
(binaries
|
||||||
(../bin/emit1.exe as emit1)
|
(../bin/emit1.exe as emit1)
|
||||||
(../bin/emit1_cohttp.exe as emit1_cohttp)
|
(../bin/emit1_cohttp.exe as emit1_cohttp)
|
||||||
|
(../bin/emit1_ocurl_lwt.exe as emit1_ocurl_lwt)
|
||||||
(../bin/emit1_eio.exe as emit1_eio)
|
(../bin/emit1_eio.exe as emit1_eio)
|
||||||
(./gather_signals.exe as gather_signals))))
|
(./gather_signals.exe as gather_signals))))
|
||||||
|
|
||||||
|
|
@ -38,8 +39,6 @@
|
||||||
(names test_cohttp_lwt_client_e2e)
|
(names test_cohttp_lwt_client_e2e)
|
||||||
(modules test_cohttp_lwt_client_e2e)
|
(modules test_cohttp_lwt_client_e2e)
|
||||||
(package opentelemetry-client-cohttp-lwt)
|
(package opentelemetry-client-cohttp-lwt)
|
||||||
(enabled_if
|
|
||||||
(>= %{ocaml_version} 5.0))
|
|
||||||
(deps %{bin:emit1_cohttp})
|
(deps %{bin:emit1_cohttp})
|
||||||
(libraries clients_e2e_lib alcotest opentelemetry opentelemetry-client))
|
(libraries clients_e2e_lib alcotest opentelemetry opentelemetry-client))
|
||||||
|
|
||||||
|
|
@ -57,8 +56,13 @@
|
||||||
(modules test_ocurl_client_e2e)
|
(modules test_ocurl_client_e2e)
|
||||||
(package opentelemetry-client-ocurl)
|
(package opentelemetry-client-ocurl)
|
||||||
(deps %{bin:emit1})
|
(deps %{bin:emit1})
|
||||||
(enabled_if
|
(libraries clients_e2e_lib alcotest opentelemetry opentelemetry-client))
|
||||||
(>= %{ocaml_version} 5.0))
|
|
||||||
|
(tests
|
||||||
|
(names test_ocurl_lwt_client_e2e)
|
||||||
|
(modules test_ocurl_lwt_client_e2e)
|
||||||
|
(package opentelemetry-client-ocurl-lwt)
|
||||||
|
(deps %{bin:emit1_ocurl_lwt})
|
||||||
(libraries clients_e2e_lib alcotest opentelemetry opentelemetry-client))
|
(libraries clients_e2e_lib alcotest opentelemetry opentelemetry-client))
|
||||||
|
|
||||||
(executable
|
(executable
|
||||||
|
|
|
||||||
|
|
@ -4,7 +4,7 @@ open Clients_e2e_lib
|
||||||
|
|
||||||
(* NOTE: This port must be different from that used by other integration tests,
|
(* NOTE: This port must be different from that used by other integration tests,
|
||||||
to prevent socket binding clashes. *)
|
to prevent socket binding clashes. *)
|
||||||
let port = 4359
|
let port = 4361
|
||||||
|
|
||||||
let url = Printf.sprintf "http://localhost:%d" port
|
let url = Printf.sprintf "http://localhost:%d" port
|
||||||
|
|
||||||
|
|
|
||||||
47
tests/client_e2e/test_ocurl_lwt_client_e2e.ml
Normal file
47
tests/client_e2e/test_ocurl_lwt_client_e2e.ml
Normal file
|
|
@ -0,0 +1,47 @@
|
||||||
|
module Client = Opentelemetry_client
|
||||||
|
module Proto = Opentelemetry.Proto
|
||||||
|
open Clients_e2e_lib
|
||||||
|
|
||||||
|
(* NOTE: This port must be different from that used by other integration tests,
|
||||||
|
to prevent socket binding clashes. *)
|
||||||
|
let port = 4359
|
||||||
|
|
||||||
|
let url = Printf.sprintf "http://localhost:%d" port
|
||||||
|
|
||||||
|
let () =
|
||||||
|
Clients_e2e_lib.run_tests ~port
|
||||||
|
[
|
||||||
|
( "emit1_ocurl_lwt",
|
||||||
|
{
|
||||||
|
url;
|
||||||
|
jobs = 1;
|
||||||
|
procs = 1;
|
||||||
|
n_outer = 1;
|
||||||
|
iterations = 1;
|
||||||
|
batch_traces = 2;
|
||||||
|
batch_metrics = 2;
|
||||||
|
batch_logs = 2;
|
||||||
|
} );
|
||||||
|
( "emit1_ocurl_lwt",
|
||||||
|
{
|
||||||
|
url;
|
||||||
|
jobs = 3;
|
||||||
|
procs = 1;
|
||||||
|
n_outer = 1;
|
||||||
|
iterations = 1;
|
||||||
|
batch_traces = 400;
|
||||||
|
batch_metrics = 3;
|
||||||
|
batch_logs = 400;
|
||||||
|
} );
|
||||||
|
( "emit1_ocurl_lwt",
|
||||||
|
{
|
||||||
|
url;
|
||||||
|
jobs = 3;
|
||||||
|
procs = 1;
|
||||||
|
n_outer = 5;
|
||||||
|
iterations = 1;
|
||||||
|
batch_traces = 400;
|
||||||
|
batch_metrics = 3;
|
||||||
|
batch_logs = 400;
|
||||||
|
} );
|
||||||
|
]
|
||||||
Loading…
Add table
Reference in a new issue