Skip to content

Commit ffe23fb

Browse files
committed
Use alloy for collecting logs
Alloy is a recommended replacement for promtail and makes collecting docker logs convenient bypassing file exporter limitations (e.g. missing container_name label). Logs now do not go via OTEL exporter by to loki directly.
1 parent 8834b5c commit ffe23fb

5 files changed

Lines changed: 54 additions & 65 deletions

File tree

Lines changed: 2 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -1,2 +1,3 @@
11
loki-data
2-
dashboards
2+
dashboards
3+
alloy-data
Lines changed: 35 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,35 @@
1+
discovery.docker "containers" {
2+
host = "unix:///var/run/docker.sock"
3+
}
4+
5+
discovery.relabel "containers" {
6+
targets = discovery.docker.containers.targets
7+
8+
rule {
9+
source_labels = ["__meta_docker_container_name"]
10+
regex = "/(.*)"
11+
target_label = "container_name"
12+
}
13+
14+
rule {
15+
source_labels = ["__meta_docker_container_log_stream"]
16+
target_label = "stream"
17+
}
18+
19+
rule {
20+
source_labels = ["__meta_docker_container_image_name"]
21+
target_label = "image"
22+
}
23+
}
24+
25+
loki.source.docker "containers" {
26+
host = "unix:///var/run/docker.sock"
27+
targets = discovery.relabel.containers.output
28+
forward_to = [loki.write.default.receiver]
29+
}
30+
31+
loki.write "default" {
32+
endpoint {
33+
url = "http://merginmaps-loki:3100/loki/api/v1/push"
34+
}
35+
}

deployment/common/telemetry/docker-compose.otel.yml

Lines changed: 13 additions & 5 deletions
Original file line numberDiff line numberDiff line change
@@ -10,22 +10,30 @@ services:
1010
container_name: merginmaps-otel-collector
1111
volumes:
1212
- ./otel-config.yaml:/etc/otelcol-contrib/config.yaml
13-
- /var/lib/docker/containers:/var/lib/docker/containers:ro
14-
- /var/run/docker.sock:/var/run/docker.sock:ro
1513
networks:
1614
- merginmaps
17-
user: "0:0"
18-
privileged: true
1915
ports:
2016
- "8125:8125/udp" # StatsD (Metrics)
2117
- "4317:4317" # OTLP (Traces)
2218
- "8889:8889" # Prometheus Scrape Port
23-
# - "8888:8889"
2419
- "55679:55679"
2520
depends_on:
2621
tempo:
2722
condition: service_started
2823

24+
alloy:
25+
image: grafana/alloy:v1.8.3
26+
container_name: merginmaps-alloy
27+
volumes:
28+
- ./alloy-config.alloy:/etc/alloy/config.alloy
29+
- /var/run/docker.sock:/var/run/docker.sock
30+
- ./alloy-data:/var/lib/alloy/data
31+
networks:
32+
- merginmaps
33+
depends_on:
34+
- loki
35+
command: run --server.http.listen-addr=0.0.0.0:12345 --storage.path=/var/lib/alloy/data /etc/alloy/config.alloy
36+
2937
tempo:
3038
image: grafana/tempo:2.8.3
3139
container_name: merginmaps-tempo

deployment/common/telemetry/loki-config.yaml

Lines changed: 4 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -27,11 +27,13 @@ schema_config:
2727
period: 24h
2828

2929
limits_config:
30+
reject_old_samples: false
31+
reject_old_samples_max_age: 336h
3032
allow_structured_metadata: true
31-
reject_old_samples: false
3233
otlp_config:
3334
resource_attributes:
3435
attributes_config:
3536
- action: index_label
3637
attributes:
37-
- container_id
38+
- container_name
39+
- image

deployment/common/telemetry/otel-config.yaml

Lines changed: 0 additions & 57 deletions
Original file line numberDiff line numberDiff line change
@@ -16,39 +16,8 @@ receivers:
1616
endpoint: "merginmaps-redis:6379"
1717
collection_interval: 10s
1818
#password: "${REDIS_PASSWORD}"
19-
# This replaces Promtail
20-
filelog:
21-
include:
22-
- /var/lib/docker/containers/*/*.log
23-
start_at: end
24-
include_file_path: true
25-
operators:
26-
- type: json_parser
27-
- type: move
28-
from: attributes.log
29-
to: body
30-
- type: regex_parser
31-
parse_from: attributes["log.file.path"]
32-
regex: '/var/lib/docker/containers/(?P<container_id>[a-f0-9]{12})'
33-
on_error: send
34-
3519
processors:
36-
resourcedetection/docker:
37-
detectors: [env, docker]
38-
timeout: 2s
39-
override: true
40-
filter/exclude_collector:
41-
logs:
42-
log_record:
43-
- 'IsMatch(body, ".*exporterhelper.*")'
44-
- 'IsMatch(body, ".*Debug.*")'
45-
- 'IsMatch(body, ".*kind.*exporter.*")'
4620
batch:
47-
transform/logs:
48-
log_statements:
49-
- context: log
50-
statements:
51-
- set(resource.attributes["container_id"], attributes["container_id"]) where attributes["container_id"] != nil
5221
transform:
5322
metric_statements:
5423
- context: metric
@@ -67,13 +36,6 @@ processors:
6736
# statements:
6837
# - set(attributes["service_name"], attributes["docker_id"])
6938
# - set(resource.attributes["service.name"], attributes["docker_id"])
70-
attributes:
71-
actions:
72-
- key: service.name
73-
action: insert
74-
value: "merginmaps"
75-
76-
7739
exporters:
7840
prometheus:
7941
endpoint: "0.0.0.0:8889" # The Collector will "host" metrics here
@@ -84,21 +46,6 @@ exporters:
8446
endpoint: "merginmaps-tempo:4317"
8547
tls:
8648
insecure: true
87-
loki:
88-
endpoint: "http://merginmaps-loki:3100/loki/api/v1/push"
89-
# This ensures the trace and span IDs are included in the log metadata
90-
default_labels_enabled:
91-
exporter: true
92-
job: true
93-
instance: true
94-
level: true
95-
debug:
96-
verbosity: detailed
97-
otlphttp/loki:
98-
endpoint: "http://loki:3100/otlp"
99-
tls:
100-
insecure: true
101-
10249
service:
10350
extensions: [health_check]
10451
telemetry:
@@ -115,7 +62,3 @@ service:
11562
receivers: [otlp]
11663
processors: [batch]
11764
exporters: [otlp]
118-
logs:
119-
receivers: [filelog]
120-
processors: [filter/exclude_collector, resourcedetection/docker, attributes, transform/logs, batch]
121-
exporters: [otlphttp/loki]

0 commit comments

Comments
 (0)