Skip to content

Commit

Permalink
Add Hop Limit Test For EKS metric_value_benchmark Test
Browse files Browse the repository at this point in the history
  • Loading branch information
sethAmazon committed Apr 10, 2024
1 parent c638bfa commit efaae09
Show file tree
Hide file tree
Showing 20 changed files with 206 additions and 45 deletions.
13 changes: 10 additions & 3 deletions generator/resources/eks_daemon_test_matrix.json
Original file line number Diff line number Diff line change
@@ -1,12 +1,19 @@
[
{
"k8s_version": "1.24",
"k8sVersion": "1.24",
"ami": "AL2_x86_64",
"instanceType":"t3a.medium",
"instanceType":"t3.medium",
"arc": "amd64"
},
{
"k8s_version": "1.24",
"k8sVersion": "1.24",
"ami": "AL2_x86_64",
"instanceType":"t3.medium",
"arc": "amd64",
"hopLimit": 1
},
{
"k8sVersion": "1.24",
"ami": "AL2_ARM_64",
"instanceType":"m6g.large",
"arc": "arm64"
Expand Down
76 changes: 45 additions & 31 deletions generator/test_case_generator.go
Original file line number Diff line number Diff line change
Expand Up @@ -29,6 +29,7 @@ type matrixRow struct {
CaCertPath string `json:"caCertPath"`
ValuesPerMinute int `json:"values_per_minute"` // Number of metrics to be sent or number of log lines to write
K8sVersion string `json:"k8s_version"`
HopLimit int `json:"hop_limit"`
TerraformDir string `json:"terraform_dir"`
UseSSM bool `json:"useSSM"`
ExcludedTests string `json:"excludedTests"`
Expand All @@ -44,13 +45,14 @@ type testConfig struct {
runMockServer bool
// define target matrix field as set(s)
// empty map means a testConfig will be created with a test entry for each entry from *_test_matrix.json
targets map[string]map[string]struct{}
targets map[string]map[any]struct{}
// maxAttempts limits the number of times a test will be run.
maxAttempts int
}

const (
testTypeKeyEc2Linux = "ec2_linux"
defaultHopLimit = 2
)

// you can't have a const map in golang
Expand All @@ -63,11 +65,11 @@ var testTypeToTestConfig = map[string][]testConfig{
{testDir: "./test/cloudwatchlogs"},
{
testDir: "./test/metrics_number_dimension",
targets: map[string]map[string]struct{}{"os": {"al2": {}}},
targets: map[string]map[any]struct{}{"os": {"al2": {}}},
},
{
testDir: "./test/emf_concurrent",
targets: map[string]map[string]struct{}{"os": {"al2": {}}},
targets: map[string]map[any]struct{}{"os": {"al2": {}}},
maxAttempts: 1,
},
{testDir: "./test/metric_value_benchmark"},
Expand All @@ -79,39 +81,39 @@ var testTypeToTestConfig = map[string][]testConfig{
{testDir: "./test/otlp"},
{
testDir: "./test/acceptance",
targets: map[string]map[string]struct{}{"os": {"ubuntu-20.04": {}}},
targets: map[string]map[any]struct{}{"os": {"ubuntu-20.04": {}}},
},
// skipping FIPS test as the test cannot be verified
// neither ssh nor SSM works after a reboot once FIPS is enabled
//{
// testDir: "./test/fips",
// targets: map[string]map[string]struct{}{"os": {"rhel8": {}}},
// targets: map[string]map[any]struct{}{"os": {"rhel8": {}}},
//},
{
testDir: "./test/lvm",
targets: map[string]map[string]struct{}{"os": {"al2": {}}},
targets: map[string]map[any]struct{}{"os": {"al2": {}}},
},
{
testDir: "./test/proxy",
targets: map[string]map[string]struct{}{"os": {"al2": {}}},
targets: map[string]map[any]struct{}{"os": {"al2": {}}},
},
{
testDir: "./test/ssl_cert",
targets: map[string]map[string]struct{}{"os": {"al2": {}}},
targets: map[string]map[any]struct{}{"os": {"al2": {}}},
},
{
testDir: "./test/userdata",
terraformDir: "terraform/ec2/userdata",
targets: map[string]map[string]struct{}{"os": {"ol9": {}}},
targets: map[string]map[any]struct{}{"os": {"ol9": {}}},
},
{
testDir: "./test/assume_role",
terraformDir: "terraform/ec2/creds",
targets: map[string]map[string]struct{}{"os": {"al2": {}}},
targets: map[string]map[any]struct{}{"os": {"al2": {}}},
},
{
testDir: "./test/app_signals",
targets: map[string]map[string]struct{}{"os": {"al2": {}}, "arc": {"amd64": {}}},
targets: map[string]map[any]struct{}{"os": {"al2": {}}, "arc": {"amd64": {}}},
},
},
/*
Expand All @@ -129,11 +131,11 @@ var testTypeToTestConfig = map[string][]testConfig{
{testDir: "../../../test/feature/windows/event_logs"},
{
testDir: "../../../test/feature/windows/custom_start/userdata",
targets: map[string]map[string]struct{}{"os": {"win-2019": {}}},
targets: map[string]map[any]struct{}{"os": {"win-2019": {}}},
},
{
testDir: "../../../test/feature/windows/custom_start/ssm_start",
targets: map[string]map[string]struct{}{"os": {"win-2019": {}}},
targets: map[string]map[any]struct{}{"os": {"win-2019": {}}},
},
// assume role test doesn't add much value, and it already being tested with linux
//{testDir: "../../../test/assume_role"},
Expand Down Expand Up @@ -167,56 +169,65 @@ var testTypeToTestConfig = map[string][]testConfig{
"ecs_ec2_daemon": {
{
testDir: "./test/metric_value_benchmark",
targets: map[string]map[string]struct{}{"metadataEnabled": {"enabled": {}}},
targets: map[string]map[any]struct{}{"metadataEnabled": {"enabled": {}}},
},
{
testDir: "./test/statsd",
targets: map[string]map[string]struct{}{"metadataEnabled": {"enabled": {}}},
targets: map[string]map[any]struct{}{"metadataEnabled": {"enabled": {}}},
},
{
testDir: "./test/emf",
targets: map[string]map[string]struct{}{"metadataEnabled": {"disabled": {}}},
targets: map[string]map[any]struct{}{"metadataEnabled": {"disabled": {}}},
},
{
testDir: "./test/emf",
targets: map[string]map[string]struct{}{"metadataEnabled": {"enabled": {}}},
targets: map[string]map[any]struct{}{"metadataEnabled": {"enabled": {}}},
},
},
"eks_daemon": {
{
testDir: "./test/metric_value_benchmark",
targets: map[string]map[string]struct{}{"arc": {"amd64": {}}},
targets: map[string]map[any]struct{}{"arc": {"amd64": {}}},
},
{
testDir: "./test/metric_value_benchmark",
terraformDir: "terraform/eks/daemon/windows/2019",
targets: map[string]map[string]struct{}{"arc": {"amd64": {}}},
targets: map[string]map[any]struct{}{"arc": {"amd64": {}}, "hopLimit": {2: {}}},
},
{
testDir: "./test/metric_value_benchmark",
terraformDir: "terraform/eks/daemon/windows/2022",
targets: map[string]map[string]struct{}{"arc": {"amd64": {}}},
targets: map[string]map[any]struct{}{"arc": {"amd64": {}}, "hopLimit": {2: {}}},
},
{
testDir: "./test/statsd", terraformDir: "terraform/eks/daemon/statsd",
targets: map[string]map[string]struct{}{"arc": {"amd64": {}}},
targets: map[string]map[any]struct{}{"arc": {"amd64": {}}, "hopLimit": {2: {}}},
},
{
testDir: "./test/emf", terraformDir: "terraform/eks/daemon/emf",
targets: map[string]map[string]struct{}{"arc": {"amd64": {}}},
targets: map[string]map[any]struct{}{"arc": {"amd64": {}}, "hopLimit": {2: {}}},
},
{
testDir: "./test/fluent", terraformDir: "terraform/eks/daemon/fluent/d",
targets: map[string]map[string]struct{}{"arc": {"amd64": {}}},
targets: map[string]map[any]struct{}{"arc": {"amd64": {}}, "hopLimit": {2: {}}},
},
{testDir: "./test/fluent", terraformDir: "terraform/eks/daemon/fluent/bit"},
{testDir: "./test/app_signals", terraformDir: "terraform/eks/daemon/app_signals",
targets: map[string]map[string]struct{}{"arc": {"amd64": {}}},
{
testDir: "./test/fluent",
terraformDir: "terraform/eks/daemon/fluent/bit",
targets: map[string]map[any]struct{}{"hopLimit": {2: {}}},
},
{
testDir: "./test/app_signals", terraformDir: "terraform/eks/daemon/app_signals",
targets: map[string]map[any]struct{}{"arc": {"amd64": {}}, "hopLimit": {2: {}}},
},
{
testDir: "./test/fluent",
terraformDir: "terraform/eks/daemon/fluent/windows/2022",
targets: map[string]map[any]struct{}{"arc": {"amd64": {}}, "hopLimit": {2: {}}},
},
{testDir: "./test/fluent", terraformDir: "terraform/eks/daemon/fluent/windows/2022"},
{
testDir: "./test/gpu", terraformDir: "terraform/eks/daemon/gpu",
targets: map[string]map[string]struct{}{"arc": {"amd64": {}}},
targets: map[string]map[any]struct{}{"arc": {"amd64": {}}, "hopLimit": {2: {}}},
},
},
"eks_deployment": {
Expand Down Expand Up @@ -254,7 +265,7 @@ func copyAllEC2LinuxTestForOnpremTesting() {
testTypeToTestConfig["ec2_linux_onprem"] = []testConfig{
{
testDir: "./test/lvm",
targets: map[string]map[string]struct{}{"os": {"al2": {}}},
targets: map[string]map[any]struct{}{"os": {"al2": {}}},
},
}
}
Expand Down Expand Up @@ -298,6 +309,7 @@ func genMatrix(testType string, testConfigs []testConfig, ami []string) []matrix
TestType: testType,
TerraformDir: testConfig.terraformDir,
MaxAttempts: testConfig.maxAttempts,
HopLimit: defaultHopLimit,
}
err = mapstructure.Decode(test, &row)
if err != nil {
Expand All @@ -318,15 +330,17 @@ func genMatrix(testType string, testConfigs []testConfig, ami []string) []matrix

// not so robust way to determine a matrix entry should be included to complete test matrix, but it serves the purpose
// struct (matrixRow) field should be added as elif to support more. could use reflection with some tradeoffs
func shouldAddTest(row *matrixRow, targets map[string]map[string]struct{}) bool {
func shouldAddTest(row *matrixRow, targets map[string]map[any]struct{}) bool {
for key, set := range targets {
var rowVal string
var rowVal any
if key == "arc" {
rowVal = row.Arc
} else if key == "os" {
rowVal = row.Os
} else if key == "metadataEnabled" {
rowVal = row.MetadataEnabled
} else if key == "hopLimit" {
rowVal = row.HopLimit
}

if rowVal == "" {
Expand Down
2 changes: 1 addition & 1 deletion terraform/ecs_ec2/daemon/main.tf
Original file line number Diff line number Diff line change
Expand Up @@ -39,7 +39,7 @@ resource "aws_launch_configuration" "cluster" {
metadata_options {
http_endpoint = "enabled"
http_tokens = "required"
http_put_response_hop_limit = 2
http_put_response_hop_limit = var.hop_limit
}
}

Expand Down
5 changes: 5 additions & 0 deletions terraform/ecs_ec2/daemon/variables.tf
Original file line number Diff line number Diff line change
Expand Up @@ -31,4 +31,9 @@ variable "cwagent_image_tag" {
variable "metadataEnabled" {
type = string
default = "enabled"
}

variable "hop_limit" {
type = number
default = 2
}
7 changes: 6 additions & 1 deletion terraform/eks/daemon/app_signals/variables.tf
Original file line number Diff line number Diff line change
Expand Up @@ -34,4 +34,9 @@ variable "ami_type" {
variable "instance_type" {
type = string
default = "t3a.medium"
}
}

variable "hop_limit" {
type = number
default = 2
}
7 changes: 6 additions & 1 deletion terraform/eks/daemon/emf/variables.tf
Original file line number Diff line number Diff line change
Expand Up @@ -34,4 +34,9 @@ variable "ami_type" {
variable "instance_type" {
type = string
default = "t3a.medium"
}
}

variable "hop_limit" {
type = number
default = 2
}
7 changes: 6 additions & 1 deletion terraform/eks/daemon/fluent/bit/variables.tf
Original file line number Diff line number Diff line change
Expand Up @@ -34,4 +34,9 @@ variable "ami_type" {
variable "instance_type" {
type = string
default = "t3a.medium"
}
}

variable "hop_limit" {
type = number
default = 2
}
7 changes: 6 additions & 1 deletion terraform/eks/daemon/fluent/common/variables.tf
Original file line number Diff line number Diff line change
Expand Up @@ -35,4 +35,9 @@ variable "ami_type" {
variable "instance_type" {
type = string
default = "t3a.medium"
}
}

variable "hop_limit" {
type = number
default = 2
}
7 changes: 6 additions & 1 deletion terraform/eks/daemon/fluent/d/variables.tf
Original file line number Diff line number Diff line change
Expand Up @@ -34,4 +34,9 @@ variable "ami_type" {
variable "instance_type" {
type = string
default = "t3a.medium"
}
}

variable "hop_limit" {
type = number
default = 2
}
7 changes: 6 additions & 1 deletion terraform/eks/daemon/fluent/windows/2019/variables.tf
Original file line number Diff line number Diff line change
Expand Up @@ -44,4 +44,9 @@ variable "windows_ami_type" {
variable "windows_os_version" {
type = string
default = "2019"
}
}

variable "hop_limit" {
type = number
default = 2
}
7 changes: 6 additions & 1 deletion terraform/eks/daemon/fluent/windows/2022/variables.tf
Original file line number Diff line number Diff line change
Expand Up @@ -44,4 +44,9 @@ variable "windows_ami_type" {
variable "windows_os_version" {
type = string
default = "2022"
}
}

variable "hop_limit" {
type = number
default = 2
}
6 changes: 6 additions & 0 deletions terraform/eks/daemon/fluent/windows/variables.tf
Original file line number Diff line number Diff line change
Expand Up @@ -45,3 +45,9 @@ variable "windows_os_version" {
type = string
default = "2022"
}

variable "hop_limit" {
type = number
default = 2
}

5 changes: 5 additions & 0 deletions terraform/eks/daemon/gpu/variables.tf
Original file line number Diff line number Diff line change
Expand Up @@ -34,4 +34,9 @@ variable "ami_type" {
variable "instance_type" {
type = string
default = "g4dn.xlarge"
}

variable "hop_limit" {
type = number
default = 2
}
Loading

0 comments on commit efaae09

Please sign in to comment.