8000 feat: Add support for custom metric queries in customized_metric_spec by mattaltberg · Pull Request #196 · terraform-aws-modules/terraform-aws-ecs · GitHub
[go: up one dir, main page]

Skip to content

feat: Add support for custom metric queries in customized_metric_spec #196

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

Conversation

mattaltberg
Copy link

Description

I added support for customized_metric_specification when using the metrics block, instead of using the current setup: https://registry.terraform.io/providers/hashicorp/aws/latest/docs/resources/appautoscaling_policy.html#create-target-tracking-scaling-policy-using-metric-math

Motivation and Context

This change adds support for metric math in queries, which is useful for things like SQS-queue size based autoscaling

Breaking Changes

No, since you can still specify a metric the old way

How Has This Been Tested?

  • I have updated at least one of the examples/* to demonstrate and validate my change(s)
  • I have tested and validated these changes using one or more of the provided examples/* projects

There was no example to test against, but the example code would look like so:

  autoscaling_policies = {
    "scale_consumer" = {
        policy_type = "TargetTrackingScaling"
        target_tracking_scaling_policy_configuration = {
          customized_metric_specification = {
            metrics = [{
                id = "m1"
                label = "Get the queue size"
                return_data = false
                metric_stat = {
                  metric = {
                    metric_name = "ApproximateNumberOfMessagesVisible"
                    namespace = "AWS/SQS"
                    dimensions = [{
                      name = "QueueName"
                      value = aws_sqs_queue.queue.name
                    }]
                  }
                  stat = "Sum"
                }
            },
            {
              id = "m2"
              label = "Get the number of running tasks"
              return_data = false
              metric_stat = {
                metric = {
                  metric_name = "RunningTaskCount"
                  namespace = "ECS/ContainerInsights"
                  dimensions = [
                    {
                      name = "ClusterName"
                      value = module.ecs_cluster.name
                    },
                    {
                      name = "ServiceName"
                      value = "queue-processing-service"
                    }
                  ]
                }
                stat = "Average"
              }
            },
            {
              id = "e1"
              label = "Calculate the backlog per group of instances"
              expression = "m1 / m2"
              return_data = true
            }]
          }
          target_value = 1000
      }
    }
  }
  • I have executed pre-commit run -a on my pull request

@mattaltberg mattaltberg changed the title feat: add support for custom metric queries in customized metric spec feat: Add support for custom metric queries in customized_metric_spec May 14, 2024
@bryantbiggs bryantbiggs merged commit edf0446 into terraform-aws-modules:wip/v6 May 31, 2024
2 checks passed
Copy link
github-actions bot commented Jul 1, 2024

I'm going to lock this pull request because it has been closed for 30 days ⏳. This helps our maintainers find and focus on the active issues. If you have found a problem that seems related to this change, please open a new issue and complete the issue template so we can capture all the details necessary to investigate further.

@github-actions github-actions bot locked as resolved and limited conversation to collaborators Jul 1, 2024
@mattaltberg mattaltberg deleted the feat/metric-query branch July 2, 2024 13:36
Sign up for free to subscribe to this conversation on GitHub. Already have an account? Sign in.
Labels
None yet
Projects
None yet
Development

Successfully merging this pull request may close these issues.

2 participants
0