-
Notifications
You must be signed in to change notification settings - Fork 208
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
Add Integration Test For Metric Number Of Dimension #451
Merged
Merged
Changes from all commits
Commits
File filter
Filter by extension
Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
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
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
Original file line number | Diff line number | Diff line change |
---|---|---|
|
@@ -84,7 +84,7 @@ variable "test_name" { | |
default = "" | ||
} | ||
|
||
variable "tag" { | ||
variable "test_dir" { | ||
type = string | ||
default = "" | ||
} |
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 was deleted.
Oops, something went wrong.
136 changes: 136 additions & 0 deletions
136
integration/test/metrics_number_dimension/metrics_number_dimension_test.go
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,136 @@ | ||
// Copyright Amazon.com, Inc. or its affiliates. All Rights Reserved. | ||
// SPDX-License-Identifier: MIT | ||
|
||
//go:build linux && integration | ||
// +build linux,integration | ||
|
||
package metrics_number_dimension | ||
|
||
import ( | ||
"context" | ||
"fmt" | ||
"github.com/aws/amazon-cloudwatch-agent/integration/test" | ||
"github.com/aws/aws-sdk-go-v2/aws" | ||
"github.com/aws/aws-sdk-go-v2/service/cloudwatch" | ||
"github.com/aws/aws-sdk-go-v2/service/cloudwatch/types" | ||
"log" | ||
"strings" | ||
"testing" | ||
"time" | ||
) | ||
|
||
const configOutputPath = "/opt/aws/amazon-cloudwatch-agent/bin/config.json" | ||
const configJSON = "/config.json" | ||
const namespace = "MetricNumberDimensionTest" | ||
sethAmazon marked this conversation as resolved.
Show resolved
Hide resolved
|
||
const instanceId = "InstanceId" | ||
const appendMetric = "append" | ||
|
||
// @TODO use the value from plugins/outputs/cloudwatch/cloudwatch.go when https://github.com/aws/amazon-cloudwatch-agent/pull/361 is merged | ||
const maxDimension = 30 | ||
|
||
//Let the agent run for 2 minutes. This will give agent enough time to call server | ||
const agentRuntime = 2 * time.Minute | ||
|
||
const targetString = "max MaxDimensions %v is less than than number of dimensions %v thus only taking the max number" | ||
|
||
type input struct { | ||
resourcePath string | ||
findTarget bool | ||
numberDimensionsInCW int | ||
metricName string | ||
} | ||
|
||
type metric struct { | ||
name string | ||
value string | ||
} | ||
|
||
//Must run this test with parallel 1 since this will fail if more than one test is running at the same time | ||
func TestNumberMetricDimension(t *testing.T) { | ||
|
||
parameters := []input{ | ||
{ | ||
resourcePath: "resources/10_dimension", | ||
findTarget: false, | ||
numberDimensionsInCW: 10, | ||
metricName: "mem_used_percent", | ||
}, | ||
// @TODO add when https://github.com/aws/amazon-cloudwatch-agent/pull/361 is merged | ||
// {resourcePath: "resources/30_dimension", findTarget: false, numberDimensionsInCW: 30, metricName: "mem_used_percent",}, | ||
// {resourcePath: "resources/35_dimension", findTarget: true, numberDimensionsInCW: 30, metricName: "mem_used_percent",}, | ||
} | ||
|
||
for _, parameter := range parameters { | ||
//before test run | ||
log.Printf("resource file location %s find target %t input number dimension %d metric name %s", | ||
parameter.resourcePath, parameter.findTarget, parameter.numberDimensionsInCW, parameter.metricName) | ||
|
||
target := fmt.Sprintf(targetString, maxDimension, parameter.numberDimensionsInCW) | ||
|
||
t.Run(fmt.Sprintf("resource file location %s find target %t", parameter.resourcePath, parameter.findTarget), func(t *testing.T) { | ||
test.CopyFile(parameter.resourcePath+configJSON, configOutputPath) | ||
test.StartAgent(configOutputPath) | ||
time.Sleep(agentRuntime) | ||
log.Printf("Agent has been running for : %s", agentRuntime.String()) | ||
test.StopAgent() | ||
|
||
// test for target string | ||
output := test.ReadAgentOutput(agentRuntime) | ||
containsTarget := outputLogContainsTarget(output, target) | ||
if (parameter.findTarget && !containsTarget) || (!parameter.findTarget && containsTarget) { | ||
t.Errorf("Find target is %t contains target is %t", parameter.findTarget, containsTarget) | ||
} | ||
|
||
// test for cloud watch metrics | ||
cxt := context.Background() | ||
dimensionFilter := buildDimensionFilterList(parameter.numberDimensionsInCW) | ||
client := test.GetCWClient(cxt) | ||
listMetricsInput := cloudwatch.ListMetricsInput{ | ||
MetricName: aws.String(parameter.metricName), | ||
Namespace: aws.String(namespace), | ||
Dimensions: dimensionFilter, | ||
} | ||
data, err := client.ListMetrics(cxt, &listMetricsInput) | ||
if err != nil { | ||
t.Errorf("Error getting metric data %v", err) | ||
} | ||
if len(data.Metrics) == 0 { | ||
SaxyPandaBear marked this conversation as resolved.
Show resolved
Hide resolved
|
||
metrics := make([]metric, len(dimensionFilter)) | ||
for i, filter := range dimensionFilter { | ||
metrics[i] = metric{ | ||
name: *filter.Name, | ||
value: *filter.Value, | ||
} | ||
} | ||
t.Errorf("No metrics found for dimension %v metric name %v namespace %v", | ||
metrics, parameter.metricName, namespace) | ||
} | ||
}) | ||
} | ||
} | ||
|
||
func buildDimensionFilterList(appendDimension int) []types.DimensionFilter { | ||
// we append dimension from 0 to max number - 2 | ||
// then we add dimension instance id | ||
// thus for max dimension 10, 0 to 8 + instance id = 10 dimension | ||
ec2InstanceId := test.GetInstanceId() | ||
dimensionFilter := make([]types.DimensionFilter, appendDimension) | ||
for i := 0; i < appendDimension-1; i++ { | ||
dimensionFilter[i] = types.DimensionFilter{ | ||
Name: aws.String(fmt.Sprintf("%s%d", appendMetric, i)), | ||
Value: aws.String(fmt.Sprintf("%s%d", appendMetric, i)), | ||
} | ||
} | ||
dimensionFilter[appendDimension-1] = types.DimensionFilter{ | ||
Name: aws.String(instanceId), | ||
Value: aws.String(ec2InstanceId), | ||
} | ||
return dimensionFilter | ||
} | ||
|
||
func outputLogContainsTarget(output string, targetString string) bool { | ||
log.Printf("Log file %s", output) | ||
contains := strings.Contains(output, targetString) | ||
log.Printf("Log file contains target string %t", contains) | ||
return contains | ||
} |
33 changes: 33 additions & 0 deletions
33
integration/test/metrics_number_dimension/resources/10_dimension/config.json
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,33 @@ | ||
{ | ||
"agent": { | ||
"metrics_collection_interval": 60, | ||
"run_as_user": "root", | ||
"debug": true, | ||
"logfile": "" | ||
}, | ||
"metrics": { | ||
"namespace": "MetricNumberDimensionTest", | ||
"append_dimensions": { | ||
"InstanceId": "${aws:InstanceId}" | ||
}, | ||
"metrics_collected": { | ||
"mem": { | ||
"measurement": [ | ||
"mem_used_percent" | ||
], | ||
"metrics_collection_interval": 60, | ||
"append_dimensions": { | ||
"append0": "append0", | ||
"append1": "append1", | ||
"append2": "append2", | ||
"append3": "append3", | ||
"append4": "append4", | ||
"append5": "append5", | ||
"append6": "append6", | ||
"append7": "append7", | ||
"append8": "append8" | ||
} | ||
} | ||
} | ||
} | ||
} |
Oops, something went wrong.
Add this suggestion to a batch that can be applied as a single commit.
This suggestion is invalid because no changes were made to the code.
Suggestions cannot be applied while the pull request is closed.
Suggestions cannot be applied while viewing a subset of changes.
Only one suggestion per line can be applied in a batch.
Add this suggestion to a batch that can be applied as a single commit.
Applying suggestions on deleted lines is not supported.
You must change the existing code in this line in order to create a valid suggestion.
Outdated suggestions cannot be applied.
This suggestion has been applied or marked resolved.
Suggestions cannot be applied from pending reviews.
Suggestions cannot be applied on multi-line comments.
Suggestions cannot be applied while the pull request is queued to merge.
Suggestion cannot be applied right now. Please check back later.
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
This is interesting. Question - is there any reason we wouldn't want to break out the sanity test as a separate workflow from the integration tests? 🤔
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
Sanity is here to test if things are working on the box. Will tell us our agent is working. I like sanity for every test case. Just makes sense to me. We can talk about this.
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
When we break out all of the integration tests by directory, does that mean we would use different hosts to run like the CA bundle tests versus the dimensions tests versus the CWL tests? If that's the case, then yeah this makes sense to me. I think when I was reading it last night, I was still in the frame of reference where the tests would be executed on the same hosts, so we only need to run sanity once, not per directory.