Skip to content

Commit

Permalink
feat(DMVP-1232): Implemented ALB all requests, request count widgets
Browse files Browse the repository at this point in the history
  • Loading branch information
viktoryathegreat committed Oct 23, 2023
1 parent ec823fa commit 824a1e8
Show file tree
Hide file tree
Showing 16 changed files with 387 additions and 0 deletions.
2 changes: 2 additions & 0 deletions modules/dashboard/README.md
Original file line number Diff line number Diff line change
Expand Up @@ -69,6 +69,8 @@
| <a name="module_container_balancer_2xx_widget"></a> [container\_balancer\_2xx\_widget](#module\_container\_balancer\_2xx\_widget) | ./modules/widgets/balancer/2xx | n/a |
| <a name="module_container_balancer_4xx_widget"></a> [container\_balancer\_4xx\_widget](#module\_container\_balancer\_4xx\_widget) | ./modules/widgets/balancer/4xx | n/a |
| <a name="module_container_balancer_5xx_widget"></a> [container\_balancer\_5xx\_widget](#module\_container\_balancer\_5xx\_widget) | ./modules/widgets/balancer/5xx | n/a |
| <a name="module_container_balancer_all_requests_widget"></a> [container\_balancer\_all\_requests\_widget](#module\_container\_balancer\_all\_requests\_widget) | ./modules/widgets/balancer/all-requests | n/a |
| <a name="module_container_balancer_request_count_widget"></a> [container\_balancer\_request\_count\_widget](#module\_container\_balancer\_request\_count\_widget) | ./modules/widgets/balancer/request-count | n/a |
| <a name="module_container_balancer_response_time_widget"></a> [container\_balancer\_response\_time\_widget](#module\_container\_balancer\_response\_time\_widget) | ./modules/widgets/balancer/response-time | n/a |
| <a name="module_container_balancer_traffic_widget"></a> [container\_balancer\_traffic\_widget](#module\_container\_balancer\_traffic\_widget) | ./modules/widgets/balancer/traffic | n/a |
| <a name="module_container_balancer_unhealthy_request_count_widget"></a> [container\_balancer\_unhealthy\_request\_count\_widget](#module\_container\_balancer\_unhealthy\_request\_count\_widget) | ./modules/widgets/balancer/unhealthy-request-count | n/a |
Expand Down
6 changes: 6 additions & 0 deletions modules/dashboard/locals.tf
Original file line number Diff line number Diff line change
Expand Up @@ -69,6 +69,8 @@ locals {
"balancer/traffic" = []
"balancer/response-time" = []
"balancer/unhealthy-request-count" = []
"balancer/request-count" = []
"balancer/all-requests" = []
"text/title" = []
"log-based" = []
"custom" = []
Expand Down Expand Up @@ -114,6 +116,8 @@ locals {
balancer_traffic = local.widget_config["balancer/traffic"]
balancer_response_time = local.widget_config["balancer/response-time"]
balancer_unhealthy_request_count = local.widget_config["balancer/unhealthy-request-count"]
balancer_request_count = local.widget_config["balancer/request-count"]
balancer_all_requests = local.widget_config["balancer/all-requests"]

text_title = local.widget_config["text/title"]

Expand Down Expand Up @@ -169,6 +173,8 @@ locals {
module.container_balancer_traffic_widget[*].data,
module.container_balancer_response_time_widget[*].data,
module.container_balancer_unhealthy_request_count_widget[*].data,
module.container_balancer_request_count_widget[*].data,
module.container_balancer_all_requests_widget[*].data,

// Widget/Text
module.text_title[*].data,
Expand Down
85 changes: 85 additions & 0 deletions modules/dashboard/modules/widgets/balancer/all-requests/README.md
Original file line number Diff line number Diff line change
@@ -0,0 +1,85 @@
<!-- BEGIN_TF_DOCS -->
## Requirements

| Name | Version |
|------|---------|
| <a name="requirement_terraform"></a> [terraform](#requirement\_terraform) | >= 1.0 |
| <a name="requirement_aws"></a> [aws](#requirement\_aws) | ~> 4.30 |

## Providers

| Name | Version |
|------|---------|
| <a name="provider_aws"></a> [aws](#provider\_aws) | ~> 4.30 |

## Modules

| Name | Source | Version |
|------|--------|---------|
| <a name="module_base"></a> [base](#module\_base) | ../../base | n/a |

## Resources

| Name | Type |
|------|------|
| [aws_alb.balancer](https://registry.terraform.io/providers/hashicorp/aws/latest/docs/data-sources/alb) | data source |

## Inputs

| Name | Description | Type | Default | Required |
|------|-------------|------|---------|:--------:|
| <a name="input_account_id"></a> [account\_id](#input\_account\_id) | n/a | `string` | `null` | no |
| <a name="input_anomaly_detection"></a> [anomaly\_detection](#input\_anomaly\_detection) | Allow to enable anomaly detection on widget metrics | `bool` | `false` | no |
| <a name="input_balancer_arn"></a> [balancer\_arn](#input\_balancer\_arn) | n/a | `string` | `null` | no |
| <a name="input_coordinates"></a> [coordinates](#input\_coordinates) | position | <pre>object({<br> x : number<br> y : number<br> width : number<br> height : number<br> })</pre> | n/a | yes |
| <a name="input_period"></a> [period](#input\_period) | stats | `number` | `300` | no |

## Outputs

| Name | Description |
|------|-------------|
| <a name="output_data"></a> [data](#output\_data) | n/a |
<!-- END_TF_DOCS -->
<!-- BEGINNING OF PRE-COMMIT-TERRAFORM DOCS HOOK -->
## Requirements

| Name | Version |
|------|---------|
| <a name="requirement_terraform"></a> [terraform](#requirement\_terraform) | >= 1.0 |
| <a name="requirement_aws"></a> [aws](#requirement\_aws) | ~> 4.30 |

## Providers

| Name | Version |
|------|---------|
| <a name="provider_aws"></a> [aws](#provider\_aws) | ~> 4.30 |

## Modules

| Name | Source | Version |
|------|--------|---------|
| <a name="module_base"></a> [base](#module\_base) | ../../base | n/a |

## Resources

| Name | Type |
|------|------|
| [aws_lb.balancer](https://registry.terraform.io/providers/hashicorp/aws/latest/docs/data-sources/lb) | data source |

## Inputs

| Name | Description | Type | Default | Required |
|------|-------------|------|---------|:--------:|
| <a name="input_account_id"></a> [account\_id](#input\_account\_id) | n/a | `string` | `null` | no |
| <a name="input_anomaly_detection"></a> [anomaly\_detection](#input\_anomaly\_detection) | Allow to enable anomaly detection on widget metrics | `bool` | `false` | no |
| <a name="input_balancer_arn"></a> [balancer\_arn](#input\_balancer\_arn) | n/a | `string` | `null` | no |
| <a name="input_balancer_name"></a> [balancer\_name](#input\_balancer\_name) | n/a | `string` | `null` | no |
| <a name="input_coordinates"></a> [coordinates](#input\_coordinates) | position | <pre>object({<br> x : number<br> y : number<br> width : number<br> height : number<br> })</pre> | n/a | yes |
| <a name="input_period"></a> [period](#input\_period) | stats | `number` | `300` | no |

## Outputs

| Name | Description |
|------|-------------|
| <a name="output_data"></a> [data](#output\_data) | n/a |
<!-- END OF PRE-COMMIT-TERRAFORM DOCS HOOK -->
Original file line number Diff line number Diff line change
@@ -0,0 +1,10 @@
data "aws_lb" "balancer" {
count = var.balancer_arn == null ? 1 : 0

name = var.balancer_name
}

locals {
balancer = split("loadbalancer/", var.balancer_arn == null ? data.aws_lb.balancer[0].arn : var.balancer_arn)[1]
balancer_name = split("/", local.balancer)[1]
}
25 changes: 25 additions & 0 deletions modules/dashboard/modules/widgets/balancer/all-requests/base.tf
Original file line number Diff line number Diff line change
@@ -0,0 +1,25 @@
module "base" {
source = "../../base"

coordinates = var.coordinates

name = "All Requests"

# stats
stat = "Sum"
period = var.period

defaults = {
MetricNamespace = "AWS/ApplicationELB"
LoadBalancer = local.balancer
accountId = var.account_id
anomaly_detection = var.anomaly_detection
}

metrics = [
{ MetricName = "HTTPCode_Target_2XX_Count", color = "#3ECE76" },
{ MetricName = "HTTPCode_Target_3XX_Count", color = "#FFC300" },
{ MetricName = "HTTPCode_Target_4XX_Count", color = "#FF774D" },
{ MetricName = "HTTPCode_Target_5XX_Count", color = "#FF0F3C" },
]
}
Original file line number Diff line number Diff line change
@@ -0,0 +1,3 @@
output "data" {
value = module.base.data
}
Original file line number Diff line number Diff line change
@@ -0,0 +1,36 @@
variable "balancer_name" {
type = string
default = null
}

variable "balancer_arn" {
type = string
default = null
}

variable "account_id" {
type = string
default = null
}

# position
variable "coordinates" {
type = object({
x : number
y : number
width : number
height : number
})
}

# stats
variable "period" {
type = number
default = 300
}

variable "anomaly_detection" {
type = bool
default = false
description = "Allow to enable anomaly detection on widget metrics"
}
Original file line number Diff line number Diff line change
@@ -0,0 +1,10 @@
terraform {
required_version = ">= 1.0"

required_providers {
aws = {
source = "hashicorp/aws"
version = "~> 4.30"
}
}
}
85 changes: 85 additions & 0 deletions modules/dashboard/modules/widgets/balancer/request-count/README.md
Original file line number Diff line number Diff line change
@@ -0,0 +1,85 @@
<!-- BEGIN_TF_DOCS -->
## Requirements

| Name | Version |
|------|---------|
| <a name="requirement_terraform"></a> [terraform](#requirement\_terraform) | >= 1.0 |
| <a name="requirement_aws"></a> [aws](#requirement\_aws) | ~> 4.30 |

## Providers

| Name | Version |
|------|---------|
| <a name="provider_aws"></a> [aws](#provider\_aws) | ~> 4.30 |

## Modules

| Name | Source | Version |
|------|--------|---------|
| <a name="module_base"></a> [base](#module\_base) | ../../base | n/a |

## Resources

| Name | Type |
|------|------|
| [aws_alb.balancer](https://registry.terraform.io/providers/hashicorp/aws/latest/docs/data-sources/alb) | data source |

## Inputs

| Name | Description | Type | Default | Required |
|------|-------------|------|---------|:--------:|
| <a name="input_account_id"></a> [account\_id](#input\_account\_id) | n/a | `string` | `null` | no |
| <a name="input_anomaly_detection"></a> [anomaly\_detection](#input\_anomaly\_detection) | Allow to enable anomaly detection on widget metrics | `bool` | `false` | no |
| <a name="input_balancer_arn"></a> [balancer\_arn](#input\_balancer\_arn) | n/a | `string` | `null` | no |
| <a name="input_coordinates"></a> [coordinates](#input\_coordinates) | position | <pre>object({<br> x : number<br> y : number<br> width : number<br> height : number<br> })</pre> | n/a | yes |
| <a name="input_period"></a> [period](#input\_period) | stats | `number` | `300` | no |

## Outputs

| Name | Description |
|------|-------------|
| <a name="output_data"></a> [data](#output\_data) | n/a |
<!-- END_TF_DOCS -->
<!-- BEGINNING OF PRE-COMMIT-TERRAFORM DOCS HOOK -->
## Requirements

| Name | Version |
|------|---------|
| <a name="requirement_terraform"></a> [terraform](#requirement\_terraform) | >= 1.0 |
| <a name="requirement_aws"></a> [aws](#requirement\_aws) | ~> 4.30 |

## Providers

| Name | Version |
|------|---------|
| <a name="provider_aws"></a> [aws](#provider\_aws) | ~> 4.30 |

## Modules

| Name | Source | Version |
|------|--------|---------|
| <a name="module_base"></a> [base](#module\_base) | ../../base | n/a |

## Resources

| Name | Type |
|------|------|
| [aws_lb.balancer](https://registry.terraform.io/providers/hashicorp/aws/latest/docs/data-sources/lb) | data source |

## Inputs

| Name | Description | Type | Default | Required |
|------|-------------|------|---------|:--------:|
| <a name="input_account_id"></a> [account\_id](#input\_account\_id) | n/a | `string` | `null` | no |
| <a name="input_anomaly_detection"></a> [anomaly\_detection](#input\_anomaly\_detection) | Allow to enable anomaly detection on widget metrics | `bool` | `false` | no |
| <a name="input_balancer_arn"></a> [balancer\_arn](#input\_balancer\_arn) | n/a | `string` | `null` | no |
| <a name="input_balancer_name"></a> [balancer\_name](#input\_balancer\_name) | n/a | `string` | `null` | no |
| <a name="input_coordinates"></a> [coordinates](#input\_coordinates) | position | <pre>object({<br> x : number<br> y : number<br> width : number<br> height : number<br> })</pre> | n/a | yes |
| <a name="input_period"></a> [period](#input\_period) | stats | `number` | `300` | no |

## Outputs

| Name | Description |
|------|-------------|
| <a name="output_data"></a> [data](#output\_data) | n/a |
<!-- END OF PRE-COMMIT-TERRAFORM DOCS HOOK -->
Original file line number Diff line number Diff line change
@@ -0,0 +1,10 @@
data "aws_lb" "balancer" {
count = var.balancer_arn == null ? 1 : 0

name = var.balancer_name
}

locals {
balancer = split("loadbalancer/", var.balancer_arn == null ? data.aws_lb.balancer[0].arn : var.balancer_arn)[1]
balancer_name = split("/", local.balancer)[1]
}
22 changes: 22 additions & 0 deletions modules/dashboard/modules/widgets/balancer/request-count/base.tf
Original file line number Diff line number Diff line change
@@ -0,0 +1,22 @@
module "base" {
source = "../../base"

coordinates = var.coordinates

name = "Request Count"

# stats
stat = "Sum"
period = var.period

defaults = {
MetricNamespace = "AWS/ApplicationELB"
LoadBalancer = local.balancer
accountId = var.account_id
anomaly_detection = var.anomaly_detection
}

metrics = [
{ MetricName = "RequestCount", color = "#127CEF" },
]
}
Original file line number Diff line number Diff line change
@@ -0,0 +1,3 @@
output "data" {
value = module.base.data
}
Original file line number Diff line number Diff line change
@@ -0,0 +1,36 @@
variable "balancer_name" {
type = string
default = null
}

variable "balancer_arn" {
type = string
default = null
}

variable "account_id" {
type = string
default = null
}

# position
variable "coordinates" {
type = object({
x : number
y : number
width : number
height : number
})
}

# stats
variable "period" {
type = number
default = 300
}

variable "anomaly_detection" {
type = bool
default = false
description = "Allow to enable anomaly detection on widget metrics"
}
Original file line number Diff line number Diff line change
@@ -0,0 +1,10 @@
terraform {
required_version = ">= 1.0"

required_providers {
aws = {
source = "hashicorp/aws"
version = "~> 4.30"
}
}
}
4 changes: 4 additions & 0 deletions modules/dashboard/tests/widgets-balancer/1-example.tf
Original file line number Diff line number Diff line change
Expand Up @@ -52,6 +52,10 @@ module "dashboard-with-balancer-metrics" {
{ type : "balancer/traffic", accountId : local.account_id, balancer_name : local.balancer_name },
{ type : "balancer/response-time", accountId : local.account_id, balancer_name : local.balancer_name },
{ type : "balancer/unhealthy-request-count", accountId : local.account_id, balancer_name : local.balancer_name, anomaly_detection : true },
{ type : "balancer/request-count", accountId : local.account_id, balancer_name : local.balancer_name },
],
[
{ type : "balancer/all-requests", accountId : local.account_id, balancer_name : local.balancer_name },
]
]

Expand Down
Loading

0 comments on commit 824a1e8

Please sign in to comment.