Skip to content

Commit

Permalink
[APM] High Cardinality: Integration testing
Browse files Browse the repository at this point in the history
The implemented tests ensure that a user can change the configuration
of CW agent to drop, keep, or replace certain metrics.
  • Loading branch information
majanjua-amzn committed Oct 23, 2023
1 parent 341d649 commit 73f4e35
Show file tree
Hide file tree
Showing 19 changed files with 1,874 additions and 9 deletions.
15 changes: 15 additions & 0 deletions generator/test_case_generator.go
Original file line number Diff line number Diff line change
Expand Up @@ -165,6 +165,21 @@ var testTypeToTestConfig = map[string][]testConfig{
{testDir: "./test/apm", terraformDir: "terraform/eks/daemon/apm",
targets: map[string]map[string]struct{}{"arc": {"amd64": {}}},
},
{
testDir: "./test/apm/high_cardinality_drop",
terraformDir: "terraform/eks/daemon/apm",
targets: map[string]map[string]struct{}{"arc": {"amd64": {}}},
},
{
testDir: "./test/apm/high_cardinality_keep",
terraformDir: "terraform/eks/daemon/apm",
targets: map[string]map[string]struct{}{"arc": {"amd64": {}}},
},
{
testDir: "./test/apm/high_cardinality_replace",
terraformDir: "terraform/eks/daemon/apm",
targets: map[string]map[string]struct{}{"arc": {"amd64": {}}},
},
},
"eks_deployment": {
{testDir: "./test/metric_value_benchmark"},
Expand Down
7 changes: 4 additions & 3 deletions test/apm/apm_test.go
Original file line number Diff line number Diff line change
Expand Up @@ -7,10 +7,11 @@ package apm

import (
"fmt"
"github.com/aws/amazon-cloudwatch-agent-test/environment/computetype"
"log"
"testing"

"github.com/aws/amazon-cloudwatch-agent-test/environment/computetype"

"github.com/stretchr/testify/suite"

"github.com/aws/amazon-cloudwatch-agent-test/environment"
Expand Down Expand Up @@ -52,11 +53,11 @@ func getEksTestRunners(env *environment.MetaData) []*test_runner.EKSTestRunner {

eksTestRunners = []*test_runner.EKSTestRunner{
{
Runner: &APMRunner{test_runner.BaseTestRunner{DimensionFactory: factory}, APMServerConsumerTestName, "EKS.Cluster"},
Runner: &APMRunner{test_runner.BaseTestRunner{DimensionFactory: factory}, APMServerConsumerTestName, "HostedIn.EKS.Cluster"},
Env: *env,
},
{
Runner: &APMRunner{test_runner.BaseTestRunner{DimensionFactory: factory}, APMClientProducerTestName, "EKS.Cluster"},
Runner: &APMRunner{test_runner.BaseTestRunner{DimensionFactory: factory}, APMClientProducerTestName, "HostedIn.EKS.Cluster"},
Env: *env,
},
}
Expand Down
3 changes: 2 additions & 1 deletion test/apm/default_test.go
Original file line number Diff line number Diff line change
Expand Up @@ -6,11 +6,12 @@
package apm

import (
"time"

"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"
"time"
)

const testRetryCount = 3
Expand Down
80 changes: 80 additions & 0 deletions test/apm/high_cardinality_drop/apm_test.go
Original file line number Diff line number Diff line change
@@ -0,0 +1,80 @@
// Copyright Amazon.com, Inc. or its affiliates. All Rights Reserved.
// SPDX-License-Identifier: MIT

//go:build !windows

package apm

import (
"fmt"
"log"
"testing"

"github.com/aws/amazon-cloudwatch-agent-test/environment/computetype"

"github.com/stretchr/testify/suite"

"github.com/aws/amazon-cloudwatch-agent-test/environment"
"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"
)

type APMTestSuite struct {
suite.Suite
test_runner.TestSuite
}

func (suite *APMTestSuite) SetupSuite() {
fmt.Println(">>>> Starting APMTestSuite")
}

func (suite *APMTestSuite) TearDownSuite() {
suite.Result.Print()
fmt.Println(">>>> Finished APMTestSuite")
}

func init() {
environment.RegisterEnvironmentMetaDataFlags()
}

var (
eksTestRunners []*test_runner.EKSTestRunner
)

func getEksTestRunners(env *environment.MetaData) []*test_runner.EKSTestRunner {
if eksTestRunners == nil {
factory := dimension.GetDimensionFactory(*env)

eksTestRunners = []*test_runner.EKSTestRunner{
{
Runner: &APMRunner{test_runner.BaseTestRunner{DimensionFactory: factory}, "APM-High-Cardinality-Drop-Metrics", "HostedIn.EKS.Cluster"},
Env: *env,
},
}
}
return eksTestRunners
}

func (suite *APMTestSuite) TestAllInSuite() {
env := environment.GetEnvironmentMetaData()
switch env.ComputeType {
case computetype.EKS:
log.Println("Environment compute type is EKS")
for _, testRunner := range getEksTestRunners(env) {
testRunner.Run(suite, env)
}
default:
return
}

suite.Assert().Equal(status.SUCCESSFUL, suite.Result.GetStatus(), "APM Test Suite Failed")
}

func (suite *APMTestSuite) AddToSuiteResult(r status.TestGroupResult) {
suite.Result.TestGroupResults = append(suite.Result.TestGroupResults, r)
}

func TestAPMSuite(t *testing.T) {
suite.Run(t, new(APMTestSuite))
}
69 changes: 69 additions & 0 deletions test/apm/high_cardinality_drop/high_cardinality_drop_test.go
Original file line number Diff line number Diff line change
@@ -0,0 +1,69 @@
// Copyright Amazon.com, Inc. or its affiliates. All Rights Reserved.
// SPDX-License-Identifier: MIT

//go:build !windows

package apm

import (
"time"

"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"
)

const testRetryCount = 3
const namespace = "AWS/APM"

type APMRunner struct {
test_runner.BaseTestRunner
testName string
dimensionKey string
}

func (t *APMRunner) Validate() status.TestGroupResult {
metricsToFetch := t.GetMeasuredMetrics()
testResults := make([]status.TestResult, len(metricsToFetch))
instructions := GetInstructions()

for i, metricName := range metricsToFetch {
var testResult status.TestResult
for j := 0; j < testRetryCount; j++ {
testResult = metric.ValidateAPMMetric(t.DimensionFactory, namespace, metricName, instructions)
if testResult.Status == status.SUCCESSFUL {
break
}
time.Sleep(15 * time.Second)
}
testResults[i] = testResult
}

return status.TestGroupResult{
Name: t.GetTestName(),
TestResults: testResults,
}
}

func (t *APMRunner) GetTestName() string {
return t.testName
}

func (t *APMRunner) GetAgentRunDuration() time.Duration {
return 3 * time.Minute
}

func (t *APMRunner) GetMeasuredMetrics() []string {
return metric.APMMetricNames
}

func (e *APMRunner) GetAgentConfigFileName() string {
return ""
}

func GetInstructions() []dimension.Instruction {
return metric.ServerConsumerInstructions
}

var _ test_runner.ITestRunner = (*APMRunner)(nil)
Loading

0 comments on commit 73f4e35

Please sign in to comment.