CloudWatch: Don't assume that errors are awserr.Error instances (#24641)

Signed-off-by: Arve Knudsen <arve.knudsen@gmail.com>
This commit is contained in:
Arve Knudsen 2020-05-13 18:57:23 +02:00 committed by GitHub
parent 4cdd8bd933
commit 8e5a3a578a
No known key found for this signature in database
GPG Key ID: 4AEE18F83AFDEB23

View File

@ -13,7 +13,6 @@ import (
"github.com/grafana/grafana-plugin-sdk-go/data"
"github.com/grafana/grafana/pkg/components/simplejson"
"github.com/grafana/grafana/pkg/tsdb"
"github.com/grafana/grafana/pkg/util/errutil"
"golang.org/x/sync/errgroup"
)
@ -165,7 +164,7 @@ func (e *CloudWatchExecutor) handleGetLogEvents(ctx context.Context, logsClient
logEvents, err := logsClient.GetLogEventsWithContext(ctx, queryRequest)
if err != nil {
return nil, errutil.Wrap(err.(awserr.Error).Message(), err)
return nil, err
}
messages := make([]*string, 0)
@ -205,7 +204,7 @@ func (e *CloudWatchExecutor) handleDescribeLogGroups(ctx context.Context, logsCl
}
if err != nil || response == nil {
return nil, errutil.Wrap(err.(awserr.Error).Message(), err)
return nil, err
}
logGroupNames := make([]*string, 0)
@ -251,7 +250,7 @@ func (e *CloudWatchExecutor) executeStartQuery(ctx context.Context, logsClient c
func (e *CloudWatchExecutor) handleStartQuery(ctx context.Context, logsClient cloudwatchlogsiface.CloudWatchLogsAPI, parameters *simplejson.Json, timeRange *tsdb.TimeRange, refID string) (*data.Frame, error) {
startQueryResponse, err := e.executeStartQuery(ctx, logsClient, parameters, timeRange)
if err != nil {
return nil, errutil.Wrap(err.(awserr.Error).Message(), err)
return nil, err
}
dataFrame := data.NewFrame(refID, data.NewField("queryId", nil, []string{*startQueryResponse.QueryId}))
@ -275,15 +274,13 @@ func (e *CloudWatchExecutor) executeStopQuery(ctx context.Context, logsClient cl
response, err := logsClient.StopQueryWithContext(ctx, queryInput)
if err != nil {
awsErr := err.(awserr.Error)
awsErr, ok := err.(awserr.Error)
// If the query has already stopped by the time CloudWatch receives the stop query request,
// an "InvalidParameterException" error is returned. For our purposes though the query has been
// stopped, so we ignore the error.
if awsErr.Code() == "InvalidParameterException" {
if ok && awsErr.Code() == "InvalidParameterException" {
response = &cloudwatchlogs.StopQueryOutput{Success: aws.Bool(false)}
err = nil
} else {
err = errutil.Wrap(awsErr.Message(), err)
}
}
@ -293,7 +290,7 @@ func (e *CloudWatchExecutor) executeStopQuery(ctx context.Context, logsClient cl
func (e *CloudWatchExecutor) handleStopQuery(ctx context.Context, logsClient cloudwatchlogsiface.CloudWatchLogsAPI, parameters *simplejson.Json) (*data.Frame, error) {
response, err := e.executeStopQuery(ctx, logsClient, parameters)
if err != nil {
return nil, errutil.Wrap(err.(awserr.Error).Message(), err)
return nil, err
}
dataFrame := data.NewFrame("StopQueryResponse", data.NewField("success", nil, []bool{*response.Success}))
@ -311,7 +308,7 @@ func (e *CloudWatchExecutor) executeGetQueryResults(ctx context.Context, logsCli
func (e *CloudWatchExecutor) handleGetQueryResults(ctx context.Context, logsClient cloudwatchlogsiface.CloudWatchLogsAPI, parameters *simplejson.Json, refID string) (*data.Frame, error) {
getQueryResultsOutput, err := e.executeGetQueryResults(ctx, logsClient, parameters)
if err != nil {
return nil, errutil.Wrap(err.(awserr.Error).Message(), err)
return nil, err
}
dataFrame, err := logsResultsToDataframes(getQueryResultsOutput)
@ -334,7 +331,7 @@ func (e *CloudWatchExecutor) handleGetLogGroupFields(ctx context.Context, logsCl
getLogGroupFieldsOutput, err := logsClient.GetLogGroupFieldsWithContext(ctx, queryInput)
if err != nil {
return nil, errutil.Wrap(err.(awserr.Error).Message(), err)
return nil, err
}
fieldNames := make([]*string, 0)