Skip to content
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

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

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
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
None yet
Projects
None yet
Development

Successfully merging this pull request may close these issues.

None yet

2 participants