From 520d6b5c4f7a66e895f1dc183ccc2461b9dad7da Mon Sep 17 00:00:00 2001 From: Jason Polanco Date: Fri, 23 Jun 2023 18:21:28 -0400 Subject: [PATCH] Implement fix for sles linux integ-test --- environment/metadata.go | 8 ++++ terraform/ec2/linux/main.tf | 2 +- terraform/ec2/linux/variables.tf | 5 ++ .../metrics_value_benchmark_test.go | 2 +- test/metric_value_benchmark/net_test.go | 46 ++++++++++++++----- 5 files changed, 50 insertions(+), 13 deletions(-) diff --git a/environment/metadata.go b/environment/metadata.go index 5d75c28dd..14dbfaa21 100644 --- a/environment/metadata.go +++ b/environment/metadata.go @@ -33,6 +33,7 @@ type MetaData struct { ProxyUrl string AssumeRoleArn string InstanceId string + OS string } type MetaDataStrings struct { @@ -52,6 +53,7 @@ type MetaDataStrings struct { ProxyUrl string AssumeRoleArn string InstanceId string + OS string } func registerComputeType(dataString *MetaDataStrings) { @@ -70,6 +72,10 @@ func registerCwaCommitSha(dataString *MetaDataStrings) { func registerCaCertPath(dataString *MetaDataStrings) { flag.StringVar(&(dataString.CaCertPath), "caCertPath", "", "ec2 path to crts ex /etc/ssl/certs/ca-certificates.crt") } + +func registerOS(dataString *MetaDataStrings) { + flag.StringVar(&(dataString.OS), "OS", "", "OS of ec2 instance") +} func registerECSData(dataString *MetaDataStrings) { flag.StringVar(&(dataString.EcsLaunchType), "ecsLaunchType", "", "EC2 or Fargate") flag.StringVar(&(dataString.EcsDeploymentStrategy), "ecsDeploymentStrategy", "", "Daemon/Replica/Sidecar") @@ -178,6 +184,7 @@ func RegisterEnvironmentMetaDataFlags(metaDataStrings *MetaDataStrings) *MetaDat registerProxyUrl(metaDataStrings) registerAssumeRoleArn(metaDataStrings) registerInstanceId(metaDataStrings) + registerOS(metaDataStrings) return metaDataStrings } @@ -191,6 +198,7 @@ func GetEnvironmentMetaData(data *MetaDataStrings) *MetaData { metaData.S3Key = data.S3Key metaData.CwaCommitSha = data.CwaCommitSha metaData.CaCertPath = data.CaCertPath + metaData.OS = data.OS metaData.ProxyUrl = data.ProxyUrl metaData.AssumeRoleArn = data.AssumeRoleArn metaData.InstanceId = data.InstanceId diff --git a/terraform/ec2/linux/main.tf b/terraform/ec2/linux/main.tf index a836095f7..d91990ee6 100644 --- a/terraform/ec2/linux/main.tf +++ b/terraform/ec2/linux/main.tf @@ -200,7 +200,7 @@ resource "null_resource" "integration_test_run" { "cd ~/amazon-cloudwatch-agent-test", "echo run sanity test && go test ./test/sanity -p 1 -v", var.pre_test_setup, - "go test ${var.test_dir} -p 1 -timeout 1h -computeType=EC2 -bucket=${var.s3_bucket} -plugins='${var.plugin_tests}' -cwaCommitSha=${var.cwa_github_sha} -caCertPath=${var.ca_cert_path} -proxyUrl=${module.proxy_instance.proxy_ip} -instanceId=${aws_instance.cwagent.id} -v" + "go test ${var.test_dir} -p 1 -timeout 1h -computeType=EC2 -bucket=${var.s3_bucket} -plugins='${var.plugin_tests}' -cwaCommitSha=${var.cwa_github_sha} -caCertPath=${var.ca_cert_path} -proxyUrl=${module.proxy_instance.proxy_ip} -OS=${var.os} -instanceId=${aws_instance.cwagent.id} -v" ] } diff --git a/terraform/ec2/linux/variables.tf b/terraform/ec2/linux/variables.tf index 0d4d53ea4..6ca5c8799 100644 --- a/terraform/ec2/linux/variables.tf +++ b/terraform/ec2/linux/variables.tf @@ -106,3 +106,8 @@ variable "pre_test_setup" { type = string default = "echo no pre-test setup" } + +variable "os" { + type = string + default = "" +} diff --git a/test/metric_value_benchmark/metrics_value_benchmark_test.go b/test/metric_value_benchmark/metrics_value_benchmark_test.go index 72bf028be..d9d5ab394 100644 --- a/test/metric_value_benchmark/metrics_value_benchmark_test.go +++ b/test/metric_value_benchmark/metrics_value_benchmark_test.go @@ -108,7 +108,7 @@ func getEc2TestRunners(env *environment.MetaData) []*test_runner.TestRunner { {TestRunner: &MemTestRunner{test_runner.BaseTestRunner{DimensionFactory: factory}}}, {TestRunner: &ProcStatTestRunner{test_runner.BaseTestRunner{DimensionFactory: factory}}}, {TestRunner: &DiskIOTestRunner{test_runner.BaseTestRunner{DimensionFactory: factory}}}, - {TestRunner: &NetTestRunner{test_runner.BaseTestRunner{DimensionFactory: factory}}}, + {TestRunner: &NetTestRunner{test_runner.BaseTestRunner{DimensionFactory: factory}, env}}, {TestRunner: &EthtoolTestRunner{test_runner.BaseTestRunner{DimensionFactory: factory}}}, {TestRunner: &EMFTestRunner{test_runner.BaseTestRunner{DimensionFactory: factory}}}, {TestRunner: &SwapTestRunner{test_runner.BaseTestRunner{DimensionFactory: factory}}}, diff --git a/test/metric_value_benchmark/net_test.go b/test/metric_value_benchmark/net_test.go index a85df11c7..0664893fa 100644 --- a/test/metric_value_benchmark/net_test.go +++ b/test/metric_value_benchmark/net_test.go @@ -6,16 +6,22 @@ package metric_value_benchmark import ( - "github.com/aws/aws-sdk-go-v2/aws" + "fmt" + "log" + "strings" + "github.com/aws/amazon-cloudwatch-agent-test/environment" "github.com/aws/amazon-cloudwatch-agent-test/test/metric" "github.com/aws/amazon-cloudwatch-agent-test/test/metric/dimension" "github.com/aws/amazon-cloudwatch-agent-test/test/status" "github.com/aws/amazon-cloudwatch-agent-test/test/test_runner" + "github.com/aws/aws-sdk-go-v2/aws" + "github.com/aws/aws-sdk-go-v2/service/cloudwatch/types" ) type NetTestRunner struct { test_runner.BaseTestRunner + env *environment.MetaData } var _ test_runner.ITestRunner = (*NetTestRunner)(nil) @@ -53,16 +59,34 @@ func (m *NetTestRunner) validateNetMetric(metricName string) status.TestResult { Status: status.FAILED, } - dims, failed := m.DimensionFactory.GetDimensions([]dimension.Instruction{ - { - Key: "interface", - Value: dimension.ExpectedDimensionValue{aws.String("docker0")}, - }, - { - Key: "InstanceId", - Value: dimension.UnknownDimensionValue(), - }, - }) + var ( + dims []types.Dimension + failed []dimension.Instruction + ) + log.Println(fmt.Sprintf("OS VERSION IS %s", m.env.OS)) + if strings.Contains(m.env.OS, "sles") { + dims, failed = m.DimensionFactory.GetDimensions([]dimension.Instruction{ + { + Key: "interface", + Value: dimension.ExpectedDimensionValue{aws.String("eth0")}, + }, + { + Key: "InstanceId", + Value: dimension.UnknownDimensionValue(), + }, + }) + } else { + dims, failed = m.DimensionFactory.GetDimensions([]dimension.Instruction{ + { + Key: "interface", + Value: dimension.ExpectedDimensionValue{aws.String("docker0")}, + }, + { + Key: "InstanceId", + Value: dimension.UnknownDimensionValue(), + }, + }) + } if len(failed) > 0 { return testResult