From 05bb8f3e4646f4f5e7fe7927790e3f23f8c20090 Mon Sep 17 00:00:00 2001 From: alessio-acitelli <97529051+alessio-acitelli@users.noreply.github.com> Date: Fri, 4 Oct 2024 09:50:18 +0200 Subject: [PATCH] feat: [PAGOPA-2202] log optimization (#6) * [PAGOPA-2202] log opt: updated maven plugin version --------- Co-authored-by: pagopa-github-bot Co-authored-by: pasqualespica <36746022+pasqualespica@users.noreply.github.com> --- Dockerfile | 10 +++++++--- docker/applicationinsights.json | 19 +++++++++++++++++++ docker/run_docker.sh | 13 ++++++++----- helm/values-prod.yaml | 2 +- pom.xml | 4 ++-- src/main/resources/application.properties | 2 +- 6 files changed, 38 insertions(+), 12 deletions(-) create mode 100644 docker/applicationinsights.json diff --git a/Dockerfile b/Dockerfile index 26e3228..4ca19f8 100644 --- a/Dockerfile +++ b/Dockerfile @@ -6,17 +6,21 @@ WORKDIR /build COPY . . RUN mvn clean package -Dmaven.test.skip=true - +# +# Package stage +# FROM amazoncorretto:17.0.9-alpine3.18@sha256:df48bf2e183230040890460ddb4359a10aa6c7aad24bd88899482c52053c7e17 as builder COPY --from=buildtime /build/target/*.jar application.jar RUN java -Djarmode=layertools -jar application.jar extract FROM ghcr.io/pagopa/docker-base-springboot-openjdk17:v1.1.0@sha256:6fa320d452fa22066441f1ef292d15eb06f944bc8bca293e1a91ea460d30a613 -ADD --chown=spring:spring https://github.com/open-telemetry/opentelemetry-java-instrumentation/releases/download/v1.25.1/opentelemetry-javaagent.jar . +#ADD --chown=spring:spring https://github.com/open-telemetry/opentelemetry-java-instrumentation/releases/download/v1.25.1/opentelemetry-javaagent.jar . COPY --chown=spring:spring --from=builder dependencies/ ./ COPY --chown=spring:spring --from=builder snapshot-dependencies/ ./ +COPY --chown=spring:spring docker/applicationinsights.json ./applicationinsights.json + # https://github.com/moby/moby/issues/37965#issuecomment-426853382 RUN true COPY --chown=spring:spring --from=builder spring-boot-loader/ ./ @@ -24,4 +28,4 @@ COPY --chown=spring:spring --from=builder application/ ./ EXPOSE 8080 -ENTRYPOINT ["java","-javaagent:opentelemetry-javaagent.jar","--enable-preview","org.springframework.boot.loader.JarLauncher"] \ No newline at end of file +#ENTRYPOINT ["java","-javaagent:opentelemetry-javaagent.jar","--enable-preview","org.springframework.boot.loader.JarLauncher"] \ No newline at end of file diff --git a/docker/applicationinsights.json b/docker/applicationinsights.json new file mode 100644 index 0000000..312fe75 --- /dev/null +++ b/docker/applicationinsights.json @@ -0,0 +1,19 @@ +{ + "selfDiagnostics": { + "destination": "console", + "level": "INFO" + }, + "sampling": { + "requestsPerSecond": 5 + }, + "preview": { + "sampling": { + "overrides": [ + { + "telemetryKind": "exception", + "percentage": 100 + } + ] + } + } +} \ No newline at end of file diff --git a/docker/run_docker.sh b/docker/run_docker.sh index 5d98b04..13e12b6 100755 --- a/docker/run_docker.sh +++ b/docker/run_docker.sh @@ -26,17 +26,21 @@ if test -f "$FILE"; then rm .env fi config=$(yq -r '."microservice-chart".envConfig' ../helm/values-$ENV.yaml) +# set word splitting IFS=$'\n' -for line in $(echo "$config" | jq -r '. | to_entries[] | select(.key) | "\(.key)=\(.value)"'); do +for line in $(echo "$config" | yq -r '. | to_entries[] | select(.key) | "\(.key)=\(.value)"'); do echo "$line" >> .env done keyvault=$(yq -r '."microservice-chart".keyvault.name' ../helm/values-$ENV.yaml) secret=$(yq -r '."microservice-chart".envSecret' ../helm/values-$ENV.yaml) -for line in $(echo "$secret" | jq -r '. | to_entries[] | select(.key) | "\(.key)=\(.value)"'); do +for line in $(echo "$secret" | yq -r '. | to_entries[] | select(.key) | "\(.key)=\(.value)"'); do IFS='=' read -r -a array <<< "$line" response=$(az keyvault secret show --vault-name $keyvault --name "${array[1]}") - value=$(echo "$response" | jq -r '.value') + response=$(echo "$response" | tr -d '\n') + value=$(echo "$response" | yq -r '.value') + value=$(echo "$value" | sed 's/\$/\$\$/g') + value=$(echo "$value" | tr -d '\n') echo "${array[0]}=$value" >> .env done @@ -44,7 +48,6 @@ done stack_name=$(cd .. && basename "$PWD") docker compose -p "${stack_name}" up -d --remove-orphans --force-recreate --build - # waiting the containers printf 'Waiting for the service' attempt_counter=0 @@ -59,4 +62,4 @@ until $(curl --output /dev/null --silent --head --fail http://localhost:8080/act attempt_counter=$((attempt_counter+1)) sleep 5 done -echo 'Service Started' +echo 'Service Started' \ No newline at end of file diff --git a/helm/values-prod.yaml b/helm/values-prod.yaml index 6582999..9c93958 100644 --- a/helm/values-prod.yaml +++ b/helm/values-prod.yaml @@ -66,7 +66,7 @@ microservice-chart: APPLICATIONINSIGHTS_ROLE_NAME: "pagopa-nodo-verifyko-aux" ENV: 'aks-dev' APP_LOGGING_LEVEL: 'INFO' - DEFAULT_LOGGING_LEVEL: 'INFO' + DEFAULT_LOGGING_LEVEL: 'WARN' CORS_CONFIGURATION: '{"origins": ["*"], "methods": ["*"]}' CACHE_ENABLED: 'true' VERIFYKO_COLDSTORAGE_TABLE: 'events' diff --git a/pom.xml b/pom.xml index 6b53b62..958679c 100644 --- a/pom.xml +++ b/pom.xml @@ -120,7 +120,7 @@ co.elastic.logging logback-ecs-encoder - 1.5.0 + 1.6.0 @@ -156,7 +156,7 @@ org.sonarsource.scanner.maven sonar-maven-plugin - 3.3.0.603 + 3.7.0.1746 verify diff --git a/src/main/resources/application.properties b/src/main/resources/application.properties index 7d31fa5..c394d8c 100644 --- a/src/main/resources/application.properties +++ b/src/main/resources/application.properties @@ -18,7 +18,7 @@ springdoc.writer-with-default-pretty-printer=true server.servlet.context-path=/ server.port=8080 # Logging -logging.level.root=${DEFAULT_LOGGING_LEVEL:INFO} +logging.level.root=${DEFAULT_LOGGING_LEVEL:WARN} logging.level.it.gov.pagopa=${APP_LOGGING_LEVEL:INFO} # CORS configuration cors.configuration=${CORS_CONFIGURATION:'{"origins": ["*"], "methods": ["*"]}'}