Skip to content

Commit 386854e

Browse files
committed
Add loki logpush via promtail
This aims to recreate the functionality from shutter-network/shutter-keyper-deployment#10 usable with the DAppnodePackage. Because we can not install the docker loki plugin, and everything is running in one container through supervisord, we need to resort to promtail and some extra log redirections to keep the docker logging working.
1 parent 38ddd5b commit 386854e

File tree

8 files changed

+117
-8
lines changed

8 files changed

+117
-8
lines changed

setup-wizard.yml

Lines changed: 13 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -31,6 +31,18 @@ fields:
3131
service: shutter
3232
required: true
3333

34+
- id: enable_push_logs
35+
title: Enable Push Logs
36+
description: |
37+
Enable the push logs feature to send logs to an external server controlled by Shutter.
38+
target:
39+
type: environment
40+
name: SHUTTER_PUSH_LOGS_ENABLED
41+
service: [shutter, metrics]
42+
enum:
43+
- "true"
44+
- "false"
45+
3446
- id: enable_push_metrics
3547
title: Enable Push Metrics
3648
description: |
@@ -46,7 +58,7 @@ fields:
4658
- id: pushgateway_url
4759
title: Pushgateway URL
4860
description: |
49-
The URL of the Pushgateway server to send metrics to.
61+
The URL of the Pushgateway server to send metrics/logs to.
5062
target:
5163
type: environment
5264
name: PUSHGATEWAY_URL

shutter/Dockerfile

Lines changed: 12 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -1,7 +1,7 @@
11
ARG ASSETS_VERSION
22
ARG UPSTREAM_VERSION
33

4-
FROM ghcr.io/shutter-network/assets:${ASSETS_VERSION} as assets
4+
FROM ghcr.io/shutter-network/assets:${ASSETS_VERSION} AS assets
55

66
RUN rsync -aq --delete /assets-source/ /assets/
77

@@ -40,6 +40,7 @@ ADD ${STAKER_SCRIPTS_URL}/dvt_lsd_tools.sh /etc/profile.d/
4040

4141
COPY go-shutter-settings ${SHUTTER_SETTINGS_SRC_DIR}
4242
COPY supervisord.conf /etc/supervisord.conf
43+
COPY promtail_config.yaml /etc/promtail_config.yaml
4344

4445
RUN go build -C ${SHUTTER_SETTINGS_SRC_DIR} -o /usr/local/bin/go_shutter_settings
4546

@@ -49,9 +50,18 @@ RUN mkdir -p ${KEYPER_CONFIG_DIR} ${SHUTTER_CHAIN_DIR} ${ASSETS_DIR} /opt/superv
4950
COPY scripts /usr/local/bin/
5051
COPY --from=assets ${ASSETS_DIR}/ ${ASSETS_DIR}/
5152

53+
# For pushing logs to loki
54+
RUN apt-get -y install wget gpg
55+
RUN mkdir -p /etc/apt/keyrings/
56+
RUN wget -q -O - https://apt.grafana.com/gpg.key | gpg --dearmor > /etc/apt/keyrings/grafana.gpg
57+
RUN echo "deb [signed-by=/etc/apt/keyrings/grafana.gpg] https://apt.grafana.com stable main" | tee /etc/apt/sources.list.d/grafana.list
58+
# promtail & rotatelogs (from apache2)
59+
RUN apt-get update && apt-get -y install promtail apache2
60+
61+
5262
# Placed here to rebuild less layers
5363
ENV CHAIN_PORT=${CHAIN_PORT} \
5464
SHUTTER_P2P_LISTENADDRESSES="/ip4/0.0.0.0/tcp/${KEYPER_PORT},/ip4/0.0.0.0/udp/${KEYPER_PORT}/quic-v1" \
5565
NETWORK=${NETWORK}
5666

57-
ENTRYPOINT ["supervisord", "-c", "/etc/supervisord.conf"]
67+
ENTRYPOINT ["supervisord", "-c", "/etc/supervisord.conf"]

shutter/promtail_config.yaml

Lines changed: 46 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,46 @@
1+
server:
2+
http_listen_port: 9080
3+
grpc_listen_port: 0
4+
5+
positions:
6+
filename: /tmp/positions.yaml
7+
8+
client:
9+
url: https://logs.metrics.shutter.network/insert/loki/api/v1/push
10+
basic_auth:
11+
username: $(PUSHGATEWAY_USERNAME)
12+
password: $(PUSHGATEWAY_PASSWORD)
13+
14+
scrape_configs:
15+
- job_name: configure
16+
pipeline_stages:
17+
- docker:
18+
static_configs:
19+
- targets:
20+
- localhost
21+
labels:
22+
job: configure
23+
host: ${HOSTNAME}
24+
__path__: /tmp/configure.log
25+
26+
- job_name: keyper
27+
pipeline_stages:
28+
- docker:
29+
static_configs:
30+
- targets:
31+
- localhost
32+
labels:
33+
job: keyper
34+
host: ${HOSTNAME}
35+
__path__: /tmp/keyper.log
36+
37+
- job_name: chain
38+
pipeline_stages:
39+
- docker:
40+
static_configs:
41+
- targets:
42+
- localhost
43+
labels:
44+
job: keyper
45+
host: ${HOSTNAME}
46+
__path__: /tmp/chain.log

shutter/scripts/run_chain.sh

Lines changed: 6 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -3,8 +3,12 @@
33
run_chain() {
44

55
echo "[INFO | chain] Starting chain..."
6-
7-
$SHUTTER_BIN chain --config "$SHUTTER_CHAIN_CONFIG_FILE"
6+
if [[ SHUTTER_PUSH_LOGS_ENABLED=true ]];
7+
then
8+
$SHUTTER_BIN chain --config "$SHUTTER_CHAIN_CONFIG_FILE" | rotatelogs -n 1 -e -c /tmp/chain.log 5M
9+
else
10+
$SHUTTER_BIN chain --config "$SHUTTER_CHAIN_CONFIG_FILE"
11+
fi
812
}
913

1014
run_chain

shutter/scripts/run_configure.sh

Lines changed: 9 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,9 @@
1+
#!/bin/bash
2+
3+
4+
if [[ SHUTTER_PUSH_LOGS_ENABLED=true ]];
5+
then
6+
./configure.sh | rotatelogs -n 1 -e -c /tmp/configure.log 5M
7+
else
8+
./configure.sh
9+
fi

shutter/scripts/run_keyper.sh

Lines changed: 6 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -18,7 +18,12 @@ perform_chain_healthcheck() {
1818
}
1919

2020
run_keyper() {
21-
$SHUTTER_BIN shutterservicekeyper --config "$KEYPER_CONFIG_FILE"
21+
if [[ SHUTTER_PUSH_LOGS_ENABLED=true ]];
22+
then
23+
$SHUTTER_BIN shutterservicekeyper --config "$KEYPER_CONFIG_FILE" | rotatelogs -n 1 -e -c /logs/keyper.log 5M
24+
else
25+
$SHUTTER_BIN shutterservicekeyper --config "$KEYPER_CONFIG_FILE"
26+
fi
2227
}
2328

2429
perform_chain_healthcheck

shutter/scripts/run_promtail.sh

Lines changed: 12 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,12 @@
1+
#!/bin/bash
2+
3+
run_promtail() {
4+
if [[ $SHUTTER_PUSH_LOGS_ENABLED=true ]];
5+
then
6+
promtail -log-config-reverse-order -print-config-stderr -config.file /etc/promtail_config.yaml
7+
else
8+
tail -f /dev/null
9+
fi
10+
}
11+
12+
run_promtail

shutter/supervisord.conf

Lines changed: 13 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -18,7 +18,7 @@ supervisor.rpcinterface_factory = supervisor.rpcinterface:make_main_rpcinterface
1818
serverurl=unix:///var/run/supervisor.sock
1919

2020
[program:configure]
21-
command = configure.sh
21+
command = run_configure.sh
2222
priority = 1
2323
autostart = true
2424
autorestart = false
@@ -47,4 +47,15 @@ autorestart = true
4747
stdout_logfile = /dev/stdout
4848
stdout_logfile_maxbytes = 0
4949
stderr_logfile = /dev/stderr
50-
stderr_logfile_maxbytes = 0
50+
stderr_logfile_maxbytes = 0
51+
52+
[program:promtail]
53+
command = run_promtail.sh
54+
priority = 4
55+
autostart = true
56+
startretries = 9999 ; A large number enough to cover node updates
57+
autorestart = true
58+
stdout_logfile = /dev/stdout
59+
stdout_logfile_maxbytes = 0
60+
stderr_logfile = /dev/stderr
61+
stderr_logfile_maxbytes = 0

0 commit comments

Comments
 (0)