Skip to content

Commit 7ceeb50

Browse files
committed
feat: store localnet logs between runs
Details: - change rm and clean commands to remove only subfolder for tmp_log folder- justification - tmp_log folder needed for the log aggregator, prevent removal on the go when log stack is running - fix promtail config to point it to the right place - add named volume to the docker-compose to store Loki indexed between localnet runs - echance debug-start-log - it checking that localnet is running, exits if not - add debug-delete-volume-log to make, it removes loki named volume, warns about sudo rm for the loki files
1 parent 9dba11d commit 7ceeb50

7 files changed

+40
-15
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

+13-5
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-volume-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
@@ -236,7 +239,7 @@ travis_rosetta_checker:
236239
TEST_REPO_BRANCH='master'
237240
bash ./scripts/travis_rosetta_checker.sh
238241

239-
debug_external: clean
242+
debug_external:
240243
bash test/debug-external.sh
241244

242245
build_localnet_validator:
@@ -252,3 +255,8 @@ debug-stop-log:
252255
bash ./test/logs_aggregator/stop_log_aggregator.sh
253256

254257
debug-restart-log: debug-stop-log debug-start-log
258+
259+
debug-delete-volume-log:
260+
docker volume rm logs_aggregator_loki_data
261+
@echo "[WARN] - it needs sudo to remove folder created with loki docker image user"
262+
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

+11-2
Original file line numberDiff line numberDiff line change
@@ -6,12 +6,13 @@ services:
66
- 3100:3100
77
volumes:
88
- ./loki-config.yml:/etc/loki/loki-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/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)