Skip to content

Commit 9929f24

Browse files
authored
Merge pull request #30 from Nasruddin/revamp
Fluentbit integration for docker
2 parents 1378bd4 + f5be1f6 commit 9929f24

File tree

15 files changed

+237
-50
lines changed

15 files changed

+237
-50
lines changed

.idea/workspace.xml

+35-9
Some generated files are not rendered by default. Learn more about customizing how changed files appear on GitHub.

docker/docker-compose-base.yml

+16
Original file line numberDiff line numberDiff line change
@@ -4,6 +4,10 @@ services:
44
mem_limit: 512m
55
environment:
66
- SPRING_PROFILES_ACTIVE=docker
7+
logging:
8+
driver: fluentd
9+
options:
10+
fluentd-address: 127.0.0.1:24224
711
networks:
812
- shared-network
913
#depends_on:
@@ -15,6 +19,10 @@ services:
1519
mem_limit: 512m
1620
environment:
1721
- SPRING_PROFILES_ACTIVE=docker
22+
logging:
23+
driver: fluentd
24+
options:
25+
fluentd-address: 127.0.0.1:24224
1826
networks:
1927
- shared-network
2028
#depends_on:
@@ -28,6 +36,10 @@ services:
2836
- "8080:8080"
2937
environment:
3038
- SPRING_PROFILES_ACTIVE=docker
39+
logging:
40+
driver: fluentd
41+
options:
42+
fluentd-address: 127.0.0.1:24224
3143
networks:
3244
- shared-network
3345

@@ -38,6 +50,10 @@ services:
3850
- "9000:9000"
3951
environment:
4052
- SPRING_PROFILES_ACTIVE=docker
53+
logging:
54+
driver: fluentd
55+
options:
56+
fluentd-address: 127.0.0.1:24224
4157
networks:
4258
- shared-network
4359

docker/docker-compose-infra.yml

+2-27
Original file line numberDiff line numberDiff line change
@@ -43,35 +43,10 @@ services:
4343
networks:
4444
- shared-network
4545

46-
prometheus:
47-
image: prom/prometheus:latest
48-
volumes:
49-
- ./prometheus/prometheus.yml:/etc/prometheus/prometheus.yml
50-
- prometheus-data:/prometheus
51-
command:
52-
- '--config.file=/etc/prometheus/prometheus.yml'
53-
- '--storage.tsdb.path=/prometheus'
54-
ports:
55-
- "9090:9090"
56-
networks:
57-
- shared-network
58-
59-
grafana:
60-
image: grafana/grafana:latest
61-
volumes:
62-
- grafana-data:/var/lib/grafana
63-
ports:
64-
- "3000:3000"
65-
environment:
66-
- GF_SECURITY_ADMIN_PASSWORD=admin
67-
depends_on:
68-
- prometheus
69-
networks:
70-
- shared-network
71-
7246
networks:
7347
shared-network:
7448
driver: bridge
7549
volumes:
7650
prometheus-data:
77-
grafana-data:
51+
grafana-data:
52+
loki-data:
+64
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,64 @@
1+
services:
2+
prometheus:
3+
image: prom/prometheus:latest
4+
volumes:
5+
- ./prometheus/prometheus.yml:/etc/prometheus/prometheus.yml
6+
- prometheus-data:/prometheus
7+
command:
8+
- '--config.file=/etc/prometheus/prometheus.yml'
9+
- '--storage.tsdb.path=/prometheus'
10+
ports:
11+
- "9090:9090"
12+
networks:
13+
- shared-network
14+
15+
grafana:
16+
image: grafana/grafana:latest
17+
volumes:
18+
- grafana-data:/var/lib/grafana
19+
ports:
20+
- "3000:3000"
21+
environment:
22+
- GF_SECURITY_ADMIN_PASSWORD=admin
23+
depends_on:
24+
- prometheus
25+
networks:
26+
- shared-network
27+
28+
loki:
29+
image: grafana/loki:3.0.0
30+
ports:
31+
- "3100:3100"
32+
command: -config.file=/etc/loki/local-config.yaml
33+
volumes:
34+
- ./loki/loki-config.yaml:/etc/loki/local-config.yaml
35+
- loki-data:/loki
36+
networks:
37+
- shared-network
38+
39+
fluent-bit:
40+
image: grafana/fluent-bit-plugin-loki:2.9.8
41+
container_name: fluent-bit
42+
ports:
43+
- "24224:24224"
44+
environment:
45+
- LOKI_URL=http://loki:3100/loki/api/v1/push
46+
volumes:
47+
- ./fluent-bit/fluent-bit.conf:/fluent-bit/etc/fluent-bit.conf
48+
networks:
49+
- shared-network
50+
tempo:
51+
image: grafana/tempo:1.5.0
52+
command: -config.file /etc/tempo-config.yml
53+
ports:
54+
- "4317:4317"
55+
volumes:
56+
- ./tempo/tempo.yml:/etc/tempo-config.yml
57+
58+
networks:
59+
shared-network:
60+
driver: bridge
61+
volumes:
62+
prometheus-data:
63+
grafana-data:
64+
loki-data:

docker/fluent-bit/fluent-bit.conf

+15
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,15 @@
1+
[INPUT]
2+
Name forward
3+
Listen 0.0.0.0
4+
Port 24224
5+
[Output]
6+
Name grafana-loki
7+
Match *
8+
Url http://loki:3100/loki/api/v1/push
9+
RemoveKeys source,container_id
10+
Labels {job="fluent-bit"}
11+
LabelKeys container_name
12+
BatchWait 1s
13+
BatchSize 1001024
14+
LineFormat json
15+
LogLevel info

docker/fluent-bit/parsers.conf

+12
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,12 @@
1+
[PARSER]
2+
Name logback_parser
3+
Format regex
4+
Regex ^(?<time>[^ ]+ [^ ]+) \[(?<thread>[^\]]+)\] (?<level>[^ ]+) (?<logger>[^ ]+) - (?<message>.*)$
5+
6+
#(?<time>[^ ]+ [^ ]+) Captures timestamp (2025-03-09 12:29:12.769)
7+
#\[(?<thread>[^\]]+)\] Captures thread name (parallel-1)
8+
#\[(?<trace_id>[^\]]+)\] Captures traceId (abc123)
9+
#\[(?<span_id>[^\]]+)\] Captures spanId (def456)
10+
#(?<level>[^ ]+) Captures log level (INFO)
11+
#(?<logger>[^ ]+) Captures logger class (com.example.ClassName)
12+
#(?<message>.*)$ Captures log message (Log message here)

docker/loki/loki-config.yaml

+31
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,31 @@
1+
auth_enabled: false
2+
server:
3+
http_listen_port: 3100
4+
ingester:
5+
lifecycler:
6+
address: 0.0.0.0
7+
ring:
8+
kvstore:
9+
store: inmemory
10+
replication_factor: 1
11+
chunk_idle_period: 5m
12+
wal:
13+
enabled: true
14+
dir: /loki/wal
15+
schema_config:
16+
configs:
17+
- from: 2025-03-01
18+
store: tsdb
19+
object_store: filesystem
20+
schema: v13
21+
index:
22+
prefix: index_
23+
period: 24h
24+
storage_config:
25+
tsdb_shipper:
26+
active_index_directory: /loki/tsdb-index
27+
cache_location: /loki/tsdb-cache
28+
filesystem:
29+
directory: /loki/chunks
30+
compactor:
31+
working_directory: /loki/compactor

microservices/course-composite-service/pom.xml

+5-1
Original file line numberDiff line numberDiff line change
@@ -65,7 +65,11 @@
6565
<groupId>io.micrometer</groupId>
6666
<artifactId>micrometer-registry-prometheus</artifactId>
6767
</dependency>
68-
68+
<!-- Logback Classic for Logging -->
69+
<dependency>
70+
<groupId>ch.qos.logback</groupId>
71+
<artifactId>logback-classic</artifactId>
72+
</dependency>
6973

7074
<dependency>
7175
<groupId>org.springframework.boot</groupId>

microservices/course-composite-service/src/main/java/io/javatab/microservices/composite/course/MetricsController.java

+22-1
Original file line numberDiff line numberDiff line change
@@ -4,17 +4,25 @@
44
import io.micrometer.core.instrument.MeterRegistry;
55
import io.micrometer.core.instrument.Timer;
66
import jakarta.annotation.PostConstruct;
7+
import org.slf4j.Logger;
8+
import org.slf4j.LoggerFactory;
9+
import org.springframework.http.HttpStatus;
710
import org.springframework.web.bind.annotation.GetMapping;
811
import org.springframework.web.bind.annotation.RequestMapping;
912
import org.springframework.web.bind.annotation.RestController;
13+
import org.springframework.web.server.ResponseStatusException;
1014

1115

1216
import java.util.Random;
1317

18+
19+
/*
20+
* Just for manual test for metrics and errors which doesn't sit under security
21+
* */
1422
@RestController
1523
@RequestMapping("/api/metrics")
1624
public class MetricsController {
17-
25+
private final Logger logger = LoggerFactory.getLogger(MetricsController.class);
1826
private final MeterRegistry meterRegistry;
1927
private Counter requestCounter;
2028
private Timer requestTimer;
@@ -41,6 +49,8 @@ public void init() {
4149

4250
@GetMapping("/hello")
4351
public String hello() {
52+
logger.info("Hello endpoint called");
53+
logger.warn("This is a warning log");
4454
// Record request count
4555
requestCounter.increment();
4656

@@ -56,4 +66,15 @@ public String hello() {
5666
}
5767
});
5868
}
69+
70+
@GetMapping("/runtime-error")
71+
public String error() {
72+
logger.error("An error occurred", new RuntimeException("Test exception"));
73+
return "Error logged";
74+
}
75+
76+
@GetMapping("/error")
77+
public String triggerError() {
78+
throw new ResponseStatusException(HttpStatus.INTERNAL_SERVER_ERROR, "Something went wrong!");
79+
}
5980
}

microservices/course-composite-service/src/main/java/io/javatab/microservices/composite/course/web/CourseCompositeIntegration.java

+3-3
Original file line numberDiff line numberDiff line change
@@ -31,11 +31,11 @@ public CourseCompositeIntegration(
3131
}
3232

3333
public Mono<CourseAggregate> getCourseDetails(Long id, Jwt jwt) {
34-
logger.info("JWT ===> {}", jwt.getTokenValue());
34+
logger.debug("JWT ===> {}", jwt.getTokenValue());
3535
String courseUrl = courseServiceUrl + "/api/courses/" + id;
3636
String reviewUrl = reviewServiceUrl + "/api/reviews?course=" + id;
37-
logger.info("Course URL ===> {}", courseUrl);
38-
logger.info("Review URL ===> {}", reviewUrl);
37+
logger.debug("Course URL ===> {}", courseUrl);
38+
logger.debug("Review URL ===> {}", reviewUrl);
3939
Mono<Course> courseMono = webClient.get()
4040
.uri(courseUrl)
4141
.header("Authorization", "Bearer " + jwt.getTokenValue())

0 commit comments

Comments
 (0)