feat(gce): add support for the predictive autoscaler
MODIFY
clouddriver-google/src/main/groovy/com/netflix/spinnaker/clouddriver/google/deploy/GCEUtil.groovy
clouddriver-google/src/main/groovy/com/netflix/spinnaker/clouddriver/google/deploy/GCEUtil.groovy
@@ -840,7 +840,8 @@ class GCEUtil {
if (cpuUtilization) {
gceAutoscalingPolicy.cpuUtilization =
- new AutoscalingPolicyCpuUtilization(utilizationTarget: cpuUtilization.utilizationTarget)
+ new AutoscalingPolicyCpuUtilization(utilizationTarget: cpuUtilization.utilizationTarget,
+ predictiveMethod: cpuUtilization.predictiveMethod)
}
if (loadBalancingUtilization) {

MODIFY
clouddriver-google/src/main/groovy/com/netflix/spinnaker/clouddriver/google/model/GoogleAutoscalingPolicy.groovy
clouddriver-google/src/main/groovy/com/netflix/spinnaker/clouddriver/google/model/GoogleAutoscalingPolicy.groovy
@@ -39,6 +39,12 @@ class GoogleAutoscalingPolicy {
@ToString(includeNames = true)
static class CpuUtilization {
Double utilizationTarget
+ PredictiveMethod predictiveMethod
+
+ enum PredictiveMethod {
+ NONE,
+ STANDARD
+ }
}
@ToString(includeNames = true)

MODIFY
clouddriver-google/src/main/groovy/com/netflix/spinnaker/clouddriver/google/provider/agent/AbstractGoogleServerGroupCachingAgent.java
clouddriver-google/src/main/groovy/com/netflix/spinnaker/clouddriver/google/provider/agent/AbstractGoogleServerGroupCachingAgent.java
@@ -83,6 +83,7 @@ import com.netflix.spinnaker.clouddriver.google.compute.Instances;
import com.netflix.spinnaker.clouddriver.google.model.GoogleAutoscalingPolicy;
import com.netflix.spinnaker.clouddriver.google.model.GoogleAutoscalingPolicy.AutoscalingMode;
import com.netflix.spinnaker.clouddriver.google.model.GoogleAutoscalingPolicy.CpuUtilization;
+import com.netflix.spinnaker.clouddriver.google.model.GoogleAutoscalingPolicy.CpuUtilization.PredictiveMethod;
import com.netflix.spinnaker.clouddriver.google.model.GoogleAutoscalingPolicy.CustomMetricUtilization;
import com.netflix.spinnaker.clouddriver.google.model.GoogleAutoscalingPolicy.CustomMetricUtilization.UtilizationTargetType;
import com.netflix.spinnaker.clouddriver.google.model.GoogleAutoscalingPolicy.FixedOrPercent;
@@ -942,6 +943,7 @@ abstract class AbstractGoogleServerGroupCachingAgent
}
CpuUtilization output = new CpuUtilization();
output.setUtilizationTarget(input.getUtilizationTarget());
+ output.setPredictiveMethod(valueOf(PredictiveMethod.class, input.getPredictiveMethod()));
return output;
}

MODIFY
clouddriver-google/src/test/groovy/com/netflix/spinnaker/clouddriver/google/provider/agent/AbstractGoogleServerGroupCachingAgentTest.java
clouddriver-google/src/test/groovy/com/netflix/spinnaker/clouddriver/google/provider/agent/AbstractGoogleServerGroupCachingAgentTest.java
@@ -725,7 +725,10 @@ class AbstractGoogleServerGroupCachingAgentTest {
AutoscalingPolicy input =
new AutoscalingPolicy()
.setCoolDownPeriodSec(123)
- .setCpuUtilization(new AutoscalingPolicyCpuUtilization().setUtilizationTarget(9.87))
+ .setCpuUtilization(
+ new AutoscalingPolicyCpuUtilization()
+ .setUtilizationTarget(9.87)
+ .setPredictiveMethod("STANDARD"))
.setLoadBalancingUtilization(
new AutoscalingPolicyLoadBalancingUtilization().setUtilizationTarget(6.54))
.setMaxNumReplicas(99)
@@ -764,6 +767,8 @@ class AbstractGoogleServerGroupCachingAgentTest {
assertThat(converted.getCoolDownPeriodSec()).isEqualTo(input.getCoolDownPeriodSec());
assertThat(converted.getCpuUtilization().getUtilizationTarget())
.isEqualTo(input.getCpuUtilization().getUtilizationTarget());
+ assertThat(converted.getCpuUtilization().getPredictiveMethod().toString())
+ .isEqualTo(input.getCpuUtilization().getPredictiveMethod());
assertThat(converted.getLoadBalancingUtilization().getUtilizationTarget())
.isEqualTo(input.getLoadBalancingUtilization().getUtilizationTarget());
assertThat(converted.getMaxNumReplicas()).isEqualTo(input.getMaxNumReplicas());
@@ -824,6 +829,65 @@ class AbstractGoogleServerGroupCachingAgentTest {
assertThat(converted.getScaleInControl()).isNull();
}
+ @Test
+ void serverGroupAutoscalingPolicy_unknownPredictiveAutoscalerMethod() {
+
+ InstanceGroupManager instanceGroupManager =
+ new InstanceGroupManager().setName("myServerGroup").setZone(ZONE_URL);
+ Autoscaler autoscaler =
+ new Autoscaler()
+ .setZone(ZONE_URL)
+ .setTarget("myServerGroup")
+ .setAutoscalingPolicy(
+ new AutoscalingPolicy()
+ .setCpuUtilization(
+ new AutoscalingPolicyCpuUtilization()
+ .setPredictiveMethod("SOME THING THAT DOESN'T REALLY EXIST")));
+
+ Compute compute =
+ new StubComputeFactory()
+ .setInstanceGroupManagers(instanceGroupManager)
+ .setAutoscalers(autoscaler)
+ .create();
+ AbstractGoogleServerGroupCachingAgent cachingAgent =
+ createCachingAgent(
+ compute, ImmutableList.of(instanceGroupManager), ImmutableList.of(autoscaler));
+
+ CacheResult cacheResult = cachingAgent.loadData(inMemoryProviderCache());
+ GoogleServerGroup serverGroup = getOnlyServerGroup(cacheResult);
+ GoogleAutoscalingPolicy converted = serverGroup.getAutoscalingPolicy();
+
+ assertThat(converted.getCpuUtilization().getPredictiveMethod()).isNull();
+ }
+
+ @Test
+ void serverGroupAutoscalingPolicy_emptyPredictiveAutoscalerMethod() {
+
+ InstanceGroupManager instanceGroupManager =
+ new InstanceGroupManager().setName("myServerGroup").setZone(ZONE_URL);
+ Autoscaler autoscaler =
+ new Autoscaler()
+ .setZone(ZONE_URL)
+ .setTarget("myServerGroup")
+ .setAutoscalingPolicy(
+ new AutoscalingPolicy().setCpuUtilization(new AutoscalingPolicyCpuUtilization()));
+
+ Compute compute =
+ new StubComputeFactory()
+ .setInstanceGroupManagers(instanceGroupManager)
+ .setAutoscalers(autoscaler)
+ .create();
+ AbstractGoogleServerGroupCachingAgent cachingAgent =
+ createCachingAgent(
+ compute, ImmutableList.of(instanceGroupManager), ImmutableList.of(autoscaler));
+
+ CacheResult cacheResult = cachingAgent.loadData(inMemoryProviderCache());
+ GoogleServerGroup serverGroup = getOnlyServerGroup(cacheResult);
+ GoogleAutoscalingPolicy converted = serverGroup.getAutoscalingPolicy();
+
+ assertThat(converted.getCpuUtilization().getPredictiveMethod()).isNull();
+ }
+
public static AbstractGoogleServerGroupCachingAgent createCachingAgent(
Compute compute, Collection<InstanceGroupManager> instanceGroupManagers) {
return createCachingAgent(

feat(gce): add support for the predictive autoscaler (#4794)

Co-authored-by: mergify[bot] <37929162+mergify[bot]@users.noreply.github.com>