Skip to content

Commit 5e1a5ef

Browse files
authored
*: evaluate env variables in prometheus.yml (#288)
Evaluate env vars in `prometheus.yml`. ticket: #289
1 parent 9f58444 commit 5e1a5ef

File tree

5 files changed

+31
-6
lines changed

5 files changed

+31
-6
lines changed

.env.sample

Lines changed: 6 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -93,6 +93,12 @@
9393
# See available tags https://github.com/prometheus/prometheus/releases.
9494
#PROMETHEUS_VERSION=
9595

96+
# Prometheus remote write token used for accessing external prometheus.
97+
#PROM_REMOTE_WRITE_TOKEN=
98+
99+
# Prometheus service owner used to uniquely identify user from which metrics are pushed.
100+
#SERVICE_OWNER=charon_user
101+
96102
######### Voluntary Exit Config #########
97103

98104
# This applies to compose-voluntary-exit.yml only

.gitignore

Lines changed: 2 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -10,4 +10,5 @@ cluster-lock.json
1010
.DS_Store
1111
data/
1212
.idea
13-
.charon
13+
.charon
14+
prometheus/prometheus.yml

docker-compose.yml

Lines changed: 5 additions & 4 deletions
Original file line numberDiff line numberDiff line change
@@ -142,12 +142,13 @@ services:
142142
image: prom/prometheus:${PROMETHEUS_VERSION:-v2.50.1}
143143
user: ":"
144144
networks: [dvnode]
145+
environment:
146+
- PROM_REMOTE_WRITE_TOKEN=${PROM_REMOTE_WRITE_TOKEN}
147+
- SERVICE_OWNER=${SERVICE_OWNER}
145148
volumes:
146-
- ./prometheus/prometheus.yml:/etc/prometheus/prometheus.yml
149+
- ./prometheus:/etc/prometheus
147150
- ./data/prometheus:/prometheus
148-
command:
149-
- "--enable-feature=expand-external-labels"
150-
- "--config.file=/etc/prometheus/prometheus.yml"
151+
entrypoint: /etc/prometheus/run.sh
151152
restart: unless-stopped
152153

153154
grafana:

prometheus/prometheus.yml renamed to prometheus/prometheus.yml.example

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -7,7 +7,7 @@ global:
77
remote_write:
88
- url: https://vm.monitoring.gcp.obol.tech/write
99
authorization:
10-
credentials: $PROM_REMOTE_WRITE_TOKEN
10+
credentials: ${PROM_REMOTE_WRITE_TOKEN}
1111
write_relabel_configs:
1212
- source_labels: [job]
1313
regex: "charon"

prometheus/run.sh

Lines changed: 17 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,17 @@
1+
#!/bin/sh
2+
3+
if [ -z "$SERVICE_OWNER" ]
4+
then
5+
echo "\$SERVICE_OWNER variable is empty"
6+
fi
7+
8+
if [ -z "$PROM_REMOTE_WRITE_TOKEN" ]
9+
then
10+
echo "\$PROM_REMOTE_WRITE_TOKEN variable is empty"
11+
fi
12+
13+
# eval is used instead of envsubst, as prometheus user doesn't have permissions to install envsubst
14+
eval "echo \"$(cat /etc/prometheus/prometheus.yml.example)\"" > /etc/prometheus/prometheus.yml
15+
16+
/bin/prometheus \
17+
--config.file=/etc/prometheus/prometheus.yml

0 commit comments

Comments
 (0)