Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Implement fix for sles linux integ-test #278

Open
wants to merge 2 commits into
base: main
Choose a base branch
from
Open
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
8 changes: 8 additions & 0 deletions environment/metadata.go
Original file line number Diff line number Diff line change
Expand Up @@ -33,6 +33,7 @@ type MetaData struct {
ProxyUrl string
AssumeRoleArn string
InstanceId string
OS string
}

type MetaDataStrings struct {
Expand All @@ -52,6 +53,7 @@ type MetaDataStrings struct {
ProxyUrl string
AssumeRoleArn string
InstanceId string
OS string
}

func registerComputeType(dataString *MetaDataStrings) {
Expand All @@ -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")
Expand Down Expand Up @@ -178,6 +184,7 @@ func RegisterEnvironmentMetaDataFlags(metaDataStrings *MetaDataStrings) *MetaDat
registerProxyUrl(metaDataStrings)
registerAssumeRoleArn(metaDataStrings)
registerInstanceId(metaDataStrings)
registerOS(metaDataStrings)
return metaDataStrings
}

Expand All @@ -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
Expand Down
2 changes: 1 addition & 1 deletion terraform/ec2/linux/main.tf
Original file line number Diff line number Diff line change
Expand Up @@ -88,7 +88,7 @@ resource "null_resource" "integration_test_run" {
"echo run sanity test && go test ./test/sanity -p 1 -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.linux_common.proxy_instance_proxy_ip} -instanceId=${module.linux_common.cwagent_id} -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"
]
}

Expand Down
5 changes: 5 additions & 0 deletions terraform/ec2/linux/variables.tf
Original file line number Diff line number Diff line change
Expand Up @@ -106,3 +106,8 @@ variable "pre_test_setup" {
type = string
default = "echo no pre-test setup"
}

variable "os" {
type = string
default = ""
}
Original file line number Diff line number Diff line change
Expand Up @@ -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}}},
Expand Down
46 changes: 35 additions & 11 deletions test/metric_value_benchmark/net_test.go
Original file line number Diff line number Diff line change
Expand Up @@ -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)
Expand Down Expand Up @@ -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))
Copy link
Contributor

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Why not just

Suggested change
log.Println(fmt.Sprintf("OS VERSION IS %s", m.env.OS))
log.Printf("OS VERSION IS %s\n", m.env.OS)

if strings.Contains(m.env.OS, "sles") {
Copy link
Contributor

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

nit - I'd prefer to use HasPrefix

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(),
},
})
}
Comment on lines +78 to +89
Copy link
Contributor

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Frankly we could consolidate this since the only thing that differs is the name of the expected dimension.

var dimName string
if strings.HasPrefix(m.env.OS, "sles") {
  dimName = "eth0"
} else {
  dimName = "docker0"
}
dims, failed = m.DimensionFactory.GetDimensions([]dimension.Instruction{
	{
		Key:   "interface",
		Value: dimension.ExpectedDimensionValue{&dimName},
	},
	{
		Key:   "InstanceId",
		Value: dimension.UnknownDimensionValue(),
	},
})


if len(failed) > 0 {
return testResult
Expand Down