CloudWatch: Backport aws-sdk-go-v2 update from external plugin (#107136)
* CloudWatch: Backport aws-sdk-go-v2 update from external plugin * Review feedback & cleaning up a couple typos
This commit is contained in:
@@ -7,8 +7,8 @@ import (
|
||||
"fmt"
|
||||
"time"
|
||||
|
||||
"github.com/aws/aws-sdk-go/service/cloudwatchlogs"
|
||||
"github.com/aws/aws-sdk-go/service/cloudwatchlogs/cloudwatchlogsiface"
|
||||
"github.com/aws/aws-sdk-go-v2/service/cloudwatchlogs"
|
||||
|
||||
"github.com/grafana/grafana-plugin-sdk-go/backend"
|
||||
"github.com/grafana/grafana-plugin-sdk-go/data"
|
||||
"github.com/grafana/grafana/pkg/tsdb/cloudwatch/kinds/dataquery"
|
||||
@@ -17,15 +17,9 @@ import (
|
||||
|
||||
const initialAlertPollPeriod = time.Second
|
||||
|
||||
var executeSyncLogQuery = func(ctx context.Context, e *cloudWatchExecutor, req *backend.QueryDataRequest) (*backend.QueryDataResponse, error) {
|
||||
var executeSyncLogQuery = func(ctx context.Context, ds *DataSource, req *backend.QueryDataRequest) (*backend.QueryDataResponse, error) {
|
||||
resp := backend.NewQueryDataResponse()
|
||||
|
||||
instance, err := e.getInstance(ctx, req.PluginContext)
|
||||
if err != nil {
|
||||
resp.Responses[req.Queries[0].RefID] = backend.ErrorResponseWithErrorSource(err)
|
||||
return resp, nil
|
||||
}
|
||||
|
||||
for _, q := range req.Queries {
|
||||
var logsQuery models.LogsQuery
|
||||
err := json.Unmarshal(q.JSON, &logsQuery)
|
||||
@@ -40,10 +34,10 @@ var executeSyncLogQuery = func(ctx context.Context, e *cloudWatchExecutor, req *
|
||||
|
||||
region := logsQuery.Region
|
||||
if region == "" || region == defaultRegion {
|
||||
logsQuery.Region = instance.Settings.Region
|
||||
logsQuery.Region = ds.Settings.Region
|
||||
}
|
||||
|
||||
logsClient, err := e.getCWLogsClient(ctx, req.PluginContext, region)
|
||||
logsClient, err := ds.getCWLogsClient(ctx, region)
|
||||
if err != nil {
|
||||
return nil, err
|
||||
}
|
||||
@@ -53,7 +47,7 @@ var executeSyncLogQuery = func(ctx context.Context, e *cloudWatchExecutor, req *
|
||||
refId = q.RefID
|
||||
}
|
||||
|
||||
getQueryResultsOutput, err := e.syncQuery(ctx, logsClient, q, logsQuery, instance.Settings.LogsTimeout.Duration)
|
||||
getQueryResultsOutput, err := ds.syncQuery(ctx, logsClient, q, logsQuery, ds.Settings.LogsTimeout.Duration)
|
||||
var sourceError backend.ErrorWithSource
|
||||
if errors.As(err, &sourceError) {
|
||||
resp.Responses[refId] = backend.ErrorResponseWithErrorSource(sourceError)
|
||||
@@ -86,9 +80,9 @@ var executeSyncLogQuery = func(ctx context.Context, e *cloudWatchExecutor, req *
|
||||
return resp, nil
|
||||
}
|
||||
|
||||
func (e *cloudWatchExecutor) syncQuery(ctx context.Context, logsClient cloudwatchlogsiface.CloudWatchLogsAPI,
|
||||
func (ds *DataSource) syncQuery(ctx context.Context, logsClient models.CWLogsClient,
|
||||
queryContext backend.DataQuery, logsQuery models.LogsQuery, logsTimeout time.Duration) (*cloudwatchlogs.GetQueryResultsOutput, error) {
|
||||
startQueryOutput, err := e.executeStartQuery(ctx, logsClient, logsQuery, queryContext.TimeRange)
|
||||
startQueryOutput, err := ds.executeStartQuery(ctx, logsClient, logsQuery, queryContext.TimeRange)
|
||||
if err != nil {
|
||||
return nil, err
|
||||
}
|
||||
@@ -113,11 +107,11 @@ func (e *cloudWatchExecutor) syncQuery(ctx context.Context, logsClient cloudwatc
|
||||
|
||||
attemptCount := 1
|
||||
for range ticker.C {
|
||||
res, err := e.executeGetQueryResults(ctx, logsClient, requestParams)
|
||||
res, err := ds.executeGetQueryResults(ctx, logsClient, requestParams)
|
||||
if err != nil {
|
||||
return nil, err
|
||||
}
|
||||
if isTerminated(*res.Status) {
|
||||
if isTerminated(res.Status) {
|
||||
return res, err
|
||||
}
|
||||
if time.Duration(attemptCount)*time.Second >= logsTimeout {
|
||||
|
||||
Reference in New Issue
Block a user