Skip to content

Commit

Permalink
feat(DMVP-1232): added new blocks for cdn, alb, service, dns, sla
Browse files Browse the repository at this point in the history
  • Loading branch information
viktoryathegreat committed Nov 6, 2023
1 parent 7c69fba commit 93210f8
Show file tree
Hide file tree
Showing 30 changed files with 514 additions and 71 deletions.
43 changes: 41 additions & 2 deletions modules/dashboard/README.md
Original file line number Diff line number Diff line change
Expand Up @@ -6,10 +6,43 @@ version: x.y.z
variables:
name: test-dashboard
rows:
- ....
- type: block/sla
balancer_name: ""
- type: block/dns
zone_name: ""
- type: block/cdn
cdn_id: ""
- type: block/alb
balancer_name: ""
account_id: ""
- type: block/service
service_name: ""
cluster: ""
balancer_name: ""
target_group_arn: ""
healthcheck_id: ""
- type: block/rds
name: ""
db_max_connections_count: 100
```

## HCL example
```
module "this" {
source = "../.."
name = "test-dashboard-with-blocks"
rows = [
[{ "type" : "block/sla", "balancer_name" : "" }],
[{ "type" : "block/dns", "zone_name" : "" }],
[{ "type" : "block/cdn", "cdn_id" : "xxxxxxxxx" }],
[{ "type" : "block/alb", "balancer_name" : "", account_id : "xxxxxxxxx" }],
[{ "type" : "block/service", service_name : "", cluster : "prod", "balancer_name" : "", target_group_arn : "xxxxxxxxx", healthcheck_id : "xxxxxxxxx" }],
[{ "type" : "block/rds", "name" : "", db_max_connections_count : 100 }],
]
}
```

## How add new block
1. create module in modules/blocks (copy from one)
Expand Down Expand Up @@ -91,8 +124,12 @@ variables:

| Name | Source | Version |
|------|--------|---------|
| <a name="module_block_alb"></a> [block\_alb](#module\_block\_alb) | ./modules/blocks/alb | n/a |
| <a name="module_block_cdn"></a> [block\_cdn](#module\_block\_cdn) | ./modules/blocks/cdn | n/a |
| <a name="module_block_dns"></a> [block\_dns](#module\_block\_dns) | ./modules/blocks/dns | n/a |
| <a name="module_block_rds"></a> [block\_rds](#module\_block\_rds) | ./modules/blocks/rds | n/a |
| <a name="module_block_sqs"></a> [block\_sqs](#module\_block\_sqs) | ./modules/blocks/sqs | n/a |
| <a name="module_block_service"></a> [block\_service](#module\_block\_service) | ./modules/blocks/service | n/a |
| <a name="module_block_sla"></a> [block\_sla](#module\_block\_sla) | ./modules/blocks/sla | n/a |
| <a name="module_container_all_requests"></a> [container\_all\_requests](#module\_container\_all\_requests) | ./modules/widgets/container/all-requests | n/a |
| <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 |
Expand Down Expand Up @@ -149,6 +186,7 @@ variables:
|------|------|
| [aws_cloudwatch_dashboard.dashboards](https://registry.terraform.io/providers/hashicorp/aws/latest/docs/resources/cloudwatch_dashboard) | resource |
| [aws_caller_identity.project](https://registry.terraform.io/providers/hashicorp/aws/latest/docs/data-sources/caller_identity) | data source |
| [aws_region.current](https://registry.terraform.io/providers/hashicorp/aws/latest/docs/data-sources/region) | data source |

## Inputs

Expand All @@ -159,6 +197,7 @@ variables:
| <a name="input_defaults"></a> [defaults](#input\_defaults) | Default values to be supplied to all modules. | `any` | `{}` | no |
| <a name="input_name"></a> [name](#input\_name) | Dashboard name. Should not contain spaces and special chars. | `string` | n/a | yes |
| <a name="input_platform"></a> [platform](#input\_platform) | The platform/service/adapter to create dashboard on. for now only cloudwatch and grafana supported | `string` | `"cloudwatch"` | no |
| <a name="input_region"></a> [region](#input\_region) | AWS region name where the dashboard will be created | `string` | `""` | no |
| <a name="input_rows"></a> [rows](#input\_rows) | List of widgets to be inserted into the dashboard. See ./modules/widgets folder to see list of available widgets. | `any` | n/a | yes |

## Outputs
Expand Down
78 changes: 53 additions & 25 deletions modules/dashboard/blocks.tf
Original file line number Diff line number Diff line change
Expand Up @@ -24,14 +24,22 @@ locals {

# bring all module results together
blocks_results = {
rds = module.block_rds.*.result
sqs = module.block_sqs.*.result
rds = module.block_rds.*.result
dns = module.block_dns.*.result
cdn = module.block_cdn.*.result
alb = module.block_alb.*.result
service = module.block_service.*.result
sla = module.block_sla.*.result
}

# annotate each block type with subIndex
blocks_by_type = {
rds = [for index2, block in local.initial_blocks : merge(block, { index2 : index2 }) if strcontains(block.type, "rds")],
sqs = [for index2, block in local.initial_blocks : merge(block, { index2 : index2 }) if strcontains(block.type, "sqs")]
rds = [for index2, block in local.initial_blocks : merge(block, { index2 : index2 }) if strcontains(block.type, "rds")],
dns = [for index2, block in local.initial_blocks : merge(block, { index2 : index2 }) if strcontains(block.type, "dns")],
cdn = [for index2, block in local.initial_blocks : merge(block, { index2 : index2 }) if strcontains(block.type, "cdn")],
alb = [for index2, block in local.initial_blocks : merge(block, { index2 : index2 }) if strcontains(block.type, "alb")]
service = [for index2, block in local.initial_blocks : merge(block, { index2 : index2 }) if strcontains(block.type, "service")]
sla = [for index2, block in local.initial_blocks : merge(block, { index2 : index2 }) if strcontains(block.type, "sla")]
}
}

Expand All @@ -41,35 +49,55 @@ module "block_rds" {

count = length(local.blocks_by_type.rds)

# coordinates
name = local.blocks_by_type.rds[count.index].block.name
# coordinates = local.alarm_status[count.index].coordinates
name = local.blocks_by_type.rds[count.index].block.name
db_max_connections_count = local.blocks_by_type.rds[count.index].block.db_max_connections_count
region = var.region != "" ? var.region : data.aws_region.current.name
}

module "block_dns" {
source = "./modules/blocks/dns"

count = length(local.blocks_by_type.dns)

zone_name = local.blocks_by_type.dns[count.index].block.zone_name
}

# # metric
# title = local.alarm_status[count.index].title
module "block_cdn" {
source = "./modules/blocks/cdn"

# alarm_arns = local.alarm_status[count.index].alarm_arns
# stacked = try(local.alarm_status[count.index].stacked, false)
count = length(local.blocks_by_type.cdn)

# account_id = try(local.alarm_status[count.index].accountId, null)
# anomaly_detection = try(local.alarm_status[count.index].anomaly_detection, false)
cdn_id = local.blocks_by_type.cdn[count.index].block.cdn_id
}

module "block_sqs" {
source = "./modules/blocks/sqs"
module "block_alb" {
source = "./modules/blocks/alb"

count = length(local.blocks_by_type.sqs)
count = length(local.blocks_by_type.alb)

# coordinates
name = local.blocks_by_type.sqs[count.index].block.name
# coordinates = local.alarm_status[count.index].coordinates
balancer_name = local.blocks_by_type.alb[count.index].block.balancer_name
account_id = local.blocks_by_type.alb[count.index].block.account_id
region = var.region != "" ? var.region : data.aws_region.current.name
}

module "block_service" {
source = "./modules/blocks/service"

count = length(local.blocks_by_type.service)

service_name = local.blocks_by_type.service[count.index].block.service_name
balancer_name = local.blocks_by_type.service[count.index].block.balancer_name
target_group_arn = local.blocks_by_type.service[count.index].block.target_group_arn
healthcheck_id = local.blocks_by_type.service[count.index].block.healthcheck_id
cluster = local.blocks_by_type.service[count.index].block.cluster
region = var.region != "" ? var.region : data.aws_region.current.name
}

# # metric
# title = local.alarm_status[count.index].title
module "block_sla" {
source = "./modules/blocks/sla"

# alarm_arns = local.alarm_status[count.index].alarm_arns
# stacked = try(local.alarm_status[count.index].stacked, false)
count = length(local.blocks_by_type.sla)

# account_id = try(local.alarm_status[count.index].accountId, null)
# anomaly_detection = try(local.alarm_status[count.index].anomaly_detection, false)
balancer_name = local.blocks_by_type.service[count.index].block.balancer_name
region = var.region != "" ? var.region : data.aws_region.current.name
}
2 changes: 2 additions & 0 deletions modules/dashboard/main.tf
Original file line number Diff line number Diff line change
Expand Up @@ -2,6 +2,8 @@ data "aws_caller_identity" "project" {
provider = aws
}

data "aws_region" "current" {}

/**
* # Example Setup
* ```tf
Expand Down
37 changes: 37 additions & 0 deletions modules/dashboard/modules/blocks/alb/README.md
Original file line number Diff line number Diff line change
@@ -0,0 +1,37 @@
# sqs

<!-- BEGINNING OF PRE-COMMIT-TERRAFORM DOCS HOOK -->
## Requirements

No requirements.

## Providers

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

## Modules

No modules.

## 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) | AWS account ID | `string` | n/a | yes |
| <a name="input_balancer_name"></a> [balancer\_name](#input\_balancer\_name) | ALB name | `string` | n/a | yes |
| <a name="input_region"></a> [region](#input\_region) | n/a | `string` | `""` | no |

## Outputs

| Name | Description |
|------|-------------|
| <a name="output_result"></a> [result](#output\_result) | description |
<!-- END OF PRE-COMMIT-TERRAFORM DOCS HOOK -->
28 changes: 28 additions & 0 deletions modules/dashboard/modules/blocks/alb/output.tf
Original file line number Diff line number Diff line change
@@ -0,0 +1,28 @@
data "aws_lb" "balancer" {
name = var.balancer_name
}

output "result" {
description = "description"
value = [
[
{ type : "text/title-with-link", text : "Load Balancer (ALB)", link_to_jump = "https://${var.region}.console.aws.amazon.com/ec2/home?region=${var.region}#LoadBalancer:loadBalancerArn=${data.aws_lb.balancer.arn};tab=listeners" }
],
[
{ type : "balancer/request-count", accountId : var.account_id, balancer_name : var.balancer_name, anomaly_detection : false },
{ type : "balancer/2xx", accountId : var.account_id, balancer_name : var.balancer_name, anomaly_detection : false },
{ type : "balancer/4xx", accountId : var.account_id, balancer_name : var.balancer_name, anomaly_detection : false },
{ type : "balancer/5xx", accountId : var.account_id, balancer_name : var.balancer_name, anomaly_detection : false },
],
[
{ type : "balancer/all-requests", accountId : var.account_id, balancer_name : var.balancer_name },
{ type : "balancer/unhealthy-request-count", accountId : var.account_id, balancer_name : var.balancer_name, anomaly_detection : false },
{ type : "balancer/error-rate", accountId : var.account_id, balancer_name : var.balancer_name, anomaly_detection = false },
{ type : "balancer/connection-issues", accountId : var.account_id, balancer_name : var.balancer_name, anomaly_detection = false },
],
[
{ type : "balancer/response-time", accountId : var.account_id, balancer_name : var.balancer_name },
{ type : "balancer/traffic", accountId : var.account_id, balancer_name : var.balancer_name },
],
]
}
14 changes: 14 additions & 0 deletions modules/dashboard/modules/blocks/alb/variables.tf
Original file line number Diff line number Diff line change
@@ -0,0 +1,14 @@
variable "account_id" {
type = string
description = "AWS account ID"
}

variable "balancer_name" {
type = string
description = "ALB name"
}

variable "region" {
type = string
default = ""
}
Original file line number Diff line number Diff line change
@@ -1,4 +1,4 @@
# sqs
# rds

<!-- BEGINNING OF PRE-COMMIT-TERRAFORM DOCS HOOK -->
## Requirements
Expand All @@ -21,7 +21,7 @@ No resources.

| Name | Description | Type | Default | Required |
|------|-------------|------|---------|:--------:|
| <a name="input_name"></a> [name](#input\_name) | description | `string` | n/a | yes |
| <a name="input_cdn_id"></a> [cdn\_id](#input\_cdn\_id) | CDN ID | `string` | n/a | yes |

## Outputs

Expand Down
14 changes: 14 additions & 0 deletions modules/dashboard/modules/blocks/cdn/output.tf
Original file line number Diff line number Diff line change
@@ -0,0 +1,14 @@
output "result" {
description = "description"
value = [
[
{ type : "text/title-with-link", text : "CDN (CloudFront)", link_to_jump = "https://us-east-1.console.aws.amazon.com/cloudfront/v3/home?region=us-east-1#/distributions/${var.cdn_id}" }
],
[
{ type : "cloudfront/requests", distribution : var.cdn_id },
{ type : "cloudfront/errors", distribution : var.cdn_id },
{ type : "cloudfront/error-rate", distribution : var.cdn_id },
{ type : "cloudfront/traffic-bytes", distribution : var.cdn_id },
],
]
}
4 changes: 4 additions & 0 deletions modules/dashboard/modules/blocks/cdn/variables.tf
Original file line number Diff line number Diff line change
@@ -0,0 +1,4 @@
variable "cdn_id" {
type = string
description = "CDN ID"
}
35 changes: 35 additions & 0 deletions modules/dashboard/modules/blocks/dns/README.md
Original file line number Diff line number Diff line change
@@ -0,0 +1,35 @@
# rds

<!-- BEGINNING OF PRE-COMMIT-TERRAFORM DOCS HOOK -->
## Requirements

No requirements.

## Providers

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

## Modules

No modules.

## Resources

| Name | Type |
|------|------|
| [aws_route53_zone.selected](https://registry.terraform.io/providers/hashicorp/aws/latest/docs/data-sources/route53_zone) | data source |

## Inputs

| Name | Description | Type | Default | Required |
|------|-------------|------|---------|:--------:|
| <a name="input_zone_name"></a> [zone\_name](#input\_zone\_name) | R53 zone name | `string` | n/a | yes |

## Outputs

| Name | Description |
|------|-------------|
| <a name="output_result"></a> [result](#output\_result) | description |
<!-- END OF PRE-COMMIT-TERRAFORM DOCS HOOK -->
16 changes: 16 additions & 0 deletions modules/dashboard/modules/blocks/dns/output.tf
Original file line number Diff line number Diff line change
@@ -0,0 +1,16 @@
data "aws_route53_zone" "selected" {
name = var.zone_name
}

output "result" {
description = "description"
value = [
[
{ type : "text/title-with-link", text : "DNS Zone", link_to_jump = "https://us-east-1.console.aws.amazon.com/route53/v2/hostedzones?region=eu-central-1#ListRecordSets/${data.aws_route53_zone.selected.zone_id}" }
],
[
{ type : "dns/queries-gauge", zone_name : var.zone_name },
{ type : "dns/queries-chart", width : 18, zone_name : var.zone_name },
],
]
}
4 changes: 4 additions & 0 deletions modules/dashboard/modules/blocks/dns/variables.tf
Original file line number Diff line number Diff line change
@@ -0,0 +1,4 @@
variable "zone_name" {
type = string
description = "R53 zone name"
}
4 changes: 3 additions & 1 deletion modules/dashboard/modules/blocks/rds/README.md
Original file line number Diff line number Diff line change
Expand Up @@ -21,7 +21,9 @@ No resources.

| Name | Description | Type | Default | Required |
|------|-------------|------|---------|:--------:|
| <a name="input_name"></a> [name](#input\_name) | description | `string` | n/a | yes |
| <a name="input_db_max_connections_count"></a> [db\_max\_connections\_count](#input\_db\_max\_connections\_count) | RDS maximum connection count | `string` | `null` | no |
| <a name="input_name"></a> [name](#input\_name) | RDS name | `string` | n/a | yes |
| <a name="input_region"></a> [region](#input\_region) | n/a | `string` | `""` | no |

## Outputs

Expand Down
4 changes: 2 additions & 2 deletions modules/dashboard/modules/blocks/rds/output.tf
Original file line number Diff line number Diff line change
Expand Up @@ -2,11 +2,11 @@ output "result" {
description = "description"
value = [
[
{ type : "text/title-with-link", text : "RDS (${var.name})", link_to_jump = "https://eu-central-1.console.aws.amazon.com/rds/home?region=eu-central-1#database:id=${var.name};is-cluster=false;tab=connectivity" }
{ type : "text/title-with-link", text : "RDS (${var.name})", link_to_jump = "https://${var.region}.console.aws.amazon.com/rds/home?region=${var.region}#database:id=${var.name};is-cluster=false;tab=connectivity" }
],
[
{ type : "rds/free-storage", rds_name : var.name },
{ type : "rds/connections", rds_name : var.name, db_max_connections_count : 100 },
{ type : "rds/connections", rds_name : var.name, db_max_connections_count : var.db_max_connections_count },
{ type : "rds/performance", rds_name : var.name },
{ type : "rds/network", rds_name : var.name },
],
Expand Down
Loading

0 comments on commit 93210f8

Please sign in to comment.