Skip to content

feat: Adds support for send_collection_latency_metrics and send_database_metrics for Datadog integrations in mongodbatlas_third_party_integration #3259

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

Merged
merged 5 commits into from
Apr 11, 2025
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
11 changes: 11 additions & 0 deletions .changelog/3259.txt
Original file line number Diff line number Diff line change
@@ -0,0 +1,11 @@
```release-note:enhancement
resource/mongodbatlas_third_party_integration: Adds support for `send_collection_latency_metrics` and `send_database_metrics` for Datadog integrations
```

```release-note:enhancement
data-source/mongodbatlas_third_party_integration: Adds support for `send_collection_latency_metrics` and `send_database_metrics` for Datadog integrations
```

```release-note:enhancement
data-source/mongodbatlas_third_party_integrations: Adds support for `send_collection_latency_metrics` and `send_database_metrics` for Datadog integrations
```
2 changes: 2 additions & 0 deletions docs/data-sources/third_party_integration.md
Original file line number Diff line number Diff line change
Expand Up @@ -46,6 +46,8 @@ Additional values based on Type
* `DATADOG`
* `api_key` - Your API Key.
* `region` - Two-letter code that indicates which API URL to use. See the `region` response field of [MongoDB API Third-Party Service Integration documentation](https://www.mongodb.com/docs/atlas/reference/api-resources-spec/v2/#tag/Third-Party-Integrations/operation/getThirdPartyIntegration) for more details. Datadog will use "US" by default.
* `send_collection_latency_metrics` - Toggle sending collection latency metrics that includes database names and collection name sand latency metrics on reads, writes, commands, and transactions.
* `send_database_metrics` - Toggle sending database metrics that includes database names and metrics on the number of collections, storage size, and index size.
* `OPS_GENIE`
* `api_key` - Your API Key.
* `region` - Two-letter code that indicates which API URL to use. See the `region` response field of [MongoDB API Third-Party Service Integration documentation](https://www.mongodb.com/docs/atlas/reference/api-resources-spec/v2/#tag/Third-Party-Integrations/operation/getThirdPartyIntegration) for more details. Opsgenie will use US by default.
Expand Down
2 changes: 2 additions & 0 deletions docs/data-sources/third_party_integrations.md
Original file line number Diff line number Diff line change
Expand Up @@ -60,6 +60,8 @@ Additional values based on Type
* `DATADOG`
* `api_key` - Your API Key.
* `region` - Two-letter code that indicates which API URL to use. See the `region` response field of [MongoDB API Third-Party Service Integration documentation](https://www.mongodb.com/docs/atlas/reference/api-resources-spec/v2/#tag/Third-Party-Integrations/operation/getThirdPartyIntegration) for more details. Datadog will use "US" by default.
* `send_collection_latency_metrics` - Toggle sending collection latency metrics that includes database names and collection names and latency metrics on reads, writes, commands, and transactions.
* `send_database_metrics` - Toggle sending database metrics that includes database names and metrics on the number of collections, storage size, and index size.
* `OPS_GENIE`
* `api_key` - Your API Key.
* `region` - Two-letter code that indicates which API URL to use. See the `region` response field of [MongoDB API Third-Party Service Integration documentation](https://www.mongodb.com/docs/atlas/reference/api-resources-spec/v2/#tag/Third-Party-Integrations/operation/getThirdPartyIntegration) for more details. Opsgenie will use US by default.
Expand Down
4 changes: 4 additions & 0 deletions docs/resources/third_party_integration.md
Original file line number Diff line number Diff line change
Expand Up @@ -43,6 +43,8 @@ resource "mongodbatlas_third_party_integration" "test_datadog" {
* `DATADOG`
* `api_key` - Your API Key.
* `region` (Required) - Two-letter code that indicates which API URL to use. See the `region` request parameter of [MongoDB API Third-Party Service Integration documentation](https://www.mongodb.com/docs/atlas/reference/api-resources-spec/v2/#tag/Third-Party-Integrations/operation/createThirdPartyIntegration) for more details. Datadog will use "US" by default.
* `send_collection_latency_metrics` - Toggle sending collection latency metrics that includes database names and collection names and latency metrics on reads, writes, commands, and transactions. Default: `false`.
* `send_database_metrics` - Toggle sending database metrics that includes database names and metrics on the number of collections, storage size, and index size. Default: `false`.
* `OPS_GENIE`
* `api_key` - Your API Key.
* `region` (Required) - Two-letter code that indicates which API URL to use. See the `region` request parameter of [MongoDB API Third-Party Service Integration documentation](https://www.mongodb.com/docs/atlas/reference/api-resources-spec/v2/#tag/Third-Party-Integrations/operation/createThirdPartyIntegration) for more details. OpsGenie will use "US" by default.
Expand All @@ -60,6 +62,8 @@ resource "mongodbatlas_third_party_integration" "test_datadog" {
* `service_discovery` - Indicates which service discovery method is used, either file or http.
* `enabled` - Whether your cluster has Prometheus enabled.

-> **NOTE:** For certain attributes with default values, it's recommended to explicitly set them back to their default instead of removing them from the configuration. For example, if `send_collection_latency_metrics` is set to `true` and you want to revert to the default (`false`), set it to `false` rather than removing it.

## Attributes Reference

* `id` - Unique identifier of the integration.
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -3,4 +3,7 @@ resource "mongodbatlas_third_party_integration" "test-datadog" {
type = "DATADOG"
api_key = var.datadog_api_key
region = var.datadog_region

send_collection_latency_metrics = var.send_collection_latency_metrics
send_database_metrics = var.send_database_metrics
}
Original file line number Diff line number Diff line change
Expand Up @@ -24,3 +24,15 @@ variable "cluster_name" {
default = "datadog-test-cluster"
type = string
}

variable "send_collection_latency_metrics" {
description = "Send collection latency metrics (only for Datadog integrations)"
default = false
type = bool
}

variable "send_database_metrics" {
description = "Send database metrics (only for Datadog integrations)"
default = false
type = bool
}
Original file line number Diff line number Diff line change
Expand Up @@ -6,6 +6,7 @@ import (

"github.com/hashicorp/terraform-plugin-sdk/v2/diag"
"github.com/hashicorp/terraform-plugin-sdk/v2/helper/schema"

"github.com/mongodb/terraform-provider-mongodbatlas/internal/config"
)

Expand Down Expand Up @@ -85,21 +86,29 @@ func thirdPartyIntegrationSchema() *schema.Resource {
"microsoft_teams_webhook_url": {
Type: schema.TypeString,
Sensitive: true,
Optional: true,
Computed: true,
},
"user_name": {
Type: schema.TypeString,
Sensitive: true,
Optional: true,
Computed: true,
},
"service_discovery": {
Type: schema.TypeString,
Sensitive: true,
Optional: true,
Computed: true,
},
"enabled": {
Type: schema.TypeBool,
Optional: true,
Computed: true,
},
"send_collection_latency_metrics": {
Type: schema.TypeBool,
Computed: true,
},
"send_database_metrics": {
Type: schema.TypeBool,
Computed: true,
},
},
}
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -4,12 +4,14 @@ import (
"context"
"fmt"

"go.mongodb.org/atlas-sdk/v20250312002/admin"

"github.com/hashicorp/terraform-plugin-sdk/v2/diag"
"github.com/hashicorp/terraform-plugin-sdk/v2/helper/id"
"github.com/hashicorp/terraform-plugin-sdk/v2/helper/schema"

"github.com/mongodb/terraform-provider-mongodbatlas/internal/common/conversion"
"github.com/mongodb/terraform-provider-mongodbatlas/internal/config"
"go.mongodb.org/atlas-sdk/v20250312002/admin"
)

func PluralDataSource() *schema.Resource {
Expand Down Expand Up @@ -89,23 +91,31 @@ func integrationToSchema(d *schema.ResourceData, integration *admin.ThirdPartyIn
if integrationSchema.Url == nil {
integrationSchema.Url = integration.Url
}
if integrationSchema.SendCollectionLatencyMetrics == nil {
integrationSchema.SendCollectionLatencyMetrics = integration.SendCollectionLatencyMetrics
}
if integrationSchema.SendDatabaseMetrics == nil {
integrationSchema.SendDatabaseMetrics = integration.SendDatabaseMetrics
}

out := map[string]any{
"id": integration.Id,
"type": integration.Type,
"api_key": integrationSchema.ApiKey,
"region": integration.Region,
"service_key": integrationSchema.ServiceKey,
"team_name": integration.TeamName,
"channel_name": integration.ChannelName,
"routing_key": integration.RoutingKey,
"url": integrationSchema.Url,
"secret": integrationSchema.Secret,
"microsoft_teams_webhook_url": integrationSchema.MicrosoftTeamsWebhookUrl,
"user_name": integration.Username,
"password": integrationSchema.Password,
"service_discovery": integration.ServiceDiscovery,
"enabled": integration.Enabled,
"id": integration.Id,
Copy link
Collaborator

Choose a reason for hiding this comment

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

[nit] Feels very verbose this function. Seems like we could do this inline

"type": integration.Type,
"api_key": integrationSchema.ApiKey,
"region": integration.Region,
"service_key": integrationSchema.ServiceKey,
"team_name": integration.TeamName,
"channel_name": integration.ChannelName,
"routing_key": integration.RoutingKey,
"url": integrationSchema.Url,
"secret": integrationSchema.Secret,
"microsoft_teams_webhook_url": integrationSchema.MicrosoftTeamsWebhookUrl,
"user_name": integration.Username,
"password": integrationSchema.Password,
"service_discovery": integration.ServiceDiscovery,
"enabled": integration.Enabled,
"send_collection_latency_metrics": integration.SendCollectionLatencyMetrics,
"send_database_metrics": integration.SendDatabaseMetrics,
}

// removing optional empty values, terraform complains about unexpected values even though they're empty
Expand Down Expand Up @@ -183,6 +193,14 @@ func schemaToIntegration(in *schema.ResourceData) (out *admin.ThirdPartyIntegrat
out.Enabled = admin.PtrBool(enabled.(bool))
}

if sendCollectionLatencyMetrics, ok := in.GetOk("send_collection_latency_metrics"); ok {
out.SendCollectionLatencyMetrics = admin.PtrBool(sendCollectionLatencyMetrics.(bool))
}

if sendDatabaseMetrics, ok := in.GetOk("send_database_metrics"); ok {
out.SendDatabaseMetrics = admin.PtrBool(sendDatabaseMetrics.(bool))
}

return out
}

Expand Down Expand Up @@ -236,4 +254,12 @@ func updateIntegrationFromSchema(d *schema.ResourceData, integration *admin.Thir
if d.HasChange("enabled") {
integration.Enabled = admin.PtrBool(d.Get("enabled").(bool))
}

if d.HasChange("send_collection_latency_metrics") {
integration.SendCollectionLatencyMetrics = admin.PtrBool(d.Get("send_collection_latency_metrics").(bool))
}

if d.HasChange("send_database_metrics") {
integration.SendDatabaseMetrics = admin.PtrBool(d.Get("send_database_metrics").(bool))
}
}
Original file line number Diff line number Diff line change
Expand Up @@ -8,6 +8,7 @@ import (
"github.com/hashicorp/go-cty/cty"
"github.com/hashicorp/terraform-plugin-sdk/v2/diag"
"github.com/hashicorp/terraform-plugin-sdk/v2/helper/schema"

"github.com/mongodb/terraform-provider-mongodbatlas/internal/common/validate"
"github.com/mongodb/terraform-provider-mongodbatlas/internal/config"
)
Expand Down Expand Up @@ -129,6 +130,16 @@ func Resource() *schema.Resource {
Computed: true,
Optional: true,
},
"send_collection_latency_metrics": {
Type: schema.TypeBool,
Computed: true,
Optional: true,
Comment on lines +135 to +136
Copy link
Member

Choose a reason for hiding this comment

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

Always returned by the API right?

Copy link
Collaborator Author

Choose a reason for hiding this comment

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

yes

},
"send_database_metrics": {
Type: schema.TypeBool,
Computed: true,
Optional: true,
},
},
}
}
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -7,6 +7,7 @@ import (

"github.com/hashicorp/terraform-plugin-testing/helper/resource"
"github.com/hashicorp/terraform-plugin-testing/terraform"

"github.com/mongodb/terraform-provider-mongodbatlas/internal/testutil/acc"
)

Expand Down Expand Up @@ -178,23 +179,57 @@ func datadogTest(tb testing.TB) *resource.TestCase {
CheckDestroy: checkDestroy,
Steps: []resource.TestStep{
{
Config: configDatadog(projectID, apiKey, "US"),
Config: configDatadog(projectID, apiKey, "US", false, false, false),
Check: resource.ComposeAggregateTestCheckFunc(
checkExists(resourceName),
resource.TestCheckResourceAttr(resourceName, "type", intType),
resource.TestCheckResourceAttr(resourceName, "api_key", apiKey),
resource.TestCheckResourceAttr(resourceName, "region", region),
resource.TestCheckResourceAttr(resourceName, "send_collection_latency_metrics", "false"),
resource.TestCheckResourceAttr(resourceName, "send_database_metrics", "false"),
resource.TestCheckResourceAttr(dataSourceName, "type", intType),
resource.TestCheckResourceAttr(dataSourceName, "region", region),
resource.TestCheckResourceAttr(dataSourceName, "send_collection_latency_metrics", "false"),
resource.TestCheckResourceAttr(dataSourceName, "send_database_metrics", "false"),
),
},
{
Config: configDatadog(projectID, apiKey, "US", true, true, false),
Check: resource.ComposeAggregateTestCheckFunc(
checkExists(resourceName),
resource.TestCheckResourceAttr(resourceName, "type", intType),
resource.TestCheckResourceAttr(resourceName, "api_key", apiKey),
resource.TestCheckResourceAttr(resourceName, "region", region),
resource.TestCheckResourceAttr(resourceName, "send_collection_latency_metrics", "true"),
resource.TestCheckResourceAttr(resourceName, "send_database_metrics", "false"),
resource.TestCheckResourceAttr(dataSourceName, "type", intType),
resource.TestCheckResourceAttr(dataSourceName, "region", region),
resource.TestCheckResourceAttr(dataSourceName, "send_collection_latency_metrics", "true"),
resource.TestCheckResourceAttr(dataSourceName, "send_database_metrics", "false"),
),
},
{
Config: configDatadog(projectID, updatedAPIKey, "US", true, false, true),
Check: resource.ComposeAggregateTestCheckFunc(
checkExists(resourceName),
resource.TestCheckResourceAttr(resourceName, "type", intType),
resource.TestCheckResourceAttr(resourceName, "api_key", updatedAPIKey),
resource.TestCheckResourceAttr(resourceName, "region", region),
resource.TestCheckResourceAttr(resourceName, "send_collection_latency_metrics", "false"),
resource.TestCheckResourceAttr(resourceName, "send_database_metrics", "true"),
),
},
{
Config: configDatadog(projectID, updatedAPIKey, "US"),
Config: configDatadog(projectID, updatedAPIKey, "US", true, true, true),
Check: resource.ComposeAggregateTestCheckFunc(
checkExists(resourceName),
resource.TestCheckResourceAttr(resourceName, "type", intType),
resource.TestCheckResourceAttr(resourceName, "api_key", updatedAPIKey),
resource.TestCheckResourceAttr(resourceName, "region", region),
resource.TestCheckResourceAttr(resourceName, "send_collection_latency_metrics", "true"),
resource.TestCheckResourceAttr(resourceName, "send_database_metrics", "true"),
resource.TestCheckResourceAttr(dataSourceName, "send_collection_latency_metrics", "true"),
resource.TestCheckResourceAttr(dataSourceName, "send_database_metrics", "true"),
),
},
importStep(resourceName),
Expand Down Expand Up @@ -424,19 +459,28 @@ func configVictorOps(projectID, apiKey string) string {
) + singularDataStr
}

func configDatadog(projectID, apiKey, region string) string {
func configDatadog(projectID, apiKey, region string, useOptionalAttr, sendCollectionLatencyMetrics, sendDatabaseMetrics bool) string {
optionalConfigAttrs := ""
if useOptionalAttr {
optionalConfigAttrs = fmt.Sprintf(
`send_collection_latency_metrics = %[1]t
send_database_metrics = %[2]t`, sendCollectionLatencyMetrics, sendDatabaseMetrics)
}
return fmt.Sprintf(`
resource "mongodbatlas_third_party_integration" "test" {
project_id = "%[1]s"
type = "%[2]s"
api_key = "%[3]s"
region ="%[4]s"

%[5]s
}
`,
projectID,
"DATADOG",
apiKey,
region,
optionalConfigAttrs,
) + singularDataStr
}

Expand Down
Loading