Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

feat: Adds new advanced_configuration.0.default_max_time_ms attribute to mongodbatlas_advanced_cluster resource and data sources #2825

Merged
merged 18 commits into from
Dec 10, 2024
11 changes: 11 additions & 0 deletions .changelog/2825.txt
Original file line number Diff line number Diff line change
@@ -0,0 +1,11 @@
```release-note:note
resource/mongodbatlas_advanced_cluster: Adds new `advanced_configuration.0.default_max_time_ms` attribute
```

```release-note:note
data-source/mongodbatlas_advanced_cluster: Adds new `advanced_configuration.0.default_max_time_ms` attribute
```

```release-note:note
data-source/mongodbatlas_advanced_clusters: Adds new `advanced_configuration.0.default_max_time_ms` attribute
```
Comment on lines +1 to +11

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Suggested change
```release-note:note
resource/mongodbatlas_advanced_cluster: Adds new `advanced_configuration.0.default_max_time_ms` attribute
```
```release-note:note
data-source/mongodbatlas_advanced_cluster: Adds new `advanced_configuration.0.default_max_time_ms` attribute
```
```release-note:note
data-source/mongodbatlas_advanced_clusters: Adds new `advanced_configuration.0.default_max_time_ms` attribute
```
```release-note:note
resource/mongodbatlas_advanced_cluster: Adds new `advanced_configuration.0.default_max_time_ms` attribute.
data-source/mongodbatlas_advanced_cluster: Adds new `advanced_configuration.0.default_max_time_ms` attribute.
data-source/mongodbatlas_advanced_clusters: Adds new `advanced_configuration.0.default_max_time_ms` attribute.

1 change: 1 addition & 0 deletions docs/data-sources/advanced_cluster.md
Original file line number Diff line number Diff line change
Expand Up @@ -200,6 +200,7 @@ Key-value pairs that categorize the cluster. Each key and value has a maximum le
* `sample_size_bi_connector` - Number of documents per database to sample when gathering schema information. Defaults to 100. Available only for Atlas deployments in which BI Connector for Atlas is enabled.
* `sample_refresh_interval_bi_connector` - Interval in seconds at which the mongosqld process re-samples data to create its relational schema. The default value is 300. The specified value must be a positive integer. Available only for Atlas deployments in which BI Connector for Atlas is enabled.
* `transaction_lifetime_limit_seconds` - Lifetime, in seconds, of multi-document transactions. Defaults to 60 seconds.
* `default_max_time_ms` - Default time limit in milliseconds for individual read operations to complete. This option corresponds to the [defaultMaxTimeMS(https://www.mongodb.com/docs/upcoming/reference/cluster-parameters/defaultMaxTimeMS/) cluster parameter. This parameter is only supported for MongoDB version 8.0 and above.
maastha marked this conversation as resolved.
Show resolved Hide resolved
* `change_stream_options_pre_and_post_images_expire_after_seconds` - (Optional) The minimum pre- and post-image retention time in seconds This parameter is only supported for MongoDB version 6.0 and above. Defaults to `-1`(off).

## Attributes Reference
Expand Down
1 change: 1 addition & 0 deletions docs/data-sources/advanced_clusters.md
Original file line number Diff line number Diff line change
Expand Up @@ -202,6 +202,7 @@ Key-value pairs that categorize the cluster. Each key and value has a maximum le
* `oplog_min_retention_hours` - Minimum retention window for cluster's oplog expressed in hours. A value of null indicates that the cluster uses the default minimum oplog window that MongoDB Cloud calculates.
* `sample_size_bi_connector` - Number of documents per database to sample when gathering schema information. Defaults to 100. Available only for Atlas deployments in which BI Connector for Atlas is enabled.
* `sample_refresh_interval_bi_connector` - Interval in seconds at which the mongosqld process re-samples data to create its relational schema. The default value is 300. The specified value must be a positive integer. Available only for Atlas deployments in which BI Connector for Atlas is enabled.
* `default_max_time_ms` - Default time limit in milliseconds for individual read operations to complete. This option corresponds to the [defaultMaxTimeMS(https://www.mongodb.com/docs/upcoming/reference/cluster-parameters/defaultMaxTimeMS/) cluster parameter. This parameter is only supported for MongoDB version 8.0 and above.
maastha marked this conversation as resolved.
Show resolved Hide resolved
* `transaction_lifetime_limit_seconds` - (Optional) Lifetime, in seconds, of multi-document transactions. Defaults to 60 seconds.
* `change_stream_options_pre_and_post_images_expire_after_seconds` - (Optional) The minimum pre- and post-image retention time in seconds. This parameter is only supported for MongoDB version 6.0 and above. Defaults to `-1`(off).

Expand Down
1 change: 1 addition & 0 deletions docs/resources/advanced_cluster.md
Original file line number Diff line number Diff line change
Expand Up @@ -460,6 +460,7 @@ Include **desired options** within advanced_configuration:
* `sample_refresh_interval_bi_connector` - (Optional) Interval in seconds at which the mongosqld process re-samples data to create its relational schema. The default value is 300. The specified value must be a positive integer. Available only for Atlas deployments in which BI Connector for Atlas is enabled.
* `transaction_lifetime_limit_seconds` - (Optional) Lifetime, in seconds, of multi-document transactions. Defaults to 60 seconds.
* `change_stream_options_pre_and_post_images_expire_after_seconds` - (Optional) The minimum pre- and post-image retention time in seconds. This option corresponds to the `changeStreamOptions.preAndPostImages.expireAfterSeconds` cluster parameter. Defaults to `-1`(off). This setting controls the retention policy of change stream pre- and post-images. Pre- and post-images are the versions of a document before and after document modification, respectively. `expireAfterSeconds` controls how long MongoDB retains pre- and post-images. When set to -1 (off), MongoDB uses the default retention policy: pre- and post-images are retained until the corresponding change stream events are removed from the oplog. To set the minimum pre- and post-image retention time, specify an integer value greater than zero. Setting this too low could increase the risk of interrupting Realm sync or triggers processing. This parameter is only supported for MongoDB version 6.0 and above.
* `default_max_time_ms` - (Optional) Default time limit in milliseconds for individual read operations to complete. This option corresponds to the [defaultMaxTimeMS(https://www.mongodb.com/docs/upcoming/reference/cluster-parameters/defaultMaxTimeMS/) cluster parameter. This parameter is only supported for MongoDB version 8.0 and above.
maastha marked this conversation as resolved.
Show resolved Hide resolved


### Tags
Expand Down
35 changes: 33 additions & 2 deletions internal/service/advancedcluster/model_advanced_cluster.go
Original file line number Diff line number Diff line change
Expand Up @@ -25,6 +25,7 @@ import (
)

const minVersionForChangeStreamOptions = 6.0
const minVersionForDefaultMaxTimeMS = 8.0

var (
DSTagsSchema = schema.Schema{
Expand Down Expand Up @@ -117,6 +118,10 @@ func SchemaAdvancedConfigDS() *schema.Schema {
Type: schema.TypeInt,
Computed: true,
},
"default_max_time_ms": {
Type: schema.TypeInt,
Computed: true,
},
},
},
}
Expand Down Expand Up @@ -262,6 +267,10 @@ func SchemaAdvancedConfig() *schema.Schema {
Optional: true,
Default: -1,
},
"default_max_time_ms": {
Type: schema.TypeInt,
Optional: true,
Copy link
Collaborator Author

@maastha maastha Nov 28, 2024

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Confirmed with upstream this is expected to be user-managed, hence keeping optional

},
},
},
}
Expand Down Expand Up @@ -511,7 +520,12 @@ func flattenProcessArgs(p20240530 *admin20240530.ClusterDescriptionProcessArgs,
} else {
flattenedProcessArgs[0]["change_stream_options_pre_and_post_images_expire_after_seconds"] = p.GetChangeStreamOptionsPreAndPostImagesExpireAfterSeconds()
}

if v := p.DefaultMaxTimeMS; v != nil {
flattenedProcessArgs[0]["default_max_time_ms"] = p.GetDefaultMaxTimeMS()
}
}

return flattenedProcessArgs
}

Expand Down Expand Up @@ -852,10 +866,19 @@ func expandProcessArgs(d *schema.ResourceData, p map[string]any, mongodbMajorVer

res.ChangeStreamOptionsPreAndPostImagesExpireAfterSeconds = conversion.IntPtr(tmpInt)
}

if _, ok := d.GetOkExists("advanced_configuration.0.default_max_time_ms"); ok {
if IsDefaultMaxTimeMinRequiredMajorVersion(mongodbMajorVersion) {
res.DefaultMaxTimeMS = conversion.Pointer(cast.ToInt(p["default_max_time_ms"]))
} else {
log.Print(ErrorDefaultMaxTimeMinVersion)
}
}

return res20240530, res
}

func IsChangeStreamOptionsMinRequiredMajorVersion(input *string) bool {
func isMinRequiredMajorVersion(input *string, minVersion float64) bool {
if input == nil || *input == "" {
return true
}
Expand All @@ -869,7 +892,15 @@ func IsChangeStreamOptionsMinRequiredMajorVersion(input *string) bool {
return false
}

return value >= minVersionForChangeStreamOptions
return value >= minVersion
}

func IsChangeStreamOptionsMinRequiredMajorVersion(input *string) bool {
return isMinRequiredMajorVersion(input, minVersionForChangeStreamOptions)
}

func IsDefaultMaxTimeMinRequiredMajorVersion(input *string) bool {
return isMinRequiredMajorVersion(input, minVersionForDefaultMaxTimeMS)
}

func expandLabelSliceFromSetSchema(d *schema.ResourceData) ([]admin20240805.ComponentLabel, diag.Diagnostics) {
Expand Down
10 changes: 8 additions & 2 deletions internal/service/advancedcluster/resource_advanced_cluster.go
Original file line number Diff line number Diff line change
Expand Up @@ -40,6 +40,7 @@ const (
ErrorClusterAdvancedSetting = "error setting `%s` for MongoDB ClusterAdvanced (%s): %s"
ErrorAdvancedClusterListStatus = "error awaiting MongoDB ClusterAdvanced List IDLE: %s"
ErrorOperationNotPermitted = "error operation not permitted"
ErrorDefaultMaxTimeMinVersion = "default_max_time_ms can not be set for mongo_db_major_version lower than 8.0"
ignoreLabel = "Infrastructure Tool"
DeprecationOldSchemaAction = "Please refer to our examples, documentation, and 1.18.0 migration guide for more details at https://registry.terraform.io/providers/mongodb/mongodbatlas/latest/docs/guides/1.18.0-upgrade-guide.html.markdown"
)
Expand Down Expand Up @@ -472,12 +473,17 @@ func resourceCreate(ctx context.Context, d *schema.ResourceData, meta any) diag.
params.ConfigServerManagementMode = conversion.StringPtr(v.(string))
}

// Validate oplog_size_mb to show the error before the cluster is created.
// Validate advanced configuration params to show the error before the cluster is created.
if oplogSizeMB, ok := d.GetOkExists("advanced_configuration.0.oplog_size_mb"); ok {
if cast.ToInt64(oplogSizeMB) < 0 {
return diag.FromErr(fmt.Errorf("`advanced_configuration.oplog_size_mb` cannot be < 0"))
}
}
if _, ok := d.GetOkExists("advanced_configuration.0.default_max_time_ms"); ok {
if !IsDefaultMaxTimeMinRequiredMajorVersion(params.MongoDBMajorVersion) {
return diag.FromErr(errors.New(ErrorDefaultMaxTimeMinVersion))
}
}

if err := CheckRegionConfigsPriorityOrder(params.GetReplicationSpecs()); err != nil {
return diag.FromErr(err)
Expand All @@ -498,7 +504,7 @@ func resourceCreate(ctx context.Context, d *schema.ResourceData, meta any) diag.
if ac, ok := d.GetOk("advanced_configuration"); ok {
if aclist, ok := ac.([]any); ok && len(aclist) > 0 {
params20240530, params := expandProcessArgs(d, aclist[0].(map[string]any), params.MongoDBMajorVersion)
_, _, err := connV220240530.ClustersApi.UpdateClusterAdvancedConfiguration(ctx, projectID, cluster.GetName(), &params20240530).Execute()
_, _, err = connV220240530.ClustersApi.UpdateClusterAdvancedConfiguration(ctx, projectID, cluster.GetName(), &params20240530).Execute()
if err != nil {
return diag.FromErr(fmt.Errorf(errorConfigUpdate, cluster.GetName(), err))
}
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -149,7 +149,7 @@ func TestMigAdvancedCluster_geoShardedMigrationFromOldToNewSchema(t *testing.T)

func TestMigAdvancedCluster_partialAdvancedConf(t *testing.T) {
acc.SkipIfTPFAdvancedCluster(t)
mig.SkipIfVersionBelow(t, "1.19.0") // version where change_stream_options_pre_and_post_images_expire_after_seconds was introduced
mig.SkipIfVersionBelow(t, "1.22.1") // version where default_max_time_ms was introduced
var (
projectID = acc.ProjectIDExecution(t)
clusterName = acc.RandomClusterName()
Expand Down Expand Up @@ -179,7 +179,8 @@ func TestMigAdvancedCluster_partialAdvancedConf(t *testing.T) {
no_table_scan = false
default_read_concern = "available"
sample_size_bi_connector = 110
sample_refresh_interval_bi_connector = 310
sample_refresh_interval_bi_connector = 310
default_max_time_ms = 65
}

bi_connector_config {
Expand Down Expand Up @@ -219,6 +220,7 @@ func TestMigAdvancedCluster_partialAdvancedConf(t *testing.T) {
resource.TestCheckResourceAttr(resourceName, "advanced_configuration.0.no_table_scan", "false"),
resource.TestCheckResourceAttr(resourceName, "advanced_configuration.0.sample_refresh_interval_bi_connector", "310"),
resource.TestCheckResourceAttr(resourceName, "advanced_configuration.0.sample_size_bi_connector", "110"),
resource.TestCheckResourceAttr(resourceName, "advanced_configuration.0.default_max_time_ms", "65"),
resource.TestCheckResourceAttr(resourceName, "bi_connector_config.0.enabled", "false"),
resource.TestCheckResourceAttr(resourceName, "bi_connector_config.0.read_preference", "secondary"),
),
Expand Down
Loading
Loading