mirror of
https://github.com/grafana/grafana.git
synced 2025-02-25 18:55:37 -06:00
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:
parent
4cdd8bd933
commit
8e5a3a578a
@ -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)
|
||||
|
Loading…
Reference in New Issue
Block a user