massdriver-cloud / terraform-provider-massdriver

https://massdriver.cloud
Apache License 2.0
0 stars 0 forks source link

First iteration at adding metric block to package alarms #22

Closed chrisghill closed 1 year ago

chrisghill commented 1 year ago

Honestly, 80% of the work here was getting the local dev environment working. I've included the changes it took for me to be able to run make testacc.

I've added a metric block to the package alarms resource, with a maximum blocks of 1 (we can add more if needed for complex metric queries). You can see an example block in the test code, but it looks like this:

resource "massdriver_package_alarm" "new" {
  cloud_resource_id = "arn:::something"
  display_name = "CPU alarm"
  metric {
    name = "Metric Name"
    namespace = "Metric/Namespace"
    statistic = "SUM"
    dimensions = {
    "foo" = "bar"
    }
  }
}

This will produce a JSON payload that looks very similar:

{
  "metadata": {
    "timestamp": "2023-02-09 19:33:00.946947985 +0000 UTC m=+0.002724070",
    "provisioner": "",
    "event_type": "package_alarm_deleted"
  },
  "payload": {
    "deployment_id": "deploy-ment-idfakefake-whatever",
    "package_alarm": {
      "cloud_resource_id": "arn:::something",
      "display_name": "CPU alarm",
      "metric": {
        "name": "Metric Name",
        "namespace": "Metric/Namespace",
        "statistic": "SUM",
        "dimensions": {
          "foo": "bar"
        }
      }
    }
  }
}

The remaining questions I have are 1) which fields should be required (I took my best guess) and 2) which fields should be ForceNew (this triggers a delete + create instead of an update if changed).

linear[bot] commented 1 year ago
PLAT-367 Add metric_name to package alarms

Massdriver must ingest the metric name when a package alarm is created in order to display metrics for package alarms in the UI. There will be a new field on the package_alarm_created called metric that should be stored with the package alarm. In order to do this the massdriver provider will have to provide additional details in the message being consumed by the platform. Additional Context: [https://massdriver.slab.com/posts/package-alarm-metadata-pd447muw](https://massdriver.slab.com/posts/package-alarm-metadata-pd447muw) new fields: namespace (aws, azure) - The monitoring namespace for the metric name - the name of the metric statistic - aggregation method i.e. SUM, AVERAGE, etc dimensions (aws) - The search criteria for the metric in cloudwatch