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

Ease using AWS ALBs in CloudWatch metrics #8808

Closed
sj26 opened this issue Sep 13, 2016 · 7 comments · Fixed by #8833
Closed

Ease using AWS ALBs in CloudWatch metrics #8808

sj26 opened this issue Sep 13, 2016 · 7 comments · Fixed by #8833

Comments

@sj26
Copy link

sj26 commented Sep 13, 2016

Fantastic to see ALBs available in Terraform so quickly. Thank you! 👏

Part of cutting over to ALBs for us involves creating equivalent CloudWatch alarms around our upstream health. The dimensions aren't just the LoadBalancerName set to aws_elb.*.name like ELBs however. For ALBs the dimension is LoadBalancer with a partial suffix from the ALB ARN:

# Alarm if this alb's targets have more than 50 5xx errors within two minutes
resource "aws_cloudwatch_metric_alarm" "my-alb-too-many-server-errors" {
  alarm_name  = "my-alb-too-many-server-errors"
  namespace   = "AWS/ApplicationELB"
  metric_name = "HTTPCode_Target_5XX_Count"

  dimensions = {
    # CloudWatch wants part of the arn. It's kinda silly.
    # arn:aws:elasticloadbalancing:us-east-1:123456:loadbalancer/app/my-alb/abc123 => app/my-alb/abc123
    LoadBalancer = "${replace("${aws_alb.my-alb.arn}", "/arn:.*?:loadbalancer\\/(.*)/", "$1")}"
  }

  statistic           = "Sum"
  period              = 60
  comparison_operator = "GreaterThanThreshold"
  threshold           = "50"
  evaluation_periods  = 2
}

This definitely works, but it's pretty clumsy. Perhaps this ARN suffix could be exposed as a derived attribute of aws_alb resources?

@sj26 sj26 changed the title Ease using ALBs in CloudWatch metrics Ease using AWS ALBs in CloudWatch metrics Sep 13, 2016
@jen20
Copy link
Contributor

jen20 commented Sep 14, 2016

Hi @sj26! This looks like a great candidate for an additional computed field. I'll look into adding this.

@jen20 jen20 self-assigned this Sep 14, 2016
jen20 added a commit that referenced this issue Sep 14, 2016
When creating a CloudWatch Metric for an Application Load Balancer it is
neccessary to use the suffix of the ARN as the reference to the load
balacner. This commit exposes that as an attribute on the `aws_alb`
resource to prevent the need to use regular expression substitution to
make the reference.

Fixes #8808.
jen20 added a commit that referenced this issue Sep 14, 2016
When creating a CloudWatch Metric for an Application Load Balancer it is
neccessary to use the suffix of the ARN as the reference to the load
balancer. This commit exposes that as an attribute on the `aws_alb`
resource to prevent the need to use regular expression substitution to
make the reference.

Fixes #8808.
jen20 added a commit that referenced this issue Sep 14, 2016
When creating a CloudWatch Metric for an Application Load Balancer it is
neccessary to use the suffix of the ARN as the reference to the load
balancer. This commit exposes that as an attribute on the `aws_alb`
resource to prevent the need to use regular expression substitution to
make the reference.

Fixes #8808.
jen20 added a commit that referenced this issue Sep 14, 2016
When creating a CloudWatch Metric for an Application Load Balancer it is
neccessary to use the suffix of the ARN as the reference to the load
balancer. This commit exposes that as an attribute on the `aws_alb`
resource to prevent the need to use regular expression substitution to
make the reference.

Fixes #8808.
radeksimko pushed a commit that referenced this issue Sep 14, 2016
When creating a CloudWatch Metric for an Application Load Balancer it is
neccessary to use the suffix of the ARN as the reference to the load
balancer. This commit exposes that as an attribute on the `aws_alb`
resource to prevent the need to use regular expression substitution to
make the reference.

Fixes #8808.
@sj26
Copy link
Author

sj26 commented Sep 14, 2016

Thanks so much! 💖

@sj26
Copy link
Author

sj26 commented Sep 15, 2016

Any chance we could do the same thing for target group resources?

http://docs.aws.amazon.com/AmazonCloudWatch/latest/monitoring/elb-metricscollected.html#load-balancer-metric-dimensions-alb

sharmaansh21 pushed a commit to sharmaansh21/terraform that referenced this issue Sep 15, 2016
When creating a CloudWatch Metric for an Application Load Balancer it is
neccessary to use the suffix of the ARN as the reference to the load
balancer. This commit exposes that as an attribute on the `aws_alb`
resource to prevent the need to use regular expression substitution to
make the reference.

Fixes hashicorp#8808.
@adhodgson1
Copy link

It would be good to have this exposed on the target group as well, as it is needed for metrics on that such as the unhealthy host count.

@jaydp17
Copy link

jaydp17 commented Oct 17, 2017

For anyone coming here looking for a solution, the below works

  • aws_alb.my-alb.arn_suffix
  • aws_alb_target_group.my-tg.arn_suffix

@hdryx
Copy link

hdryx commented Jan 20, 2020

I was searching for this for hours. Why it's not documented here https://www.terraform.io/docs/providers/aws/d/lb.html ?

@ghost
Copy link

ghost commented Jan 21, 2020

I'm going to lock this issue 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 similar to this, please open a new issue and complete the issue template so we can capture all the details necessary to investigate further.

@ghost ghost locked and limited conversation to collaborators Jan 21, 2020
Sign up for free to subscribe to this conversation on GitHub. Already have an account? Sign in.
Projects
None yet
Development

Successfully merging a pull request may close this issue.

5 participants