Skip to content

Commit 9bbc50d

Browse files
authored
Fix OTLP Export Testing issues by removing test runs for itar and china regions (#670)
1 parent 84992f3 commit 9bbc50d

3 files changed

Lines changed: 52 additions & 30 deletions

File tree

generator/test_case_generator.go

Lines changed: 21 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -444,6 +444,8 @@ type partition struct {
444444
// testConfigOverrides allows partition-specific test configurations
445445
// key is testDir, value is the override config
446446
testConfigOverrides map[string]testConfig
447+
// excludedTestDirs allows excluding specific test directories from a partition
448+
excludedTestDirs map[string]struct{}
447449
}
448450

449451
var partitionTests = map[string]partition{
@@ -456,6 +458,11 @@ var partitionTests = map[string]partition{
456458
configName: "_itar",
457459
tests: []string{testTypeKeyEc2Linux},
458460
ami: []string{"cloudwatch-agent-integration-test-aarch64-al2023*"},
461+
excludedTestDirs: map[string]struct{}{
462+
"./test/otlp_export/hostmetrics": {},
463+
"./test/otlp_export/statsd": {},
464+
"./test/otlp_export/collectd": {},
465+
},
459466
testConfigOverrides: map[string]testConfig{
460467
"./test/metric_value_benchmark": {
461468
// Exclude DiskIOInstanceStore and DiskIOEBS tests - custom AMI doesn't support NVMe instance store metrics
@@ -471,6 +478,11 @@ var partitionTests = map[string]partition{
471478
configName: "_china",
472479
tests: []string{testTypeKeyEc2Linux},
473480
ami: []string{"cloudwatch-agent-integration-test-aarch64-al2023*"},
481+
excludedTestDirs: map[string]struct{}{
482+
"./test/otlp_export/hostmetrics": {},
483+
"./test/otlp_export/statsd": {},
484+
"./test/otlp_export/collectd": {},
485+
},
474486
testConfigOverrides: map[string]testConfig{
475487
"./test/metric_value_benchmark": {
476488
// Exclude DiskIOInstanceStore and DiskIOEBS tests - custom AMI doesn't support NVMe instance store metrics
@@ -498,7 +510,7 @@ func main() {
498510
if len(partition.tests) != 0 && !slices.Contains(partition.tests, testType) {
499511
continue
500512
}
501-
testMatrix := genMatrix(testType, testConfigs, partition.ami, partition.testConfigOverrides)
513+
testMatrix := genMatrix(testType, testConfigs, partition.ami, partition.testConfigOverrides, partition.excludedTestDirs)
502514
writeTestMatrixFile(testType+partition.configName, testMatrix)
503515
}
504516
}
@@ -528,7 +540,7 @@ func generateTestName(testType string, test_directory string) string {
528540

529541
return strings.Join(cleaned, "_")
530542
}
531-
func genMatrix(testType string, testConfigs []testConfig, ami []string, overrides map[string]testConfig) []matrixRow {
543+
func genMatrix(testType string, testConfigs []testConfig, ami []string, overrides map[string]testConfig, excludedTestDirs map[string]struct{}) []matrixRow {
532544
openTestMatrix, err := os.Open(fmt.Sprintf("generator/resources/%v_test_matrix.json", testType))
533545

534546
if err != nil {
@@ -548,6 +560,13 @@ func genMatrix(testType string, testConfigs []testConfig, ami []string, override
548560
testMatrixComplete := make([]matrixRow, 0, len(testMatrix))
549561
for _, test := range testMatrix {
550562
for _, testConfig := range testConfigs {
563+
// Skip test dirs excluded for this partition
564+
if excludedTestDirs != nil {
565+
if _, excluded := excludedTestDirs[testConfig.testDir]; excluded {
566+
continue
567+
}
568+
}
569+
551570
// Apply partition-specific overrides if available
552571
if overrides != nil {
553572
if override, ok := overrides[testConfig.testDir]; ok {

test/otlp_export/otlpvalidation/validate.go

Lines changed: 31 additions & 12 deletions
Original file line numberDiff line numberDiff line change
@@ -14,22 +14,41 @@ import (
1414
)
1515

1616
func ValidateOtlpMetrics(testName string, region string, metrics []string) status.TestGroupResult {
17+
const maxRetries = 5
18+
const retryInterval = 20 * time.Second
19+
20+
// Track which metrics have been validated
21+
validated := make(map[string]bool, len(metrics))
22+
23+
for attempt := 0; attempt < maxRetries; attempt++ {
24+
if attempt > 0 {
25+
time.Sleep(retryInterval)
26+
}
27+
for _, m := range metrics {
28+
if validated[m] {
29+
continue
30+
}
31+
promql := fmt.Sprintf(`{__name__="%s"}`, m)
32+
resp, err := awsservice.QueryOtlpMetrics(region, promql)
33+
if err != nil || len(resp.Data.Result) == 0 {
34+
continue
35+
}
36+
validated[m] = true
37+
}
38+
if len(validated) == len(metrics) {
39+
break
40+
}
41+
}
42+
1743
results := make([]status.TestResult, 0, len(metrics)+1)
18-
successCount := 0
1944
for _, m := range metrics {
20-
promql := fmt.Sprintf(`{__name__="%s"}`, m)
21-
resp, err := awsservice.QueryOtlpMetricsWithRetry(region, promql, 10, 30*time.Second)
22-
if err != nil {
23-
results = append(results, status.TestResult{Name: m, Status: status.FAILED, Reason: err})
24-
continue
25-
}
26-
if len(resp.Data.Result) == 0 {
27-
results = append(results, status.TestResult{Name: m, Status: status.FAILED, Reason: fmt.Errorf("no results for %s", m)})
28-
continue
45+
if validated[m] {
46+
results = append(results, status.TestResult{Name: m, Status: status.SUCCESSFUL})
47+
} else {
48+
results = append(results, status.TestResult{Name: m, Status: status.FAILED, Reason: fmt.Errorf("metric %s not found after %d retries", m, maxRetries)})
2949
}
30-
results = append(results, status.TestResult{Name: m, Status: status.SUCCESSFUL})
31-
successCount++
3250
}
51+
successCount := len(validated)
3352
if successCount != len(metrics) {
3453
results = append(results, status.TestResult{
3554
Name: "MetricCountCheck",

util/awsservice/otlpmetricsquery.go

Lines changed: 0 additions & 16 deletions
Original file line numberDiff line numberDiff line change
@@ -90,19 +90,3 @@ func QueryOtlpMetrics(region string, promql string) (PrometheusResponse, error)
9090
return resp, nil
9191
}
9292

93-
func QueryOtlpMetricsWithRetry(region string, promql string, retries int, retryInterval time.Duration) (PrometheusResponse, error) {
94-
var lastErr error
95-
for i := 0; i < retries; i++ {
96-
resp, err := QueryOtlpMetrics(region, promql)
97-
if err == nil && resp.Status == "success" && len(resp.Data.Result) > 0 {
98-
return resp, nil
99-
}
100-
if err != nil {
101-
lastErr = err
102-
} else {
103-
lastErr = fmt.Errorf("otlp query unsuccessful: status=%s, results=%d, error=%s", resp.Status, len(resp.Data.Result), resp.Error)
104-
}
105-
time.Sleep(retryInterval)
106-
}
107-
return PrometheusResponse{}, fmt.Errorf("otlp query failed after %d retries: %w", retries, lastErr)
108-
}

0 commit comments

Comments
 (0)