diff --git a/test/agent_otel_merging/agent_otel_merging_test.go b/test/agent_otel_merging/agent_otel_merging_test.go index 1cf700a48..04724fe98 100644 --- a/test/agent_otel_merging/agent_otel_merging_test.go +++ b/test/agent_otel_merging/agent_otel_merging_test.go @@ -1,10 +1,12 @@ package agent_otel_merging import ( - "encoding/json" "fmt" "github.com/aws/amazon-cloudwatch-agent-test/environment" + "github.com/aws/amazon-cloudwatch-agent-test/util/awsservice" "github.com/aws/amazon-cloudwatch-agent-test/util/common" + "github.com/aws/aws-sdk-go-v2/aws" + "github.com/aws/aws-sdk-go-v2/service/cloudwatch/types" "github.com/stretchr/testify/require" "os" "os/exec" @@ -45,35 +47,24 @@ func TestOtelMerging(t *testing.T) { "-H", "Content-Type: application/json", "-d", payloadStr) curlOutput, err := curlCmd.CombinedOutput() require.NoError(t, err, "Failed to send metrics: %s", curlOutput) - time.Sleep(1 * time.Minute) + time.Sleep(2 * time.Minute) - //Verifying payload reach CW - verifyCmd := exec.Command("aws", "cloudwatch", "get-metric-statistics", - "--namespace", "CWAgent-testing-otel", - "--metric-name", "test_metric", - "--dimensions", "Name=service.name,Value=test-service", - "--start-time", time.Now().Add(-5*time.Minute).Format("2024-01-02T15:04:05Z"), - "--end-time", time.Now().Format("2024-01-02T15:04:05Z"), - "--period", "60", // Period in seconds - "--statistics", "Average") - - verifyOutput, err := verifyCmd.CombinedOutput() - require.NoError(t, err, "Failed to fetch metric: %s", verifyOutput) - - type MetricStatistics struct { - Datapoints []struct { - Timestamp time.Time `json:"Timestamp"` - Average float64 `json:"Average"` - } `json:"Datapoints"` - Label string `json:"Label"` + metricDimensions := []types.Dimension{ + { + Name: aws.String("service.name"), + Value: aws.String("test-service"), + }, } + statList := []types.Statistic{ + types.StatisticAverage, + } + stats, err := awsservice.GetMetricStatistics("test_metric", "CWAgent-testing-otel-merging", + metricDimensions, + time.Now().Add(-5*time.Minute), + time.Now(), 60, statList, nil) - var stats MetricStatistics - err = json.Unmarshal(verifyOutput, &stats) require.NoError(t, err, "Failed to parse CloudWatch response") require.NotEmpty(t, stats.Datapoints, "No data points found for the metric") - t.Logf("CloudWatch Metric Output: %s", verifyOutput) - common.StopAgent() }