From 0c84d5371d20a511d26859d3f2a008068b17cdba Mon Sep 17 00:00:00 2001 From: "antonio.torre" Date: Mon, 13 Jan 2025 09:41:27 +0100 Subject: [PATCH] chore: Added prometheus + fix openApi handling --- Dockerfile | 2 +- build.gradle.kts | 17 +++++++++++++--- gradle.lockfile | 5 +++++ src/main/resources/application.yml | 31 +++++++++++++++++++++++++----- 4 files changed, 46 insertions(+), 9 deletions(-) diff --git a/Dockerfile b/Dockerfile index cee3b16..42c852e 100644 --- a/Dockerfile +++ b/Dockerfile @@ -101,7 +101,7 @@ RUN mkdir -p src/main/java && \ USER ${APP_USER} -RUN gradle openApiGenerate dependencies --no-daemon +RUN gradle dependenciesBuild dependencies --no-daemon # # 🏗️ Build Stage diff --git a/build.gradle.kts b/build.gradle.kts index 2c1884f..d8e96ab 100644 --- a/build.gradle.kts +++ b/build.gradle.kts @@ -37,6 +37,7 @@ dependencies { implementation("org.springframework.boot:spring-boot-starter-web") implementation("org.springframework.boot:spring-boot-starter-actuator") implementation("io.micrometer:micrometer-tracing-bridge-otel:$micrometerVersion") + implementation("io.micrometer:micrometer-registry-prometheus") implementation("org.springdoc:springdoc-openapi-starter-webmvc-ui:$springDocOpenApiVersion") implementation("com.fasterxml.jackson.datatype:jackson-datatype-jsr310") implementation("org.openapitools:jackson-databind-nullable:$openApiToolsVersion") @@ -82,7 +83,16 @@ configurations { } tasks.compileJava { - dependsOn("openApiGenerate") + dependsOn("dependenciesBuild") +} + +tasks.register("dependenciesBuild") { + group = "AutomaticallyGeneratedCode" + description = "grouping all together automatically generate code tasks" + + dependsOn( + "openApiGenerate" + ) } configure { @@ -107,8 +117,9 @@ openApiGenerate { "useSpringBoot3" to "true", "interfaceOnly" to "true", "useTags" to "true", - "generateConstructorWithAllArgs" to "false", + "useBeanValidation" to "true", + "generateConstructorWithAllArgs" to "true", "generatedConstructorWithRequiredArgs" to "true", - "additionalModelTypeAnnotations" to "@lombok.Data @lombok.Builder @lombok.AllArgsConstructor" + "additionalModelTypeAnnotations" to "@lombok.Builder" )) } diff --git a/gradle.lockfile b/gradle.lockfile index dbe58cc..ab6de54 100644 --- a/gradle.lockfile +++ b/gradle.lockfile @@ -17,6 +17,7 @@ io.micrometer:micrometer-commons:1.14.2=compileClasspath io.micrometer:micrometer-core:1.14.2=compileClasspath io.micrometer:micrometer-jakarta9:1.14.2=compileClasspath io.micrometer:micrometer-observation:1.14.2=compileClasspath +io.micrometer:micrometer-registry-prometheus:1.14.2=compileClasspath io.micrometer:micrometer-tracing-bridge-otel:1.4.1=compileClasspath io.micrometer:micrometer-tracing:1.4.1=compileClasspath io.opentelemetry.instrumentation:opentelemetry-instrumentation-api-incubator:2.9.0-alpha=compileClasspath @@ -30,6 +31,10 @@ io.opentelemetry:opentelemetry-sdk-logs:1.43.0=compileClasspath io.opentelemetry:opentelemetry-sdk-metrics:1.43.0=compileClasspath io.opentelemetry:opentelemetry-sdk-trace:1.43.0=compileClasspath io.opentelemetry:opentelemetry-sdk:1.43.0=compileClasspath +io.prometheus:prometheus-metrics-config:1.3.5=compileClasspath +io.prometheus:prometheus-metrics-core:1.3.5=compileClasspath +io.prometheus:prometheus-metrics-model:1.3.5=compileClasspath +io.prometheus:prometheus-metrics-tracer-common:1.3.5=compileClasspath io.swagger.core.v3:swagger-annotations-jakarta:2.2.25=compileClasspath io.swagger.core.v3:swagger-core-jakarta:2.2.25=compileClasspath io.swagger.core.v3:swagger-models-jakarta:2.2.25=compileClasspath diff --git a/src/main/resources/application.yml b/src/main/resources/application.yml index 91ace00..2b3bae5 100644 --- a/src/main/resources/application.yml +++ b/src/main/resources/application.yml @@ -1,3 +1,6 @@ +server: + http: "\${SERVER_PORT:8080}" + spring: application: name: ${artifactId} @@ -8,14 +11,32 @@ spring: enabled: "\${VIRTUAL_THREADS_ENABLED:true}" management: + endpoints: + jmx: + exposure.include: "*" + web: + exposure: + include: health, info, prometheus, metrics + base-path: /actuator endpoint: health: probes.enabled: true group: readiness.include: "*" liveness.include: livenessState,diskSpace,ping - endpoints: - jmx: - exposure.include: "*" - web: - exposure.include: info, health + prometheus: + enabled: true + metrics: + tags: + application: ${artifactId} + export: + prometheus: + enabled: true + step: 1m + descriptions: true + enable: + jvm: true + process: true + system: true + http: true + logback: true