From f41ee1e57712ed656674a0381a2101a4b1eb0b10 Mon Sep 17 00:00:00 2001 From: a10zn8 Date: Tue, 21 Mar 2023 16:58:08 +0300 Subject: [PATCH] health endpoint should check available for requests endpoint (#180) --- .../dshackle/monitoring/HealthCheckSetup.kt | 7 +++--- .../monitoring/HealthCheckSetupSpec.groovy | 22 +++++++++---------- 2 files changed, 14 insertions(+), 15 deletions(-) diff --git a/src/main/kotlin/io/emeraldpay/dshackle/monitoring/HealthCheckSetup.kt b/src/main/kotlin/io/emeraldpay/dshackle/monitoring/HealthCheckSetup.kt index 6c9b8a89..da8b98e3 100644 --- a/src/main/kotlin/io/emeraldpay/dshackle/monitoring/HealthCheckSetup.kt +++ b/src/main/kotlin/io/emeraldpay/dshackle/monitoring/HealthCheckSetup.kt @@ -18,7 +18,6 @@ package io.emeraldpay.dshackle.monitoring import com.sun.net.httpserver.HttpServer import io.emeraldpay.dshackle.config.HealthConfig import io.emeraldpay.dshackle.upstream.MultistreamHolder -import io.emeraldpay.dshackle.upstream.UpstreamAvailability import org.slf4j.LoggerFactory import org.springframework.beans.factory.annotation.Autowired import org.springframework.http.HttpStatus @@ -83,9 +82,9 @@ class HealthCheckSetup( if (!up.isAvailable()) { return@mapNotNull "${it.blockchain} UNAVAILABLE" } - val avail = up.getAll().count { it.getStatus() == UpstreamAvailability.OK } + val avail = up.getAll().count { it.isAvailable() } if (avail < it.minAvailable) { - return@mapNotNull "${it.blockchain} LACKS MIN AVAILABILITY" + return@mapNotNull "${it.blockchain} LACKS MIN AVAILABILITY [CURRENT: $avail]" } null } @@ -112,7 +111,7 @@ class HealthCheckSetup( } else { val ups = up.getAll() val checks = if (required != null) { - val avail = ups.count { it.getStatus() == UpstreamAvailability.OK } + val avail = ups.count { it.isAvailable() } if (avail < required.minAvailable) { chainUnavailable = true listOf(" LACKS MIN AVAILABILITY") diff --git a/src/test/groovy/io/emeraldpay/dshackle/monitoring/HealthCheckSetupSpec.groovy b/src/test/groovy/io/emeraldpay/dshackle/monitoring/HealthCheckSetupSpec.groovy index 9ab5ae6a..fee2c39c 100644 --- a/src/test/groovy/io/emeraldpay/dshackle/monitoring/HealthCheckSetupSpec.groovy +++ b/src/test/groovy/io/emeraldpay/dshackle/monitoring/HealthCheckSetupSpec.groovy @@ -46,7 +46,7 @@ class HealthCheckSetupSpec extends Specification { 1 * multistream.getUpstream(Chain.ETHEREUM) >> ethereumUpstreams 1 * ethereumUpstreams.available >> true 1 * ethereumUpstreams.getAll() >> [up1] - 1 * up1.status >> UpstreamAvailability.OK + 1 * up1.isAvailable() >> true } def "OK when meets availability - 1 - bitcoin"() { @@ -70,7 +70,7 @@ class HealthCheckSetupSpec extends Specification { 1 * multistream.getUpstream(Chain.BITCOIN) >> bitcoinUpstreams 1 * bitcoinUpstreams.available >> true 1 * bitcoinUpstreams.getAll() >> [up1] - 1 * up1.status >> UpstreamAvailability.OK + 1 * up1.isAvailable() >> true } def "OK when meets availability - 2/3"() { @@ -96,9 +96,9 @@ class HealthCheckSetupSpec extends Specification { 1 * multistream.getUpstream(Chain.ETHEREUM) >> ethereumUpstreams 1 * ethereumUpstreams.available >> true 1 * ethereumUpstreams.getAll() >> [up1, up2, up3] - 1 * up1.status >> UpstreamAvailability.OK - 1 * up2.status >> UpstreamAvailability.SYNCING - 1 * up3.status >> UpstreamAvailability.OK + 1 * up1.isAvailable() >> true + 1 * up2.isAvailable() >> false + 1 * up3.isAvailable() >> true } def "OK when doesn't meet availability - 2/3"() { @@ -124,9 +124,9 @@ class HealthCheckSetupSpec extends Specification { 1 * multistream.getUpstream(Chain.ETHEREUM) >> ethereumUpstreams 1 * ethereumUpstreams.available >> true 1 * ethereumUpstreams.getAll() >> [up1, up2, up3] - 1 * up1.status >> UpstreamAvailability.OK - 1 * up2.status >> UpstreamAvailability.SYNCING - 1 * up3.status >> UpstreamAvailability.LAGGING + 1 * up1.isAvailable() >> true + 1 * up2.isAvailable() >> false + 1 * up3.isAvailable() >> false } def "OK when meets availability - 2/3 - detailed"() { @@ -153,8 +153,8 @@ class HealthCheckSetupSpec extends Specification { 1 * multistream.getUpstream(Chain.ETHEREUM) >> ethereumUpstreams 1 * ethereumUpstreams.available >> true 1 * ethereumUpstreams.getAll() >> [up1, up2, up3] - _ * up1.status >> UpstreamAvailability.OK - _ * up2.status >> UpstreamAvailability.SYNCING - _ * up3.status >> UpstreamAvailability.OK + _ * up1.isAvailable() >> true + _ * up2.isAvailable() >> false + _ * up3.isAvailable() >> true } }