Skip to content

Commit cbd726e

Browse files
committed
Make x-ray's ALLOY_CONFIG re-usable
This also changes the default tmp dir to be not hidden
1 parent c6754bf commit cbd726e

File tree

8 files changed

+267
-15
lines changed

8 files changed

+267
-15
lines changed

demo/2025-11/README.md

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -94,5 +94,5 @@ To clean up just delete the working directories
9494

9595
```shell
9696
rm -fr .tmp-leios-202511-demo
97-
rm -fr .tmp-x-ray
97+
rm -fr tmp-x-ray
9898
```

demo/extras/x_ray/README.md

Lines changed: 49 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -1,9 +1,21 @@
1-
# X-RAY - socket stats with Grafana
1+
# X-RAY - Observability stack with Grafana
2+
3+
X-ray provides a complete observability stack for Leios demos using Grafana, Prometheus, Loki, and Alloy.
4+
5+
## Quick Start
6+
7+
**Using nix:**
8+
9+
```shell
10+
nix run github:input-output-hk/ouroboros-leios#x_ray
11+
```
12+
13+
**Without nix:**
214

315
Position your terminal into the current directory and enter the shell with
416

517
```shell
6-
nix develop .#dev-x-ray
18+
nix develop .#dev-demo-extras-x-ray
719
```
820

921
Or if you use Direnv with Nix
@@ -12,6 +24,34 @@ Or if you use Direnv with Nix
1224
direnv allow
1325
```
1426

27+
Then run:
28+
29+
```shell
30+
./run.sh
31+
```
32+
33+
## Configuration
34+
35+
You can customize the x_ray stack by setting environment variables before running:
36+
37+
```shell
38+
export ALLOY_CONFIG=/path/to/custom/alloy
39+
export LOG_PATH=/path/to/logs/*.log
40+
./run.sh
41+
```
42+
43+
Available environment variables:
44+
- `ALLOY_CONFIG` - Path to Alloy configuration file
45+
- `LOG_PATH` - Glob pattern for log files to collect
46+
- `WORKING_DIR` - Working directory for runtime data (default: `tmp-x-ray`)
47+
- `GRAFANA_INI`, `GRAFANA_HOMEPATH` - Grafana configuration
48+
- `PROMETHEUS_CONFIG`, `LOKI_CONFIG` - Other service configs
49+
- `SS_FILTER` - Socket statistics filter expression
50+
51+
All variables have sensible defaults and can be overridden as needed.
52+
53+
## Manual Setup
54+
1555
You can either work with this setup step by step, or use the
1656
awesome [process-compose](https://f1bonacc1.github.io/process-compose/)
1757

@@ -70,7 +110,13 @@ pkill "socat|grafana|prometheus|alloy"
70110

71111
## process-compose
72112

73-
Run the setup
113+
Run the setup using the wrapper script:
114+
115+
```shell
116+
./run.sh
117+
```
118+
119+
Or run process-compose directly (requires environment variables to be set):
74120

75121
```shell
76122
process-compose -f process-compose.yaml

demo/extras/x_ray/build.nix

Lines changed: 7 additions & 7 deletions
Original file line numberDiff line numberDiff line change
@@ -27,23 +27,23 @@
2727
};
2828
};
2929

30-
packages = lib.optionalAttrs (system == "x86_64-linux") {
31-
x_ray = pkgs.writeShellApplication {
30+
packages = lib.optionalAttrs (system == "x86_64-linux") rec {
31+
x-ray = pkgs.writeShellApplication {
3232
name = "x_ray";
3333
runtimeInputs = config.devShells.dev-demo-extras-x-ray.nativeBuildInputs;
3434
runtimeEnv = {
35-
inherit (config.devShells.dev-demo-extras-x-ray) GRAFANA_SHARE;
35+
GRAFANA_SHARE = "${pkgs.grafana}/share/grafana";
3636
GRAFANA_INI = ./grafana.ini;
3737
GRAFANA_HOMEPATH = ./grafana;
3838
ALLOY_CONFIG = ./alloy;
3939
PROMETHEUS_CONFIG = ./prometheus.yaml;
4040
LOKI_CONFIG = ./loki.yaml;
41+
LOG_PATH = "../../leios-202511-demo/.tmp-leios-202511-demo/*/log";
4142
};
42-
text = ''
43-
process-compose --no-server -f ${./process-compose.yaml};
44-
'';
43+
text = builtins.readFile ./run.sh;
4544
};
46-
45+
# XXX: Drop once people forgot about it
46+
x_ray = x-ray;
4747
};
4848
};
4949
}

demo/extras/x_ray/process-compose.yaml

Lines changed: 0 additions & 4 deletions
Original file line numberDiff line numberDiff line change
@@ -1,10 +1,6 @@
11
version: "0.5"
22

3-
environment:
4-
- "WORKING_DIR=.tmp-x-ray"
5-
63
processes:
7-
84
Init:
95
command: |
106
set -exuo pipefail;

demo/extras/x_ray/run.sh

Lines changed: 35 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,35 @@
1+
#!/usr/bin/env bash
2+
#
3+
# Wrapper script to set defaults and run the x_ray observability stack using process-compose
4+
set -eo pipefail
5+
6+
# Get the directory where this script is located
7+
SOURCE_DIR="$(cd "$(dirname "${BASH_SOURCE[0]}")" && pwd)"
8+
9+
# Set defaults for all environment variables
10+
# These can be overridden by:
11+
# 1. Nix (via runtimeEnv in build.nix)
12+
# 2. User exports before running this script
13+
set -a
14+
: "${WORKING_DIR:=tmp-x-ray}"
15+
: "${GRAFANA_INI:=${SOURCE_DIR}/grafana.ini}"
16+
: "${GRAFANA_HOMEPATH:=${SOURCE_DIR}/grafana}"
17+
: "${ALLOY_CONFIG:=${SOURCE_DIR}/alloy}"
18+
: "${PROMETHEUS_CONFIG:=${SOURCE_DIR}/prometheus.yaml}"
19+
: "${LOKI_CONFIG:=${SOURCE_DIR}/loki.yaml}"
20+
: "${LOG_PATH:=../../leios-202511-demo/.tmp-leios-202511-demo/*/log}"
21+
: "${SS_FILTER:=( sport = 3001 and dport = 3002 ) or ( sport = 3002 and dport = 3001 ) or ( sport = 3002 and dport = 3003 ) or ( sport = 3003 and dport = 3002 )}"
22+
: "${GRAFANA_SHARE:=}"
23+
set +a
24+
25+
# Warn if GRAFANA_SHARE is not set (required for Grafana to work)
26+
if [ -z "${GRAFANA_SHARE}" ]; then
27+
echo "Warning: GRAFANA_SHARE not set. Grafana may not work correctly."
28+
fi
29+
30+
echo "Starting x_ray with process-compose..."
31+
echo " ALLOY_CONFIG: ${ALLOY_CONFIG}"
32+
echo " LOG_PATH: ${LOG_PATH}"
33+
echo " WORKING_DIR: ${WORKING_DIR}"
34+
35+
process-compose --no-server -f "${SOURCE_DIR}/process-compose.yaml"

demo/proto-devnet/README.md

Lines changed: 27 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -64,6 +64,33 @@ export WORKING_DIR=my-devnet
6464
./run.sh
6565
```
6666

67+
## Observability with X-ray
68+
69+
Proto-devnet generates an Alloy configuration for use with the X-ray observability stack.
70+
71+
To use it:
72+
73+
1. Start proto-devnet (using one of the methods above)
74+
75+
2. In another terminal, start x_ray with the generated config:
76+
77+
**Using nix:**
78+
79+
``` shell
80+
ALLOY_CONFIG="$(realpath tmp-devnet/alloy)" nix run github:input-output-hk/ouroboros-leios#x_ray
81+
```
82+
83+
**Without nix:**
84+
85+
``` shell
86+
cd ../extras/x_ray
87+
ALLOY_CONFIG="$(realpath ../../proto-devnet/tmp-devnet/alloy)" ./run.sh
88+
```
89+
90+
3. Access Grafana at <http://localhost:3000>
91+
92+
The generated alloy config is customized for proto-devnet with correct node IPs and Prometheus ports.
93+
6794
## Clean up
6895

6996
To reset the demo, simply remove the working directory, for example:

demo/proto-devnet/alloy.template

Lines changed: 141 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,141 @@
1+
prometheus.remote_write "prometheus" {
2+
endpoint {
3+
url = "http://127.0.0.1:9090/api/v1/write"
4+
}
5+
}
6+
7+
prometheus.scrape "cardano_node_exporter" {
8+
targets = [
9+
{
10+
"__address__" = "${IP_NODE1}:${METRICS_PORT_NODE1}",
11+
"job" = "cardano_node_metrics",
12+
"instance" = "localhost",
13+
"alias" = "node1",
14+
"process" = "Node1",
15+
},
16+
{
17+
"__address__" = "${IP_NODE2}:${METRICS_PORT_NODE2}",
18+
"job" = "cardano_node_metrics",
19+
"instance" = "localhost",
20+
"alias" = "node2",
21+
"process" = "Node2",
22+
},
23+
{
24+
"__address__" = "${IP_NODE3}:${METRICS_PORT_NODE3}",
25+
"job" = "cardano_node_metrics",
26+
"instance" = "localhost",
27+
"alias" = "node3",
28+
"process" = "Node3",
29+
},
30+
]
31+
32+
metrics_path = "/metrics"
33+
34+
scrape_timeout = "1s"
35+
scrape_interval = "1s"
36+
37+
forward_to = [prometheus.remote_write.prometheus.receiver]
38+
}
39+
40+
loki.write "loki" {
41+
endpoint {
42+
url = "http://localhost:3100/loki/api/v1/push"
43+
batch_size = "2MB"
44+
}
45+
}
46+
47+
local.file_match "local_files" {
48+
path_targets = [{"__path__" = "${LOG_PATH}"}]
49+
sync_period = "5s"
50+
}
51+
52+
loki.source.file "process_compose_log_scrape" {
53+
targets = local.file_match.local_files.targets
54+
forward_to = [loki.process.extract_process_compose_logs.receiver]
55+
tail_from_end = false
56+
}
57+
58+
loki.process "extract_process_compose_logs" {
59+
stage.json {
60+
expressions = {
61+
level = "level",
62+
process = "process",
63+
replica = "replica",
64+
message = "message",
65+
}
66+
drop_malformed = true
67+
}
68+
69+
stage.labels {
70+
values = {
71+
level = "level",
72+
process = "process",
73+
replica = "replica",
74+
}
75+
}
76+
77+
stage.static_labels {
78+
values = {
79+
service = "process-compose",
80+
type = "process-compose",
81+
}
82+
}
83+
84+
stage.output {
85+
source = "message"
86+
}
87+
88+
forward_to = [
89+
loki.write.loki.receiver,
90+
loki.process.extract_cardano_node_logs.receiver,
91+
]
92+
}
93+
94+
loki.process "extract_cardano_node_logs" {
95+
stage.json {
96+
expressions = {
97+
at = "at",
98+
sev = "sev",
99+
host = "host",
100+
thread = "thread",
101+
ns = "ns",
102+
data = "data",
103+
}
104+
drop_malformed = true
105+
}
106+
107+
stage.drop {
108+
source = "process"
109+
value = "Analyze"
110+
}
111+
112+
stage.timestamp {
113+
source = "at"
114+
format = "RFC3339"
115+
}
116+
117+
stage.labels {
118+
values = {
119+
level = "sev",
120+
alias = "host",
121+
host = "host",
122+
instance = "host",
123+
sev = "sev",
124+
thread = "thread",
125+
ns = "ns",
126+
}
127+
}
128+
129+
stage.static_labels {
130+
values = {
131+
service = "cardano-node",
132+
type = "cardano-node",
133+
}
134+
}
135+
136+
stage.output {
137+
source = "data"
138+
}
139+
140+
forward_to = [loki.write.loki.receiver]
141+
}

demo/proto-devnet/run.sh

Lines changed: 7 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -16,6 +16,10 @@ set -a
1616
: "${PORT_NODE2:=3002}"
1717
: "${IP_NODE3:=0.0.0.0}"
1818
: "${PORT_NODE3:=3003}"
19+
: "${METRICS_PORT_NODE1:=12901}"
20+
: "${METRICS_PORT_NODE2:=12902}"
21+
: "${METRICS_PORT_NODE3:=12903}"
22+
: "${LOG_PATH:=${WORKING_DIR}/node*/node.log}"
1923
set +a
2024

2125
# Check for required commands
@@ -137,5 +141,8 @@ find "$WORKING_DIR/utxo-keys" -name "*.skey" -exec chmod 400 {} \;
137141
# Configure tx-generator
138142
envsubst <"${SOURCE_DIR}/gen.template.json" >"${WORKING_DIR}/gen.json"
139143

144+
# Configure alloy for x_ray observability
145+
envsubst <"${SOURCE_DIR}/alloy.template" >"${WORKING_DIR}/alloy"
146+
140147
echo "Starting proto-devnet with process-compose..."
141148
process-compose --no-server -f "${SOURCE_DIR}/process-compose.yaml"

0 commit comments

Comments
 (0)