Skip to content

Commit

Permalink
Merge pull request #24 from imandra-ai/wip-better-client
Browse files Browse the repository at this point in the history
improve client code
  • Loading branch information
c-cube authored Jul 7, 2022
2 parents 85b6e91 + 41e9962 commit 586e16e
Show file tree
Hide file tree
Showing 10 changed files with 517 additions and 381 deletions.
2 changes: 1 addition & 1 deletion dune
Original file line number Diff line number Diff line change
@@ -1,3 +1,3 @@
(env
(_
(flags :standard -warn-error -a+8)))
(flags :standard -warn-error -a+8 -strict-sequence)))
27 changes: 0 additions & 27 deletions src/client/FQueue.ml

This file was deleted.

11 changes: 0 additions & 11 deletions src/client/FQueue.mli

This file was deleted.

4 changes: 4 additions & 0 deletions src/client/common_.ml
Original file line number Diff line number Diff line change
Expand Up @@ -3,6 +3,10 @@ include Opentelemetry.Lock

let[@inline] ( let@ ) f x = f x

let spf = Printf.sprintf

let tid () = Thread.id @@ Thread.self ()

let debug_ =
ref
(match Sys.getenv_opt "OTEL_OCAML_DEBUG" with
Expand Down
22 changes: 16 additions & 6 deletions src/client/config.ml
Original file line number Diff line number Diff line change
Expand Up @@ -8,7 +8,7 @@ type t = {
batch_metrics: int option;
batch_logs: int option;
batch_timeout_ms: int;
thread: bool;
bg_threads: int;
ticker_thread: bool;
}

Expand All @@ -24,20 +24,30 @@ let pp out self =
batch_metrics;
batch_logs;
batch_timeout_ms;
thread;
bg_threads;
ticker_thread;
} =
self
in
Format.fprintf out
"{@[ debug=%B;@ url=%S;@ headers=%a;@ batch_traces=%a;@ batch_metrics=%a;@ \
batch_logs=%a;@ batch_timeout_ms=%d; thread=%B;@ ticker_thread=%B @]}"
batch_logs=%a;@ batch_timeout_ms=%d; bg_threads=%d;@ ticker_thread=%B @]}"
debug url ppheaders headers ppiopt batch_traces ppiopt batch_metrics ppiopt
batch_logs batch_timeout_ms thread ticker_thread
batch_logs batch_timeout_ms bg_threads ticker_thread

let make ?(debug = !debug_) ?(url = get_url ()) ?(headers = get_headers ())
?(batch_traces = Some 400) ?(batch_metrics = None) ?(batch_logs = Some 400)
?(batch_timeout_ms = 500) ?(thread = true) ?(ticker_thread = true) () : t =
?(batch_timeout_ms = 500) ?(thread = true) ?bg_threads
?(ticker_thread = true) () : t =
let bg_threads =
match bg_threads with
| Some n -> max n 0
| None ->
if thread then
4
else
0
in
{
debug;
url;
Expand All @@ -46,6 +56,6 @@ let make ?(debug = !debug_) ?(url = get_url ()) ?(headers = get_headers ())
batch_metrics;
batch_timeout_ms;
batch_logs;
thread;
bg_threads;
ticker_thread;
}
13 changes: 10 additions & 3 deletions src/client/config.mli
Original file line number Diff line number Diff line change
Expand Up @@ -28,12 +28,13 @@ type t = private {
incomplete.
Note that the batch might take longer than that, because this is
only checked when a new event occurs. Default 500. *)
thread: bool; (** Is there a background thread? Default [true] *)
bg_threads: int;
(** Are there background threads, and how many? Default [4] *)
ticker_thread: bool;
(** Is there a ticker thread? Default [true].
This thread will regularly call [tick()] on the backend, to make
sure it makes progress, and regularly send events to the collector.
This option is ignored if [thread=false]. *)
This option is ignored if [bg_threads=0]. *)
}
(** Configuration.
Expand All @@ -49,9 +50,15 @@ val make :
?batch_logs:int option ->
?batch_timeout_ms:int ->
?thread:bool ->
?bg_threads:int ->
?ticker_thread:bool ->
unit ->
t
(** Make a configuration *)
(** Make a configuration.
@param thread if true and [bg_threads] is not provided, we will pick a number
of bg threads. Otherwise the number of [bg_threads] superseeds this option.
*)

val pp : Format.formatter -> t -> unit
Loading

0 comments on commit 586e16e

Please sign in to comment.