style: format code for improved readability and consistency
Build & Test (NowChessSystems) TeamCity build failed
Build & Test (NowChessSystems) TeamCity build failed
This commit is contained in:
+12
-8
@@ -45,8 +45,8 @@ class AutoScaler:
|
|||||||
if kubeClientInstance.isUnsatisfied then None
|
if kubeClientInstance.isUnsatisfied then None
|
||||||
else Some(kubeClientInstance.get())
|
else Some(kubeClientInstance.get())
|
||||||
|
|
||||||
private val argoApiVersion = "argoproj.io/v1alpha1"
|
private val argoApiVersion = "argoproj.io/v1alpha1"
|
||||||
private val argoKind = "Rollout"
|
private val argoKind = "Rollout"
|
||||||
private val metricsApiVersion = "metrics.k8s.io/v1beta1"
|
private val metricsApiVersion = "metrics.k8s.io/v1beta1"
|
||||||
|
|
||||||
@PostConstruct
|
@PostConstruct
|
||||||
@@ -75,10 +75,12 @@ class AutoScaler:
|
|||||||
private def isResourceConstrained(instanceId: String): Boolean =
|
private def isResourceConstrained(instanceId: String): Boolean =
|
||||||
kubeClientOpt.fold(false) { kube =>
|
kubeClientOpt.fold(false) { kube =>
|
||||||
try
|
try
|
||||||
val pods = kube.pods().inNamespace(config.k8sNamespace).withLabel(config.k8sRolloutLabelSelector).list().getItems.asScala
|
val pods =
|
||||||
|
kube.pods().inNamespace(config.k8sNamespace).withLabel(config.k8sRolloutLabelSelector).list().getItems.asScala
|
||||||
pods.find(_.getMetadata.getName.contains(instanceId)).exists { pod =>
|
pods.find(_.getMetadata.getName.contains(instanceId)).exists { pod =>
|
||||||
try
|
try
|
||||||
val metricsRes = kube.genericKubernetesResources(metricsApiVersion, "PodMetrics")
|
val metricsRes = kube
|
||||||
|
.genericKubernetesResources(metricsApiVersion, "PodMetrics")
|
||||||
.inNamespace(config.k8sNamespace)
|
.inNamespace(config.k8sNamespace)
|
||||||
.withName(pod.getMetadata.getName)
|
.withName(pod.getMetadata.getName)
|
||||||
.get()
|
.get()
|
||||||
@@ -92,11 +94,12 @@ class AutoScaler:
|
|||||||
.flatMap(u => Option(u.get("cpu")))
|
.flatMap(u => Option(u.get("cpu")))
|
||||||
.map(_.toString)
|
.map(_.toString)
|
||||||
.exists { cpuStr =>
|
.exists { cpuStr =>
|
||||||
val cpuMillis = if cpuStr.endsWith("m") then cpuStr.dropRight(1).toLongOption.getOrElse(0L) else cpuStr.toLongOption.map(_ * 1000).getOrElse(0L)
|
val cpuMillis =
|
||||||
|
if cpuStr.endsWith("m") then cpuStr.dropRight(1).toLongOption.getOrElse(0L)
|
||||||
|
else cpuStr.toLongOption.map(_ * 1000).getOrElse(0L)
|
||||||
cpuMillis > 800
|
cpuMillis > 800
|
||||||
}
|
}
|
||||||
catch
|
catch case _: Exception => false
|
||||||
case _: Exception => false
|
|
||||||
}
|
}
|
||||||
catch
|
catch
|
||||||
case ex: Exception =>
|
case ex: Exception =>
|
||||||
@@ -117,7 +120,8 @@ class AutoScaler:
|
|||||||
val hasHighCpuOrMemory = instances.exists(inst => isResourceConstrained(inst.instanceId))
|
val hasHighCpuOrMemory = instances.exists(inst => isResourceConstrained(inst.instanceId))
|
||||||
|
|
||||||
if avgLoad > config.scaleUpThreshold * config.maxGamesPerCore || hasHighCpuOrMemory then scaleUp()
|
if avgLoad > config.scaleUpThreshold * config.maxGamesPerCore || hasHighCpuOrMemory then scaleUp()
|
||||||
else if avgLoad < config.scaleDownThreshold * config.maxGamesPerCore && instances.size > config.scaleMinReplicas then scaleDown()
|
else if avgLoad < config.scaleDownThreshold * config.maxGamesPerCore && instances.size > config.scaleMinReplicas
|
||||||
|
then scaleDown()
|
||||||
|
|
||||||
def scaleUp(): Unit =
|
def scaleUp(): Unit =
|
||||||
log.info("Scaling up Argo Rollout")
|
log.info("Scaling up Argo Rollout")
|
||||||
|
|||||||
Reference in New Issue
Block a user