forked from quarkusio/quarkus
-
Notifications
You must be signed in to change notification settings - Fork 1
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
feat (quarkusio#7788) Add knative autoscaling properties
- Loading branch information
Showing
17 changed files
with
462 additions
and
1 deletion.
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
15 changes: 15 additions & 0 deletions
15
...es/vanilla/deployment/src/main/java/io/quarkus/kubernetes/deployment/AutoScalerClass.java
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,15 @@ | ||
|
||
package io.quarkus.kubernetes.deployment; | ||
|
||
public enum AutoScalerClass { | ||
|
||
/** | ||
* Kubernetes Pod Autoscaler | ||
**/ | ||
kpa, | ||
|
||
/** | ||
* Horizontal Pod Autoscaler | ||
**/ | ||
hpa | ||
} |
14 changes: 14 additions & 0 deletions
14
...a/deployment/src/main/java/io/quarkus/kubernetes/deployment/AutoScalerClassConverter.java
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,14 @@ | ||
package io.quarkus.kubernetes.deployment; | ||
|
||
public class AutoScalerClassConverter { | ||
|
||
public static io.dekorate.knative.config.AutoScalerClass convert(AutoScalerClass clazz) { | ||
if (clazz == AutoScalerClass.hpa) { | ||
return io.dekorate.knative.config.AutoScalerClass.hpa; | ||
} else if (clazz == AutoScalerClass.kpa) { | ||
return io.dekorate.knative.config.AutoScalerClass.kpa; | ||
} else { | ||
throw new IllegalStateException("Failed to map autoscaler class: " + clazz + "!"); | ||
} | ||
} | ||
} |
49 changes: 49 additions & 0 deletions
49
.../vanilla/deployment/src/main/java/io/quarkus/kubernetes/deployment/AutoScalingConfig.java
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,49 @@ | ||
|
||
package io.quarkus.kubernetes.deployment; | ||
|
||
import java.util.Optional; | ||
|
||
import io.quarkus.runtime.annotations.ConfigGroup; | ||
|
||
@ConfigGroup | ||
public class AutoScalingConfig { | ||
|
||
/** | ||
* The Autoscaler class. | ||
* Knative Serving comes with its own autoscaler, the KPA (Knative Pod Autoscaler) but can also be configured to use | ||
* Kubernetes’ HPA (Horizontal Pod Autoscaler) or even a custom third-party autoscaler. | ||
* Possible values (kpa, hpa, default: kpa). | ||
* | ||
* @return The autoscaler class. | ||
*/ | ||
|
||
Optional<AutoScalerClass> autoScalerClass; | ||
|
||
/** | ||
* The autoscaling metric to use. | ||
* Possible values (concurency, rps, cpu). | ||
* | ||
* @return The cpu metric or NONE if no metric has been selected. | ||
*/ | ||
Optional<AutoScalingMetric> metric; | ||
|
||
/** | ||
* The autoscaling target. | ||
* | ||
* @reutrn the selected target or zero if no target is selected. | ||
*/ | ||
Optional<Integer> target; | ||
|
||
/** | ||
* The exact amount of requests allowed to the replica at a time. | ||
* Its default value is “0”, which means an unlimited number of requests are allowed to flow into the replica. | ||
* | ||
* @return the container concurrenct or zero if its not bound. | ||
*/ | ||
Optional<Integer> containerConcurrency; | ||
|
||
/** | ||
* This value specifies a percentage of the target to actually be targeted by the autoscaler. | ||
*/ | ||
Optional<Integer> targetUtilizationPercentage; | ||
} |
19 changes: 19 additions & 0 deletions
19
.../vanilla/deployment/src/main/java/io/quarkus/kubernetes/deployment/AutoScalingMetric.java
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,19 @@ | ||
|
||
package io.quarkus.kubernetes.deployment; | ||
|
||
public enum AutoScalingMetric { | ||
/** | ||
* Concurrency | ||
*/ | ||
concurrency, | ||
|
||
/** | ||
* Requests per second | ||
**/ | ||
rps, | ||
|
||
/** | ||
* CPU | ||
**/ | ||
cpu; | ||
} |
16 changes: 16 additions & 0 deletions
16
...deployment/src/main/java/io/quarkus/kubernetes/deployment/AutoScalingMetricConverter.java
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,16 @@ | ||
package io.quarkus.kubernetes.deployment; | ||
|
||
public class AutoScalingMetricConverter { | ||
|
||
public static io.dekorate.knative.config.AutoscalingMetric convert(AutoScalingMetric metric) { | ||
if (metric == AutoScalingMetric.concurrency) { | ||
return io.dekorate.knative.config.AutoscalingMetric.concurrency; | ||
} else if (metric == AutoScalingMetric.rps) { | ||
return io.dekorate.knative.config.AutoscalingMetric.rps; | ||
} else if (metric == AutoScalingMetric.cpu) { | ||
return io.dekorate.knative.config.AutoscalingMetric.cpu; | ||
} else { | ||
throw new IllegalStateException("Failed to map autoscaling metric: " + metric + "!"); | ||
} | ||
} | ||
} |
38 changes: 38 additions & 0 deletions
38
...la/deployment/src/main/java/io/quarkus/kubernetes/deployment/GlobalAutoScalingConfig.java
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,38 @@ | ||
package io.quarkus.kubernetes.deployment; | ||
|
||
import java.util.Optional; | ||
|
||
import io.quarkus.runtime.annotations.ConfigGroup; | ||
|
||
@ConfigGroup | ||
public class GlobalAutoScalingConfig { | ||
|
||
/** | ||
* The Autoscaler class. | ||
* Knative Serving comes with its own autoscaler, the KPA (Knative Pod Autoscaler) but can also be configured to use | ||
* Kubernetes’ HPA (Horizontal Pod Autoscaler) or even a custom third-party autoscaler. | ||
* Possible values (kpa, hpa, default: kpa). | ||
* | ||
* @return The autoscaler class. | ||
*/ | ||
Optional<AutoScalerClass> autoScalerClass; | ||
|
||
/** | ||
* The exact amount of requests allowed to the replica at a time. | ||
* Its default value is “0”, which means an unlimited number of requests are allowed to flow Integer>o the replica. | ||
* | ||
* @return the container concurrenct or zero if its not bound. | ||
*/ | ||
Optional<Integer> containerConcurrency; | ||
|
||
/** | ||
* This value specifies a percentage of the target to actually be targeted by the autoscaler. | ||
*/ | ||
Optional<Integer> targetUtilizationPercentage; | ||
|
||
/** | ||
* The requests per second per replica. | ||
*/ | ||
Optional<Integer> requestsPerSecond; | ||
|
||
} |
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
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
51 changes: 51 additions & 0 deletions
51
...tandard-way/src/test/java/io/quarkus/it/kubernetes/KnativeGlobalContainerConcurrency.java
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,51 @@ | ||
package io.quarkus.it.kubernetes; | ||
|
||
import static org.assertj.core.api.Assertions.assertThat; | ||
import static org.assertj.core.api.Assertions.entry; | ||
|
||
import java.io.IOException; | ||
import java.nio.file.Path; | ||
import java.util.List; | ||
|
||
import org.jboss.shrinkwrap.api.ShrinkWrap; | ||
import org.jboss.shrinkwrap.api.spec.JavaArchive; | ||
import org.junit.jupiter.api.Test; | ||
import org.junit.jupiter.api.extension.RegisterExtension; | ||
|
||
import io.fabric8.kubernetes.api.model.ConfigMap; | ||
import io.fabric8.kubernetes.api.model.HasMetadata; | ||
import io.quarkus.test.ProdBuildResults; | ||
import io.quarkus.test.ProdModeTestResults; | ||
import io.quarkus.test.QuarkusProdModeTest; | ||
|
||
public class KnativeGlobalContainerConcurrency { | ||
|
||
@RegisterExtension | ||
static final QuarkusProdModeTest config = new QuarkusProdModeTest() | ||
.setArchiveProducer(() -> ShrinkWrap.create(JavaArchive.class).addClasses(GreetingResource.class)) | ||
.setApplicationName("knative-global-container-concurrency") | ||
.setApplicationVersion("0.1-SNAPSHOT") | ||
.withConfigurationResource("knative-global-container-concurrency.properties"); | ||
|
||
@ProdBuildResults | ||
private ProdModeTestResults prodModeTestResults; | ||
|
||
@Test | ||
public void assertGeneratedResources() throws IOException { | ||
Path kubernetesDir = prodModeTestResults.getBuildDir().resolve("kubernetes"); | ||
assertThat(kubernetesDir) | ||
.isDirectoryContaining(p -> p.getFileName().endsWith("knative.json")) | ||
.isDirectoryContaining(p -> p.getFileName().endsWith("knative.yml")) | ||
.satisfies(p -> assertThat(p.toFile().listFiles()).hasSize(2)); | ||
|
||
List<HasMetadata> kubernetesList = DeserializationUtil | ||
.deserializeAsList(kubernetesDir.resolve("knative.yml")); | ||
|
||
assertThat(kubernetesList).filteredOn(i -> "ConfigMap".equals(i.getKind())).hasOnlyOneElementSatisfying(c -> { | ||
assertThat(c.getMetadata()).satisfies(m -> assertThat(m.getName()).isEqualTo("config-autoscaler")); | ||
assertThat(c).isInstanceOfSatisfying(ConfigMap.class, m -> { | ||
assertThat(m.getData()).contains(entry("container-concurrency", "100")); | ||
}); | ||
}); | ||
} | ||
} |
51 changes: 51 additions & 0 deletions
51
...s-standard-way/src/test/java/io/quarkus/it/kubernetes/KnativeGlobalRequestsPerSecond.java
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,51 @@ | ||
package io.quarkus.it.kubernetes; | ||
|
||
import static org.assertj.core.api.Assertions.assertThat; | ||
import static org.assertj.core.api.Assertions.entry; | ||
|
||
import java.io.IOException; | ||
import java.nio.file.Path; | ||
import java.util.List; | ||
|
||
import org.jboss.shrinkwrap.api.ShrinkWrap; | ||
import org.jboss.shrinkwrap.api.spec.JavaArchive; | ||
import org.junit.jupiter.api.Test; | ||
import org.junit.jupiter.api.extension.RegisterExtension; | ||
|
||
import io.fabric8.kubernetes.api.model.ConfigMap; | ||
import io.fabric8.kubernetes.api.model.HasMetadata; | ||
import io.quarkus.test.ProdBuildResults; | ||
import io.quarkus.test.ProdModeTestResults; | ||
import io.quarkus.test.QuarkusProdModeTest; | ||
|
||
public class KnativeGlobalRequestsPerSecond { | ||
|
||
@RegisterExtension | ||
static final QuarkusProdModeTest config = new QuarkusProdModeTest() | ||
.setArchiveProducer(() -> ShrinkWrap.create(JavaArchive.class).addClasses(GreetingResource.class)) | ||
.setApplicationName("knative-global-requests-per-second") | ||
.setApplicationVersion("0.1-SNAPSHOT") | ||
.withConfigurationResource("knative-global-requests-per-second.properties"); | ||
|
||
@ProdBuildResults | ||
private ProdModeTestResults prodModeTestResults; | ||
|
||
@Test | ||
public void assertGeneratedResources() throws IOException { | ||
Path kubernetesDir = prodModeTestResults.getBuildDir().resolve("kubernetes"); | ||
assertThat(kubernetesDir) | ||
.isDirectoryContaining(p -> p.getFileName().endsWith("knative.json")) | ||
.isDirectoryContaining(p -> p.getFileName().endsWith("knative.yml")) | ||
.satisfies(p -> assertThat(p.toFile().listFiles()).hasSize(2)); | ||
|
||
List<HasMetadata> kubernetesList = DeserializationUtil | ||
.deserializeAsList(kubernetesDir.resolve("knative.yml")); | ||
|
||
assertThat(kubernetesList).filteredOn(i -> "ConfigMap".equals(i.getKind())).hasOnlyOneElementSatisfying(c -> { | ||
assertThat(c.getMetadata()).satisfies(m -> assertThat(m.getName()).isEqualTo("config-autoscaler")); | ||
assertThat(c).isInstanceOfSatisfying(ConfigMap.class, m -> { | ||
assertThat(m.getData()).contains(entry("requests-per-second-target-default", "150")); | ||
}); | ||
}); | ||
} | ||
} |
Oops, something went wrong.