-
Notifications
You must be signed in to change notification settings - Fork 0
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
La til tester for felles helsesjekk-lib
- Loading branch information
1 parent
34bc1e7
commit 86b8acb
Showing
10 changed files
with
383 additions
and
103 deletions.
There are no files selected for viewing
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
43 changes: 0 additions & 43 deletions
43
...error-handling/src/main/kotlin/no/nav/paw/health/listener/KafkaHealthIndicatorListener.kt
This file was deleted.
Oops, something went wrong.
59 changes: 59 additions & 0 deletions
59
lib/error-handling/src/main/kotlin/no/nav/paw/health/listener/KafkaStreamsStatusListener.kt
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,59 @@ | ||
package no.nav.paw.health.listener | ||
|
||
import no.nav.paw.health.model.LivenessHealthIndicator | ||
import no.nav.paw.health.model.ReadinessHealthIndicator | ||
import org.apache.kafka.streams.KafkaStreams | ||
import org.slf4j.LoggerFactory | ||
|
||
private val logger = LoggerFactory.getLogger("paw.application.health.kafka") | ||
|
||
fun KafkaStreams.withHealthIndicatorStateListener( | ||
livenessIndicator: LivenessHealthIndicator, | ||
readinessIndicator: ReadinessHealthIndicator | ||
) = KafkaStreams.StateListener { newState, previousState -> | ||
when (newState) { | ||
KafkaStreams.State.CREATED -> { | ||
readinessIndicator.setUnhealthy() | ||
livenessIndicator.setHealthy() | ||
} | ||
|
||
KafkaStreams.State.RUNNING -> { | ||
readinessIndicator.setHealthy() | ||
livenessIndicator.setHealthy() | ||
} | ||
|
||
KafkaStreams.State.REBALANCING -> { | ||
readinessIndicator.setHealthy() | ||
livenessIndicator.setHealthy() | ||
} | ||
|
||
KafkaStreams.State.PENDING_ERROR -> { | ||
readinessIndicator.setUnhealthy() | ||
livenessIndicator.setHealthy() | ||
} | ||
|
||
KafkaStreams.State.ERROR -> { | ||
readinessIndicator.setUnhealthy() | ||
livenessIndicator.setUnhealthy() | ||
} | ||
|
||
KafkaStreams.State.PENDING_SHUTDOWN -> { | ||
readinessIndicator.setUnhealthy() | ||
livenessIndicator.setUnhealthy() | ||
} | ||
|
||
KafkaStreams.State.NOT_RUNNING -> { | ||
readinessIndicator.setUnhealthy() | ||
livenessIndicator.setUnhealthy() | ||
} | ||
|
||
else -> { | ||
readinessIndicator.setUnknown() | ||
livenessIndicator.setUnknown() | ||
} | ||
} | ||
|
||
logger.debug("Kafka Streams state endret seg ${previousState.name} -> ${newState.name}") | ||
logger.info("Kafka Streams liveness er ${livenessIndicator.getStatus().value}") | ||
logger.info("Kafka Streams readiness er ${readinessIndicator.getStatus().value}") | ||
} |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
29 changes: 29 additions & 0 deletions
29
lib/error-handling/src/main/kotlin/no/nav/paw/health/repository/HealthIndicatorRepository.kt
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,29 @@ | ||
package no.nav.paw.health.repository | ||
|
||
import no.nav.paw.health.model.HealthIndicatorList | ||
import no.nav.paw.health.model.LivenessHealthIndicator | ||
import no.nav.paw.health.model.ReadinessHealthIndicator | ||
|
||
class HealthIndicatorRepository { | ||
|
||
private val readinessIndicators: HealthIndicatorList = mutableListOf() | ||
private val livenessIndicators: HealthIndicatorList = mutableListOf() | ||
|
||
fun addReadinessIndicator(healthIndicator: ReadinessHealthIndicator): ReadinessHealthIndicator { | ||
readinessIndicators.add(healthIndicator) | ||
return healthIndicator | ||
} | ||
|
||
fun addLivenessIndicator(healthIndicator: LivenessHealthIndicator): LivenessHealthIndicator { | ||
livenessIndicators.add(healthIndicator) | ||
return healthIndicator | ||
} | ||
|
||
fun getReadinessIndicators(): HealthIndicatorList { | ||
return readinessIndicators | ||
} | ||
|
||
fun getLivenessIndicators(): HealthIndicatorList { | ||
return livenessIndicators | ||
} | ||
} |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
43 changes: 0 additions & 43 deletions
43
lib/error-handling/src/main/kotlin/no/nav/paw/health/service/HealthIndicatorService.kt
This file was deleted.
Oops, something went wrong.
62 changes: 62 additions & 0 deletions
62
...ror-handling/src/test/kotlin/no/nav/paw/health/listener/KafkaStreamsStatusListenerTest.kt
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,62 @@ | ||
package no.nav.paw.health.listener | ||
|
||
import io.kotest.core.spec.style.FreeSpec | ||
import io.kotest.matchers.shouldBe | ||
import io.mockk.mockkClass | ||
import no.nav.paw.health.model.HealthStatus | ||
import no.nav.paw.health.model.LivenessHealthIndicator | ||
import no.nav.paw.health.model.ReadinessHealthIndicator | ||
import no.nav.paw.health.model.getAggregatedStatus | ||
import no.nav.paw.health.repository.HealthIndicatorRepository | ||
import org.apache.kafka.streams.KafkaStreams | ||
|
||
class KafkaStreamsStatusListenerTest : FreeSpec({ | ||
|
||
"Kafka Streams Status Listener skal returnere korrekt helsesjekk-status" { | ||
val kafkaStreams = mockkClass(KafkaStreams::class) | ||
val healthIndicatorRepository = HealthIndicatorRepository() | ||
|
||
val liveness = healthIndicatorRepository.addLivenessIndicator(LivenessHealthIndicator()) | ||
val readiness = healthIndicatorRepository.addReadinessIndicator(ReadinessHealthIndicator()) | ||
|
||
val listener = kafkaStreams.withHealthIndicatorStateListener(liveness, readiness) | ||
|
||
healthIndicatorRepository.getReadinessIndicators().getAggregatedStatus() shouldBe HealthStatus.UNKNOWN | ||
healthIndicatorRepository.getLivenessIndicators().getAggregatedStatus() shouldBe HealthStatus.HEALTHY | ||
|
||
listener.onChange(KafkaStreams.State.CREATED, KafkaStreams.State.CREATED) | ||
|
||
healthIndicatorRepository.getReadinessIndicators().getAggregatedStatus() shouldBe HealthStatus.UNHEALTHY | ||
healthIndicatorRepository.getLivenessIndicators().getAggregatedStatus() shouldBe HealthStatus.HEALTHY | ||
|
||
listener.onChange(KafkaStreams.State.RUNNING, KafkaStreams.State.RUNNING) | ||
|
||
healthIndicatorRepository.getReadinessIndicators().getAggregatedStatus() shouldBe HealthStatus.HEALTHY | ||
healthIndicatorRepository.getLivenessIndicators().getAggregatedStatus() shouldBe HealthStatus.HEALTHY | ||
|
||
listener.onChange(KafkaStreams.State.REBALANCING, KafkaStreams.State.REBALANCING) | ||
|
||
healthIndicatorRepository.getReadinessIndicators().getAggregatedStatus() shouldBe HealthStatus.HEALTHY | ||
healthIndicatorRepository.getLivenessIndicators().getAggregatedStatus() shouldBe HealthStatus.HEALTHY | ||
|
||
listener.onChange(KafkaStreams.State.PENDING_ERROR, KafkaStreams.State.PENDING_ERROR) | ||
|
||
healthIndicatorRepository.getReadinessIndicators().getAggregatedStatus() shouldBe HealthStatus.UNHEALTHY | ||
healthIndicatorRepository.getLivenessIndicators().getAggregatedStatus() shouldBe HealthStatus.HEALTHY | ||
|
||
listener.onChange(KafkaStreams.State.ERROR, KafkaStreams.State.ERROR) | ||
|
||
healthIndicatorRepository.getReadinessIndicators().getAggregatedStatus() shouldBe HealthStatus.UNHEALTHY | ||
healthIndicatorRepository.getLivenessIndicators().getAggregatedStatus() shouldBe HealthStatus.UNHEALTHY | ||
|
||
listener.onChange(KafkaStreams.State.PENDING_SHUTDOWN, KafkaStreams.State.PENDING_SHUTDOWN) | ||
|
||
healthIndicatorRepository.getReadinessIndicators().getAggregatedStatus() shouldBe HealthStatus.UNHEALTHY | ||
healthIndicatorRepository.getLivenessIndicators().getAggregatedStatus() shouldBe HealthStatus.UNHEALTHY | ||
|
||
listener.onChange(KafkaStreams.State.NOT_RUNNING, KafkaStreams.State.NOT_RUNNING) | ||
|
||
healthIndicatorRepository.getReadinessIndicators().getAggregatedStatus() shouldBe HealthStatus.UNHEALTHY | ||
healthIndicatorRepository.getLivenessIndicators().getAggregatedStatus() shouldBe HealthStatus.UNHEALTHY | ||
} | ||
}) |
Oops, something went wrong.