Skip to content

Commit 6800988

Browse files
authored
Merge pull request #92 from mongodb/cluster-autoscaling
Cluster autoscaling compute
2 parents c06f919 + 2fe57cf commit 6800988

File tree

2 files changed

+109
-22
lines changed

2 files changed

+109
-22
lines changed

mongodbatlas/clusters.go

Lines changed: 19 additions & 9 deletions
Original file line numberDiff line numberDiff line change
@@ -32,7 +32,16 @@ var _ ClustersService = &ClustersServiceOp{}
3232

3333
// AutoScaling configures your cluster to automatically scale its storage
3434
type AutoScaling struct {
35-
DiskGBEnabled *bool `json:"diskGBEnabled,omitempty"`
35+
DiskGBEnabled *bool `json:"diskGBEnabled,omitempty"`
36+
Compute *Compute `json:"compute,omitempty"`
37+
}
38+
39+
// Compute Specifies whether the cluster automatically scales its cluster tier and whether the cluster can scale down.
40+
type Compute struct {
41+
Enabled *bool `json:"enabled,omitempty"`
42+
ScaleDownEnabled *bool `json:"scaleDownEnabled,omitempty"`
43+
MinInstanceSize string `json:"minInstanceSize,omitempty"`
44+
MaxInstanceSize string `json:"maxInstanceSize,omitempty"`
3645
}
3746

3847
// BiConnector specifies BI Connector for Atlas configuration on this cluster
@@ -43,14 +52,15 @@ type BiConnector struct {
4352

4453
// ProviderSettings configuration for the provisioned servers on which MongoDB runs. The available options are specific to the cloud service provider.
4554
type ProviderSettings struct {
46-
BackingProviderName string `json:"backingProviderName,omitempty"`
47-
DiskIOPS *int64 `json:"diskIOPS,omitempty"`
48-
DiskTypeName string `json:"diskTypeName,omitempty"`
49-
EncryptEBSVolume *bool `json:"encryptEBSVolume,omitempty"`
50-
InstanceSizeName string `json:"instanceSizeName,omitempty"`
51-
ProviderName string `json:"providerName,omitempty"`
52-
RegionName string `json:"regionName,omitempty"`
53-
VolumeType string `json:"volumeType,omitempty"`
55+
BackingProviderName string `json:"backingProviderName,omitempty"`
56+
DiskIOPS *int64 `json:"diskIOPS,omitempty"`
57+
DiskTypeName string `json:"diskTypeName,omitempty"`
58+
EncryptEBSVolume *bool `json:"encryptEBSVolume,omitempty"`
59+
InstanceSizeName string `json:"instanceSizeName,omitempty"`
60+
ProviderName string `json:"providerName,omitempty"`
61+
RegionName string `json:"regionName,omitempty"`
62+
VolumeType string `json:"volumeType,omitempty"`
63+
AutoScaling *AutoScaling `json:"autoScaling,omitempty"`
5464
}
5565

5666
// RegionsConfig describes the region’s priority in elections and the number and type of MongoDB nodes Atlas deploys to the region.

mongodbatlas/clusters_test.go

Lines changed: 90 additions & 13 deletions
Original file line numberDiff line numberDiff line change
@@ -20,7 +20,11 @@ func TestClusters_ListClusters(t *testing.T) {
2020
"results": [
2121
{
2222
"autoScaling": {
23-
"diskGBEnabled": true
23+
"diskGBEnabled": true,
24+
"compute": {
25+
"enabled": true,
26+
"scaleDownEnabled": true
27+
}
2428
},
2529
"backupEnabled": true,
2630
"biConnector": {
@@ -55,7 +59,13 @@ func TestClusters_ListClusters(t *testing.T) {
5559
"diskIOPS": 1320,
5660
"encryptEBSVolume": false,
5761
"instanceSizeName": "M40",
58-
"regionName": "US_WEST_2"
62+
"regionName": "US_WEST_2",
63+
"autoScaling": {
64+
"compute": {
65+
"maxInstanceSize": "M60",
66+
"minInstanceSize": "M10"
67+
}
68+
}
5969
},
6070
"replicationFactor": 3,
6171
"replicationSpec": {
@@ -70,7 +80,11 @@ func TestClusters_ListClusters(t *testing.T) {
7080
},
7181
{
7282
"autoScaling": {
73-
"diskGBEnabled": true
83+
"diskGBEnabled": true,
84+
"compute": {
85+
"enabled": true,
86+
"scaleDownEnabled": true
87+
}
7488
},
7589
"backupEnabled": true,
7690
"biConnector": {
@@ -105,7 +119,13 @@ func TestClusters_ListClusters(t *testing.T) {
105119
"diskIOPS": 1320,
106120
"encryptEBSVolume": false,
107121
"instanceSizeName": "M40",
108-
"regionName": "US_WEST_2"
122+
"regionName": "US_WEST_2",
123+
"autoScaling": {
124+
"compute": {
125+
"maxInstanceSize": "M60",
126+
"minInstanceSize": "M10"
127+
}
128+
}
109129
},
110130
"replicationFactor": 3,
111131
"replicationSpec": {
@@ -129,7 +149,13 @@ func TestClusters_ListClusters(t *testing.T) {
129149
}
130150

131151
cluster1 := Cluster{
132-
AutoScaling: &AutoScaling{DiskGBEnabled: pointy.Bool(true)},
152+
AutoScaling: &AutoScaling{
153+
DiskGBEnabled: pointy.Bool(true),
154+
Compute: &Compute{
155+
Enabled: pointy.Bool(true),
156+
ScaleDownEnabled: pointy.Bool(true),
157+
},
158+
},
133159
BackupEnabled: pointy.Bool(true),
134160
BiConnector: &BiConnector{Enabled: pointy.Bool(false), ReadPreference: "secondary"},
135161
ClusterType: "REPLICASET",
@@ -141,6 +167,7 @@ func TestClusters_ListClusters(t *testing.T) {
141167
Private: "mongodb://cluster0-shard-00-00-pri.auylw.mongodb.net:27017,cluster0-shard-00-01-pri.auylw.mongodb.net:27017,cluster0-shard-00-02-pri.auylw.mongodb.net:27017/?ssl=true&authSource=admin&replicaSet=Cluster0-shard-0",
142168
PrivateSrv: "mongodb+srv://cluster0-pri.auylw.mongodb.net",
143169
},
170+
144171
DiskSizeGB: pointy.Float64(160),
145172
EncryptionAtRestProvider: "AWS",
146173
GroupID: "5356823b3794de37132bb7b",
@@ -157,6 +184,12 @@ func TestClusters_ListClusters(t *testing.T) {
157184
EncryptEBSVolume: pointy.Bool(false),
158185
InstanceSizeName: "M40",
159186
RegionName: "US_WEST_2",
187+
AutoScaling: &AutoScaling{
188+
Compute: &Compute{
189+
MaxInstanceSize: "M60",
190+
MinInstanceSize: "M10",
191+
},
192+
},
160193
},
161194
ReplicationFactor: pointy.Int64(3),
162195

@@ -262,8 +295,9 @@ func TestClusters_Create(t *testing.T) {
262295
groupID := "1"
263296

264297
createRequest := &Cluster{
265-
ID: "1",
266-
AutoScaling: &AutoScaling{DiskGBEnabled: pointy.Bool(true)},
298+
ID: "1",
299+
AutoScaling: &AutoScaling{DiskGBEnabled: pointy.Bool(true),
300+
Compute: &Compute{Enabled: pointy.Bool(true), ScaleDownEnabled: pointy.Bool(true)}},
267301
BackupEnabled: pointy.Bool(true),
268302
BiConnector: &BiConnector{Enabled: pointy.Bool(false), ReadPreference: "secondary"},
269303
ClusterType: "REPLICASET",
@@ -283,6 +317,7 @@ func TestClusters_Create(t *testing.T) {
283317
EncryptEBSVolume: pointy.Bool(false),
284318
InstanceSizeName: "M40",
285319
RegionName: "US_WEST_2",
320+
AutoScaling: &AutoScaling{Compute: &Compute{MinInstanceSize: "M10", MaxInstanceSize: "M60"}},
286321
},
287322
ReplicationFactor: pointy.Int64(3),
288323

@@ -302,6 +337,10 @@ func TestClusters_Create(t *testing.T) {
302337
"id": "1",
303338
"autoScaling": map[string]interface{}{
304339
"diskGBEnabled": true,
340+
"compute": map[string]interface{}{
341+
"enabled": true,
342+
"scaleDownEnabled": true,
343+
},
305344
},
306345
"backupEnabled": true,
307346
"biConnector": map[string]interface{}{
@@ -325,6 +364,12 @@ func TestClusters_Create(t *testing.T) {
325364
"encryptEBSVolume": false,
326365
"instanceSizeName": "M40",
327366
"regionName": "US_WEST_2",
367+
"autoScaling": map[string]interface{}{
368+
"compute": map[string]interface{}{
369+
"minInstanceSize": "M10",
370+
"maxInstanceSize": "M60",
371+
},
372+
},
328373
},
329374
"replicationFactor": float64(3),
330375
"replicationSpec": map[string]interface{}{
@@ -342,7 +387,11 @@ func TestClusters_Create(t *testing.T) {
342387
{
343388
"id":"1",
344389
"autoScaling": {
345-
"diskGBEnabled": true
390+
"diskGBEnabled": true,
391+
"compute": {
392+
"enabled": true,
393+
"scaleDownEnabled": true
394+
}
346395
},
347396
"backupEnabled": true,
348397
"biConnector": {
@@ -366,7 +415,13 @@ func TestClusters_Create(t *testing.T) {
366415
"diskIOPS": 1320,
367416
"encryptEBSVolume": false,
368417
"instanceSizeName": "M40",
369-
"regionName": "US_WEST_2"
418+
"regionName": "US_WEST_2",
419+
"autoScaling": {
420+
"compute": {
421+
"minInstanceSize": "M10",
422+
"maxInstanceSize": "M60"
423+
}
424+
}
370425
},
371426
"replicationFactor": 3,
372427
"replicationSpec": {
@@ -422,8 +477,9 @@ func TestClusters_Update(t *testing.T) {
422477
clusterName := "AppData"
423478

424479
updateRequest := &Cluster{
425-
ID: "1",
426-
AutoScaling: &AutoScaling{DiskGBEnabled: pointy.Bool(true)},
480+
ID: "1",
481+
AutoScaling: &AutoScaling{DiskGBEnabled: pointy.Bool(true),
482+
Compute: &Compute{Enabled: pointy.Bool(true), ScaleDownEnabled: pointy.Bool(true)}},
427483
BackupEnabled: pointy.Bool(true),
428484
BiConnector: &BiConnector{Enabled: pointy.Bool(false), ReadPreference: "secondary"},
429485
ClusterType: "REPLICASET",
@@ -443,6 +499,7 @@ func TestClusters_Update(t *testing.T) {
443499
EncryptEBSVolume: pointy.Bool(false),
444500
InstanceSizeName: "M40",
445501
RegionName: "US_WEST_2",
502+
AutoScaling: &AutoScaling{Compute: &Compute{MinInstanceSize: "M20", MaxInstanceSize: "M80"}},
446503
},
447504
ReplicationFactor: pointy.Int64(3),
448505

@@ -462,6 +519,10 @@ func TestClusters_Update(t *testing.T) {
462519
"id": "1",
463520
"autoScaling": map[string]interface{}{
464521
"diskGBEnabled": true,
522+
"compute": map[string]interface{}{
523+
"enabled": true,
524+
"scaleDownEnabled": true,
525+
},
465526
},
466527
"backupEnabled": true,
467528
"biConnector": map[string]interface{}{
@@ -485,6 +546,12 @@ func TestClusters_Update(t *testing.T) {
485546
"encryptEBSVolume": false,
486547
"instanceSizeName": "M40",
487548
"regionName": "US_WEST_2",
549+
"autoScaling": map[string]interface{}{
550+
"compute": map[string]interface{}{
551+
"minInstanceSize": "M20",
552+
"maxInstanceSize": "M80",
553+
},
554+
},
488555
},
489556
"replicationFactor": float64(3),
490557
"replicationSpec": map[string]interface{}{
@@ -501,7 +568,11 @@ func TestClusters_Update(t *testing.T) {
501568
jsonBlob := `
502569
{
503570
"autoScaling": {
504-
"diskGBEnabled": true
571+
"diskGBEnabled": true,
572+
"compute": {
573+
"enabled": true,
574+
"scaleDownEnabled": true
575+
}
505576
},
506577
"backupEnabled": true,
507578
"biConnector": {
@@ -525,7 +596,13 @@ func TestClusters_Update(t *testing.T) {
525596
"diskIOPS": 1320,
526597
"encryptEBSVolume": false,
527598
"instanceSizeName": "M40",
528-
"regionName": "US_WEST_2"
599+
"regionName": "US_WEST_2",
600+
"autoScaling": {
601+
"compute": {
602+
"minInstanceSize": "M10",
603+
"maxInstanceSize": "M60"
604+
}
605+
}
529606
},
530607
"replicationFactor": 3,
531608
"replicationSpec": {

0 commit comments

Comments
 (0)