Skip to content

Commit

Permalink
Configure logs in docker
Browse files Browse the repository at this point in the history
  • Loading branch information
Romanow committed Sep 13, 2024
1 parent 3ebbcaa commit db8614b
Show file tree
Hide file tree
Showing 16 changed files with 79 additions and 13 deletions.
1 change: 1 addition & 0 deletions README.md
Original file line number Diff line number Diff line change
Expand Up @@ -93,6 +93,7 @@ $ brew install k6
$ docker compose \
-f docker-compose.yml \
-f docker-compose.tracing.yml \
-f docker-compose.logging.yml \
-f docker-compose.monitoring.yml \
up -d --wait

Expand Down
35 changes: 30 additions & 5 deletions common-service/src/main/resources/logback-spring.xml
Original file line number Diff line number Diff line change
Expand Up @@ -5,18 +5,43 @@

<springProperty scope="context" name="APPLICATION_NAME" source="spring.application.name"/>

<springProfile name="docker">
<appender name="FLUENT-BIT" class="net.logstash.logback.appender.LogstashTcpSocketAppender">
<destination>fluent-bit:5170</destination>
<encoder class="net.logstash.logback.encoder.LoggingEventCompositeJsonEncoder">
<providers>
<pattern>
<pattern>
{
"timestamp": "@timestamp",
"level": "%level",
"application": "${APPLICATION_NAME:-}",
"trace": "%X{traceId:-}",
"span": "%X{spanId:-}",
"pid": "${PID:-}",
"thread": "%thread",
"class": "%logger{40}",
"message": "%message"
}
</pattern>
</pattern>
</providers>
</encoder>
</appender>
<root level="info">
<appender-ref ref="FLUENT-BIT"/>
</root>
</springProfile>

<springProfile name="k8s">
<appender name="LOGSTASH" class="ch.qos.logback.core.rolling.RollingFileAppender">
<appender name="FLUENT-BIT" class="ch.qos.logback.core.rolling.RollingFileAppender">
<file>/var/log/${APPLICATION_NAME}/application.log</file>
<rollingPolicy class="ch.qos.logback.core.rolling.TimeBasedRollingPolicy">
<fileNamePattern>application.%d{yyyy-MM-dd}.log.gz}</fileNamePattern>
<maxHistory>7</maxHistory>
</rollingPolicy>
<encoder class="net.logstash.logback.encoder.LoggingEventCompositeJsonEncoder">
<providers>
<timestamp>
<timeZone>UTC</timeZone>
</timestamp>
<pattern>
<pattern>
{
Expand All @@ -36,7 +61,7 @@
</encoder>
</appender>
<root level="info">
<appender-ref ref="LOGSTASH"/>
<appender-ref ref="FLUENT-BIT"/>
</root>
</springProfile>

Expand Down
10 changes: 6 additions & 4 deletions docker-compose.logging.yml
Original file line number Diff line number Diff line change
Expand Up @@ -39,15 +39,17 @@ services:
condition: service_healthy

fluent-bit:
image: fluent/fluent-bit:3.0
image: fluent/fluent-bit:3.1.7-debug
container_name: fluent-bit
ports:
- "5170:5170"
healthcheck:
test: [ "CMD-SHELL", "curl --silent --fail http://localhost:2020/api/v1/health" ]
interval: 5s
timeout: 2s
retries: 5
volumes:
- ./docker/fluent-bit/fluent-bit.conf:/fluent-bit/etc/fluent-bit.conf
depends_on:
elastic:
condition: service_healthy

volumes:
elastic-data:
Expand Down
6 changes: 6 additions & 0 deletions docker/fluent-bit/fluent-bit.conf
Original file line number Diff line number Diff line change
@@ -1,3 +1,9 @@
[SERVICE]
HTTP_Server On
HTTP_Listen 127.0.0.1
HTTP_PORT 2020
Health_Check On

[INPUT]
Name tcp
Listen 0.0.0.0
Expand Down
2 changes: 1 addition & 1 deletion order-service/Dockerfile
Original file line number Diff line number Diff line change
@@ -1,4 +1,4 @@
FROM amazoncorretto:17 as builder
FROM amazoncorretto:17 AS builder
WORKDIR application
ARG JAR_FILE=build/libs/order-service.jar
COPY ${JAR_FILE} application.jar
Expand Down
4 changes: 4 additions & 0 deletions order-service/src/main/resources/application-docker.yml
Original file line number Diff line number Diff line change
Expand Up @@ -13,3 +13,7 @@ management:
otlp:
tracing:
endpoint: http://jaeger:4318/v1/traces

logging:
pattern:
correlation: "[%X{traceId:-},%X{spanId:-}]"
4 changes: 4 additions & 0 deletions order-service/src/main/resources/application-k8s.yml
Original file line number Diff line number Diff line change
Expand Up @@ -13,3 +13,7 @@ management:
otlp:
tracing:
endpoint: http://jaeger:4318/v1/traces

logging:
pattern:
correlation: "[%X{traceId:-},%X{spanId:-}]"
2 changes: 1 addition & 1 deletion store-service/Dockerfile
Original file line number Diff line number Diff line change
@@ -1,4 +1,4 @@
FROM amazoncorretto:17 as builder
FROM amazoncorretto:17 AS builder
WORKDIR application
ARG JAR_FILE=build/libs/store-service.jar
COPY ${JAR_FILE} application.jar
Expand Down
4 changes: 4 additions & 0 deletions store-service/src/main/resources/application-docker.yml
Original file line number Diff line number Diff line change
Expand Up @@ -9,3 +9,7 @@ management:
endpoint: http://jaeger:4318/v1/traces
tracing:
enabled: true

logging:
pattern:
correlation: "[%X{traceId:-},%X{spanId:-}]"
4 changes: 4 additions & 0 deletions store-service/src/main/resources/application-k8s.yml
Original file line number Diff line number Diff line change
Expand Up @@ -7,3 +7,7 @@ management:
otlp:
tracing:
endpoint: http://jaeger:4318/v1/traces

logging:
pattern:
correlation: "[%X{traceId:-},%X{spanId:-}]"
2 changes: 1 addition & 1 deletion warehouse-service/Dockerfile
Original file line number Diff line number Diff line change
@@ -1,4 +1,4 @@
FROM amazoncorretto:17 as builder
FROM amazoncorretto:17 AS builder
WORKDIR application
ARG JAR_FILE=build/libs/warehouse-service.jar
COPY ${JAR_FILE} application.jar
Expand Down
4 changes: 4 additions & 0 deletions warehouse-service/src/main/resources/application-docker.yml
Original file line number Diff line number Diff line change
Expand Up @@ -12,3 +12,7 @@ management:
otlp:
tracing:
endpoint: http://jaeger:4318/v1/traces

logging:
pattern:
correlation: "[%X{traceId:-},%X{spanId:-}]"
4 changes: 4 additions & 0 deletions warehouse-service/src/main/resources/application-k8s.yml
Original file line number Diff line number Diff line change
Expand Up @@ -12,3 +12,7 @@ management:
otlp:
tracing:
endpoint: http://jaeger:4318/v1/traces

logging:
pattern:
correlation: "[%X{traceId:-},%X{spanId:-}]"
2 changes: 1 addition & 1 deletion warranty-service/Dockerfile
Original file line number Diff line number Diff line change
@@ -1,4 +1,4 @@
FROM amazoncorretto:17 as builder
FROM amazoncorretto:17 AS builder
WORKDIR application
ARG JAR_FILE=build/libs/warranty-service.jar
COPY ${JAR_FILE} application.jar
Expand Down
4 changes: 4 additions & 0 deletions warranty-service/src/main/resources/application-docker.yml
Original file line number Diff line number Diff line change
Expand Up @@ -9,3 +9,7 @@ management:
otlp:
tracing:
endpoint: http://jaeger:4318/v1/traces

logging:
pattern:
correlation: "[%X{traceId:-},%X{spanId:-}]"
4 changes: 4 additions & 0 deletions warranty-service/src/main/resources/application-k8s.yml
Original file line number Diff line number Diff line change
Expand Up @@ -9,3 +9,7 @@ management:
otlp:
tracing:
endpoint: http://jaeger:4318/v1/traces

logging:
pattern:
correlation: "[%X{traceId:-},%X{spanId:-}]"

0 comments on commit db8614b

Please sign in to comment.