Skip to content

Commit 7a7e845

Browse files
committed
Fix #30477: improve instance obsolete check
1 parent 04bd3fe commit 7a7e845

2 files changed

Lines changed: 25 additions & 12 deletions

File tree

src/main/kotlin/eu/openanalytics/shinyproxyoperator/controller/IRecyclableChecker.kt

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -25,6 +25,6 @@ import eu.openanalytics.shinyproxyoperator.crd.ShinyProxyInstance
2525

2626
interface IRecyclableChecker {
2727

28-
fun isInstanceRecyclable(shinyProxy: ShinyProxy, shinyProxyInstance: ShinyProxyInstance): Boolean
28+
suspend fun isInstanceRecyclable(shinyProxy: ShinyProxy, shinyProxyInstance: ShinyProxyInstance): Boolean
2929

3030
}

src/main/kotlin/eu/openanalytics/shinyproxyoperator/controller/RecyclableChecker.kt

Lines changed: 24 additions & 11 deletions
Original file line numberDiff line numberDiff line change
@@ -25,6 +25,7 @@ import com.fasterxml.jackson.databind.ObjectMapper
2525
import com.fasterxml.jackson.module.kotlin.registerKotlinModule
2626
import eu.openanalytics.shinyproxyoperator.crd.ShinyProxy
2727
import eu.openanalytics.shinyproxyoperator.crd.ShinyProxyInstance
28+
import kotlinx.coroutines.delay
2829
import mu.KotlinLogging
2930
import okhttp3.OkHttpClient
3031
import okhttp3.Request
@@ -46,21 +47,33 @@ class RecyclableChecker(
4647

4748
data class Response(@JsonProperty("isRecyclable") val isRecyclable: Boolean, @JsonProperty("activeConnections") val activeConnections: Int)
4849

49-
override fun isInstanceRecyclable(shinyProxy: ShinyProxy, shinyProxyInstance: ShinyProxyInstance): Boolean {
50+
override suspend fun isInstanceRecyclable(shinyProxy: ShinyProxy, shinyProxyInstance: ShinyProxyInstance): Boolean {
5051
val pods = podRetriever.getShinyProxyPods(shinyProxy, shinyProxyInstance)
5152

5253
for (pod in pods) {
5354
for (i in 1..5) {
54-
val resp = checkServer(pod.status.podIP)
55-
if (resp == null) {
56-
// no response received, try to check again
57-
logger.warn { "${shinyProxy.logPrefix(shinyProxyInstance)} unreachable for recyclable check (using ${pod.status.podIP})" }
58-
Thread.sleep(500)
59-
continue
60-
}
61-
if (!resp.isRecyclable) {
62-
logger.info { "${shinyProxy.logPrefix(shinyProxyInstance)} Replica is not recyclable." }
63-
return false
55+
try {
56+
val podIP: String? = pod.status.podIP
57+
if (podIP == null) {
58+
// no response received, try to check again
59+
logger.warn { "${shinyProxy.logPrefix(shinyProxyInstance)} no ip found during recyclable check" }
60+
delay(500)
61+
continue
62+
}
63+
val resp = checkServer(pod.status.podIP)
64+
if (resp == null) {
65+
// no response received, try to check again
66+
logger.warn { "${shinyProxy.logPrefix(shinyProxyInstance)} unreachable for recyclable check (using ${pod.status.podIP})" }
67+
delay(500)
68+
continue
69+
}
70+
if (!resp.isRecyclable) {
71+
logger.info { "${shinyProxy.logPrefix(shinyProxyInstance)} Replica is not recyclable." }
72+
return false
73+
}
74+
} catch (e: Throwable) {
75+
logger.warn(e) { "${shinyProxy.logPrefix(shinyProxyInstance)} exception during recyclable check" }
76+
delay(500)
6477
}
6578
}
6679
}

0 commit comments

Comments
 (0)