From db8614bb98049e8abed6b70e4dc49de9313dba27 Mon Sep 17 00:00:00 2001 From: romanow Date: Fri, 13 Sep 2024 13:53:59 +0300 Subject: [PATCH] Configure logs in docker --- README.md | 1 + .../src/main/resources/logback-spring.xml | 35 ++++++++++++++++--- docker-compose.logging.yml | 10 +++--- docker/fluent-bit/fluent-bit.conf | 6 ++++ order-service/Dockerfile | 2 +- .../src/main/resources/application-docker.yml | 4 +++ .../src/main/resources/application-k8s.yml | 4 +++ store-service/Dockerfile | 2 +- .../src/main/resources/application-docker.yml | 4 +++ .../src/main/resources/application-k8s.yml | 4 +++ warehouse-service/Dockerfile | 2 +- .../src/main/resources/application-docker.yml | 4 +++ .../src/main/resources/application-k8s.yml | 4 +++ warranty-service/Dockerfile | 2 +- .../src/main/resources/application-docker.yml | 4 +++ .../src/main/resources/application-k8s.yml | 4 +++ 16 files changed, 79 insertions(+), 13 deletions(-) diff --git a/README.md b/README.md index fb40ae7..f13fb5b 100644 --- a/README.md +++ b/README.md @@ -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 diff --git a/common-service/src/main/resources/logback-spring.xml b/common-service/src/main/resources/logback-spring.xml index 24e1888..d408939 100644 --- a/common-service/src/main/resources/logback-spring.xml +++ b/common-service/src/main/resources/logback-spring.xml @@ -5,8 +5,36 @@ + + + fluent-bit:5170 + + + + + { + "timestamp": "@timestamp", + "level": "%level", + "application": "${APPLICATION_NAME:-}", + "trace": "%X{traceId:-}", + "span": "%X{spanId:-}", + "pid": "${PID:-}", + "thread": "%thread", + "class": "%logger{40}", + "message": "%message" + } + + + + + + + + + + - + /var/log/${APPLICATION_NAME}/application.log application.%d{yyyy-MM-dd}.log.gz} @@ -14,9 +42,6 @@ - - UTC - { @@ -36,7 +61,7 @@ - + diff --git a/docker-compose.logging.yml b/docker-compose.logging.yml index bd59f05..4db627c 100644 --- a/docker-compose.logging.yml +++ b/docker-compose.logging.yml @@ -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: diff --git a/docker/fluent-bit/fluent-bit.conf b/docker/fluent-bit/fluent-bit.conf index 189775e..215badb 100644 --- a/docker/fluent-bit/fluent-bit.conf +++ b/docker/fluent-bit/fluent-bit.conf @@ -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 diff --git a/order-service/Dockerfile b/order-service/Dockerfile index 07fd5fc..b37875b 100644 --- a/order-service/Dockerfile +++ b/order-service/Dockerfile @@ -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 diff --git a/order-service/src/main/resources/application-docker.yml b/order-service/src/main/resources/application-docker.yml index 08ef25e..88113eb 100644 --- a/order-service/src/main/resources/application-docker.yml +++ b/order-service/src/main/resources/application-docker.yml @@ -13,3 +13,7 @@ management: otlp: tracing: endpoint: http://jaeger:4318/v1/traces + +logging: + pattern: + correlation: "[%X{traceId:-},%X{spanId:-}]" diff --git a/order-service/src/main/resources/application-k8s.yml b/order-service/src/main/resources/application-k8s.yml index c9ba9d3..5940827 100644 --- a/order-service/src/main/resources/application-k8s.yml +++ b/order-service/src/main/resources/application-k8s.yml @@ -13,3 +13,7 @@ management: otlp: tracing: endpoint: http://jaeger:4318/v1/traces + +logging: + pattern: + correlation: "[%X{traceId:-},%X{spanId:-}]" diff --git a/store-service/Dockerfile b/store-service/Dockerfile index c93e443..baac882 100644 --- a/store-service/Dockerfile +++ b/store-service/Dockerfile @@ -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 diff --git a/store-service/src/main/resources/application-docker.yml b/store-service/src/main/resources/application-docker.yml index 8277011..0c554bf 100644 --- a/store-service/src/main/resources/application-docker.yml +++ b/store-service/src/main/resources/application-docker.yml @@ -9,3 +9,7 @@ management: endpoint: http://jaeger:4318/v1/traces tracing: enabled: true + +logging: + pattern: + correlation: "[%X{traceId:-},%X{spanId:-}]" diff --git a/store-service/src/main/resources/application-k8s.yml b/store-service/src/main/resources/application-k8s.yml index 08f75cc..ebfb303 100644 --- a/store-service/src/main/resources/application-k8s.yml +++ b/store-service/src/main/resources/application-k8s.yml @@ -7,3 +7,7 @@ management: otlp: tracing: endpoint: http://jaeger:4318/v1/traces + +logging: + pattern: + correlation: "[%X{traceId:-},%X{spanId:-}]" diff --git a/warehouse-service/Dockerfile b/warehouse-service/Dockerfile index 7182f84..039f339 100644 --- a/warehouse-service/Dockerfile +++ b/warehouse-service/Dockerfile @@ -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 diff --git a/warehouse-service/src/main/resources/application-docker.yml b/warehouse-service/src/main/resources/application-docker.yml index 728f763..6a287cb 100644 --- a/warehouse-service/src/main/resources/application-docker.yml +++ b/warehouse-service/src/main/resources/application-docker.yml @@ -12,3 +12,7 @@ management: otlp: tracing: endpoint: http://jaeger:4318/v1/traces + +logging: + pattern: + correlation: "[%X{traceId:-},%X{spanId:-}]" diff --git a/warehouse-service/src/main/resources/application-k8s.yml b/warehouse-service/src/main/resources/application-k8s.yml index b417b9b..a150907 100644 --- a/warehouse-service/src/main/resources/application-k8s.yml +++ b/warehouse-service/src/main/resources/application-k8s.yml @@ -12,3 +12,7 @@ management: otlp: tracing: endpoint: http://jaeger:4318/v1/traces + +logging: + pattern: + correlation: "[%X{traceId:-},%X{spanId:-}]" diff --git a/warranty-service/Dockerfile b/warranty-service/Dockerfile index 7c71900..2b7285e 100644 --- a/warranty-service/Dockerfile +++ b/warranty-service/Dockerfile @@ -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 diff --git a/warranty-service/src/main/resources/application-docker.yml b/warranty-service/src/main/resources/application-docker.yml index 284362b..2ccf9b7 100644 --- a/warranty-service/src/main/resources/application-docker.yml +++ b/warranty-service/src/main/resources/application-docker.yml @@ -9,3 +9,7 @@ management: otlp: tracing: endpoint: http://jaeger:4318/v1/traces + +logging: + pattern: + correlation: "[%X{traceId:-},%X{spanId:-}]" diff --git a/warranty-service/src/main/resources/application-k8s.yml b/warranty-service/src/main/resources/application-k8s.yml index 3837253..7e31613 100644 --- a/warranty-service/src/main/resources/application-k8s.yml +++ b/warranty-service/src/main/resources/application-k8s.yml @@ -9,3 +9,7 @@ management: otlp: tracing: endpoint: http://jaeger:4318/v1/traces + +logging: + pattern: + correlation: "[%X{traceId:-},%X{spanId:-}]"