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.
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.
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.


### Tags
Expand Down
18 changes: 18 additions & 0 deletions internal/service/advancedcluster/model_advanced_cluster.go
Original file line number Diff line number Diff line change
Expand Up @@ -117,6 +117,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 +266,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 +519,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,6 +865,11 @@ 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 {
res.DefaultMaxTimeMS = conversion.Pointer(cast.ToInt(p["default_max_time_ms"]))
}

return res20240530, res
}

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
Original file line number Diff line number Diff line change
Expand Up @@ -248,10 +248,10 @@ func TestAccClusterAdvancedCluster_pausedToUnpaused(t *testing.T) {
func TestAccClusterAdvancedCluster_advancedConfig(t *testing.T) {
acc.SkipIfTPFAdvancedCluster(t)
var (
projectID = acc.ProjectIDExecution(t)
clusterName = acc.RandomClusterName()
clusterNameUpdated = acc.RandomClusterName()
processArgs = &admin20240530.ClusterDescriptionProcessArgs{
projectID = acc.ProjectIDExecution(t)
clusterName = acc.RandomClusterName()
clusterNameUpdated = acc.RandomClusterName()
processArgs20240530 = &admin20240530.ClusterDescriptionProcessArgs{
DefaultReadConcern: conversion.StringPtr("available"),
DefaultWriteConcern: conversion.StringPtr("1"),
FailIndexKeyTooLong: conversion.Pointer(false),
Expand All @@ -263,7 +263,11 @@ func TestAccClusterAdvancedCluster_advancedConfig(t *testing.T) {
SampleSizeBIConnector: conversion.Pointer(110),
TransactionLifetimeLimitSeconds: conversion.Pointer[int64](300),
}
processArgsUpdated = &admin20240530.ClusterDescriptionProcessArgs{
processArgs = &admin.ClusterDescriptionProcessArgs20240805{
ChangeStreamOptionsPreAndPostImagesExpireAfterSeconds: conversion.IntPtr(-1), // this will not be set in the TF configuration
}

processArgs20240530Updated = &admin20240530.ClusterDescriptionProcessArgs{
DefaultReadConcern: conversion.StringPtr("available"),
DefaultWriteConcern: conversion.StringPtr("0"),
FailIndexKeyTooLong: conversion.Pointer(false),
Expand All @@ -275,6 +279,10 @@ func TestAccClusterAdvancedCluster_advancedConfig(t *testing.T) {
SampleSizeBIConnector: conversion.Pointer(110),
TransactionLifetimeLimitSeconds: conversion.Pointer[int64](300),
}
processArgsUpdated = &admin.ClusterDescriptionProcessArgs20240805{
DefaultMaxTimeMS: conversion.IntPtr(65),
ChangeStreamOptionsPreAndPostImagesExpireAfterSeconds: conversion.IntPtr(100),
}
)

resource.ParallelTest(t, resource.TestCase{
Expand All @@ -283,12 +291,12 @@ func TestAccClusterAdvancedCluster_advancedConfig(t *testing.T) {
CheckDestroy: acc.CheckDestroyCluster,
Steps: []resource.TestStep{
{
Config: configAdvanced(projectID, clusterName, processArgs, nil),
Check: checkAdvanced(clusterName, "TLS1_1", "-1"),
Config: configAdvanced(projectID, clusterName, processArgs20240530, processArgs),
Check: checkAdvanced(clusterName, "TLS1_1", processArgs),
},
{
Config: configAdvanced(projectID, clusterNameUpdated, processArgsUpdated, conversion.IntPtr(100)),
Check: checkAdvanced(clusterNameUpdated, "TLS1_2", "100"),
Config: configAdvanced(projectID, clusterNameUpdated, processArgs20240530Updated, processArgsUpdated),
Check: checkAdvanced(clusterNameUpdated, "TLS1_2", processArgsUpdated),
},
},
})
Expand Down Expand Up @@ -1320,10 +1328,16 @@ func checkSingleProviderPaused(name string, paused bool) resource.TestCheckFunc
"paused": strconv.FormatBool(paused)})
}

func configAdvanced(projectID, clusterName string, p *admin20240530.ClusterDescriptionProcessArgs, changeStreamOptions *int) string {
func configAdvanced(projectID, clusterName string, p20240530 *admin20240530.ClusterDescriptionProcessArgs, p *admin.ClusterDescriptionProcessArgs20240805) string {
changeStreamOptionsString := ""
if changeStreamOptions != nil {
changeStreamOptionsString = fmt.Sprintf(`change_stream_options_pre_and_post_images_expire_after_seconds = %[1]d`, *changeStreamOptions)
defaultMaxTimeString := ""
if p != nil {
if p.ChangeStreamOptionsPreAndPostImagesExpireAfterSeconds != conversion.IntPtr(-1) {
changeStreamOptionsString = fmt.Sprintf(`change_stream_options_pre_and_post_images_expire_after_seconds = %[1]d`, *p.ChangeStreamOptionsPreAndPostImagesExpireAfterSeconds)
}
if p.DefaultMaxTimeMS != nil {
defaultMaxTimeString = fmt.Sprintf(`default_max_time_ms = %[1]d`, *p.DefaultMaxTimeMS)
}
}
return fmt.Sprintf(`
resource "mongodbatlas_advanced_cluster" "test" {
Expand Down Expand Up @@ -1357,6 +1371,7 @@ func configAdvanced(projectID, clusterName string, p *admin20240530.ClusterDescr
sample_refresh_interval_bi_connector = %[9]d
transaction_lifetime_limit_seconds = %[10]d
%[11]s
%[12]s
}
}

Expand All @@ -1369,27 +1384,36 @@ func configAdvanced(projectID, clusterName string, p *admin20240530.ClusterDescr
project_id = mongodbatlas_advanced_cluster.test.project_id
Copy link
Member

Choose a reason for hiding this comment

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

Just to a double check from our draft checklist, is the attribute supported in older MongoDB versions? Could be good to try an older MongoDB version and attribute is not defined.

Copy link
Collaborator Author

Choose a reason for hiding this comment

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

added validation and acceptance test for this scenario

}
`, projectID, clusterName,
p.GetFailIndexKeyTooLong(), p.GetJavascriptEnabled(), p.GetMinimumEnabledTlsProtocol(), p.GetNoTableScan(),
p.GetOplogSizeMB(), p.GetSampleSizeBIConnector(), p.GetSampleRefreshIntervalBIConnector(), p.GetTransactionLifetimeLimitSeconds(), changeStreamOptionsString)
}
p20240530.GetFailIndexKeyTooLong(), p20240530.GetJavascriptEnabled(), p20240530.GetMinimumEnabledTlsProtocol(), p20240530.GetNoTableScan(),
p20240530.GetOplogSizeMB(), p20240530.GetSampleSizeBIConnector(), p20240530.GetSampleRefreshIntervalBIConnector(), p20240530.GetTransactionLifetimeLimitSeconds(),
changeStreamOptionsString, defaultMaxTimeString)
}

func checkAdvanced(name, tls string, processArgs *admin.ClusterDescriptionProcessArgs20240805) resource.TestCheckFunc {
advancedConfig := map[string]string{
"name": name,
"advanced_configuration.0.minimum_enabled_tls_protocol": tls,
"advanced_configuration.0.fail_index_key_too_long": "false",
"advanced_configuration.0.javascript_enabled": "true",
"advanced_configuration.0.no_table_scan": "false",
"advanced_configuration.0.oplog_size_mb": "1000",
"advanced_configuration.0.sample_refresh_interval_bi_connector": "310",
"advanced_configuration.0.sample_size_bi_connector": "110",
"advanced_configuration.0.transaction_lifetime_limit_seconds": "300",
"advanced_configuration.0.change_stream_options_pre_and_post_images_expire_after_seconds": strconv.Itoa(*processArgs.ChangeStreamOptionsPreAndPostImagesExpireAfterSeconds),
}

if processArgs.DefaultMaxTimeMS != nil {
advancedConfig["advanced_configuration.0.default_max_time_ms"] = strconv.Itoa(*processArgs.DefaultMaxTimeMS)
}

func checkAdvanced(name, tls, changeStreamOptions string) resource.TestCheckFunc {
return checkAggr(
[]string{"project_id", "replication_specs.#", "replication_specs.0.region_configs.#"},
map[string]string{
"name": name,
"advanced_configuration.0.minimum_enabled_tls_protocol": tls,
"advanced_configuration.0.fail_index_key_too_long": "false",
"advanced_configuration.0.javascript_enabled": "true",
"advanced_configuration.0.no_table_scan": "false",
"advanced_configuration.0.oplog_size_mb": "1000",
"advanced_configuration.0.sample_refresh_interval_bi_connector": "310",
"advanced_configuration.0.sample_size_bi_connector": "110",
"advanced_configuration.0.transaction_lifetime_limit_seconds": "300",
"advanced_configuration.0.change_stream_options_pre_and_post_images_expire_after_seconds": changeStreamOptions},
advancedConfig,
resource.TestCheckResourceAttrSet(dataSourcePluralName, "results.#"),
resource.TestCheckResourceAttrSet(dataSourcePluralName, "results.0.replication_specs.#"),
resource.TestCheckResourceAttrSet(dataSourcePluralName, "results.0.name"))
resource.TestCheckResourceAttrSet(dataSourcePluralName, "results.0.name"),
)
}

func configAdvancedDefaultWrite(projectID, clusterName string, p *admin20240530.ClusterDescriptionProcessArgs) string {
Expand Down
Loading