Skip to content

Commit 7067b65

Browse files
committed
feat(prod): add grafana stack
1 parent 7dd54f8 commit 7067b65

File tree

7 files changed

+189
-3
lines changed

7 files changed

+189
-3
lines changed

.github/workflows/cd.yml

Lines changed: 2 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -30,3 +30,5 @@ jobs:
3030
NATS_TOKEN: ${{ secrets.NATS_TOKEN }}
3131

3232
GEMINI_URL: ${{ secrets.GEMINI_URL }}
33+
34+
GRAFANA_ADMIN_PASSWORD: ${{ secrets.GRAFANA_ADMIN_PASSWORD }}

deploy/dev/docker-compose.yaml

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -54,7 +54,7 @@ services:
5454
POSTGRES_PASSWORD: root
5555
healthcheck:
5656
test: pg_isready -d root -U root
57-
start_period: 1m
57+
start_period: 2m
5858
start_interval: 1s
5959
interval: 5s
6060

deploy/prod/.env.template

Lines changed: 2 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -6,3 +6,5 @@ POSTGRES_REPLICA_PASSWORD=replica
66
NATS_TOKEN=nats
77

88
GEMINI_URL=https://my-gemini.vercel.app
9+
10+
GRAFANA_ADMIN_PASSWORD=grafana

deploy/prod/alloy/config.alloy

Lines changed: 47 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,47 @@
1+
// This component is responsible for disovering new containers within the docker environment
2+
discovery.docker "getting_started" {
3+
host = "unix:///var/run/docker.sock"
4+
refresh_interval = "5s"
5+
}
6+
7+
// This component is responsible for relabeling the discovered containers
8+
discovery.relabel "getting_started" {
9+
targets = []
10+
11+
rule {
12+
source_labels = ["__meta_docker_container_name"]
13+
regex = "/(.*)"
14+
target_label = "container"
15+
}
16+
}
17+
18+
// This component is responsible for collecting logs from the discovered containers
19+
loki.source.docker "getting_started" {
20+
host = "unix:///var/run/docker.sock"
21+
targets = discovery.docker.getting_started.targets
22+
forward_to = [loki.process.getting_started.receiver]
23+
relabel_rules = discovery.relabel.getting_started.rules
24+
refresh_interval = "5s"
25+
}
26+
27+
// This component is responsible for processing the logs (In this case adding static labels)
28+
loki.process "getting_started" {
29+
stage.static_labels {
30+
values = {
31+
env = "production",
32+
}
33+
}
34+
forward_to = [loki.write.getting_started.receiver]
35+
}
36+
37+
// This component is responsible for writing the logs to Loki
38+
loki.write "getting_started" {
39+
endpoint {
40+
url = "http://loki:3100/loki/api/v1/push"
41+
}
42+
}
43+
44+
// Enables the ability to view logs in the Alloy UI in realtime
45+
livedebugging {
46+
enabled = true
47+
}

deploy/prod/docker-compose.yaml

Lines changed: 65 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -2,6 +2,7 @@ name: ttt
22

33
services:
44
ttt:
5+
image: ttt:prod
56
build:
67
context: ../../
78
dockerfile: deploy/prod/ttt/Dockerfile
@@ -86,7 +87,7 @@ services:
8687
mem_limit: 30mb
8788
healthcheck:
8889
test: pg_isready -d ttt -U ttt
89-
start_period: 1m
90+
start_period: 2m
9091
start_interval: 1s
9192
interval: 5s
9293

@@ -116,7 +117,7 @@ services:
116117
mem_limit: 30mb
117118
healthcheck:
118119
test: pg_isready -d ttt -U ttt
119-
start_period: 1m
120+
start_period: 2m
120121
start_interval: 1s
121122
interval: 5s
122123

@@ -154,6 +155,63 @@ services:
154155
entrypoint: [""]
155156
command: ["bash", "/mnt/add_streams.sh"]
156157

158+
alloy:
159+
image: grafana/alloy:v1.10.0
160+
container_name: ttt-alloy
161+
# ports:
162+
# - 12345:12345
163+
# - 4317:4317
164+
# - 4318:4318
165+
volumes:
166+
- ./alloy/config.alloy:/etc/alloy/config.alloy
167+
- /var/run/docker.sock:/var/run/docker.sock
168+
networks:
169+
- loki
170+
command: run --server.http.listen-addr=0.0.0.0:12345 --storage.path=/var/lib/alloy/data /etc/alloy/config.alloy
171+
depends_on:
172+
- loki
173+
174+
loki:
175+
image: grafana/loki:3.4.5
176+
container_name: ttt-loki
177+
environment:
178+
TZ: ${SYSTEM_TIMEZONE:-Europe/Moscow}
179+
# ports:
180+
# - 3100:3100
181+
volumes:
182+
- loki-data:/loki
183+
- ./loki/loki-config.yaml:/etc/loki/local-config.yaml
184+
networks:
185+
- loki
186+
command: -config.file=/etc/loki/local-config.yaml
187+
188+
grafana:
189+
image: grafana/grafana:12.0.2-ubuntu
190+
container_name: ttt-grafana
191+
environment:
192+
- GF_PATHS_PROVISIONING=/etc/grafana/provisioning
193+
- GF_FEATURE_TOGGLES_ENABLE=grafanaManagedRecordingRules
194+
195+
- GF_AUTH_ANONYMOUS_ENABLED=false
196+
- GF_AUTH_BASIC_ENABLED=true
197+
198+
- GF_SECURITY_FORCE_PASSWORD_CHANGE=true
199+
- GF_SECURITY_DISABLE_INITIAL_ADMIN_CREATION=false
200+
- GF_SECURITY_ADMIN_USER=admin
201+
- GF_SECURITY_ADMIN_PASSWORD=${GRAFANA_ADMIN_PASSWORD}
202+
- GF_SECURITY_MIN_PASSWORD_LENGTH=4
203+
204+
- GF_USERS_ALLOW_SIGN_UP=false
205+
206+
- TZ=${SYSTEM_TIMEZONE:-Europe/Moscow}
207+
ports:
208+
- 3000:3000
209+
volumes:
210+
- grafana-data:/var/lib/grafana
211+
- ./grafana/provisioning/datasources:/etc/grafana/provisioning/datasources
212+
networks:
213+
- loki
214+
157215
volumes:
158216
postgres-replica1-data:
159217
name: "ttt-prod-postgres-replica1-data"
@@ -163,11 +221,16 @@ volumes:
163221
name: "ttt-prod-redis-data"
164222
nats-data:
165223
name: "ttt-prod-nats-data"
224+
loki-data:
225+
name: "ttt-prod-loki-data"
226+
grafana-data:
227+
name: "ttt-prod-grafana-data"
166228

167229
networks:
168230
postgres: null
169231
redis: null
170232
nats: null
233+
loki: null
171234

172235
secrets:
173236
secrets:
Lines changed: 11 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,11 @@
1+
apiVersion: 1
2+
datasources:
3+
- name: Loki
4+
type: loki
5+
access: proxy
6+
orgId: 1
7+
url: http://loki:3100
8+
basicAuth: false
9+
isDefault: true
10+
version: 1
11+
editable: true

deploy/prod/loki/loki-config.yaml

Lines changed: 61 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,61 @@
1+
auth_enabled: false
2+
3+
server:
4+
http_listen_port: 3100
5+
grpc_listen_port: 9096
6+
log_level: info
7+
grpc_server_max_concurrent_streams: 1000
8+
9+
common:
10+
instance_addr: 127.0.0.1
11+
path_prefix: /tmp/loki
12+
storage:
13+
filesystem:
14+
chunks_directory: /tmp/loki/chunks
15+
rules_directory: /tmp/loki/rules
16+
replication_factor: 1
17+
ring:
18+
kvstore:
19+
store: inmemory
20+
21+
query_range:
22+
results_cache:
23+
cache:
24+
embedded_cache:
25+
enabled: true
26+
max_size_mb: 100
27+
28+
limits_config:
29+
metric_aggregation_enabled: true
30+
allow_structured_metadata: true
31+
volume_enabled: true
32+
retention_period: 24h # 24h
33+
34+
schema_config:
35+
configs:
36+
- from: 2020-10-24
37+
store: tsdb
38+
object_store: filesystem
39+
schema: v13
40+
index:
41+
prefix: index_
42+
period: 24h
43+
44+
pattern_ingester:
45+
enabled: true
46+
metric_aggregation:
47+
loki_address: localhost:3100
48+
49+
ruler:
50+
enable_alertmanager_discovery: true
51+
enable_api: true
52+
53+
54+
frontend:
55+
encoding: protobuf
56+
57+
58+
compactor:
59+
working_directory: /tmp/loki/retention
60+
delete_request_store: filesystem
61+
retention_enabled: true

0 commit comments

Comments
 (0)