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

Increase Max Dimensions To 30 #361

Merged
merged 1 commit into from
May 9, 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
2 changes: 1 addition & 1 deletion .github/workflows/integrationTest.yml
Original file line number Diff line number Diff line change
Expand Up @@ -610,7 +610,7 @@ jobs:
fi

- name: Terraform destroy
if: ${{ cancelled() && steps.ecs-fargate-integration-test.outputs.cache-hit != 'true'
if: ${{ cancelled() && steps.ecs-fargate-integration-test.outputs.cache-hit != 'true' }}
sethAmazon marked this conversation as resolved.
Show resolved Hide resolved
uses: nick-invision/retry@v2
with:
max_attempts: 3
Expand Down
11 changes: 7 additions & 4 deletions integration/test/agent_util.go
Original file line number Diff line number Diff line change
Expand Up @@ -37,16 +37,20 @@ func CopyFile(pathIn string, pathOut string) {
log.Printf("File : %s copied to : %s", pathIn, pathOut)
}

func StartAgent(configOutputPath string) {
func StartAgent(configOutputPath string, fatalOnFailure bool) error {
out, err := exec.
Command("bash", "-c", "sudo /opt/aws/amazon-cloudwatch-agent/bin/amazon-cloudwatch-agent-ctl -a fetch-config -m ec2 -s -c file:"+configOutputPath).
Output()

if err != nil {
if err != nil && fatalOnFailure {
log.Fatal(fmt.Sprint(err) + string(out))
} else if err != nil {
log.Printf(fmt.Sprint(err) + string(out))
} else {
log.Printf("Agent has started")
}

log.Printf("Agent has started")
return err
}

func StopAgent() {
Expand Down Expand Up @@ -131,4 +135,3 @@ func GetCWClient(cxt context.Context) *cloudwatch.Client {
}
return cloudwatch.NewFromConfig(defaultConfig)
}

2 changes: 1 addition & 1 deletion integration/test/ca_bundle/ca_bundle_test.go
Original file line number Diff line number Diff line change
Expand Up @@ -52,7 +52,7 @@ func TestBundle(t *testing.T) {
test.ReplaceLocalStackHostName(parameter.dataInput + configJSON)
test.CopyFile(parameter.dataInput+configJSON, configOutputPath)
test.CopyFile(parameter.dataInput+commonConfigTOML, commonConfigOutputPath)
test.StartAgent(configOutputPath)
test.StartAgent(configOutputPath, true)
time.Sleep(agentRuntime)
log.Printf("Agent has been running for : %s", agentRuntime.String())
test.StopAgent()
Expand Down
4 changes: 2 additions & 2 deletions integration/test/cloudwatchlogs/publish_logs_test.go
Original file line number Diff line number Diff line change
Expand Up @@ -66,7 +66,7 @@ func TestWriteLogsToCloudWatch(t *testing.T) {

test.CopyFile(param.configPath, configOutputPath)

test.StartAgent(configOutputPath)
test.StartAgent(configOutputPath, true)

// ensure that there is enough time from the "start" time and the first log line,
// so we don't miss it in the GetLogEvents call
Expand Down Expand Up @@ -100,7 +100,7 @@ func TestRotatingLogsDoesNotSkipLines(t *testing.T) {
start := time.Now()
test.CopyFile(cfgFilePath, configOutputPath)

test.StartAgent(configOutputPath)
test.StartAgent(configOutputPath, true)

// ensure that there is enough time from the "start" time and the first log line,
// so we don't miss it in the GetLogEvents call
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -10,11 +10,11 @@ import (
"context"
"fmt"
"log"
"strings"
"testing"
"time"

"github.com/aws/amazon-cloudwatch-agent/integration/test"
cwPlugin "github.com/aws/amazon-cloudwatch-agent/plugins/outputs/cloudwatch"
"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"
Expand All @@ -24,19 +24,15 @@ const configOutputPath = "/opt/aws/amazon-cloudwatch-agent/bin/config.json"
const configJSON = "/config.json"
const namespace = "MetricNumberDimensionTest"
const instanceId = "InstanceId"
const loremIpsum = "Lorem ipsum dolor sit amet consectetur adipiscing elit Vivamus non mauris malesuada mattis ex eget porttitor purus Suspendisse potenti Praesent vel sollicitudin ipsum Quisque luctus pretium lorem non faucibus Ut vel quam dui Nunc fermentum condimentum consectetur Morbi tellus mauris tristique tincidunt elit consectetur hendrerit placerat dui In nulla erat finibus eget erat a hendrerit sodales urna In sapien purus auctor sit amet congue ut congue eget nisi Vivamus sed neque ut ligula lobortis accumsan quis id metus In feugiat velit et leo mattis non fringilla dui elementum Proin a nisi ac sapien vulputate consequat Vestibulum eu tellus mi Integer consectetur efficitur"
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
failToStart bool
numberDimensionsInCW int
metricName string
}
Expand All @@ -52,36 +48,46 @@ func TestNumberMetricDimension(t *testing.T) {
parameters := []input{
{
resourcePath: "resources/10_dimension",
findTarget: false,
failToStart: 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",},
{
resourcePath: "resources/30_dimension",
failToStart: false,
numberDimensionsInCW: 30,
metricName: "mem_used_percent",
},
{
resourcePath: "resources/35_dimension",
failToStart: true,
numberDimensionsInCW: 35,
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)
log.Printf("resource file location %s fail to start %t input number dimension %d metric name %s",
parameter.resourcePath, parameter.failToStart, 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) {
t.Run(fmt.Sprintf("resource file location %s find target %t", parameter.resourcePath, parameter.failToStart), func(t *testing.T) {
test.CopyFile(parameter.resourcePath+configJSON, configOutputPath)
test.StartAgent(configOutputPath)
err := test.StartAgent(configOutputPath, false)

// for append dimension we auto fail over 30 for custom metrics (statsd we collect remove dimension and continue)
SaxyPandaBear marked this conversation as resolved.
Show resolved Hide resolved
// Go output starts at the time of failure so the failure message gets chopped off. Thus have to use if there is an error and just assume reason.
if parameter.failToStart && err == nil {
t.Fatalf("Agent should not have started for append %v dimension", parameter.numberDimensionsInCW)
} else if parameter.failToStart {
log.Printf("Agent could not start due to appending more than %v dimension", cwPlugin.MaxDimensions)
return
}

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)
Expand Down Expand Up @@ -119,7 +125,7 @@ func buildDimensionFilterList(appendDimension int) []types.DimensionFilter {
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)),
Value: aws.String(fmt.Sprintf("%s%d", loremIpsum+appendMetric, i)),
}
}
dimensionFilter[appendDimension-1] = types.DimensionFilter{
Expand All @@ -128,10 +134,3 @@ func buildDimensionFilterList(appendDimension int) []types.DimensionFilter {
}
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
}
Original file line number Diff line number Diff line change
Expand Up @@ -17,15 +17,15 @@
],
"metrics_collection_interval": 60,
"append_dimensions": {
"append0": "append0",
"append1": "append1",
"append2": "append2",
"append3": "append3",
"append4": "append4",
"append5": "append5",
"append6": "append6",
"append7": "append7",
"append8": "append8"
"append0": "Lorem ipsum dolor sit amet consectetur adipiscing elit Vivamus non mauris malesuada mattis ex eget porttitor purus Suspendisse potenti Praesent vel sollicitudin ipsum Quisque luctus pretium lorem non faucibus Ut vel quam dui Nunc fermentum condimentum consectetur Morbi tellus mauris tristique tincidunt elit consectetur hendrerit placerat dui In nulla erat finibus eget erat a hendrerit sodales urna In sapien purus auctor sit amet congue ut congue eget nisi Vivamus sed neque ut ligula lobortis accumsan quis id metus In feugiat velit et leo mattis non fringilla dui elementum Proin a nisi ac sapien vulputate consequat Vestibulum eu tellus mi Integer consectetur efficiturappend0",
"append1": "Lorem ipsum dolor sit amet consectetur adipiscing elit Vivamus non mauris malesuada mattis ex eget porttitor purus Suspendisse potenti Praesent vel sollicitudin ipsum Quisque luctus pretium lorem non faucibus Ut vel quam dui Nunc fermentum condimentum consectetur Morbi tellus mauris tristique tincidunt elit consectetur hendrerit placerat dui In nulla erat finibus eget erat a hendrerit sodales urna In sapien purus auctor sit amet congue ut congue eget nisi Vivamus sed neque ut ligula lobortis accumsan quis id metus In feugiat velit et leo mattis non fringilla dui elementum Proin a nisi ac sapien vulputate consequat Vestibulum eu tellus mi Integer consectetur efficiturappend1",
"append2": "Lorem ipsum dolor sit amet consectetur adipiscing elit Vivamus non mauris malesuada mattis ex eget porttitor purus Suspendisse potenti Praesent vel sollicitudin ipsum Quisque luctus pretium lorem non faucibus Ut vel quam dui Nunc fermentum condimentum consectetur Morbi tellus mauris tristique tincidunt elit consectetur hendrerit placerat dui In nulla erat finibus eget erat a hendrerit sodales urna In sapien purus auctor sit amet congue ut congue eget nisi Vivamus sed neque ut ligula lobortis accumsan quis id metus In feugiat velit et leo mattis non fringilla dui elementum Proin a nisi ac sapien vulputate consequat Vestibulum eu tellus mi Integer consectetur efficiturappend2",
"append3": "Lorem ipsum dolor sit amet consectetur adipiscing elit Vivamus non mauris malesuada mattis ex eget porttitor purus Suspendisse potenti Praesent vel sollicitudin ipsum Quisque luctus pretium lorem non faucibus Ut vel quam dui Nunc fermentum condimentum consectetur Morbi tellus mauris tristique tincidunt elit consectetur hendrerit placerat dui In nulla erat finibus eget erat a hendrerit sodales urna In sapien purus auctor sit amet congue ut congue eget nisi Vivamus sed neque ut ligula lobortis accumsan quis id metus In feugiat velit et leo mattis non fringilla dui elementum Proin a nisi ac sapien vulputate consequat Vestibulum eu tellus mi Integer consectetur efficiturappend3",
"append4": "Lorem ipsum dolor sit amet consectetur adipiscing elit Vivamus non mauris malesuada mattis ex eget porttitor purus Suspendisse potenti Praesent vel sollicitudin ipsum Quisque luctus pretium lorem non faucibus Ut vel quam dui Nunc fermentum condimentum consectetur Morbi tellus mauris tristique tincidunt elit consectetur hendrerit placerat dui In nulla erat finibus eget erat a hendrerit sodales urna In sapien purus auctor sit amet congue ut congue eget nisi Vivamus sed neque ut ligula lobortis accumsan quis id metus In feugiat velit et leo mattis non fringilla dui elementum Proin a nisi ac sapien vulputate consequat Vestibulum eu tellus mi Integer consectetur efficiturappend4",
"append5": "Lorem ipsum dolor sit amet consectetur adipiscing elit Vivamus non mauris malesuada mattis ex eget porttitor purus Suspendisse potenti Praesent vel sollicitudin ipsum Quisque luctus pretium lorem non faucibus Ut vel quam dui Nunc fermentum condimentum consectetur Morbi tellus mauris tristique tincidunt elit consectetur hendrerit placerat dui In nulla erat finibus eget erat a hendrerit sodales urna In sapien purus auctor sit amet congue ut congue eget nisi Vivamus sed neque ut ligula lobortis accumsan quis id metus In feugiat velit et leo mattis non fringilla dui elementum Proin a nisi ac sapien vulputate consequat Vestibulum eu tellus mi Integer consectetur efficiturappend5",
"append6": "Lorem ipsum dolor sit amet consectetur adipiscing elit Vivamus non mauris malesuada mattis ex eget porttitor purus Suspendisse potenti Praesent vel sollicitudin ipsum Quisque luctus pretium lorem non faucibus Ut vel quam dui Nunc fermentum condimentum consectetur Morbi tellus mauris tristique tincidunt elit consectetur hendrerit placerat dui In nulla erat finibus eget erat a hendrerit sodales urna In sapien purus auctor sit amet congue ut congue eget nisi Vivamus sed neque ut ligula lobortis accumsan quis id metus In feugiat velit et leo mattis non fringilla dui elementum Proin a nisi ac sapien vulputate consequat Vestibulum eu tellus mi Integer consectetur efficiturappend6",
"append7": "Lorem ipsum dolor sit amet consectetur adipiscing elit Vivamus non mauris malesuada mattis ex eget porttitor purus Suspendisse potenti Praesent vel sollicitudin ipsum Quisque luctus pretium lorem non faucibus Ut vel quam dui Nunc fermentum condimentum consectetur Morbi tellus mauris tristique tincidunt elit consectetur hendrerit placerat dui In nulla erat finibus eget erat a hendrerit sodales urna In sapien purus auctor sit amet congue ut congue eget nisi Vivamus sed neque ut ligula lobortis accumsan quis id metus In feugiat velit et leo mattis non fringilla dui elementum Proin a nisi ac sapien vulputate consequat Vestibulum eu tellus mi Integer consectetur efficiturappend7",
"append8": "Lorem ipsum dolor sit amet consectetur adipiscing elit Vivamus non mauris malesuada mattis ex eget porttitor purus Suspendisse potenti Praesent vel sollicitudin ipsum Quisque luctus pretium lorem non faucibus Ut vel quam dui Nunc fermentum condimentum consectetur Morbi tellus mauris tristique tincidunt elit consectetur hendrerit placerat dui In nulla erat finibus eget erat a hendrerit sodales urna In sapien purus auctor sit amet congue ut congue eget nisi Vivamus sed neque ut ligula lobortis accumsan quis id metus In feugiat velit et leo mattis non fringilla dui elementum Proin a nisi ac sapien vulputate consequat Vestibulum eu tellus mi Integer consectetur efficiturappend8"
}
}
}
Expand Down
Loading