Skip to content

Commit

Permalink
fix(fis): apply awsfis module (#66)
Browse files Browse the repository at this point in the history
* chore(fis): rename files of fis example

* fix(fis): apply awsfis module

* chore(fis): grooming awscw resources
  • Loading branch information
Young-ook authored Apr 18, 2022
1 parent 200d3c8 commit 1c6fb72
Show file tree
Hide file tree
Showing 8 changed files with 168 additions and 267 deletions.
33 changes: 0 additions & 33 deletions examples/fis/aws-cw.tf

This file was deleted.

150 changes: 0 additions & 150 deletions examples/fis/aws-fis.tf

This file was deleted.

84 changes: 84 additions & 0 deletions examples/fis/awscw.tf
Original file line number Diff line number Diff line change
@@ -0,0 +1,84 @@
resource "aws_ssm_association" "install-cwagent" {
depends_on = [module.ec2]
name = "AWS-ConfigureAWSPackage"

targets {
key = "tag:release"
values = ["baseline,canary"]
}

parameters = {
action = "Install"
name = "AmazonCloudWatchAgent"
}
}

resource "time_sleep" "wait" {
depends_on = [aws_ssm_association.install-cwagent]
create_duration = "30s"
}

resource "aws_ssm_association" "start-cwagent" {
depends_on = [time_sleep.wait]
name = "AmazonCloudWatch-ManageAgent"

targets {
key = "tag:release"
values = ["baseline,canary"]
}

parameters = {
action = "start"
}
}

### application/monitoring
resource "aws_cloudwatch_metric_alarm" "cpu" {
alarm_name = local.cw_cpu_alarm_name
alarm_description = "This metric monitors ec2 cpu utilization"
tags = merge(local.default-tags, var.tags)
comparison_operator = "GreaterThanOrEqualToThreshold"
evaluation_periods = 3
metric_name = "CPUUtilization"
namespace = "AWS/EC2"
period = 60
statistic = "Average"
threshold = 60
insufficient_data_actions = []

dimensions = {
AutoScalingGroupName = module.ec2.cluster.data_plane.node_groups.baseline.name
}
}

resource "aws_cloudwatch_metric_alarm" "api-p90" {
alarm_name = local.cw_api_p90_alarm_name
alarm_description = "This metric monitors percentile of response latency"
tags = merge(local.default-tags, var.tags)
comparison_operator = "GreaterThanThreshold"
evaluation_periods = 1
metric_name = "TargetResponseTime"
namespace = "AWS/ApplicationELB"
period = 60
unit = "Seconds"
threshold = 0.1
extended_statistic = "p90"

dimensions = {
LoadBalancer = aws_lb.alb.arn_suffix
}
}

resource "aws_cloudwatch_metric_alarm" "api-avg" {
alarm_name = local.cw_api_avg_alarm_name
alarm_description = "This metric monitors average time of response latency"
tags = merge(local.default-tags, var.tags)
comparison_operator = "GreaterThanThreshold"
evaluation_periods = 1
metric_name = "TargetResponseTime"
namespace = "AWS/ApplicationELB"
period = 60
unit = "Seconds"
statistic = "Average"
threshold = 0.1

84 changes: 84 additions & 0 deletions examples/fis/awsfis.tf
Original file line number Diff line number Diff line change
@@ -0,0 +1,84 @@
### systems manager document for fault injection simulator experiment

resource "aws_ssm_document" "disk-stress" {
name = "FIS-Run-Disk-Stress"
tags = merge(local.default-tags, var.tags)
document_format = "YAML"
document_type = "Command"
content = file("${path.module}/templates/disk-stress.yaml")
}

### fault injection simulator experiment templates

# drawing lots for choosing a subnet
resource "random_integer" "az" {
min = 0
max = length(var.azs) - 1
}

locals {
target_vpc = module.vpc.vpc.id
target_role = module.ec2.role.arn
target_asg = module.ec2.cluster.data_plane.node_groups.baseline.name
fis_role = module.awsfis.role.arn

experiments = [
{
name = "cpu-stress"
template = "${path.cwd}/templates/cpu-stress.tpl"
params = {
asg = local.target_asg
region = var.aws_region
alarm = aws_cloudwatch_metric_alarm.cpu.arn
role = local.fis_role
}
},
{
name = "network-latency"
template = "${path.cwd}/templates/network-latency.tpl"
params = {
asg = local.target_asg
region = var.aws_region
alarm = aws_cloudwatch_metric_alarm.cpu.arn
role = local.fis_role
}
},
{
name = "terminate-instances"
template = "${path.cwd}/templates/terminate-instances.tpl"
params = {
asg = local.target_asg
az = var.azs[random_integer.az.result]
vpc = local.target_vpc
alarm = aws_cloudwatch_metric_alarm.cpu.arn
role = local.fis_role
}
},
{
name = "throttle-ec2-api"
template = "${path.cwd}/templates/throttle-ec2-api.tpl"
params = {
asg_role = local.target_role
alarm = aws_cloudwatch_metric_alarm.cpu.arn
role = local.fis_role
}
},
{
name = "disk-stress"
template = "${path.cwd}/templates/disk-stress.tpl"
params = {
doc_arn = aws_ssm_document.disk-stress.arn
region = var.aws_region
alarm = aws_cloudwatch_metric_alarm.cpu.arn
role = local.fis_role
}
},
]
}

module "awsfis" {
source = "Young-ook/fis/aws"
name = var.name
tags = var.tags
experiments = local.experiments
}
File renamed without changes.
Loading

0 comments on commit 1c6fb72

Please sign in to comment.