Skip to content

Commit e343109

Browse files
authored
feat: Adds is_slow_operation_thresholding_enabled attribute to mongodbatlas_project (#2698)
* feat: Initial support for is_slow_operation_thresholding_enabled * test: fix test cases * chore: add changelog entry * test: Add extra check for plural data source * refactor: only set SetSlowOperationThresholding once during update * chore: fix lint error * fix: need to set SetSlowOperationThresholding before reading project props from API * chore: address PR comment * doc: Add documentation for `is_slow_operation_thresholding_enabled` to project (#2700)
1 parent ac412ea commit e343109

File tree

11 files changed

+149
-42
lines changed

11 files changed

+149
-42
lines changed

.changelog/2698.txt

Lines changed: 11 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,11 @@
1+
```release-note:enhancement
2+
resource/mongodbatlas_project: Adds `is_slow_operation_thresholding_enabled` attribute
3+
```
4+
5+
```release-note:enhancement
6+
data-source/mongodbatlas_project: Adds `is_slow_operation_thresholding_enabled` attribute
7+
```
8+
9+
```release-note:enhancement
10+
data-source/mongodbatlas_projects: Adds `is_slow_operation_thresholding_enabled` attribute
11+
```

docs/data-sources/project.md

Lines changed: 1 addition & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -90,6 +90,7 @@ In addition to all arguments above, the following attributes are exported:
9090
* `is_realtime_performance_panel_enabled` - Flag that indicates whether to enable Real Time Performance Panel for the project. If enabled, you can see real time metrics from your MongoDB database.
9191
* `is_schema_advisor_enabled` - Flag that indicates whether to enable Schema Advisor for the project. If enabled, you receive customized recommendations to optimize your data model and enhance performance. Disable this setting to disable schema suggestions in the [Performance Advisor](https://www.mongodb.com/docs/atlas/performance-advisor/#std-label-performance-advisor) and the [Data Explorer](https://www.mongodb.com/docs/atlas/atlas-ui/#std-label-atlas-ui).
9292
* `region_usage_restrictions` - If GOV_REGIONS_ONLY the project can be used for government regions only, otherwise defaults to standard regions. For more information see [MongoDB Atlas for Government](https://www.mongodb.com/docs/atlas/government/api/#creating-a-project).
93+
* `is_slow_operation_thresholding_enabled` - Flag that enables MongoDB Cloud to use its slow operation threshold for the specified project. The threshold determines which operations the Performance Advisor and Query Profiler considers slow. When enabled, MongoDB Cloud uses the average execution time for operations on your cluster to determine slow-running queries. As a result, the threshold is more pertinent to your cluster workload. The slow operation threshold is enabled by default for dedicated clusters (M10+). When disabled, MongoDB Cloud considers any operation that takes longer than 100 milliseconds to be slow. To use this resource, the requesting API Key must have the Project Owner role.
9394

9495

9596
### Teams

docs/data-sources/projects.md

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -65,7 +65,7 @@ data "mongodbatlas_projects" "test" {
6565
* `is_realtime_performance_panel_enabled` - Flag that indicates whether to enable Real Time Performance Panel for the project. If enabled, you can see real time metrics from your MongoDB database.
6666
* `is_schema_advisor_enabled` - Flag that indicates whether to enable Schema Advisor for the project. If enabled, you receive customized recommendations to optimize your data model and enhance performance. Disable this setting to disable schema suggestions in the [Performance Advisor](https://www.mongodb.com/docs/atlas/performance-advisor/#std-label-performance-advisor) and the [Data Explorer](https://www.mongodb.com/docs/atlas/atlas-ui/#std-label-atlas-ui).
6767
* `region_usage_restrictions` - If GOV_REGIONS_ONLY the project can be used for government regions only, otherwise defaults to standard regions. For more information see [MongoDB Atlas for Government](https://www.mongodb.com/docs/atlas/government/api/#creating-a-project).
68-
68+
* `is_slow_operation_thresholding_enabled` - Flag that enables MongoDB Cloud to use its slow operation threshold for the specified project. The threshold determines which operations the Performance Advisor and Query Profiler considers slow. When enabled, MongoDB Cloud uses the average execution time for operations on your cluster to determine slow-running queries. As a result, the threshold is more pertinent to your cluster workload. The slow operation threshold is enabled by default for dedicated clusters (M10+). When disabled, MongoDB Cloud considers any operation that takes longer than 100 milliseconds to be slow. To use this resource, the requesting API Key must have the Project Owner role.
6969

7070
### Teams
7171

docs/resources/project.md

Lines changed: 2 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -41,6 +41,7 @@ resource "mongodbatlas_project" "test" {
4141
is_performance_advisor_enabled = true
4242
is_realtime_performance_panel_enabled = true
4343
is_schema_advisor_enabled = true
44+
is_slow_operation_thresholding_enabled = true
4445
}
4546
```
4647

@@ -58,6 +59,7 @@ resource "mongodbatlas_project" "test" {
5859
* `is_realtime_performance_panel_enabled` - (Optional) Flag that indicates whether to enable Real Time Performance Panel for the project. If enabled, you can see real time metrics from your MongoDB database. By default, this flag is set to true.
5960
* `is_schema_advisor_enabled` - (Optional) Flag that indicates whether to enable Schema Advisor for the project. If enabled, you receive customized recommendations to optimize your data model and enhance performance. Disable this setting to disable schema suggestions in the [Performance Advisor](https://www.mongodb.com/docs/atlas/performance-advisor/#std-label-performance-advisor) and the [Data Explorer](https://www.mongodb.com/docs/atlas/atlas-ui/#std-label-atlas-ui). By default, this flag is set to true.
6061
* `region_usage_restrictions` - (Optional - set value to GOV_REGIONS_ONLY) Designates that this project can be used for government regions only. If not set the project will default to standard regions. You cannot deploy clusters across government and standard regions in the same project. AWS is the only cloud provider for AtlasGov. For more information see [MongoDB Atlas for Government](https://www.mongodb.com/docs/atlas/government/api/#creating-a-project).
62+
* `is_slow_operation_thresholding_enabled` - (Optional) Flag that enables MongoDB Cloud to use its slow operation threshold for the specified project. The threshold determines which operations the Performance Advisor and Query Profiler considers slow. When enabled, MongoDB Cloud uses the average execution time for operations on your cluster to determine slow-running queries. As a result, the threshold is more pertinent to your cluster workload. The slow operation threshold is enabled by default for dedicated clusters (M10+). When disabled, MongoDB Cloud considers any operation that takes longer than 100 milliseconds to be slow. To use this resource, the requesting API Key must have the Project Owner role.
6163

6264
### Tags
6365

internal/service/project/data_source_project.go

Lines changed: 5 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -49,6 +49,7 @@ type TFProjectDSModel struct {
4949
IsPerformanceAdvisorEnabled types.Bool `tfsdk:"is_performance_advisor_enabled"`
5050
IsExtendedStorageSizesEnabled types.Bool `tfsdk:"is_extended_storage_sizes_enabled"`
5151
IsDataExplorerEnabled types.Bool `tfsdk:"is_data_explorer_enabled"`
52+
IsSlowOperationThresholdingEnabled types.Bool `tfsdk:"is_slow_operation_thresholding_enabled"`
5253
}
5354

5455
type TFTeamDSModel struct {
@@ -101,6 +102,9 @@ func (d *projectDS) Schema(ctx context.Context, req datasource.SchemaRequest, re
101102
"is_schema_advisor_enabled": schema.BoolAttribute{
102103
Computed: true,
103104
},
105+
"is_slow_operation_thresholding_enabled": schema.BoolAttribute{
106+
Computed: true,
107+
},
104108
"region_usage_restrictions": schema.StringAttribute{
105109
Computed: true,
106110
},
@@ -209,7 +213,7 @@ func (d *projectDS) Read(ctx context.Context, req datasource.ReadRequest, resp *
209213
}
210214
}
211215

212-
projectProps, err := GetProjectPropsFromAPI(ctx, connV2.ProjectsApi, connV2.TeamsApi, project.GetId())
216+
projectProps, err := GetProjectPropsFromAPI(ctx, connV2.ProjectsApi, connV2.TeamsApi, connV2.PerformanceAdvisorApi, project.GetId())
213217
if err != nil {
214218
resp.Diagnostics.AddError("error when getting project properties", fmt.Sprintf(ErrorProjectRead, project.GetId(), err.Error()))
215219
return

internal/service/project/data_source_projects.go

Lines changed: 4 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -97,6 +97,9 @@ func (d *ProjectsDS) Schema(ctx context.Context, req datasource.SchemaRequest, r
9797
"is_schema_advisor_enabled": schema.BoolAttribute{
9898
Computed: true,
9999
},
100+
"is_slow_operation_thresholding_enabled": schema.BoolAttribute{
101+
Computed: true,
102+
},
100103
"region_usage_restrictions": schema.StringAttribute{
101104
Computed: true,
102105
},
@@ -210,7 +213,7 @@ func populateProjectsDataSourceModel(ctx context.Context, connV2 *admin.APIClien
210213
results := make([]*TFProjectDSModel, 0, len(input))
211214
for i := range input {
212215
project := input[i]
213-
projectProps, err := GetProjectPropsFromAPI(ctx, connV2.ProjectsApi, connV2.TeamsApi, project.GetId())
216+
projectProps, err := GetProjectPropsFromAPI(ctx, connV2.ProjectsApi, connV2.TeamsApi, connV2.PerformanceAdvisorApi, project.GetId())
214217
if err == nil { // if the project is still valid, e.g. could have just been deleted
215218
projectModel, diags := NewTFProjectDataSourceModel(ctx, &project, *projectProps)
216219
diagnostics = append(diagnostics, diags...)

internal/service/project/model_project.go

Lines changed: 13 additions & 11 deletions
Original file line numberDiff line numberDiff line change
@@ -36,6 +36,7 @@ func NewTFProjectDataSourceModel(ctx context.Context, project *admin.Group, proj
3636
Limits: NewTFLimitsDataSourceModel(ctx, projectProps.Limits),
3737
IPAddresses: ipAddressesModel,
3838
Tags: NewTFTags(project.GetTags()),
39+
IsSlowOperationThresholdingEnabled: types.BoolValue(projectProps.IsSlowOperationThresholdingEnabled),
3940
}, nil
4041
}
4142

@@ -100,17 +101,18 @@ func NewTFProjectResourceModel(ctx context.Context, projectRes *admin.Group, pro
100101
return nil, diags
101102
}
102103
projectPlan := TFProjectRSModel{
103-
ID: types.StringValue(projectRes.GetId()),
104-
Name: types.StringValue(projectRes.Name),
105-
OrgID: types.StringValue(projectRes.OrgId),
106-
ClusterCount: types.Int64Value(projectRes.ClusterCount),
107-
RegionUsageRestrictions: types.StringPointerValue(projectRes.RegionUsageRestrictions),
108-
Created: types.StringValue(conversion.TimeToString(projectRes.Created)),
109-
WithDefaultAlertsSettings: types.BoolPointerValue(projectRes.WithDefaultAlertsSettings),
110-
Teams: newTFTeamsResourceModel(ctx, projectProps.Teams),
111-
Limits: newTFLimitsResourceModel(ctx, projectProps.Limits),
112-
IPAddresses: ipAddressesModel,
113-
Tags: NewTFTags(projectRes.GetTags()),
104+
ID: types.StringValue(projectRes.GetId()),
105+
Name: types.StringValue(projectRes.Name),
106+
OrgID: types.StringValue(projectRes.OrgId),
107+
ClusterCount: types.Int64Value(projectRes.ClusterCount),
108+
RegionUsageRestrictions: types.StringPointerValue(projectRes.RegionUsageRestrictions),
109+
Created: types.StringValue(conversion.TimeToString(projectRes.Created)),
110+
WithDefaultAlertsSettings: types.BoolPointerValue(projectRes.WithDefaultAlertsSettings),
111+
Teams: newTFTeamsResourceModel(ctx, projectProps.Teams),
112+
Limits: newTFLimitsResourceModel(ctx, projectProps.Limits),
113+
IPAddresses: ipAddressesModel,
114+
Tags: NewTFTags(projectRes.GetTags()),
115+
IsSlowOperationThresholdingEnabled: types.BoolValue(projectProps.IsSlowOperationThresholdingEnabled),
114116
}
115117

116118
projectSettings := projectProps.Settings

internal/service/project/model_project_test.go

Lines changed: 8 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -231,6 +231,7 @@ func TestProjectDataSourceSDKToDataSourceTFModel(t *testing.T) {
231231
IsPerformanceAdvisorEnabled: types.BoolValue(true),
232232
IsRealtimePerformancePanelEnabled: types.BoolValue(true),
233233
IsSchemaAdvisorEnabled: types.BoolValue(true),
234+
IsSlowOperationThresholdingEnabled: types.BoolValue(false),
234235
Teams: teamsDSTF,
235236
Limits: limitsTF,
236237
IPAddresses: ipAddressesTF,
@@ -246,9 +247,10 @@ func TestProjectDataSourceSDKToDataSourceTFModel(t *testing.T) {
246247
Results: &teamRolesSDK,
247248
TotalCount: conversion.IntPtr(1),
248249
},
249-
Settings: &projectSettingsSDK,
250-
IPAddresses: &IPAddressesSDK,
251-
Limits: limitsSDK,
250+
Settings: &projectSettingsSDK,
251+
IPAddresses: &IPAddressesSDK,
252+
Limits: limitsSDK,
253+
IsSlowOperationThresholdingEnabled: true,
252254
},
253255
expectedTFModel: project.TFProjectDSModel{
254256

@@ -264,6 +266,7 @@ func TestProjectDataSourceSDKToDataSourceTFModel(t *testing.T) {
264266
IsPerformanceAdvisorEnabled: types.BoolValue(true),
265267
IsRealtimePerformancePanelEnabled: types.BoolValue(true),
266268
IsSchemaAdvisorEnabled: types.BoolValue(true),
269+
IsSlowOperationThresholdingEnabled: types.BoolValue(true),
267270
Teams: teamsDSTF,
268271
Limits: limitsTF,
269272
IPAddresses: ipAddressesTF,
@@ -315,6 +318,7 @@ func TestProjectDataSourceSDKToResourceTFModel(t *testing.T) {
315318
IsPerformanceAdvisorEnabled: types.BoolValue(true),
316319
IsRealtimePerformancePanelEnabled: types.BoolValue(true),
317320
IsSchemaAdvisorEnabled: types.BoolValue(true),
321+
IsSlowOperationThresholdingEnabled: types.BoolValue(false),
318322
Teams: teamsTFSet,
319323
Limits: limitsTFSet,
320324
IPAddresses: ipAddressesTF,
@@ -347,6 +351,7 @@ func TestProjectDataSourceSDKToResourceTFModel(t *testing.T) {
347351
IsPerformanceAdvisorEnabled: types.BoolValue(true),
348352
IsRealtimePerformancePanelEnabled: types.BoolValue(true),
349353
IsSchemaAdvisorEnabled: types.BoolValue(true),
354+
IsSlowOperationThresholdingEnabled: types.BoolValue(false),
350355
Teams: teamsTFSet,
351356
Limits: limitsTFSet,
352357
IPAddresses: ipAddressesTF,

0 commit comments

Comments
 (0)