Skip to content

Commit 7ce92db

Browse files
author
Marge Bot
committed
Merge tezos/tezos!14890: Tezt/Cloud: Add the OpenTelemetry stack
Co-authored-by: François Thiré <[email protected]> Approved-by: Paul Laforgue <[email protected]> Approved-by: Guillaume B <[email protected]> Approved-by: François Thiré <[email protected]> See merge request https://gitlab.com/tezos/tezos/-/merge_requests/14890
2 parents 8dfed5b + f762cd9 commit 7ce92db

File tree

9 files changed

+207
-1
lines changed

9 files changed

+207
-1
lines changed

tezt/lib_cloud/cli.ml

Lines changed: 9 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -227,3 +227,12 @@ let octez_release =
227227
~placeholder:"<tag>"
228228
~description:"Use the octez release <tag> instead of local octez binaries."
229229
()
230+
231+
let open_telemetry =
232+
Clap.flag
233+
~section
234+
~set_long:"open-telemetry"
235+
~unset_long:"no-open-telemetry"
236+
~set_long_synonyms:["otel"]
237+
~description:"Run the Open Telemetry stack"
238+
grafana

tezt/lib_cloud/cli.mli

Lines changed: 3 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -100,3 +100,6 @@ val os : string
100100

101101
(** The tag of the octez release to be used. *)
102102
val octez_release : string option
103+
104+
(** Activate the Open Telemetry collector. *)
105+
val open_telemetry : bool

tezt/lib_cloud/cloud.ml

Lines changed: 22 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -88,6 +88,8 @@ type t = {
8888
website : Web.t option;
8989
prometheus : Prometheus.t option;
9090
grafana : Grafana.t option;
91+
otel : Otel.t option;
92+
jaeger : Jaeger.t option;
9193
deployement : Deployement.t option;
9294
}
9395

@@ -163,6 +165,8 @@ let shutdown ?exn t =
163165
let* () =
164166
Option.fold ~none:Lwt.return_unit ~some:Grafana.shutdown t.grafana
165167
in
168+
let* () = Option.fold ~none:Lwt.return_unit ~some:Otel.shutdown t.otel in
169+
let* () = Option.fold ~none:Lwt.return_unit ~some:Jaeger.shutdown t.jaeger in
166170
let* () =
167171
Option.fold
168172
~none:Lwt.return_unit
@@ -215,9 +219,24 @@ let orchestrator deployement f =
215219
Lwt.return_some grafana
216220
else Lwt.return_none
217221
in
222+
let* otel, jaeger =
223+
if Env.open_telemetry then
224+
let* otel = Otel.run ~jaeger:true in
225+
let* jaeger = Jaeger.run () in
226+
Lwt.return (Some otel, Some jaeger)
227+
else Lwt.return (None, None)
228+
in
218229
Log.info "Post prometheus" ;
219230
let t =
220-
{website; agents; prometheus; grafana; deployement = Some deployement}
231+
{
232+
website;
233+
agents;
234+
prometheus;
235+
grafana;
236+
otel;
237+
jaeger;
238+
deployement = Some deployement;
239+
}
221240
in
222241
let sigint = sigint () in
223242
let main_promise =
@@ -500,6 +519,8 @@ let register ?proxy_files ?vms ~__FILE__ ~title ~tags ?seed f =
500519
agents = [default_agent];
501520
website = None;
502521
grafana = None;
522+
otel = None;
523+
jaeger = None;
503524
prometheus = None;
504525
deployement = None;
505526
}

tezt/lib_cloud/env.ml

Lines changed: 2 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -70,6 +70,8 @@ let dns = Cli.dns
7070

7171
let os = Cli.os
7272

73+
let open_telemetry = Cli.open_telemetry
74+
7375
let docker_image =
7476
(* In localhost mode, we don't want to interact with GCP. The image is taken
7577
locally. *)

tezt/lib_cloud/env.mli

Lines changed: 2 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -79,6 +79,8 @@ val dns : bool
7979

8080
val os : string
8181

82+
val open_telemetry : bool
83+
8284
val init : unit -> unit Lwt.t
8385

8486
val project_id : unit -> string Lwt.t

tezt/lib_cloud/jaeger.ml

Lines changed: 40 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,40 @@
1+
(*****************************************************************************)
2+
(* *)
3+
(* SPDX-License-Identifier: MIT *)
4+
(* SPDX-FileCopyrightText: 2024 Nomadic Labs <[email protected]> *)
5+
(* *)
6+
(*****************************************************************************)
7+
8+
type t = unit
9+
10+
let run () =
11+
let* () =
12+
Process.run
13+
"docker"
14+
[
15+
"run";
16+
"-d";
17+
"--network";
18+
"host";
19+
"--rm";
20+
"--name";
21+
"jaeger";
22+
"-p";
23+
"16686:16686";
24+
"-p";
25+
"14250:14250";
26+
"jaegertracing/all-in-one:latest";
27+
]
28+
in
29+
let is_ready output = String.trim output = "200" in
30+
let run () =
31+
Process.spawn
32+
"curl"
33+
["-s"; "-o"; "/dev/null"; "-w"; "%{http_code}"; "http://localhost:16686/"]
34+
in
35+
let* _ = Env.wait_process ~is_ready ~run () in
36+
Lwt.return ()
37+
38+
let shutdown () =
39+
let* () = Docker.kill "jaeger" |> Process.check in
40+
Lwt.return_unit

tezt/lib_cloud/jaeger.mli

Lines changed: 12 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,12 @@
1+
(*****************************************************************************)
2+
(* *)
3+
(* SPDX-License-Identifier: MIT *)
4+
(* SPDX-FileCopyrightText: 2024 Nomadic Labs <[email protected]> *)
5+
(* *)
6+
(*****************************************************************************)
7+
8+
type t
9+
10+
val run : unit -> t Lwt.t
11+
12+
val shutdown : t -> unit Lwt.t

tezt/lib_cloud/otel.ml

Lines changed: 105 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,105 @@
1+
(*****************************************************************************)
2+
(* *)
3+
(* SPDX-License-Identifier: MIT *)
4+
(* SPDX-FileCopyrightText: 2024 Nomadic Labs <[email protected]> *)
5+
(* *)
6+
(*****************************************************************************)
7+
8+
type t = unit
9+
10+
let configuration ~jaeger =
11+
let jaeger =
12+
if jaeger then
13+
{|
14+
otlp/jaeger:
15+
endpoint: http://localhost:4317
16+
tls:
17+
insecure: true
18+
|}
19+
else ""
20+
in
21+
Format.asprintf
22+
{|
23+
receivers:
24+
otlp:
25+
protocols:
26+
http:
27+
endpoint: "0.0.0.0:55681"
28+
29+
exporters:
30+
31+
%s
32+
33+
processors:
34+
batch: # Batch processor to optimize telemetry processing
35+
timeout: 5s
36+
37+
service:
38+
pipelines:
39+
traces: # Pipeline to process trace data
40+
receivers: [otlp]
41+
processors: [batch]
42+
exporters: [otlp/jaeger]
43+
44+
telemetry:
45+
metrics:
46+
address: "0.0.0.0:8888" # Optional: Expose metrics for the collector itself (Prometheus scrapeable)
47+
48+
extensions:
49+
- health_check
50+
51+
extensions:
52+
health_check:
53+
endpoint: "localhost:13133"
54+
|}
55+
jaeger
56+
57+
let run ~jaeger =
58+
let configuration_file =
59+
Filename.get_temp_dir_name () // "otel-config.yaml"
60+
in
61+
let contents = configuration ~jaeger in
62+
write_file configuration_file ~contents ;
63+
let* () =
64+
Process.run
65+
"docker"
66+
[
67+
"run";
68+
"-d";
69+
"--rm";
70+
"--network";
71+
"host";
72+
"--name";
73+
"otel-collector";
74+
"-p";
75+
"4317-4318:4317-4318";
76+
"-p";
77+
"13133:13133";
78+
"-p";
79+
"55680-55681:55680-55681";
80+
"-v";
81+
Format.asprintf "%s:/etc/otel/config.yaml" configuration_file;
82+
"otel/opentelemetry-collector:latest";
83+
"--config";
84+
"/etc/otel/config.yaml";
85+
]
86+
in
87+
let is_ready output = String.trim output = "200" in
88+
let run () =
89+
Process.spawn
90+
"curl"
91+
[
92+
"-s";
93+
"-o";
94+
"/dev/null";
95+
"-w";
96+
"%{http_code}";
97+
"http://localhost:13133/healthz";
98+
]
99+
in
100+
let* _ = Env.wait_process ~is_ready ~run () in
101+
Lwt.return ()
102+
103+
let shutdown () =
104+
let* () = Docker.kill "otel-collector" |> Process.check in
105+
Lwt.return_unit

tezt/lib_cloud/otel.mli

Lines changed: 12 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,12 @@
1+
(*****************************************************************************)
2+
(* *)
3+
(* SPDX-License-Identifier: MIT *)
4+
(* SPDX-FileCopyrightText: 2024 Nomadic Labs <[email protected]> *)
5+
(* *)
6+
(*****************************************************************************)
7+
8+
type t
9+
10+
val run : jaeger:bool -> t Lwt.t
11+
12+
val shutdown : t -> unit Lwt.t

0 commit comments

Comments
 (0)