FlexibleEngineCloud / terraform-provider-flexibleengine

Terraform flexibleengine provider
https://www.terraform.io/docs/providers/flexibleengine/
Mozilla Public License 2.0
30 stars 53 forks source link

[flexibleengine_ces_alarmrule] - unable to monitor multiple RDS nodes inside the same alarm #679

Closed alpersid closed 1 year ago

alpersid commented 2 years ago

Hello guys,

I'm trying to create an Alarm which will monitor the RDS instance ( MYSQL HA ).

Each Mysql RDS instance have 2 nodes ( master / slave ).

While creating from the GUI everything is working properly. However, I think there's a limitation using terraform or the API.

If there is only one monitoring object ( flexibleengine_rds_instance_v3.RDS_instance.nodes[0].id in my example), everything is working properly. However, if I put two dimensions blocks, it will create a "dummy" monitoring object which will not link to an existing one.

Terraform Version

15

Affected Resource(s)

Terraform Configuration Files

Not working Code

resource "flexibleengine_ces_alarmrule" "rds_alarm_rule_" {
  for_each = { for instance in var.RDS_alarms : instance.alarm_name => instance }
  alarm_name = "${flexibleengine_rds_instance_v3.RDS_instance.name}_alarm_${each.value.alarm_name}"
  alarm_level = each.value.alarm_level

  metric {
    namespace = each.value.namespace
    metric_name = each.value.metric_name
    dynamic "dimensions" {
      for_each = flexibleengine_rds_instance_v3.RDS_instance.nodes
      content {
        name = "rds_instance_id"
        value = dimensions.value.id
      }
    }

  }
  condition  {
    period              = each.value.period
    filter              = each.value.filter
    comparison_operator = each.value.comparison_operator
    value               = each.value.value
    unit                = each.value.unit
    count               = each.value.count
  }
  alarm_actions {
    type = "notification"
    notification_list = [  var.smn_topic   ]
  }
  ok_actions {
    type = "notification"
    notification_list = [  var.smn_topic   ]
  }
}

Working Code

resource "flexibleengine_ces_alarmrule" "rds_alarm_rule_" {
  for_each = { for instance in var.RDS_alarms : instance.alarm_name => instance }
  alarm_name = "${flexibleengine_rds_instance_v3.RDS_instance.name}_alarm_${each.value.alarm_name}"
  alarm_level = each.value.alarm_level

  metric {
    namespace = each.value.namespace
    metric_name = each.value.metric_name
    dimensions {
        name = "rds_instance_id"
        value = flexibleengine_rds_instance_v3.RDS_instance.nodes[0].id

    }

  }
  condition  {
    period              = each.value.period
    filter              = each.value.filter
    comparison_operator = each.value.comparison_operator
    value               = each.value.value
    unit                = each.value.unit
    count               = each.value.count
  }
  alarm_actions {
    type = "notification"
    notification_list = [  var.smn_topic   ]
  }
  ok_actions {
    type = "notification"
    notification_list = [  var.smn_topic   ]
  }
}

API Response - with 2 monitored objects created from Terraform - but not linked with an actual object

{
    "metric_alarms": [
        {
            "alarm_id": "al1640699420424o7znR7lnX",
            "alarm_name": "OPL_PPY_rds_instance_alarm_RDS_cpu_util",
            "alarm_description": "",
            "metric": {
                "namespace": "SYS.RDS",
                "dimensions": [
                    {
                        "name": "rds_instance_id",
                        "value": "1c26fdc40a7649fb9b7e7910376d210cno01"
                    },
                    {
                        "name": "rds_instance_id",
                        "value": "b47d2ceb964b489ab0828c71f6af0906no01"
                    }
                ],
                "metric_name": "rds001_cpu_util"
            },
            "condition": {
                "period": 1,
                "filter": "average",
                "comparison_operator": ">",
                "value": 80,
                "unit": "%",
                "count": 5
            },
            "alarm_level": 2,
            "alarm_enabled": true,
            "alarm_action_enabled": true,
            "alarm_actions": [
                {
                    "type": "notification",
                    "notificationList": [
                        "urn:smn:eu-west-0:1ab0a970c2964be0aba4e9e860ce6a5b:OPL_smn_topic"
                    ]
                }
            ],
            "ok_actions": [
                {
                    "type": "notification",
                    "notificationList": [
                        "urn:smn:eu-west-0:1ab0a970c2964be0aba4e9e860ce6a5b:OPL_smn_topic"
                    ]
                }
            ],
            "insufficientdata_actions": [],
            "update_time": 1640699420000,
            "alarm_state": "insufficient_data",
            "enterprise_project_id": "0"
        }
    ]
}

image

API Response - with 2 monitored objects created from GUI - working properly from GUI

{
    "metric_alarms": [
        {
            "alarm_id": "al1640679470292Dqo7VQJ3B",
            "alarm_name": "OPL_KRM_rds_instance_alarm_RDS_Active_Connections",
            "alarm_description": "",
            "metric": {
                "namespace": "SYS.RDS",
                "dimensions": [
                    {
                        "name": "rds_instance_id"
                    }
                ],
                "metric_name": "rds072_conn_usage"
            },
            "condition": {
                "period": 1,
                "filter": "average",
                "comparison_operator": ">=",
                "value": 75,
                "unit": "%",
                "count": 3
            },
            "alarm_level": 2,
            "alarm_type": "MULTI_INSTANCE",
            "alarm_enabled": true,
            "alarm_action_enabled": true,
            "alarm_actions": [
                {
                    "type": "notification",
                    "notificationList": [
                        "urn:smn:eu-west-0:1ab0a970c2964be0aba4e9e860ce6a5b:OPL_smn_topic"
                    ]
                }
            ],
            "ok_actions": [
                {
                    "type": "notification",
                    "notificationList": [
                        "urn:smn:eu-west-0:1ab0a970c2964be0aba4e9e860ce6a5b:OPL_smn_topic"
                    ]
                }
            ],
            "insufficientdata_actions": [],
            "alarm_action_begin_time": "00:00",
            "alarm_action_end_time": "23:59",
            "update_time": 1640679636000,
            "alarm_state": "ok",
            "enterprise_project_id": "0"
        }
    ]
}

API Response - with 1 monitored object created from Terraform

{
    "metric_alarms": [
        {
            "alarm_id": "al1640679471357jxogEa3L1",
            "alarm_name": "OPL_PPY_rds_instance_alarm_RDS_Active_Connections",
            "alarm_description": "",
            "metric": {
                "namespace": "SYS.RDS",
                "dimensions": [
                    {
                        "name": "rds_instance_id",
                        "value": "1c26fdc40a7649fb9b7e7910376d210cno01"
                    }
                ],
                "metric_name": "rds072_conn_usage"
            },
            "condition": {
                "period": 1,
                "filter": "average",
                "comparison_operator": ">=",
                "value": 75,
                "unit": "%",
                "count": 3
            },
            "alarm_level": 2,
            "alarm_enabled": true,
            "alarm_action_enabled": true,
            "alarm_actions": [
                {
                    "type": "notification",
                    "notificationList": [
                        "urn:smn:eu-west-0:1ab0a970c2964be0aba4e9e860ce6a5b:OPL_smn_topic"
                    ]
                }
            ],
            "ok_actions": [
                {
                    "type": "notification",
                    "notificationList": [
                        "urn:smn:eu-west-0:1ab0a970c2964be0aba4e9e860ce6a5b:OPL_smn_topic"
                    ]
                }
            ],
            "insufficientdata_actions": [],
            "update_time": 1640679471000,
            "alarm_state": "ok",
            "enterprise_project_id": "0"
        }
    ]
}

Actual Behavior

There's no way to have multiple RDS nodes inside the same alarm

Steps to Reproduce

  1. terraform apply
ShiChangkuo commented 2 years ago

@alpersid According to the API Response between with 2 monitored objects created from Terraform and with 1 monitored object created from Terraform, I find that the value of "metric_name" are different, can you use rds001_cpu_util and try again?

You can also open a service ticket to OCB for technical support.

ShiChangkuo commented 1 year ago

@alpersid I'm going to close this issue because there are no updates for 20 days. If you have found a problem that seems similar to this, please open a new issue and complete the issue template so we can capture all the details necessary to investigate further.