Skip to content

Commit

Permalink
feat: Adds is_slow_operation_thresholding_enabled attribute to `mon…
Browse files Browse the repository at this point in the history
…godbatlas_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)
  • Loading branch information
EspenAlbert authored Oct 17, 2024
1 parent ac412ea commit e343109
Show file tree
Hide file tree
Showing 11 changed files with 149 additions and 42 deletions.
11 changes: 11 additions & 0 deletions .changelog/2698.txt
Original file line number Diff line number Diff line change
@@ -0,0 +1,11 @@
```release-note:enhancement
resource/mongodbatlas_project: Adds `is_slow_operation_thresholding_enabled` attribute
```

```release-note:enhancement
data-source/mongodbatlas_project: Adds `is_slow_operation_thresholding_enabled` attribute
```

```release-note:enhancement
data-source/mongodbatlas_projects: Adds `is_slow_operation_thresholding_enabled` attribute
```
1 change: 1 addition & 0 deletions docs/data-sources/project.md
Original file line number Diff line number Diff line change
Expand Up @@ -90,6 +90,7 @@ In addition to all arguments above, the following attributes are exported:
* `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.
* `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).
* `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).
* `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.


### Teams
Expand Down
2 changes: 1 addition & 1 deletion docs/data-sources/projects.md
Original file line number Diff line number Diff line change
Expand Up @@ -65,7 +65,7 @@ data "mongodbatlas_projects" "test" {
* `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.
* `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).
* `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).

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

### Teams

Expand Down
2 changes: 2 additions & 0 deletions docs/resources/project.md
Original file line number Diff line number Diff line change
Expand Up @@ -41,6 +41,7 @@ resource "mongodbatlas_project" "test" {
is_performance_advisor_enabled = true
is_realtime_performance_panel_enabled = true
is_schema_advisor_enabled = true
is_slow_operation_thresholding_enabled = true
}
```

Expand All @@ -58,6 +59,7 @@ resource "mongodbatlas_project" "test" {
* `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.
* `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.
* `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).
* `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.

### Tags

Expand Down
6 changes: 5 additions & 1 deletion internal/service/project/data_source_project.go
Original file line number Diff line number Diff line change
Expand Up @@ -49,6 +49,7 @@ type TFProjectDSModel struct {
IsPerformanceAdvisorEnabled types.Bool `tfsdk:"is_performance_advisor_enabled"`
IsExtendedStorageSizesEnabled types.Bool `tfsdk:"is_extended_storage_sizes_enabled"`
IsDataExplorerEnabled types.Bool `tfsdk:"is_data_explorer_enabled"`
IsSlowOperationThresholdingEnabled types.Bool `tfsdk:"is_slow_operation_thresholding_enabled"`
}

type TFTeamDSModel struct {
Expand Down Expand Up @@ -101,6 +102,9 @@ func (d *projectDS) Schema(ctx context.Context, req datasource.SchemaRequest, re
"is_schema_advisor_enabled": schema.BoolAttribute{
Computed: true,
},
"is_slow_operation_thresholding_enabled": schema.BoolAttribute{
Computed: true,
},
"region_usage_restrictions": schema.StringAttribute{
Computed: true,
},
Expand Down Expand Up @@ -209,7 +213,7 @@ func (d *projectDS) Read(ctx context.Context, req datasource.ReadRequest, resp *
}
}

projectProps, err := GetProjectPropsFromAPI(ctx, connV2.ProjectsApi, connV2.TeamsApi, project.GetId())
projectProps, err := GetProjectPropsFromAPI(ctx, connV2.ProjectsApi, connV2.TeamsApi, connV2.PerformanceAdvisorApi, project.GetId())
if err != nil {
resp.Diagnostics.AddError("error when getting project properties", fmt.Sprintf(ErrorProjectRead, project.GetId(), err.Error()))
return
Expand Down
5 changes: 4 additions & 1 deletion internal/service/project/data_source_projects.go
Original file line number Diff line number Diff line change
Expand Up @@ -97,6 +97,9 @@ func (d *ProjectsDS) Schema(ctx context.Context, req datasource.SchemaRequest, r
"is_schema_advisor_enabled": schema.BoolAttribute{
Computed: true,
},
"is_slow_operation_thresholding_enabled": schema.BoolAttribute{
Computed: true,
},
"region_usage_restrictions": schema.StringAttribute{
Computed: true,
},
Expand Down Expand Up @@ -210,7 +213,7 @@ func populateProjectsDataSourceModel(ctx context.Context, connV2 *admin.APIClien
results := make([]*TFProjectDSModel, 0, len(input))
for i := range input {
project := input[i]
projectProps, err := GetProjectPropsFromAPI(ctx, connV2.ProjectsApi, connV2.TeamsApi, project.GetId())
projectProps, err := GetProjectPropsFromAPI(ctx, connV2.ProjectsApi, connV2.TeamsApi, connV2.PerformanceAdvisorApi, project.GetId())
if err == nil { // if the project is still valid, e.g. could have just been deleted
projectModel, diags := NewTFProjectDataSourceModel(ctx, &project, *projectProps)
diagnostics = append(diagnostics, diags...)
Expand Down
24 changes: 13 additions & 11 deletions internal/service/project/model_project.go
Original file line number Diff line number Diff line change
Expand Up @@ -36,6 +36,7 @@ func NewTFProjectDataSourceModel(ctx context.Context, project *admin.Group, proj
Limits: NewTFLimitsDataSourceModel(ctx, projectProps.Limits),
IPAddresses: ipAddressesModel,
Tags: NewTFTags(project.GetTags()),
IsSlowOperationThresholdingEnabled: types.BoolValue(projectProps.IsSlowOperationThresholdingEnabled),
}, nil
}

Expand Down Expand Up @@ -100,17 +101,18 @@ func NewTFProjectResourceModel(ctx context.Context, projectRes *admin.Group, pro
return nil, diags
}
projectPlan := TFProjectRSModel{
ID: types.StringValue(projectRes.GetId()),
Name: types.StringValue(projectRes.Name),
OrgID: types.StringValue(projectRes.OrgId),
ClusterCount: types.Int64Value(projectRes.ClusterCount),
RegionUsageRestrictions: types.StringPointerValue(projectRes.RegionUsageRestrictions),
Created: types.StringValue(conversion.TimeToString(projectRes.Created)),
WithDefaultAlertsSettings: types.BoolPointerValue(projectRes.WithDefaultAlertsSettings),
Teams: newTFTeamsResourceModel(ctx, projectProps.Teams),
Limits: newTFLimitsResourceModel(ctx, projectProps.Limits),
IPAddresses: ipAddressesModel,
Tags: NewTFTags(projectRes.GetTags()),
ID: types.StringValue(projectRes.GetId()),
Name: types.StringValue(projectRes.Name),
OrgID: types.StringValue(projectRes.OrgId),
ClusterCount: types.Int64Value(projectRes.ClusterCount),
RegionUsageRestrictions: types.StringPointerValue(projectRes.RegionUsageRestrictions),
Created: types.StringValue(conversion.TimeToString(projectRes.Created)),
WithDefaultAlertsSettings: types.BoolPointerValue(projectRes.WithDefaultAlertsSettings),
Teams: newTFTeamsResourceModel(ctx, projectProps.Teams),
Limits: newTFLimitsResourceModel(ctx, projectProps.Limits),
IPAddresses: ipAddressesModel,
Tags: NewTFTags(projectRes.GetTags()),
IsSlowOperationThresholdingEnabled: types.BoolValue(projectProps.IsSlowOperationThresholdingEnabled),
}

projectSettings := projectProps.Settings
Expand Down
11 changes: 8 additions & 3 deletions internal/service/project/model_project_test.go
Original file line number Diff line number Diff line change
Expand Up @@ -231,6 +231,7 @@ func TestProjectDataSourceSDKToDataSourceTFModel(t *testing.T) {
IsPerformanceAdvisorEnabled: types.BoolValue(true),
IsRealtimePerformancePanelEnabled: types.BoolValue(true),
IsSchemaAdvisorEnabled: types.BoolValue(true),
IsSlowOperationThresholdingEnabled: types.BoolValue(false),
Teams: teamsDSTF,
Limits: limitsTF,
IPAddresses: ipAddressesTF,
Expand All @@ -246,9 +247,10 @@ func TestProjectDataSourceSDKToDataSourceTFModel(t *testing.T) {
Results: &teamRolesSDK,
TotalCount: conversion.IntPtr(1),
},
Settings: &projectSettingsSDK,
IPAddresses: &IPAddressesSDK,
Limits: limitsSDK,
Settings: &projectSettingsSDK,
IPAddresses: &IPAddressesSDK,
Limits: limitsSDK,
IsSlowOperationThresholdingEnabled: true,
},
expectedTFModel: project.TFProjectDSModel{

Expand All @@ -264,6 +266,7 @@ func TestProjectDataSourceSDKToDataSourceTFModel(t *testing.T) {
IsPerformanceAdvisorEnabled: types.BoolValue(true),
IsRealtimePerformancePanelEnabled: types.BoolValue(true),
IsSchemaAdvisorEnabled: types.BoolValue(true),
IsSlowOperationThresholdingEnabled: types.BoolValue(true),
Teams: teamsDSTF,
Limits: limitsTF,
IPAddresses: ipAddressesTF,
Expand Down Expand Up @@ -315,6 +318,7 @@ func TestProjectDataSourceSDKToResourceTFModel(t *testing.T) {
IsPerformanceAdvisorEnabled: types.BoolValue(true),
IsRealtimePerformancePanelEnabled: types.BoolValue(true),
IsSchemaAdvisorEnabled: types.BoolValue(true),
IsSlowOperationThresholdingEnabled: types.BoolValue(false),
Teams: teamsTFSet,
Limits: limitsTFSet,
IPAddresses: ipAddressesTF,
Expand Down Expand Up @@ -347,6 +351,7 @@ func TestProjectDataSourceSDKToResourceTFModel(t *testing.T) {
IsPerformanceAdvisorEnabled: types.BoolValue(true),
IsRealtimePerformancePanelEnabled: types.BoolValue(true),
IsSchemaAdvisorEnabled: types.BoolValue(true),
IsSlowOperationThresholdingEnabled: types.BoolValue(false),
Teams: teamsTFSet,
Limits: limitsTFSet,
IPAddresses: ipAddressesTF,
Expand Down
Loading

0 comments on commit e343109

Please sign in to comment.