From 642713e14c6c31c052ffbe6ad7643226b161e0ca Mon Sep 17 00:00:00 2001 From: Jim Martens Date: Thu, 17 Aug 2023 00:02:45 +0200 Subject: [PATCH] Fixed rest health indicator --- .../monitoring/actuator/RestHealthIndicator.kt | 13 ++++++++----- 1 file changed, 8 insertions(+), 5 deletions(-) diff --git a/module-server/src/main/kotlin/de/twomartens/wahlrecht/monitoring/actuator/RestHealthIndicator.kt b/module-server/src/main/kotlin/de/twomartens/wahlrecht/monitoring/actuator/RestHealthIndicator.kt index bef5c5c..b2cedc8 100644 --- a/module-server/src/main/kotlin/de/twomartens/wahlrecht/monitoring/actuator/RestHealthIndicator.kt +++ b/module-server/src/main/kotlin/de/twomartens/wahlrecht/monitoring/actuator/RestHealthIndicator.kt @@ -1,6 +1,7 @@ package de.twomartens.wahlrecht.monitoring.actuator import de.twomartens.wahlrecht.interceptor.HeaderInterceptorRest +import de.twomartens.wahlrecht.property.ServiceProperties import org.springframework.boot.actuate.health.Health import org.springframework.boot.actuate.health.HealthIndicator import org.springframework.boot.actuate.health.Status @@ -28,8 +29,10 @@ import java.time.Clock */ @Component class RestHealthIndicator( - clock: Clock, interceptor: HeaderInterceptorRest, - serverProperties: ServerProperties, private val restTemplateRestHealthIndicator: RestTemplate + clock: Clock, interceptor: HeaderInterceptorRest, + serverProperties: ServerProperties, + private val restTemplateRestHealthIndicator: RestTemplate, + private val serviceProperties: ServiceProperties ) : AbstractHealthIndicator(clock, Preparable { interceptor.markAsHealthCheck() }), HealthIndicator { private val randomizer = SecureRandom() private val urlPrefix: String = (HTTP_PREFIX + HOST + HOST_PORT_SEPARATOR @@ -43,10 +46,10 @@ class RestHealthIndicator( val random = randomizer.nextInt(100000, 999999).toString() val url = "$urlPrefix{random}" val response = restTemplateRestHealthIndicator.getForEntity(url, String::class.java, random) - val status = if (response.body == random) Status.UP else Status.DOWN + val status = if (response.body == serviceProperties.greeting.format(random)) Status.UP else Status.DOWN return Health.status(status) - .withDetail(DETAIL_ENDPOINT_KEY, url) - .build() + .withDetail(DETAIL_ENDPOINT_KEY, url) + .build() } companion object {