forked from aws-observability/aws-otel-test-framework
-
Notifications
You must be signed in to change notification settings - Fork 0
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
Merge pull request #34 from wyTrivail/terraform-fix
fix skip logic in validator
- Loading branch information
Showing
21 changed files
with
370 additions
and
33 deletions.
There are no files selected for viewing
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,101 @@ | ||
# ------------------------------------------------------------------------ | ||
# Copyright 2020 Amazon.com, Inc. or its affiliates. All Rights Reserved. | ||
# | ||
# Licensed under the Apache License, Version 2.0 (the "License"). | ||
# You may not use this file except in compliance with the License. | ||
# A copy of the License is located at | ||
# | ||
# http://www.apache.org/licenses/LICENSE-2.0 | ||
# | ||
# or in the "license" file accompanying this file. This file is distributed | ||
# on an "AS IS" BASIS, WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either | ||
# express or implied. See the License for the specific language governing | ||
# permissions and limitations under the License. | ||
# ------------------------------------------------------------------------- | ||
|
||
## install cwagent on the instance to collect metric from otel-collector | ||
data "template_file" "cwagent_config" { | ||
count = var.soaking ? 1 : 0 | ||
template = file(local.ami_family["soaking_cwagent_config"]) | ||
|
||
vars = { | ||
soaking_metric_namespace = var.soaking_metric_namespace | ||
} | ||
} | ||
|
||
resource "null_resource" "install_cwagent" { | ||
count = var.soaking ? 1 : 0 | ||
|
||
// copy cwagent config to the instance | ||
provisioner "file" { | ||
content = data.template_file.cwagent_config[0].rendered | ||
destination = local.ami_family["soaking_cwagent_config_destination"] | ||
|
||
connection { | ||
type = local.connection_type | ||
user = local.login_user | ||
private_key = local.connection_type == "ssh" ? data.aws_s3_bucket_object.ssh_private_key.body : null | ||
password = local.connection_type == "winrm" ? rsadecrypt(aws_instance.aoc.password_data, data.aws_s3_bucket_object.ssh_private_key.body) : null | ||
host = aws_instance.aoc.public_ip | ||
} | ||
} | ||
|
||
provisioner "remote-exec" { | ||
inline = [ | ||
local.ami_family["cwagent_download_command"], | ||
local.ami_family["cwagent_start_command"] | ||
] | ||
|
||
connection { | ||
type = local.connection_type | ||
user = local.login_user | ||
private_key = local.connection_type == "ssh" ? data.aws_s3_bucket_object.ssh_private_key.body : null | ||
password = local.connection_type == "winrm" ? rsadecrypt(aws_instance.aoc.password_data, data.aws_s3_bucket_object.ssh_private_key.body) : null | ||
host = aws_instance.aoc.public_ip | ||
} | ||
} | ||
} | ||
|
||
## create cloudwatch alarm base on the metrics emitted by cwagent | ||
# wait 2 minute for the metrics to be available on cloudwatch | ||
resource "time_sleep" "wait_2_minutes" { | ||
depends_on = [null_resource.install_cwagent[0]] | ||
|
||
create_duration = "120s" | ||
} | ||
# cpu alarm | ||
resource "aws_cloudwatch_metric_alarm" "cpu_alarm" { | ||
depends_on = [time_sleep.wait_2_minutes] | ||
alarm_name = "otel-soaking-cpu-alarm-${module.common.testing_id}" | ||
comparison_operator = "GreaterThanOrEqualToThreshold" | ||
evaluation_periods = 2 | ||
threshold = "50" | ||
|
||
metric_query { | ||
id = "cpu" | ||
return_data = true | ||
|
||
metric { | ||
metric_name = local.ami_family["soaking_cpu_metric_name"] | ||
namespace = var.soaking_metric_namespace | ||
period = 60 | ||
stat = "Average" | ||
unit = "Percent" | ||
|
||
# use this dimension to identify each test | ||
dimensions = { | ||
InstanceId = aws_instance.aoc.id | ||
} | ||
} | ||
} | ||
} | ||
|
||
# soaking alarm pulling | ||
resource "null_resource" "bake_alarms" { | ||
depends_on = [aws_cloudwatch_metric_alarm.cpu_alarm] | ||
count = var.soaking ? 1 : 0 | ||
provisioner "local-exec" { | ||
command = "${module.common.validator_path} --args='-c ${var.validation_config} -t ${module.common.testing_id} --region ${var.region} --alarm-names ${aws_cloudwatch_metric_alarm.cpu_alarm.alarm_name}'" | ||
working_dir = "../../" | ||
} | ||
} |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,3 @@ | ||
|
||
|
||
|
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,54 @@ | ||
{ | ||
"agent": { | ||
"metrics_collection_interval": 10 | ||
}, | ||
"metrics": { | ||
"append_dimensions": { | ||
"InstanceId": "$${aws:InstanceId}" | ||
}, | ||
"metrics_collected": { | ||
"cpu": { | ||
"measurement": [ | ||
"cpu_usage_idle", | ||
"cpu_usage_iowait", | ||
"cpu_usage_user", | ||
"cpu_usage_system" | ||
], | ||
"totalcpu": false | ||
}, | ||
"disk": { | ||
"measurement": [ | ||
"used_percent", | ||
"inodes_free" | ||
] | ||
}, | ||
"diskio": { | ||
"measurement": [ | ||
"io_time" | ||
] | ||
}, | ||
"mem": { | ||
"measurement": [ | ||
"mem_used_percent" | ||
] | ||
}, | ||
"statsd": { | ||
}, | ||
"swap": { | ||
"measurement": [ | ||
"swap_used_percent" | ||
] | ||
}, | ||
"procstat": [ | ||
{ | ||
"measurement": [ | ||
"cpu_usage", | ||
"memory_rss" | ||
], | ||
"exe": "aws-otel-collector" | ||
} | ||
] | ||
}, | ||
"namespace": "${soaking_metric_namespace}" | ||
} | ||
} |
File renamed without changes.
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,13 @@ | ||
# enable soaking | ||
soaking = true | ||
|
||
# assuming the sample app will generate high volume data by default | ||
sample_app_callable = false | ||
|
||
# ask validator to pull the alarms | ||
validation_config="alarm-pulling-validation.yml" | ||
|
||
# use amazonlinux2 by default to soak | ||
testing_ami = "amazonlinux2" | ||
|
||
aoc_version = "v0.1.13-311011856" |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
28 changes: 28 additions & 0 deletions
28
validator/src/main/java/com/amazon/aoc/services/CloudWatchAlarmService.java
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,28 @@ | ||
package com.amazon.aoc.services; | ||
|
||
import com.amazonaws.services.cloudwatch.AmazonCloudWatch; | ||
import com.amazonaws.services.cloudwatch.AmazonCloudWatchClientBuilder; | ||
import com.amazonaws.services.cloudwatch.model.DescribeAlarmsRequest; | ||
import com.amazonaws.services.cloudwatch.model.DescribeAlarmsResult; | ||
import com.amazonaws.services.cloudwatch.model.MetricAlarm; | ||
|
||
import java.util.List; | ||
|
||
public class CloudWatchAlarmService { | ||
AmazonCloudWatch amazonCloudWatch; | ||
|
||
public CloudWatchAlarmService(String region) { | ||
amazonCloudWatch = AmazonCloudWatchClientBuilder.standard().withRegion(region).build(); | ||
} | ||
|
||
/** | ||
* Get alarm list base on name. | ||
* @param alarmNameList alarm name list | ||
* @return the list of MetricAlarm Object | ||
*/ | ||
public List<MetricAlarm> listAlarms(List<String> alarmNameList) { | ||
DescribeAlarmsResult describeALarmsResult = | ||
amazonCloudWatch.describeAlarms(new DescribeAlarmsRequest().withAlarmNames(alarmNameList)); | ||
return describeALarmsResult.getMetricAlarms(); | ||
} | ||
} |
Oops, something went wrong.