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

Reduce code for ethool test and change variables for terraform script #584

Merged
merged 3 commits into from
Aug 30, 2022
Merged
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
15 changes: 7 additions & 8 deletions .github/workflows/integrationTest.yml
Original file line number Diff line number Diff line change
Expand Up @@ -81,7 +81,6 @@ jobs:
echo "${GPG_PRIVATE_KEY}" | gpg --batch --import -
for f in $(find build/bin/); do if [ ! -d $f ]; then echo "Signing file $f" && echo "${PASSPHRASE}" | gpg --detach-sign --passphrase-fd 0 --batch --default-key "${GPG_KEY_NAME}" $f ; fi ; done


- name: Upload to s3
if: steps.cached_binaries.outputs.cache-hit != 'true'
run: aws s3 cp build/bin s3://${S3_INTEGRATION_BUCKET}/integration-test/binary/${{ github.sha }} --recursive
Expand Down Expand Up @@ -373,11 +372,11 @@ jobs:
run: >
echo run terraform and execute test code &&
terraform apply --auto-approve
-var="ssh_key=${PRIVATE_KEY}"
-var="ssh_key_value=${PRIVATE_KEY}"
-var="github_repo=${GITHUB_SERVER_URL}/${GITHUB_REPOSITORY}.git"
-var="github_sha=${GITHUB_SHA}"
-var="s3_bucket=${S3_INTEGRATION_BUCKET}"
-var="key_name=${KEY_NAME}" &&
-var="ssh_key_name=${KEY_NAME}" &&
LOCAL_STACK_HOST_NAME=$(terraform output -raw public_dns) &&
echo $LOCAL_STACK_HOST_NAME &&
echo "::set-output name=local_stack_host_name::$LOCAL_STACK_HOST_NAME" &&
Expand Down Expand Up @@ -428,7 +427,7 @@ jobs:
cd integration/terraform/ec2/linux
terraform init
if terraform apply --auto-approve \
-var="ssh_key=${PRIVATE_KEY}" -var="github_repo=${GITHUB_SERVER_URL}/${GITHUB_REPOSITORY}.git" \
-var="ssh_key_value=${PRIVATE_KEY}" -var="github_repo=${GITHUB_SERVER_URL}/${GITHUB_REPOSITORY}.git" \
-var="github_sha=${GITHUB_SHA}" -var="install_agent=${{ matrix.arrays.installAgentCommand }}" \
-var="ec2_instance_type=${{ matrix.arrays.instanceType }}" \
-var="user=${{ matrix.arrays.username }}" \
Expand All @@ -438,7 +437,7 @@ jobs:
-var="binary_name=${{ matrix.arrays.binaryName }}" \
-var="local_stack_host_name=${{ needs.StartLocalStack.outputs.local_stack_host_name }}" \
-var="s3_bucket=${S3_INTEGRATION_BUCKET}" \
-var="key_name=${KEY_NAME}" \
-var="ssh_key_name=${KEY_NAME}" \
-var="test_name=${{ matrix.arrays.os }}" \
-var="test_dir=${{ matrix.arrays.test_dir }}" ; then terraform destroy -auto-approve
else
Expand Down Expand Up @@ -500,7 +499,7 @@ jobs:
cd integration/terraform/ec2/win
terraform init
if terraform apply --auto-approve \
-var="ssh_key=${PRIVATE_KEY}" -var="key_name=${KEY_NAME}" \
-var="ssh_key_value=${PRIVATE_KEY}" -var="ssh_key_name=${KEY_NAME}" \
-var="github_repo=${GITHUB_SERVER_URL}/${GITHUB_REPOSITORY}.git" \
-var="github_sha=${GITHUB_SHA}" -var="ami=${{ matrix.arrays.ami }}" \
-var="test_name=${{ matrix.arrays.os }}" \
Expand Down Expand Up @@ -664,7 +663,7 @@ jobs:
cd integration/terraform/ec2/linux
terraform init
if terraform apply --auto-approve \
-var="ssh_key=${PRIVATE_KEY}" -var="github_repo=${GITHUB_SERVER_URL}/${GITHUB_REPOSITORY}.git" \
-var="ssh_key_value=${PRIVATE_KEY}" -var="github_repo=${GITHUB_SERVER_URL}/${GITHUB_REPOSITORY}.git" \
-var="github_sha=${GITHUB_SHA}" -var="install_agent=${{ matrix.arrays.installAgentCommand }}" \
-var="user=${{ matrix.arrays.username }}" \
-var="ami=${{ matrix.arrays.ami }}" \
Expand All @@ -673,7 +672,7 @@ jobs:
-var="binary_name=${{ matrix.arrays.binaryName }}" \
-var="local_stack_host_name=${{ needs.StartLocalStack.outputs.local_stack_host_name }}" \
-var="s3_bucket=${S3_INTEGRATION_BUCKET}" \
-var="key_name=${KEY_NAME}" \
-var="ssh_key_name=${KEY_NAME}" \
-var="github_sha_date=${{ steps.sha_date.outputs.sha_date }}" \
-var="test_name=${{ matrix.arrays.os }}" \
-var="performance_number_of_logs=${{ matrix.arrays.performance_number_of_logs}}"\
Expand Down
8 changes: 4 additions & 4 deletions integration/terraform/ec2/README.md
Original file line number Diff line number Diff line change
Expand Up @@ -320,10 +320,10 @@ terraform apply --auto-approve \
-var="github_repo=${gh repo you want to use ex https://github.com/aws/amazon-cloudwatch-agent.git}" \
-var="github_sha=${commit sha you want to use ex fb9229b9eaabb42461a4c049d235567f9c0439f8}" \
-var='vpc_security_group_ids=["${name of your security group}"]' \
-var="key_name=${name of key pair your created}" \
-var="ssh_key_name=${name of key pair your created}" \
-var="s3_bucket=${name of your s3 bucket created}" \
-var="iam_instance_profile=${name of your iam role created}" \
-var="ssh_key=${your key that you downloaded}"
-var="ssh_key_value=${your key that you downloaded}"
```

> See the list of parameters or table of GitHub secret params as reference
Expand Down Expand Up @@ -358,7 +358,7 @@ terraform apply --auto-approve \
-var='vpc_security_group_ids=["${name of your security group}"]' \
-var="s3_bucket=${name of your s3 bucket created}" \
-var="iam_instance_profile=${name of your iam role created}" \
-var="key_name=${name of key pair your created}" \
-var="ssh_key_name=${name of key pair your created}" \
-var="ami=${ami for test you want to use ex cloudwatch-agent-integration-test-ubuntu*}" \
-var="user=${log in for the ec2 instance ex ubuntu}" \
-var="install_agent=${command to install agent ex dpkg -i -E ./amazon-cloudwatch-agent.deb}" \
Expand All @@ -367,7 +367,7 @@ terraform apply --auto-approve \
-var="binary_name=${binary to install ex amazon-cloudwatch-agent.deb}" \
-var="local_stack_host_name=${dns value you got from the local stack terraform apply step}" \
-var="test_name=${what you want to call the ec2 instance name}" \
-var="ssh_key=${your key that you downloaded}"
-var="ssh_key_value=${your key that you downloaded}"
```

> See the list of parameters or table of GitHub secret params as reference
Expand Down
8 changes: 4 additions & 4 deletions integration/terraform/ec2/linux/main.tf
Original file line number Diff line number Diff line change
Expand Up @@ -10,20 +10,20 @@ resource "random_id" "testing_id" {
#####################################################################

resource "tls_private_key" "ssh_key" {
count = var.ssh_key == "" ? 1 : 0
count = var.ssh_key_name == "" ? 1 : 0
algorithm = "RSA"
rsa_bits = 4096
}

resource "aws_key_pair" "aws_ssh_key" {
count = var.ssh_key == "" ? 1 : 0
count = var.ssh_key_name == "" ? 1 : 0
key_name = "ec2-key-pair-${random_id.testing_id.hex}"
public_key = tls_private_key.ssh_key[0].public_key_openssh
}

locals {
ssh_key_name = var.key_name != "" ? var.key_name : aws_key_pair.aws_ssh_key[0].key_name
private_key_content = var.ssh_key != "" ? var.ssh_key : tls_private_key.ssh_key[0].private_key_pem
ssh_key_name = var.ssh_key_name != "" ? var.ssh_key_name : aws_key_pair.aws_ssh_key[0].key_name
private_key_content = var.ssh_key_name != "" ? var.ssh_key_value : tls_private_key.ssh_key[0].private_key_pem
}

#####################################################################
Expand Down
4 changes: 2 additions & 2 deletions integration/terraform/ec2/linux/variables.tf
Original file line number Diff line number Diff line change
Expand Up @@ -8,7 +8,7 @@ variable "ec2_instance_type" {
default = "t3a.xlarge"
}

variable "key_name" {
variable "ssh_key_name" {
type = string
default = "cwagent-integ-test-key"
}
Expand All @@ -18,7 +18,7 @@ variable "ami" {
default = "cloudwatch-agent-integration-test-ubuntu*"
}

variable "ssh_key" {
variable "ssh_key_value" {
type = string
default = ""
}
Expand Down
8 changes: 4 additions & 4 deletions integration/terraform/ec2/localstack/main.tf
Original file line number Diff line number Diff line change
Expand Up @@ -10,20 +10,20 @@ resource "random_id" "testing_id" {
#####################################################################

resource "tls_private_key" "ssh_key" {
count = var.ssh_key == "" ? 1 : 0
count = var.ssh_key_name == "" ? 1 : 0
algorithm = "RSA"
rsa_bits = 4096
}

resource "aws_key_pair" "aws_ssh_key" {
count = var.ssh_key == "" ? 1 : 0
count = var.ssh_key_name == "" ? 1 : 0
key_name = "ec2-key-pair-${random_id.testing_id.hex}"
public_key = tls_private_key.ssh_key[0].public_key_openssh
}

locals {
ssh_key_name = var.ssh_key != "" ? var.key_name : aws_key_pair.aws_ssh_key[0].key_name
private_key_content = var.ssh_key != "" ? var.ssh_key : tls_private_key.ssh_key[0].private_key_pem
ssh_key_name = var.ssh_key_name != "" ? var.ssh_key_name : aws_key_pair.aws_ssh_key[0].key_name
private_key_content = var.ssh_key_name != "" ? var.ssh_key_value : tls_private_key.ssh_key[0].private_key_pem
}

resource "aws_instance" "integration-test" {
Expand Down
4 changes: 2 additions & 2 deletions integration/terraform/ec2/localstack/variables.tf
Original file line number Diff line number Diff line change
Expand Up @@ -3,7 +3,7 @@ variable "ec2_instance_type" {
default = "t3a.xlarge"
}

variable "key_name" {
variable "ssh_key_name" {
type = string
default = "cwagent-integ-test-key"
}
Expand All @@ -13,7 +13,7 @@ variable "region" {
default = "us-west-2"
}

variable "ssh_key" {
variable "ssh_key_value" {
type = string
default = ""
}
Expand Down
2 changes: 1 addition & 1 deletion integration/terraform/ec2/win/main.tf
Original file line number Diff line number Diff line change
Expand Up @@ -61,7 +61,7 @@ resource "null_resource" "integration_test" {
type = "ssh"
user = "Administrator"
private_key = local.private_key_content
password = rsadecrypt(aws_instance.cwagent.password_data, tls_private_key.ssh_key[0].private_key_pem)
password = rsadecrypt(aws_instance.cwagent.password_data, local.private_key_content)
host = aws_instance.cwagent.public_ip
target_platform = "windows"
}
Expand Down
18 changes: 8 additions & 10 deletions translator/translate/metrics/metrics_collect/ethtool/ethtool.go
Original file line number Diff line number Diff line change
Expand Up @@ -10,16 +10,14 @@ import (

var ChildRule = map[string]translator.Rule{}

//
// "ethtool" : {
// "interface_include": "*",
// "interface_exclude": "",
// "metrics_include": [
// "bw_in_allowance_exceeded",
// "bw_out_allowance_exceeded"
// ]
// }
//
// "ethtool" : {
// "interface_include": "*",
// "interface_exclude": "",
// "metrics_include": [
// "bw_in_allowance_exceeded",
// "bw_out_allowance_exceeded"
// ]
// }
const SectionKey_Ethtool = "ethtool"

func GetCurPath() string {
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -15,18 +15,14 @@ func TestDefaultConfig(t *testing.T) {
var input interface{}
err := json.Unmarshal([]byte(`{"ethtool": {
}}`), &input)
if err == nil {
_, actual := d.ApplyRule(input)
assert.NoError(t, err)
_, actual := d.ApplyRule(input)

d := []interface{}{map[string]interface{}{
"interface_include": []string{"*"},
"fieldpass": []string{},
},
}
assert.Equal(t, d, actual, "Expected to be equal")
} else {
panic(err)
expected := []interface{}{map[string]interface{}{
"interface_include": []string{"*"},
"fieldpass": []string{}},
}
assert.Equal(t, expected, actual, "Expected to be equal")
}

func TestFullConfig(t *testing.T) {
Expand All @@ -43,31 +39,24 @@ func TestFullConfig(t *testing.T) {
"bw_in_allowance_exceeded"
]
}}`), &input)
if err == nil {
_, actual := d.ApplyRule(input)

expected := []interface{}{map[string]interface{}{
"interface_include": []string{"eth0"},
"interface_exclude": []string{"eth1"},
"fieldpass": []string{"bw_in_allowance_exceeded"},
},
}
assert.NoError(t, err)
_, actual := d.ApplyRule(input)

expected := []interface{}{map[string]interface{}{
"interface_include": []string{"eth0"},
"interface_exclude": []string{"eth1"},
"fieldpass": []string{"bw_in_allowance_exceeded"},
},
}

// compare marshalled values since unmarshalled values have type conflicts
// the actual uses interface instead of expected string type
// interface will be converted to string on marshall
// this is going to be marshalled into toml not pogo
marshalActual, err := json.Marshal(actual)
if err != nil {
return
}
marshalExpected, err := json.Marshal(expected)
if err != nil {
return
}
// compare marshalled values since unmarshalled values have type conflicts
// the actual uses interface instead of expected string type
// interface will be converted to string on marshall
// this is going to be marshalled into toml not pogo
marshalActual, err := json.Marshal(actual)
assert.NoError(t, err)
marshalExpected, err := json.Marshal(expected)
assert.NoError(t, err)
assert.Equal(t, string(marshalExpected), string(marshalActual), "Expected to be equal")

assert.Equal(t, string(marshalExpected), string(marshalActual), "Expected to be equal")
} else {
panic(err)
}
}