CloudWatch: Migrate to aws-sdk-go-v2 (#103106)

* Cloudwatch: Migrate to aws-sdk-go-v2 (#99643)
* CloudWatch: use PDC fix from new grafana-aws-sdk
This commit is contained in:
Nathan Vērzemnieks
2025-04-01 10:03:06 +02:00
committed by GitHub
parent 3e15459d20
commit a65cc0df93
60 changed files with 1497 additions and 1607 deletions
+49 -47
View File
@@ -5,8 +5,10 @@ import (
"testing"
"time"
"github.com/aws/aws-sdk-go/aws"
"github.com/aws/aws-sdk-go/service/cloudwatchlogs"
"github.com/aws/aws-sdk-go-v2/aws"
"github.com/aws/aws-sdk-go-v2/service/cloudwatchlogs"
cloudwatchlogstypes "github.com/aws/aws-sdk-go-v2/service/cloudwatchlogs/types"
"github.com/grafana/grafana-plugin-sdk-go/data"
"github.com/stretchr/testify/assert"
@@ -19,63 +21,63 @@ import (
func TestLogsResultsToDataframes(t *testing.T) {
fakeCloudwatchResponse := &cloudwatchlogs.GetQueryResultsOutput{
Results: [][]*cloudwatchlogs.ResultField{
Results: [][]cloudwatchlogstypes.ResultField{
{
&cloudwatchlogs.ResultField{
cloudwatchlogstypes.ResultField{
Field: aws.String("@ptr"),
Value: aws.String("fake ptr"),
},
&cloudwatchlogs.ResultField{
cloudwatchlogstypes.ResultField{
Field: aws.String("@timestamp"),
Value: aws.String("2020-03-02 15:04:05.000"),
},
&cloudwatchlogs.ResultField{
cloudwatchlogstypes.ResultField{
Field: aws.String("line"),
Value: aws.String("test message 1"),
},
&cloudwatchlogs.ResultField{
cloudwatchlogstypes.ResultField{
Field: aws.String("@logStream"),
Value: aws.String("fakelogstream"),
},
&cloudwatchlogs.ResultField{
cloudwatchlogstypes.ResultField{
Field: aws.String("@log"),
Value: aws.String("fakelog"),
},
&cloudwatchlogs.ResultField{
cloudwatchlogstypes.ResultField{
Field: aws.String(logStreamIdentifierInternal),
Value: aws.String("fakelogstream"),
},
&cloudwatchlogs.ResultField{
cloudwatchlogstypes.ResultField{
Field: aws.String(logIdentifierInternal),
Value: aws.String("fakelog"),
},
},
{
&cloudwatchlogs.ResultField{
cloudwatchlogstypes.ResultField{
Field: aws.String("@ptr"),
Value: aws.String("fake ptr"),
},
&cloudwatchlogs.ResultField{
cloudwatchlogstypes.ResultField{
Field: aws.String("@timestamp"),
Value: aws.String("2020-03-02 16:04:05.000"),
},
&cloudwatchlogs.ResultField{
cloudwatchlogstypes.ResultField{
Field: aws.String("line"),
Value: aws.String("test message 2"),
},
&cloudwatchlogs.ResultField{
cloudwatchlogstypes.ResultField{
Field: aws.String("@logStream"),
Value: aws.String("fakelogstream"),
},
&cloudwatchlogs.ResultField{
cloudwatchlogstypes.ResultField{
Field: aws.String("@log"),
Value: aws.String("fakelog"),
},
&cloudwatchlogs.ResultField{
cloudwatchlogstypes.ResultField{
Field: aws.String(logStreamIdentifierInternal),
Value: aws.String("fakelogstream"),
},
&cloudwatchlogs.ResultField{
cloudwatchlogstypes.ResultField{
Field: aws.String(logIdentifierInternal),
Value: aws.String("fakelog"),
},
@@ -84,47 +86,47 @@ func TestLogsResultsToDataframes(t *testing.T) {
{},
// or rows with only timestamp
{
&cloudwatchlogs.ResultField{
cloudwatchlogstypes.ResultField{
Field: aws.String("@timestamp"),
Value: aws.String("2020-03-02 17:04:05.000"),
},
},
{
&cloudwatchlogs.ResultField{
cloudwatchlogstypes.ResultField{
Field: aws.String("@ptr"),
Value: aws.String("fake ptr"),
},
&cloudwatchlogs.ResultField{
cloudwatchlogstypes.ResultField{
Field: aws.String("@timestamp"),
Value: aws.String("2020-03-02 17:04:05.000"),
},
&cloudwatchlogs.ResultField{
cloudwatchlogstypes.ResultField{
Field: aws.String("line"),
Value: aws.String("test message 3"),
},
&cloudwatchlogs.ResultField{
cloudwatchlogstypes.ResultField{
Field: aws.String("@logStream"),
Value: aws.String("fakelogstream"),
},
&cloudwatchlogs.ResultField{
cloudwatchlogstypes.ResultField{
Field: aws.String("@log"),
Value: aws.String("fakelog"),
},
&cloudwatchlogs.ResultField{
cloudwatchlogstypes.ResultField{
Field: aws.String(logStreamIdentifierInternal),
Value: aws.String("fakelogstream"),
},
&cloudwatchlogs.ResultField{
cloudwatchlogstypes.ResultField{
Field: aws.String(logIdentifierInternal),
Value: aws.String("fakelog"),
},
},
},
Status: aws.String("ok"),
Statistics: &cloudwatchlogs.QueryStatistics{
BytesScanned: aws.Float64(2000),
RecordsMatched: aws.Float64(3),
RecordsScanned: aws.Float64(5000),
Status: "ok",
Statistics: &cloudwatchlogstypes.QueryStatistics{
BytesScanned: 2000,
RecordsMatched: 3,
RecordsScanned: 5000,
},
}
@@ -224,33 +226,33 @@ func TestLogsResultsToDataframes(t *testing.T) {
func TestLogsResultsToDataframes_MixedTypes_NumericValuesMixedWithStringFallBackToStringValues(t *testing.T) {
dataframes, err := logsResultsToDataframes(&cloudwatchlogs.GetQueryResultsOutput{
Results: [][]*cloudwatchlogs.ResultField{
Results: [][]cloudwatchlogstypes.ResultField{
{
&cloudwatchlogs.ResultField{
cloudwatchlogstypes.ResultField{
Field: aws.String("numberOrString"),
Value: aws.String("-1.234"),
},
},
{
&cloudwatchlogs.ResultField{
cloudwatchlogstypes.ResultField{
Field: aws.String("numberOrString"),
Value: aws.String("1"),
},
},
{
&cloudwatchlogs.ResultField{
cloudwatchlogstypes.ResultField{
Field: aws.String("numberOrString"),
Value: aws.String("not a number"),
},
},
{
&cloudwatchlogs.ResultField{
cloudwatchlogstypes.ResultField{
Field: aws.String("numberOrString"),
Value: aws.String("2.000"),
},
},
},
Status: aws.String("ok"),
Status: "ok",
}, []string{})
require.NoError(t, err)
@@ -284,27 +286,27 @@ func TestLogsResultsToDataframes_With_Millisecond_Timestamps(t *testing.T) {
ingestionTimeField := int64(1732790372916)
dataframes, err := logsResultsToDataframes(&cloudwatchlogs.GetQueryResultsOutput{
Results: [][]*cloudwatchlogs.ResultField{
Results: [][]cloudwatchlogstypes.ResultField{
{
&cloudwatchlogs.ResultField{
cloudwatchlogstypes.ResultField{
Field: aws.String("@timestamp"),
Value: aws.String(fmt.Sprintf("%d", timestampField)),
},
&cloudwatchlogs.ResultField{
cloudwatchlogstypes.ResultField{
Field: aws.String("@ingestionTime"),
Value: aws.String(fmt.Sprintf("%d", ingestionTimeField)),
},
&cloudwatchlogs.ResultField{
cloudwatchlogstypes.ResultField{
Field: aws.String("stringTimeField"),
Value: aws.String(stringTimeField),
},
&cloudwatchlogs.ResultField{
cloudwatchlogstypes.ResultField{
Field: aws.String("message"),
Value: aws.String("log message"),
},
},
},
Status: aws.String("ok"),
Status: "ok",
}, []string{})
require.NoError(t, err)
@@ -348,23 +350,23 @@ func TestLogsResultsToDataframes_With_Int_Grouping_Field(t *testing.T) {
timestampField := int64(1732749534876)
dataframes, err := logsResultsToDataframes(&cloudwatchlogs.GetQueryResultsOutput{
Results: [][]*cloudwatchlogs.ResultField{
Results: [][]cloudwatchlogstypes.ResultField{
{
&cloudwatchlogs.ResultField{
cloudwatchlogstypes.ResultField{
Field: aws.String("@timestamp"),
Value: aws.String(fmt.Sprintf("%d", timestampField)),
},
&cloudwatchlogs.ResultField{
cloudwatchlogstypes.ResultField{
Field: aws.String("numberField"),
Value: aws.String("8"),
},
&cloudwatchlogs.ResultField{
cloudwatchlogstypes.ResultField{
Field: aws.String("groupingNumber"),
Value: aws.String("100"),
},
},
},
Status: aws.String("ok"),
Status: "ok",
}, []string{"groupingNumber"})
require.NoError(t, err)