Skip to content

Commit 73aef22

Browse files
authored
Merge pull request #4982 from raft-tech/3258-alloy-conversion
3258 - Alloy conversion
2 parents 407a0ee + 63d6d1e commit 73aef22

File tree

7 files changed

+119
-120
lines changed

7 files changed

+119
-120
lines changed

scripts/deploy-backend.sh

Lines changed: 5 additions & 8 deletions
Original file line numberDiff line numberDiff line change
@@ -87,13 +87,10 @@ generate_jwt_cert()
8787
cf set-env "$CGAPPNAME_BACKEND" JWT_KEY "$(cat key.pem)"
8888
}
8989

90-
prepare_promtail() {
91-
pushd tdrs-backend/plg/promtail
92-
CONFIG=config.yml
93-
yq eval -i ".scrape_configs[0].job_name = \"system-$backend_app_name\"" $CONFIG
94-
yq eval -i ".scrape_configs[0].static_configs[0].labels.job = \"system-$backend_app_name\"" $CONFIG
95-
yq eval -i ".scrape_configs[1].job_name = \"backend-$backend_app_name\"" $CONFIG
96-
yq eval -i ".scrape_configs[1].static_configs[0].labels.job = \"backend-$backend_app_name\"" $CONFIG
90+
prepare_alloy() {
91+
pushd tdrs-backend/plg/alloy
92+
cf set-env "$CGAPPNAME_BACKEND" ALLOY_SYSTEM_NAME "system-$backend_app_name"
93+
cf set-env "$CGAPPNAME_BACKEND" ALLOY_BACKEND_NAME "backend-$backend_app_name"
9794
popd
9895
}
9996

@@ -216,7 +213,7 @@ else
216213
CYPRESS_TOKEN=$CYPRESS_TOKEN
217214
fi
218215

219-
prepare_promtail
216+
prepare_alloy
220217
if [ "$DEPLOY_STRATEGY" = "rolling" ] ; then
221218
# Perform a rolling update for the backend and frontend deployments if
222219
# specified, otherwise perform a normal deployment

tdrs-backend/docker-compose.yml

Lines changed: 5 additions & 5 deletions
Original file line numberDiff line numberDiff line change
@@ -110,16 +110,16 @@ services:
110110
- alertmanager
111111
- mimir
112112

113-
promtail:
113+
alloy:
114114
restart: always
115-
image: grafana/promtail:3.1.1
115+
image: grafana/alloy:v1.8.0
116116
ports:
117-
- 9080:9080
117+
- 12345:12345
118118
volumes:
119-
- ./plg/promtail/config.local.yml:/etc/promtail/config.yml
119+
- ./plg/alloy:/etc/alloy
120120
- ~/tdp-logs/nginx:/var/log/nginx
121121
- logs:/logs
122-
command: -config.file=/etc/promtail/config.yml
122+
command: run --server.http.listen-addr=0.0.0.0:12345 --storage.path=/var/lib/alloy/data /etc/alloy/alloy.local.config
123123

124124
loki:
125125
restart: always

tdrs-backend/gunicorn_start.sh

Lines changed: 6 additions & 4 deletions
Original file line numberDiff line numberDiff line change
@@ -37,10 +37,12 @@ fi
3737
gunicorn_cmd="gunicorn $gunicorn_params"
3838

3939
if [[ $1 == "cloud" ]]; then
40-
echo "Starting Promtail"
41-
wget https://github.com/grafana/loki/releases/download/v3.1.1/promtail-linux-amd64.zip
42-
unzip -a promtail-linux-amd64.zip && rm -rf promtail-linux-amd64.zip
43-
./promtail-linux-amd64 -config.file=./plg/promtail/config.yml &
40+
echo "Starting Alloy"
41+
mkdir /home/vcap/app/alloy-data
42+
wget https://github.com/grafana/alloy/releases/download/v1.8.1/alloy-boringcrypto-linux-amd64.zip
43+
unzip -a alloy-boringcrypto-linux-amd64.zip && rm -rf alloy-boringcrypto-linux-amd64.zip
44+
chmod +x alloy-boringcrypto-linux-amd64
45+
./alloy-boringcrypto-linux-amd64 run --server.http.listen-addr=0.0.0.0:12345 --storage.path=/home/vcap/app/alloy-data /home/vcap/app/plg/alloy/alloy.config &
4446

4547
echo "Starting the Celery Exporter"
4648
curl -L https://github.com/danihodovic/celery-exporter/releases/download/latest/celery-exporter -o ./celery-exporter
Lines changed: 42 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,42 @@
1+
local.file_match "system" {
2+
path_targets = [{
3+
__address__ = "localhost",
4+
__path__ = "/var/log/*log",
5+
job = sys.env("ALLOY_SYSTEM_NAME"),
6+
}]
7+
}
8+
9+
loki.source.file "system" {
10+
targets = local.file_match.system.targets
11+
forward_to = [loki.write.default.receiver]
12+
legacy_positions_file = "/tmp/positions.yaml"
13+
}
14+
15+
local.file_match "backend" {
16+
path_targets = [{
17+
__address__ = "localhost",
18+
__path__ = "/tmp/django.log",
19+
job = sys.env("ALLOY_BACKEND_NAME"),
20+
}]
21+
}
22+
23+
loki.process "backend_process" {
24+
forward_to = [loki.write.default.receiver]
25+
26+
stage.regex {
27+
expression = "^(?P<time>\\d{4}-\\d{2}-\\d{2} \\d{2}:\\d{2}:\\d{2},\\d{3}) (?P<level>\\w+) (?P<logger>\\S+) (?P<message>.*)$"
28+
}
29+
}
30+
31+
loki.source.file "backend" {
32+
targets = local.file_match.backend.targets
33+
forward_to = [loki.process.backend_process.receiver]
34+
legacy_positions_file = "/tmp/positions.yaml"
35+
}
36+
37+
loki.write "default" {
38+
endpoint {
39+
url = "http://loki.apps.internal:8080/loki/api/v1/push"
40+
}
41+
external_labels = {}
42+
}
Lines changed: 61 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,61 @@
1+
local.file_match "system" {
2+
path_targets = [{
3+
__address__ = "localhost",
4+
__path__ = "/var/log/*log",
5+
job = "varlogs-local",
6+
}]
7+
}
8+
9+
loki.source.file "system" {
10+
targets = local.file_match.system.targets
11+
forward_to = [loki.write.default.receiver]
12+
legacy_positions_file = "/tmp/positions.yaml ?? not in tmp"
13+
}
14+
15+
local.file_match "backend" {
16+
path_targets = [{
17+
__address__ = "localhost",
18+
__path__ = "/logs/django.log",
19+
job = "backend-local",
20+
}]
21+
}
22+
23+
loki.process "backend_process" {
24+
forward_to = [loki.write.default.receiver]
25+
26+
stage.regex {
27+
expression = "^(?P<time>\\d{4}-\\d{2}-\\d{2} \\d{2}:\\d{2}:\\d{2},\\d{3}) (?P<level>\\w+) (?P<logger>\\S+) (?P<message>.*)$"
28+
}
29+
}
30+
31+
loki.source.file "backend" {
32+
targets = local.file_match.backend.targets
33+
forward_to = [loki.process.backend_process.receiver]
34+
legacy_positions_file = "/tmp/positions.yaml"
35+
}
36+
local.file_match "frontend" {
37+
path_targets = [{
38+
__address__ = "localhost",
39+
__path__ = "/var/log/nginx/access_log.log",
40+
job = "frontend-local",
41+
level = "DEBUG",
42+
}, {
43+
__address__ = "localhost",
44+
__path__ = "/var/log/nginx/error_log.log",
45+
job = "frontend-local",
46+
level = "ERROR",
47+
}]
48+
}
49+
50+
loki.source.file "frontend" {
51+
targets = local.file_match.frontend.targets
52+
forward_to = [loki.write.default.receiver]
53+
legacy_positions_file = "/tmp/positions.yaml"
54+
}
55+
56+
loki.write "default" {
57+
endpoint {
58+
url = "http://loki:3100/loki/api/v1/push"
59+
}
60+
external_labels = {}
61+
}

tdrs-backend/plg/promtail/config.local.yml

Lines changed: 0 additions & 55 deletions
This file was deleted.

tdrs-backend/plg/promtail/config.yml

Lines changed: 0 additions & 48 deletions
This file was deleted.

0 commit comments

Comments
 (0)