Skip to content

Commit f7bec84

Browse files
authored
feat: store localnet logs between runs (#4830)
2 parents 1b4d625 + 2cda0ae commit f7bec84

8 files changed

+45
-18
lines changed

.gitignore

+1
Original file line numberDiff line numberDiff line change
@@ -101,3 +101,4 @@ cache_*_db
101101

102102
# log aggregation logs folder variable file, no sense to track it
103103
test/logs_aggregator/.env
104+
test/logs_aggregator/loki

Makefile

+12-7
Original file line numberDiff line numberDiff line change
@@ -55,10 +55,13 @@ help:
5555
@echo "travis_rpc_checker - run the Travis RPC checker script, defaulting the test branch to 'master' unless overridden by TEST_REPO_BRANCH"
5656
@echo "travis_rosetta_checker - run the Travis Rosetta checker script, defaulting the test branch to 'master' unless overridden by TEST_REPO_BRANCH"
5757
@echo "debug_external - cleans up environment, rebuilds the binary, and deploys with external nodes"
58+
@echo "debug-multi-bls - cleans up environment, rebuilds the binary, and deploys with external nodes in configuration 1 harmony process -> 2 validators"
5859
@echo "build_localnet_validator - imports validator keys, funds validator accounts, waits for the epoch, and creates external validators on a local network"
59-
@echo "debug-start-log - start a docker compose Promtail->Loki->Grafana stack against localnet logs, needs docker compose and started localnet"
60+
@echo "debug-start-log - start a docker compose Promtail->Loki->Grafana stack against localnet logs, creates"\
61+
"persistent volume to store parsed logs between localnet runs, needs docker compose and started localnet"
6062
@echo "debug-stop-log - stops a docker compose Promtail->Loki->Grafana stack"
6163
@echo "debug-restart-log - restart a docker compose Promtail->Loki->Grafana stack"
64+
@echo "debug-delete-log - removes persistent volume for the Loki and host folder for it"
6265

6366
libs:
6467
make -C $(TOP)/mcl -j8
@@ -101,7 +104,7 @@ debug-multi-bls:
101104
echo sleep 10s before creating the external validator
102105
sleep 10
103106
bash ./test/build-localnet-validator.sh
104-
107+
105108
debug-multi-bls-with-terminal:
106109
# add VERBOSE=true before bash or run `export VERBOSE=true` on the shell level for have max logging
107110
# add LEGACY_SYNC=true before bash or run `export LEGACY_SYNC=true` on the shell level to switch to the legacy sync
@@ -111,7 +114,7 @@ debug-multi-bls-with-terminal:
111114
bash ./test/build-localnet-validator.sh
112115
screen -r localnet
113116

114-
debug-multi-bls-multi-ext-node: pre-external
117+
debug-multi-bls-multi-ext-node:
115118
# add VERBOSE=true before bash or run `export VERBOSE=true` on the shell level for have max logging
116119
# add LEGACY_SYNC=true before bash or run `export LEGACY_SYNC=true` on the shell level to switch to the legacy sync
117120
./test/debug.sh ./test/configs/local-multi-bls-multi-ext-node.txt &
@@ -120,7 +123,7 @@ debug-multi-bls-multi-ext-node: pre-external
120123
bash ./test/build-localnet-validator.sh
121124

122125
clean:
123-
rm -rf ./tmp_log*
126+
rm -rf ./tmp_log/*
124127
rm -rf ./.dht*
125128
rm -rf ./db-*
126129
rm -rf ./latest
@@ -232,9 +235,6 @@ travis_rpc_checker:
232235
travis_rosetta_checker:
233236
bash ./scripts/travis_rosetta_checker.sh
234237

235-
debug_external: clean
236-
bash test/debug-external.sh
237-
238238
build_localnet_validator:
239239
bash test/build-localnet-validator.sh
240240

@@ -248,3 +248,8 @@ debug-stop-log:
248248
bash ./test/logs_aggregator/stop_log_aggregator.sh
249249

250250
debug-restart-log: debug-stop-log debug-start-log
251+
252+
debug-delete-log:
253+
docker volume rm logs_aggregator_loki_data
254+
@echo "[WARN] - it needs sudo to remove folder created with loki docker image user"
255+
sudo rm -rf test/logs_aggregator/loki

test/debug-external.sh

+1-1
Original file line numberDiff line numberDiff line change
@@ -1,7 +1,7 @@
11
#!/usr/bin/env bash
22

33
./test/kill_node.sh
4-
rm -rf tmp_log* 2> /dev/null
4+
rm -rf tmp_log/* 2> /dev/null
55
rm *.rlp 2> /dev/null
66
rm -rf .dht* 2> /dev/null
77
scripts/go_executable_build.sh -S || exit 1 # dynamic builds are faster for debug iteration...

test/debug.sh

+1-1
Original file line numberDiff line numberDiff line change
@@ -6,7 +6,7 @@ Localnet_Blocks_Per_Epoch=$2
66
Localnet_Blocks_Per_Epoch_V2=$3
77

88
./test/kill_node.sh
9-
rm -rf tmp_log* 2> /dev/null
9+
rm -rf tmp_log/* 2> /dev/null
1010
rm *.rlp 2> /dev/null
1111
rm -rf .dht* 2> /dev/null
1212
scripts/go_executable_build.sh -S || exit 1 # dynamic builds are faster for debug iteration...

test/logs_aggregator/docker-compose.yml

+12-3
Original file line numberDiff line numberDiff line change
@@ -5,13 +5,14 @@ services:
55
ports:
66
- 3100:3100
77
volumes:
8-
- ./loki-config.yml:/etc/loki/loki-config.yaml
8+
- ./loki-config.yml:/etc/loki/local-config.yaml
9+
- loki_data:/loki
910
promtail:
1011
container_name: promtail
1112
image: grafana/promtail:latest
1213
volumes:
13-
- ./promtail-config.yml:/etc/promtail/promtail-config.yaml
14-
- ${CURRENT_SESSION_LOGS}:/var/log/
14+
- ./promtail-config.yml:/etc/promtail/config.yml
15+
- ${LOG_FOLDER}:/var/log/
1516
grafana:
1617
container_name: grafana
1718
image: grafana/grafana
@@ -23,3 +24,11 @@ services:
2324
- 3000:3000
2425
volumes:
2526
- ./loki-datasource.yaml:/etc/grafana/provisioning/datasources/loki-datasource.yaml
27+
28+
volumes:
29+
loki_data:
30+
driver: local
31+
driver_opts:
32+
type: none
33+
o: bind
34+
device: ${LOKI_FOLDER}

test/logs_aggregator/loki-config.yml

+5
Original file line numberDiff line numberDiff line change
@@ -32,3 +32,8 @@ schema_config:
3232
index:
3333
prefix: index_
3434
period: 24h
35+
36+
limits_config:
37+
ingestion_rate_strategy: local
38+
ingestion_rate_mb: 30
39+
ingestion_burst_size_mb: 50

test/logs_aggregator/promtail-config.yml

+1-1
Original file line numberDiff line numberDiff line change
@@ -15,4 +15,4 @@ scrape_configs:
1515
- "localhost"
1616
labels:
1717
job: varlogs
18-
__path__: /var/log/*.log
18+
__path__: /var/log/log*/*.log

test/logs_aggregator/start_log_aggregator.sh

+12-5
Original file line numberDiff line numberDiff line change
@@ -5,13 +5,20 @@ set -eou pipefail
55
DIR="$(cd "$(dirname "${BASH_SOURCE[0]}")" >/dev/null 2>&1 && pwd)"
66
echo "working in ${DIR}"
77
cd $DIR && pwd
8-
logs="$(ls -1 '../../tmp_log/')"
98
path="$(readlink -f '../../tmp_log/')"
10-
echo "Current localnet logs are placed into '${path}/${logs}'"
11-
echo "CURRENT_SESSION_LOGS='${path}/${logs}'" > .env
12-
echo "CURRENT_SESSION_LOGS='${path}/${logs}'"
13-
echo "starting docker compose lor log aggregation"
9+
test -d "${path}" || (echo "logs folder do not exist - ${path},"\
10+
"please create a localnet first, exiting" && exit 1)
11+
log_path="$(find ${path} -type d | sort | tail -n 1)"
12+
log_path=$(echo "${log_path}" | sed "s#.*/tmp_log/#/var/log/#")
13+
loki_path="${DIR}/loki"
14+
mkdir -p "${loki_path}"
15+
echo "LOG_FOLDER='${path}'" > .env
16+
echo "LOKI_FOLDER='${loki_path}'" >> .env
17+
echo "starting docker compose for log aggregation"
1418
docker compose up --detach
1519
sleep 5
20+
echo "Whole list of log folders"
21+
find ${path} -type d | sort | grep 'log-'
1622
echo "Opening Grafana"
1723
python3 -m webbrowser "http://localhost:3000/explore"
24+
echo "Please, use {filename=~\"${log_path}/.*\"} to get the latest run localnet logs"

0 commit comments

Comments
 (0)