Add service discovery and health fixes: configure Consul registration, update health-check paths and ports, expand scanBasePackages, and ensure consistent service startup across modules.
This commit is contained in:
parent
8e40d13954
commit
19934e2a96
|
|
@ -0,0 +1,28 @@
|
|||
spring:
|
||||
application:
|
||||
name: billing-service
|
||||
datasource:
|
||||
url: ${SPRING_DATASOURCE_URL:jdbc:postgresql://localhost:5432/pg-meldestelle-db}
|
||||
username: ${SPRING_DATASOURCE_USERNAME:pg-user}
|
||||
password: ${SPRING_DATASOURCE_PASSWORD:pg-password}
|
||||
cloud:
|
||||
consul:
|
||||
host: ${CONSUL_HOST:localhost}
|
||||
port: ${CONSUL_PORT:8500}
|
||||
discovery:
|
||||
enabled: true
|
||||
register: true
|
||||
health-check-path: /actuator/health
|
||||
health-check-interval: 10s
|
||||
|
||||
server:
|
||||
port: ${SERVER_PORT:${BILLING_SERVICE_PORT:8087}}
|
||||
|
||||
management:
|
||||
endpoints:
|
||||
web:
|
||||
exposure:
|
||||
include: health,info,metrics,prometheus
|
||||
endpoint:
|
||||
health:
|
||||
show-details: always
|
||||
|
|
@ -11,7 +11,7 @@ fun main(args: Array<String>) {
|
|||
runApplication<EntriesServiceApplication>(*args)
|
||||
}
|
||||
|
||||
@SpringBootApplication(scanBasePackages = ["at.mocode.entries", "at.mocode.billing"])
|
||||
@SpringBootApplication(scanBasePackages = ["at.mocode.entries", "at.mocode.billing", "at.mocode.infrastructure.security"])
|
||||
@EnableAspectJAutoProxy
|
||||
class EntriesServiceApplication {
|
||||
|
||||
|
|
|
|||
|
|
@ -18,6 +18,7 @@ spring:
|
|||
discovery:
|
||||
enabled: true
|
||||
register: true
|
||||
prefer-ip-address: true
|
||||
health-check-path: /actuator/health
|
||||
health-check-interval: 10s
|
||||
|
||||
|
|
|
|||
|
|
@ -22,6 +22,8 @@ dependencies {
|
|||
implementation(libs.spring.boot.starter.validation)
|
||||
implementation(libs.spring.boot.starter.security)
|
||||
implementation(libs.spring.boot.starter.oauth2.resource.server)
|
||||
implementation(libs.spring.boot.starter.actuator)
|
||||
implementation(libs.spring.cloud.starter.consul.discovery)
|
||||
|
||||
implementation(libs.exposed.core)
|
||||
implementation(libs.exposed.jdbc)
|
||||
|
|
|
|||
|
|
@ -0,0 +1,35 @@
|
|||
server:
|
||||
port: ${SERVER_PORT:${IDENTITY_SERVICE_PORT:8088}}
|
||||
|
||||
spring:
|
||||
application:
|
||||
name: identity-service
|
||||
datasource:
|
||||
url: ${SPRING_DATASOURCE_URL:jdbc:postgresql://localhost:5432/pg-meldestelle-db}
|
||||
username: ${SPRING_DATASOURCE_USERNAME:pg-user}
|
||||
password: ${SPRING_DATASOURCE_PASSWORD:pg-password}
|
||||
cloud:
|
||||
consul:
|
||||
host: ${CONSUL_HOST:localhost}
|
||||
port: ${CONSUL_PORT:8500}
|
||||
discovery:
|
||||
enabled: true
|
||||
register: true
|
||||
prefer-ip-address: true
|
||||
health-check-path: /actuator/health
|
||||
health-check-interval: 10s
|
||||
security:
|
||||
oauth2:
|
||||
resourceserver:
|
||||
jwt:
|
||||
issuer-uri: ${SPRING_SECURITY_OAUTH2_RESOURCESERVER_JWT_ISSUER_URI:http://localhost:8180/realms/meldestelle}
|
||||
jwk-set-uri: ${SPRING_SECURITY_OAUTH2_RESOURCESERVER_JWT_JWK_SET_URI:http://localhost:8180/realms/meldestelle/protocol/openid-connect/certs}
|
||||
|
||||
management:
|
||||
endpoints:
|
||||
web:
|
||||
exposure:
|
||||
include: health,info,metrics,prometheus
|
||||
endpoint:
|
||||
health:
|
||||
show-details: always
|
||||
|
|
@ -22,7 +22,7 @@ spring:
|
|||
prefer-ip-address: true # Nutze IP im Docker-Netzwerk
|
||||
health-check-path: /actuator/health
|
||||
health-check-interval: 10s
|
||||
health-check-port: ${server.port} # Health Check läuft auf Spring Port
|
||||
health-check-port: 8086 # Spring Boot Port (Tomcat), NICHT Ktor (8091)
|
||||
instance-id: ${spring.application.name}:${server.port}:${random.uuid}
|
||||
service-name: ${spring.application.name}
|
||||
port: ${masterdata.http.port} # Ktor API Port registrieren
|
||||
|
|
|
|||
|
|
@ -19,13 +19,14 @@ spring:
|
|||
discovery:
|
||||
enabled: ${CONSUL_ENABLED:true}
|
||||
register: ${CONSUL_ENABLED:true}
|
||||
prefer-ip-address: true
|
||||
health-check-path: /actuator/health
|
||||
health-check-interval: 10s
|
||||
instance-id: ${spring.application.name}-${server.port}-${random.uuid}
|
||||
service-name: ${spring.application.name}
|
||||
|
||||
server:
|
||||
port: 8088
|
||||
port: ${SERVER_PORT:${RESULTS_SERVICE_PORT:8084}}
|
||||
|
||||
management:
|
||||
endpoints:
|
||||
|
|
|
|||
|
|
@ -0,0 +1,30 @@
|
|||
# Curator Log - 2026-04-13 - Billing Service Startup Fix
|
||||
|
||||
## Status
|
||||
- **Abteilung:** Backend / Infrastructure
|
||||
- **Agent:** Curator
|
||||
- **Datum:** 2026-04-13
|
||||
- **Task:** Fix `billing-service` startup failure due to missing configuration.
|
||||
|
||||
## Analyse
|
||||
Der `billing-service` konnte lokal nicht gestartet werden, da keine `application.yaml` vorhanden war. Dies führte zu zwei kritischen Fehlern:
|
||||
1. **Consul Registration Error:** Ohne `spring.application.name` konnte kein gültiger Service-ID für Consul generiert werden (`null`).
|
||||
2. **Database Initialization Skip:** Ohne `spring.datasource.url` wurde die Datenbank-Initialisierung übersprungen.
|
||||
|
||||
## Änderungen
|
||||
|
||||
### Backend (Billing Service)
|
||||
- **Konfiguration:** Eine neue `src/main/resources/application.yaml` wurde erstellt.
|
||||
- Setzt `spring.application.name` auf `billing-service`.
|
||||
- Konfiguriert den Standard-Port auf `8087`.
|
||||
- Fügt die notwendigen `spring.datasource` Einstellungen für PostgreSQL hinzu (inkl. Umgebungsvariablen-Fallbacks).
|
||||
- Konfiguriert Consul Discovery und Actuator Endpunkte für Health-Checks.
|
||||
|
||||
## Verifizierung
|
||||
- **BootRun:** Der Service startet nun erfolgreich via `./gradlew :backend:services:billing:billing-service:bootRun`.
|
||||
- **Health Check:** Der Endpunkt `http://localhost:8087/actuator/health` liefert den Status `UP`.
|
||||
- **Consul:** Der Service registriert sich korrekt bei Consul (ID: `billing-service-8087`).
|
||||
- **Database:** Die Logs bestätigen: `Billing database schema initialized successfully`.
|
||||
|
||||
## Notizen
|
||||
- Die Konfiguration folgt dem Muster des `entries-service` und stellt sicher, dass der Service sowohl lokal als auch in Docker-Umgebungen stabil läuft.
|
||||
|
|
@ -0,0 +1,31 @@
|
|||
# Curator Log - 13.04.2026 - Identity Service Startup Fix
|
||||
|
||||
## Status
|
||||
- **Abteilung:** Backend / Infrastruktur
|
||||
- **Status:** ✅ Abgeschlossen
|
||||
- **Autor:** Junie (AI Agent)
|
||||
|
||||
## Problembeschreibung
|
||||
Der `identity-service` konnte nicht starten, da keine `application.yaml` vorhanden war. Dies führte zu:
|
||||
1. `Failed to configure a DataSource`: Da das Package `at.mocode.backend.infrastructure.persistence` gescannt wurde, versuchte Spring Boot eine DataSource zu konfigurieren, fand aber keine URL.
|
||||
2. `JwtDecoder bean not found`: Die globale Sicherheitskonfiguration (`GlobalSecurityConfig`) erforderte OAuth2-Einstellungen, die ebenfalls fehlten.
|
||||
3. Fehlender Actuator: Der Service hatte keine Abhängigkeit zum Actuator-Starter, was das Monitoring erschwerte.
|
||||
|
||||
## Durchgeführte Änderungen
|
||||
### Backend (Identity Service)
|
||||
- **Konfiguration:** `src/main/resources/application.yaml` erstellt.
|
||||
- Port auf `8088` festgelegt (nächster freier Port nach Billing `8087`).
|
||||
- PostgreSQL-Datenquelle konfiguriert.
|
||||
- Consul-Service-Discovery aktiviert.
|
||||
- OAuth2/JWT-Issuer und JWK-Set URIs für die Authentifizierung konfiguriert.
|
||||
- Actuator-Endpoints freigeschaltet.
|
||||
- **Build:** `spring-boot-starter-actuator` zur `build.gradle.kts` hinzugefügt.
|
||||
|
||||
## Verifizierung
|
||||
- **BootRun:** Der Service startet nun erfolgreich mit `./gradlew :backend:services:identity:identity-service:bootRun`.
|
||||
- **Health-Check:** Der Endpoint `http://localhost:8088/actuator/health` liefert `{"status":"UP"}`.
|
||||
- **Datenbank:** Flyway-Validierung und Hikari-Pool-Initialisierung erfolgreich durchgeführt.
|
||||
|
||||
## Nächste Schritte
|
||||
- Registrierung der neuen Identity-Routen im `api-gateway`.
|
||||
- Hinzufügen des `identity-service` zur `dc-backend.yaml` für den Docker-Betrieb.
|
||||
|
|
@ -0,0 +1,24 @@
|
|||
# Curator Log - 13.04.2026 - Results Service Startup Fix
|
||||
|
||||
## 🧐 Problem analysis
|
||||
The `results-service` failed to start due to a port conflict. It was configured to use port 8088, which is already assigned to the `identity-service`.
|
||||
|
||||
## 🛠️ Proposed changes
|
||||
- Change `results-service` port to 8084.
|
||||
- Enable `prefer-ip-address: true` for Consul discovery to ensure correct registration in Docker environments.
|
||||
- Ensure all services use unique ports in the 808x range.
|
||||
|
||||
## ✅ Verification results
|
||||
- Successfully started `results-service` on port 8084.
|
||||
- Verified "passing" health status in Consul for `results-service`.
|
||||
- Actuator health endpoint returns `UP`.
|
||||
|
||||
## 📝 Details
|
||||
- **Port Assignment:**
|
||||
- 8081: Gateway
|
||||
- 8082: Ping Service
|
||||
- 8083: Entries Service
|
||||
- 8084: Results Service (Fixed)
|
||||
- 8086: Masterdata Service
|
||||
- 8087: Billing Service
|
||||
- 8088: Identity Service
|
||||
|
|
@ -0,0 +1,40 @@
|
|||
# Curator Log - 13.04.2026 - Service Discovery & Health Fixes
|
||||
|
||||
## Status
|
||||
Behebung von Problemen bei der Consul-Registrierung und dem Health-Status mehrerer Backend-Services.
|
||||
|
||||
## Analyse & Maßnahmen
|
||||
|
||||
### 1. Identity Service (Registrierung & Health)
|
||||
* **Problem:** Der Service meldete sich nicht bei Consul an.
|
||||
* **Ursache:** Fehlende Abhängigkeit `spring-cloud-starter-consul-discovery` in der `build.gradle.kts` und unvollständige Konfiguration in der `application.yaml`.
|
||||
* **Lösung:**
|
||||
* Abhängigkeit hinzugefügt.
|
||||
* `spring.cloud.consul.discovery.prefer-ip-address: true` gesetzt.
|
||||
* Health-Check-Pfad explizit auf `/actuator/health` konfiguriert.
|
||||
* **Ergebnis:** Service registriert sich erfolgreich und ist "passing".
|
||||
|
||||
### 2. Entries Service (Health Status)
|
||||
* **Problem:** Service registriert, aber Health-Status "critical" (401 Unauthorized).
|
||||
* **Ursache:** Die `GlobalSecurityConfig` wurde nicht geladen, da das Package `at.mocode.infrastructure.security` nicht im `scanBasePackages` der `EntriesServiceApplication` enthalten war. Dadurch griff die Standard-Security von Spring Boot, die den Actuator-Endpunkt schützte.
|
||||
* **Lösung:**
|
||||
* `scanBasePackages` um das Security-Package erweitert.
|
||||
* `prefer-ip-address: true` in `application.yaml` ergänzt.
|
||||
* **Ergebnis:** Security-Regeln greifen nun (Actuator ist permitAll), Health-Status wird korrekt an Consul gemeldet.
|
||||
|
||||
### 3. Masterdata Service (Health Status)
|
||||
* **Problem:** Service registriert, aber Health-Status "critical" (404 Not Found).
|
||||
* **Ursache:** Der Service registrierte den Ktor-Port (8091) für den Health-Check, aber der Actuator-Endpunkt läuft auf dem Spring-Boot-Port (8086).
|
||||
* **Lösung:**
|
||||
* `spring.cloud.consul.discovery.health-check-port: 8086` explizit gesetzt.
|
||||
* **Ergebnis:** Consul fragt nun den korrekten Port für den Health-Status ab.
|
||||
|
||||
## Verifikation
|
||||
* Überprüfung via Consul-API (`/v1/health/service/{service-name}`) bestätigt für alle korrigierten Services den Status "passing".
|
||||
* Lokal gestartete Instanzen zeigen korrekte Log-Ausgaben für die Registrierung.
|
||||
|
||||
## Checkliste für neue Services
|
||||
* [ ] `spring-cloud-starter-consul-discovery` in `build.gradle.kts`.
|
||||
* [ ] `spring.cloud.consul.discovery.prefer-ip-address: true` in `application.yaml`.
|
||||
* [ ] `scanBasePackages` muss `at.mocode.infrastructure.security` enthalten, falls Actuator-Security benötigt wird.
|
||||
* [ ] Bei Multi-Port-Setups (Ktor + Spring) den `health-check-port` explizit angeben.
|
||||
Loading…
Reference in New Issue
Block a user