mongodb / terraform-provider-mongodbatlas

Terraform MongoDB Atlas Provider: Deploy, update, and manage MongoDB Atlas infrastructure as code through HashiCorp Terraform
https://registry.terraform.io/providers/mongodb/mongodbatlas
Mozilla Public License 2.0
241 stars 167 forks source link

Can't create a alert for Replication Oplog Window #227

Closed michelzanini closed 4 years ago

michelzanini commented 4 years ago

Hi,

I can't create a alert for Replication Oplog Window is below 1 hours using Terraform.

This is what I have:

resource "mongodbatlas_alert_configuration" "pager_duty_alert_replication_window" {
  project_id = mongodbatlas_project.project.id
  event_type = "REPLICATION_OPLOG_WINDOW_RUNNING_OUT"
  enabled    = true

  notification {
    type_name    = "PAGER_DUTY"
    service_key  = var.pager_duty_service_key
    delay_min    = 0
    interval_min = local.pager_duty_interval_min
  }
}

But this won't work as this alert needs a threshold. See error:

400 (request "Bad Request") A threshold must be specified for the specified event type.

This threshold has a different JSON format than when using OUTSIDE_METRIC_THRESHOLD. For OUTSIDE_METRIC_THRESHOLD the JSON looks like this:

"metricThreshold": {
   "metricName": "CONNECTIONS_PERCENT",
   "mode": "AVERAGE",
   "operator": "GREATER_THAN",
   "threshold": 80.0,
   "units": "RAW"
},

But for this metric, REPLICATION_OPLOG_WINDOW_RUNNING_OUT, it looks like this:

"threshold": {
   "operator": "LESS_THAN",
   "threshold": 1
}

I tried using in Terraform:

threshold = {
    operator    = "LESS_THAN"
    threshold   = 1
}

But get this error:

Error: Unsupported argument
An argument named "threshold" is not expected here.

And:

metric_threshold = {
    operator    = "LESS_THAN"
    threshold   = 1
    units       = "RAW"
    mode        = "AVERAGE"
  }

And get:

400 (request "Bad Request") The metric threshold should only be specific for host metric alerts.

Is it possible that this metric is not support on Terraform right now, or how do I create it?

Thanks.

michelzanini commented 4 years ago

I am using version 0.5.1 of the provider, Terraform version 0.12.16

themantissa commented 4 years ago

@michelzanini we'll take a look but have you reached out to Atlas support? Issues in this repo is for bugs per the README. If you can narrow down the issue with support first it helps a great deal, especially as alerts are some of the most complicated to track down due to the variations available. Also note Atlas API documentation for Alerts was updated recently so there may be some things in the Atlas API we were not able to account for and will have to adjust to match: https://docs.atlas.mongodb.com/reference/api/alert-configurations-create-config/

michelzanini commented 4 years ago

I can create the alert via API with a POST:

{
    "enabled": true,
    "eventTypeName": "REPLICATION_OPLOG_WINDOW_RUNNING_OUT",
    "matchers": [],
    "notifications": [
        {
            "delayMin": 0,
            "intervalMin": 60,
            "typeName": "PAGER_DUTY",
            "serviceKey": "2f57fda20b70462bbf8001cfa7a1835a"
        }
    ],
    "threshold": {
        "operator": "LESS_THAN",
        "threshold": 1
    }
}

From Terraform I can't define the threshold block. I think this is missing...

Not sure why would I create a Atlas support ticket for this, but if you still want me to create I can. Please let me know. Thanks.

themantissa commented 4 years ago

@michelzanini If you were able to set it via API directly but not via Terraform then no, you do not need a support ticket. The reason I mention support is they have the access and staffing to help (much more quickly and thoroughly) and narrow down potential bugs for the developers to address. In this case it seems you have done this on your own, thank you.

I'm assuming this is one that was left off due to the documentation being out of date. Now that the doc is caught up we'll need to improve the provider to match the Atlas reality. We'll update here when addressed.

michelzanini commented 4 years ago

@themantissa - Actually the documentation seems still not updated as I don't see threshold block in there. Only metricThreshold, which is supported by Terraform. The reason why I knew how to create it is because I analysed the JSON that returns when doing a GET call.

Resuming - the docs are not up-to-date and so is not Terraform.

Maybe for that a support ticket is needed? Not sure...

Thanks.

themantissa commented 4 years ago

@michelzanini indeed - I think you are correct. You've done quite a bit of work already. I'll get this sorted out from here on both sides. Thank you!

themantissa commented 4 years ago

@michelzanini apologies for the length of time to resolution here but wanted to assure you and anyone else that we are working on this and will post updates as we have them.

themantissa commented 4 years ago

End of week update: believe we've identified what we need to correct this in the provider. Should have what we need early/mid July and then will be able to determine when we can ensure the provider supports this correctly.

jtmdb commented 4 years ago

Hi @themantissa I'm using mongodbatlas provider version 0.6.3 and terraform version 0.13 and encountered the same errors when attempting to set event_type = "REPLICATION_OPLOG_WINDOW_RUNNING_OUT".

I have tried with: "threshold": { "operator": "LESS_THAN", "threshold": 1 }

as well as: metric_threshold = { operator = "LESS_THAN" threshold = 1.0 units = "HOURS" }

themantissa commented 4 years ago

@jtmdb apologizes but we had to get a review and update of how to properly support Atlas alerts in Terraform with the underlying API. We have the information now and the work is on the work board but we have not yet gotten to it. We hope to soon but no firm ETA at this time, estimated currently in September.

PacoDw commented 4 years ago

Hello @jtmdb, I created a PR implementing the threshold attribute if you want to check more details or play with the new feature see the PR #298.

Let me know if you have another comment or concern, thanks

michelzanini commented 4 years ago

I can confirm the fix works after 0.6.4 release. Thanks!

themantissa commented 4 years ago

Thank you @michelzanini! Very glad to hear that.