Skip to content

Commit 87f5342

Browse files
authored
Merge pull request #13 from shutter-network/logpush
Add loki logpush via promtail
2 parents d0ccde1 + 0688cbd commit 87f5342

File tree

9 files changed

+127
-14
lines changed

9 files changed

+127
-14
lines changed

docker-compose.yml

Lines changed: 7 additions & 4 deletions
Original file line numberDiff line numberDiff line change
@@ -18,10 +18,13 @@ services:
1818
STAKER_SCRIPTS_VERSION: v0.1.1
1919
restart: unless-stopped
2020
environment:
21-
SHUTTER_API_NODE_PRIVATEKEY: ""
22-
SHUTTER_PUSH_METRICS_ENABLED: false
23-
KEYPER_NAME: ""
24-
ETHEREUM_WS: ""
21+
- SHUTTER_API_NODE_PRIVATEKEY=""
22+
- SHUTTER_PUSH_METRICS_ENABLED=false
23+
- KEYPER_NAME=""
24+
- ETHEREUM_WS=""
25+
- SHUTTER_PUSH_LOGS_ENABLED=false
26+
- PUSHGATEWAY_USERNAME=""
27+
- PUSHGATEWAY_PASSWORD=""
2528
volumes:
2629
- chain:/chain
2730
- keyper-config:/keyper/config

setup-wizard.yml

Lines changed: 15 additions & 3 deletions
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
@@ -61,7 +73,7 @@ fields:
6173
target:
6274
type: environment
6375
name: PUSHGATEWAY_USERNAME
64-
service: metrics
76+
service: [metrics, shutter]
6577
required: false
6678
if: { enable_push_metrics: { "enum": ["true"] } }
6779

@@ -72,7 +84,7 @@ fields:
7284
target:
7385
type: environment
7486
name: PUSHGATEWAY_PASSWORD
75-
service: metrics
87+
service: [metrics, shutter]
7688
required: false
7789
secret: true
7890
if: { enable_push_metrics: { "enum": ["true"] } }

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: ${KEYPER_NAME}
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: ${KEYPER_NAME}
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: chain
45+
host: ${KEYPER_NAME}
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 /tmp/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 -config.expand-env=true -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: 14 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,16 @@ 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 ; we ingest 'rotatelogs' managed logfiles -- there is potential for some missed log lines.
54+
priority = 4
55+
autostart = %(ENV_SHUTTER_PUSH_LOGS_ENABLED)s
56+
startretries = 9999 ; A large number enough to cover node updates
57+
autorestart = %(ENV_SHUTTER_PUSH_LOGS_ENABLED)s
58+
environment = KEYPER_NAME="%(ENV_KEYPER_NAME)s",PUSHGATEWAY_USERNAME="%(ENV_PUSHGATEWAY_USERNAME)s",PUSHGATEWAY_PASSWORD="%(ENV_PUSHGATEWAY_PASSWORD)s",SHUTTER_PUSH_LOGS_ENABLED="%(ENV_SHUTTER_PUSH_LOGS_ENABLED)s"
59+
stdout_logfile = /dev/stdout
60+
stdout_logfile_maxbytes = 0
61+
stderr_logfile = /dev/stderr
62+
stderr_logfile_maxbytes = 0

0 commit comments

Comments
 (0)