Skip to content

Commit 6b8c83e

Browse files
authored
CLOUDP-342256: Add predictiveAutoscaling Field (#2639)
* add predictiveAutoscaling field * add tests
1 parent f7ce151 commit 6b8c83e

File tree

7 files changed

+181
-20
lines changed

7 files changed

+181
-20
lines changed

api/v1/atlasdeployment_types.go

Lines changed: 4 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -353,6 +353,10 @@ type ComputeSpec struct {
353353
// Maximum instance size to which your deployment can automatically scale (such as M40). Atlas requires this parameter if "autoScaling.compute.enabled" : true.
354354
// +optional
355355
MaxInstanceSize string `json:"maxInstanceSize,omitempty"`
356+
357+
// Flag that indicates whether predictive instance size auto-scaling is enabled.
358+
// +optional
359+
PredictiveEnabled *bool `json:"predictiveEnabled,omitempty"`
356360
}
357361

358362
type ProcessArgs struct {

api/v1/zz_generated.deepcopy.go

Lines changed: 5 additions & 0 deletions
Some generated files are not rendered by default. Learn more about customizing how changed files appear on GitHub.

config/crd/bases/atlas.mongodb.com_atlasdeployments.yaml

Lines changed: 8 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -289,6 +289,10 @@ spec:
289289
if "autoScaling.compute.scaleDownEnabled"
290290
: true.'
291291
type: string
292+
predictiveEnabled:
293+
description: Flag that indicates whether predictive
294+
instance size auto-scaling is enabled.
295+
type: boolean
292296
scaleDownEnabled:
293297
description: 'Flag that indicates whether
294298
the deployment tier may scale down. Atlas
@@ -820,6 +824,10 @@ spec:
820824
Atlas requires this parameter if "autoScaling.compute.scaleDownEnabled"
821825
: true.'
822826
type: string
827+
predictiveEnabled:
828+
description: Flag that indicates whether predictive
829+
instance size auto-scaling is enabled.
830+
type: boolean
823831
scaleDownEnabled:
824832
description: 'Flag that indicates whether the deployment
825833
tier may scale down. Atlas requires this parameter

internal/controller/atlasdeployment/advanced_deployment_test.go

Lines changed: 123 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -949,6 +949,129 @@ func TestHandleAdvancedDeployment(t *testing.T) {
949949
WithMessageRegexp("Cluster upgrade to dedicated instance initiated in Atlas. The process may take several minutes"),
950950
},
951951
},
952+
"enable autoscaling with predictive autoscaling": {
953+
atlasDeployment: &akov2.AtlasDeployment{
954+
ObjectMeta: metav1.ObjectMeta{
955+
Name: "cluster0",
956+
Namespace: "test",
957+
},
958+
Spec: akov2.AtlasDeploymentSpec{
959+
DeploymentSpec: &akov2.AdvancedDeploymentSpec{
960+
Name: "cluster0",
961+
ClusterType: "REPLICASET",
962+
ReplicationSpecs: []*akov2.AdvancedReplicationSpec{
963+
{
964+
RegionConfigs: []*akov2.AdvancedRegionConfig{
965+
{
966+
ProviderName: "AWS",
967+
RegionName: "US_WEST_1",
968+
Priority: pointer.MakePtr(7),
969+
ElectableSpecs: &akov2.Specs{
970+
InstanceSize: "M20",
971+
NodeCount: pointer.MakePtr(3),
972+
},
973+
AutoScaling: &akov2.AdvancedAutoScalingSpec{
974+
Compute: &akov2.ComputeSpec{
975+
Enabled: pointer.MakePtr(true),
976+
ScaleDownEnabled: pointer.MakePtr(false),
977+
MinInstanceSize: "M20",
978+
MaxInstanceSize: "M40",
979+
PredictiveEnabled: pointer.MakePtr(true),
980+
},
981+
},
982+
},
983+
},
984+
},
985+
},
986+
},
987+
},
988+
},
989+
deploymentInAtlas: &deployment.Cluster{
990+
ProjectID: "project-id",
991+
State: "IDLE",
992+
AdvancedDeploymentSpec: &akov2.AdvancedDeploymentSpec{
993+
Name: "cluster0",
994+
ClusterType: "REPLICASET",
995+
ReplicationSpecs: []*akov2.AdvancedReplicationSpec{
996+
{
997+
RegionConfigs: []*akov2.AdvancedRegionConfig{
998+
{
999+
ProviderName: "AWS",
1000+
RegionName: "US_WEST_1",
1001+
Priority: pointer.MakePtr(7),
1002+
ElectableSpecs: &akov2.Specs{
1003+
InstanceSize: "M20",
1004+
NodeCount: pointer.MakePtr(3),
1005+
},
1006+
AutoScaling: &akov2.AdvancedAutoScalingSpec{
1007+
Compute: &akov2.ComputeSpec{
1008+
Enabled: pointer.MakePtr(false),
1009+
},
1010+
DiskGB: &akov2.DiskGB{
1011+
Enabled: pointer.MakePtr(false),
1012+
},
1013+
},
1014+
},
1015+
},
1016+
},
1017+
},
1018+
},
1019+
},
1020+
deploymentService: func() deployment.AtlasDeploymentsService {
1021+
service := translation.NewAtlasDeploymentsServiceMock(t)
1022+
1023+
service.EXPECT().UpdateDeployment(context.Background(), mock.AnythingOfType("*deployment.Cluster")).
1024+
Return(
1025+
&deployment.Cluster{
1026+
ProjectID: "project-id",
1027+
State: "UPDATING",
1028+
AdvancedDeploymentSpec: &akov2.AdvancedDeploymentSpec{
1029+
Name: "cluster0",
1030+
ClusterType: "REPLICASET",
1031+
ReplicationSpecs: []*akov2.AdvancedReplicationSpec{
1032+
{
1033+
RegionConfigs: []*akov2.AdvancedRegionConfig{
1034+
{
1035+
ProviderName: "AWS",
1036+
RegionName: "US_WEST_1",
1037+
Priority: pointer.MakePtr(7),
1038+
ElectableSpecs: &akov2.Specs{
1039+
InstanceSize: "M20",
1040+
NodeCount: pointer.MakePtr(3),
1041+
},
1042+
AutoScaling: &akov2.AdvancedAutoScalingSpec{
1043+
Compute: &akov2.ComputeSpec{
1044+
Enabled: pointer.MakePtr(true),
1045+
ScaleDownEnabled: pointer.MakePtr(false),
1046+
MinInstanceSize: "M20",
1047+
MaxInstanceSize: "M40",
1048+
PredictiveEnabled: pointer.MakePtr(true),
1049+
},
1050+
},
1051+
},
1052+
},
1053+
},
1054+
},
1055+
},
1056+
},
1057+
nil,
1058+
)
1059+
1060+
return service
1061+
},
1062+
sdkMock: func() *admin.APIClient {
1063+
return &admin.APIClient{}
1064+
},
1065+
expectedResult: workflowRes{
1066+
res: ctrl.Result{RequeueAfter: workflow.DefaultRetry},
1067+
err: nil,
1068+
},
1069+
expectedConditions: []api.Condition{
1070+
api.FalseCondition(api.DeploymentReadyType).
1071+
WithReason(string(workflow.DeploymentUpdating)).
1072+
WithMessageRegexp("deployment is updating"),
1073+
},
1074+
},
9521075
}
9531076

9541077
for name, tt := range tests {

internal/translation/deployment/compare.go

Lines changed: 4 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -343,6 +343,10 @@ func computeAutoscalingConfigAreEqual(desired, current *akov2.ComputeSpec) bool
343343
return false
344344
}
345345

346+
if desired.PredictiveEnabled != nil && !areEqual(desired.PredictiveEnabled, current.PredictiveEnabled) {
347+
return false
348+
}
349+
346350
return true
347351
}
348352

internal/translation/deployment/compare_test.go

Lines changed: 28 additions & 16 deletions
Original file line numberDiff line numberDiff line change
@@ -1874,21 +1874,23 @@ func TestAutoscalingConfigAreEqual(t *testing.T) {
18741874
Enabled: pointer.MakePtr(true),
18751875
},
18761876
Compute: &akov2.ComputeSpec{
1877-
Enabled: pointer.MakePtr(true),
1878-
ScaleDownEnabled: pointer.MakePtr(true),
1879-
MinInstanceSize: "M10",
1880-
MaxInstanceSize: "M40",
1877+
Enabled: pointer.MakePtr(true),
1878+
ScaleDownEnabled: pointer.MakePtr(true),
1879+
MinInstanceSize: "M10",
1880+
MaxInstanceSize: "M40",
1881+
PredictiveEnabled: pointer.MakePtr(true),
18811882
},
18821883
},
18831884
atlasAutoscaling: &akov2.AdvancedAutoScalingSpec{
18841885
DiskGB: &akov2.DiskGB{
18851886
Enabled: pointer.MakePtr(true),
18861887
},
18871888
Compute: &akov2.ComputeSpec{
1888-
Enabled: pointer.MakePtr(true),
1889-
ScaleDownEnabled: pointer.MakePtr(true),
1890-
MinInstanceSize: "M10",
1891-
MaxInstanceSize: "M40",
1889+
Enabled: pointer.MakePtr(true),
1890+
ScaleDownEnabled: pointer.MakePtr(true),
1891+
MinInstanceSize: "M10",
1892+
MaxInstanceSize: "M40",
1893+
PredictiveEnabled: pointer.MakePtr(true),
18921894
},
18931895
},
18941896
expected: true,
@@ -2010,6 +2012,14 @@ func TestComputeAutoscalingConfigAreEqual(t *testing.T) {
20102012
MaxInstanceSize: "M10",
20112013
},
20122014
},
2015+
"should return false when predictive autoscaling has changed": {
2016+
akoAutoscaling: &akov2.ComputeSpec{
2017+
PredictiveEnabled: pointer.MakePtr(true),
2018+
},
2019+
atlasAutoscaling: &akov2.ComputeSpec{
2020+
PredictiveEnabled: pointer.MakePtr(false),
2021+
},
2022+
},
20132023
"should return true when autoscaling enabled flags are unset": {
20142024
akoAutoscaling: &akov2.ComputeSpec{
20152025
MinInstanceSize: "M10",
@@ -2025,16 +2035,18 @@ func TestComputeAutoscalingConfigAreEqual(t *testing.T) {
20252035
},
20262036
"should return true when autoscaling are equal": {
20272037
akoAutoscaling: &akov2.ComputeSpec{
2028-
Enabled: pointer.MakePtr(true),
2029-
ScaleDownEnabled: pointer.MakePtr(true),
2030-
MinInstanceSize: "M10",
2031-
MaxInstanceSize: "M40",
2038+
Enabled: pointer.MakePtr(true),
2039+
ScaleDownEnabled: pointer.MakePtr(true),
2040+
MinInstanceSize: "M10",
2041+
MaxInstanceSize: "M40",
2042+
PredictiveEnabled: pointer.MakePtr(true),
20322043
},
20332044
atlasAutoscaling: &akov2.ComputeSpec{
2034-
Enabled: pointer.MakePtr(true),
2035-
ScaleDownEnabled: pointer.MakePtr(true),
2036-
MinInstanceSize: "M10",
2037-
MaxInstanceSize: "M40",
2045+
Enabled: pointer.MakePtr(true),
2046+
ScaleDownEnabled: pointer.MakePtr(true),
2047+
MinInstanceSize: "M10",
2048+
MaxInstanceSize: "M40",
2049+
PredictiveEnabled: pointer.MakePtr(true),
20382050
},
20392051
expected: true,
20402052
},

internal/translation/deployment/conversion.go

Lines changed: 9 additions & 4 deletions
Original file line numberDiff line numberDiff line change
@@ -751,10 +751,11 @@ func replicationSpecFromAtlas(replicationSpecs []admin.ReplicationSpec20240805)
751751

752752
if compute.GetEnabled() {
753753
autoscaling.Compute = &akov2.ComputeSpec{
754-
Enabled: compute.Enabled,
755-
ScaleDownEnabled: compute.ScaleDownEnabled,
756-
MinInstanceSize: compute.GetMinInstanceSize(),
757-
MaxInstanceSize: compute.GetMaxInstanceSize(),
754+
Enabled: compute.Enabled,
755+
ScaleDownEnabled: compute.ScaleDownEnabled,
756+
MinInstanceSize: compute.GetMinInstanceSize(),
757+
MaxInstanceSize: compute.GetMaxInstanceSize(),
758+
PredictiveEnabled: compute.PredictiveEnabled,
758759
}
759760
}
760761

@@ -927,6 +928,10 @@ func replicationSpecToAtlas(replicationSpecs []*akov2.AdvancedReplicationSpec, c
927928
if spec.Compute.ScaleDownEnabled != nil && *spec.Compute.ScaleDownEnabled {
928929
autoscaling.Compute.MinInstanceSize = &spec.Compute.MinInstanceSize
929930
}
931+
932+
if spec.Compute.PredictiveEnabled != nil && *spec.Compute.PredictiveEnabled {
933+
autoscaling.Compute.PredictiveEnabled = spec.Compute.PredictiveEnabled
934+
}
930935
}
931936

932937
if diskGBExist {

0 commit comments

Comments
 (0)