From e40f3d9453e175db262cb09af699fb205f2ffa11 Mon Sep 17 00:00:00 2001 From: stefan Date: Tue, 16 Sep 2025 13:08:25 +0200 Subject: [PATCH] fixing gateway prometheus --- client/build.gradle.kts | 1 - dockerfiles/infrastructure/gateway/Dockerfile | 2 +- dockerfiles/services/ping-service/Dockerfile | 2 +- gradle/libs.versions.toml | 4 ++-- .../gateway/metrics/GatewayMetricsConfig.kt | 14 +++++--------- .../gateway/src/main/resources/application.yml | 15 ++++++++------- 6 files changed, 17 insertions(+), 21 deletions(-) diff --git a/client/build.gradle.kts b/client/build.gradle.kts index a72877dc..0d713a77 100644 --- a/client/build.gradle.kts +++ b/client/build.gradle.kts @@ -98,7 +98,6 @@ kotlin { "-Xwasm-debugger-custom-formatters", // Optimize debug info for smaller size "-Xwasm-enable-array-range-checks", // Optimize array bounds checking "-Xwasm-generate-wat=false", // Skip WAT generation for smaller output - "-Xwasm-target=wasm32", // Explicit WASM32 target "-opt-in=kotlin.ExperimentalStdlibApi", // Enable stdlib optimizations "-opt-in=kotlin.js.ExperimentalJsExport" // Enable JS export optimizations ) diff --git a/dockerfiles/infrastructure/gateway/Dockerfile b/dockerfiles/infrastructure/gateway/Dockerfile index fd2eaa62..eba1ccfc 100644 --- a/dockerfiles/infrastructure/gateway/Dockerfile +++ b/dockerfiles/infrastructure/gateway/Dockerfile @@ -173,7 +173,7 @@ ENV JAVA_OPTS="-XX:MaxRAMPercentage=80.0 \ -Dspring.backgroundpreinitializer.ignore=true \ -Dmanagement.endpoints.web.exposure.include=health,info,metrics,prometheus,gateway \ -Dmanagement.endpoint.health.show-details=always \ - -Dmanagement.metrics.export.prometheus.enabled=true" + -Dmanagement.prometheus.metrics.export.enabled=true" # Spring Boot configuration ENV SPRING_OUTPUT_ANSI_ENABLED=ALWAYS \ diff --git a/dockerfiles/services/ping-service/Dockerfile b/dockerfiles/services/ping-service/Dockerfile index 0579b240..7811eab3 100644 --- a/dockerfiles/services/ping-service/Dockerfile +++ b/dockerfiles/services/ping-service/Dockerfile @@ -164,7 +164,7 @@ ENV JAVA_OPTS="-XX:MaxRAMPercentage=75.0 \ -Dspring.backgroundpreinitializer.ignore=true \ -Dmanagement.endpoints.web.exposure.include=health,info,metrics,prometheus \ -Dmanagement.endpoint.health.show-details=always \ - -Dmanagement.metrics.export.prometheus.enabled=true" + -Dmanagement.prometheus.metrics.export.enabled=true" # Spring Boot configuration ENV SPRING_OUTPUT_ANSI_ENABLED=ALWAYS \ diff --git a/gradle/libs.versions.toml b/gradle/libs.versions.toml index 14391b07..260f2762 100644 --- a/gradle/libs.versions.toml +++ b/gradle/libs.versions.toml @@ -122,7 +122,7 @@ springdoc-openapi-starter-common = { module = "org.springdoc:springdoc-openapi-s springdoc-openapi-starter-webmvc-ui = { module = "org.springdoc:springdoc-openapi-starter-webmvc-ui", version.ref = "springdoc" } # --- Spring Cloud --- -spring-cloud-starter-gateway = { module = "org.springframework.cloud:spring-cloud-starter-gateway" } +spring-cloud-starter-gateway-server-webflux = { module = "org.springframework.cloud:spring-cloud-starter-gateway-server-webflux" } spring-cloud-starter-consul-discovery = { module = "org.springframework.cloud:spring-cloud-starter-consul-discovery" } # --- Database & Persistence --- @@ -271,7 +271,7 @@ monitoring-client = [ ] # Bündelt die Kernabhängigkeiten für das Spring Cloud Gateway. spring-cloud-gateway = [ - "spring-cloud-starter-gateway", + "spring-cloud-starter-gateway-server-webflux", "spring-cloud-starter-consul-discovery" ] diff --git a/infrastructure/gateway/src/main/kotlin/at/mocode/infrastructure/gateway/metrics/GatewayMetricsConfig.kt b/infrastructure/gateway/src/main/kotlin/at/mocode/infrastructure/gateway/metrics/GatewayMetricsConfig.kt index 486bedba..bcc63946 100644 --- a/infrastructure/gateway/src/main/kotlin/at/mocode/infrastructure/gateway/metrics/GatewayMetricsConfig.kt +++ b/infrastructure/gateway/src/main/kotlin/at/mocode/infrastructure/gateway/metrics/GatewayMetricsConfig.kt @@ -29,7 +29,7 @@ class GatewayMetricsConfig { companion object { // Metric Namen als Konstanten für bessere Wartbarkeit - const val GATEWAY_REQUEST_TIMER = "gateway_request_duration" + const val GATEWAY_REQUEST_TIMER = "gateway_custom_request_duration" const val GATEWAY_ERROR_COUNTER = "gateway_errors_total" const val GATEWAY_REQUESTS_COUNTER = "gateway_requests_total" const val GATEWAY_CIRCUIT_BREAKER_COUNTER = "gateway_circuit_breaker_events_total" @@ -72,15 +72,11 @@ class GatewayMetricsConfig { } /** - * Bean für Request Duration Timer - ermöglicht manuelle Messungen. + * Bean für Request Duration Timer - entfernt um Konflikte mit dem WebFilter zu vermeiden. + * Die Request-Zeiten werden automatisch im GatewayMetricsWebFilter erfasst. */ - @Bean - fun requestTimer(meterRegistry: MeterRegistry): Timer { - return Timer.builder(GATEWAY_REQUEST_TIMER) - .description("Gateway Request-Verarbeitungszeit") - .tag("type", "http") - .register(meterRegistry) - } + // @Bean - Entfernt um Prometheus Meter-Konflikte zu vermeiden + // fun requestTimer(meterRegistry: MeterRegistry): Timer { ... } /** * Bean für Error Counter - ermöglicht manuelles Error Tracking. diff --git a/infrastructure/gateway/src/main/resources/application.yml b/infrastructure/gateway/src/main/resources/application.yml index eda013da..7e96bd4c 100644 --- a/infrastructure/gateway/src/main/resources/application.yml +++ b/infrastructure/gateway/src/main/resources/application.yml @@ -225,21 +225,19 @@ management: metrics: distribution: percentiles-histogram: - spring.cloud.gateway.requests: true http.server.requests: true percentiles: - spring.cloud.gateway.requests: 0.5,0.90,0.95,0.99 http.server.requests: 0.5,0.90,0.95,0.99 minimum-expected-value: - spring.cloud.gateway.requests: 1ms http.server.requests: 1ms maximum-expected-value: - spring.cloud.gateway.requests: 30s http.server.requests: 30s tags: application: ${spring.application.name} environment: ${spring.profiles.active} instance: ${spring.cloud.consul.discovery.instance-id} + service: gateway + component: infrastructure gateway: api-gateway info: env: @@ -252,12 +250,15 @@ management: enabled: true # Tracing-Konfiguration - Aktiviert (Micrometer Tracing + Zipkin) tracing: - enabled: true + enabled: ${TRACING_ENABLED:false} sampling: probability: ${TRACING_SAMPLING_PROBABILITY:1.0} zipkin: tracing: - endpoint: ${ZIPKIN_TRACING_ENDPOINT:http://zipkin:9411/api/v2/spans} + endpoint: ${ZIPKIN_TRACING_ENDPOINT:http://localhost:9411/api/v2/spans} + # Reduziert Verbindungsfehler wenn Zipkin nicht verfügbar ist + connect-timeout: 1s + read-timeout: 10s # Erweiterte Logging-Konfiguration logging: @@ -274,7 +275,7 @@ logging: console: "%clr(%d{yyyy-MM-dd HH:mm:ss.SSS}){faint} %clr(${LOG_LEVEL_PATTERN:-%5p}) %clr(${PID:- }){magenta} %clr(---){faint} %clr([%15.15t]){faint} %clr(%-40.40logger{39}){cyan} %clr([%X{correlationId:-}]){yellow} %clr(:){faint} %m%n${LOG_EXCEPTION_CONVERSION_WORD:-%wEx}" file: "%d{yyyy-MM-dd HH:mm:ss.SSS} [%thread] %-5level [%X{correlationId:-}] %logger{36} - %msg%n" file: - name: logs/gateway.log + name: infrastructure/gateway/logs/gateway.log logback: rolling policy: clean-history-on-start: true