Commit e921f3b6 by Marcus Efraimsson Committed by GitHub

Merge pull request #12698 from mtanda/cw_400_err

CloudWatch backend return 400 if user input error
parents a63fca03 d9bf8943
...@@ -52,7 +52,7 @@ func QueryMetrics(c *m.ReqContext, reqDto dtos.MetricRequest) Response { ...@@ -52,7 +52,7 @@ func QueryMetrics(c *m.ReqContext, reqDto dtos.MetricRequest) Response {
if res.Error != nil { if res.Error != nil {
res.ErrorString = res.Error.Error() res.ErrorString = res.Error.Error()
resp.Message = res.ErrorString resp.Message = res.ErrorString
statusCode = 500 statusCode = 400
} }
} }
......
...@@ -17,6 +17,7 @@ import ( ...@@ -17,6 +17,7 @@ import (
"golang.org/x/sync/errgroup" "golang.org/x/sync/errgroup"
"github.com/aws/aws-sdk-go/aws" "github.com/aws/aws-sdk-go/aws"
"github.com/aws/aws-sdk-go/aws/awserr"
"github.com/aws/aws-sdk-go/aws/request" "github.com/aws/aws-sdk-go/aws/request"
"github.com/aws/aws-sdk-go/service/cloudwatch" "github.com/aws/aws-sdk-go/service/cloudwatch"
"github.com/aws/aws-sdk-go/service/ec2/ec2iface" "github.com/aws/aws-sdk-go/service/ec2/ec2iface"
...@@ -100,7 +101,10 @@ func (e *CloudWatchExecutor) executeTimeSeriesQuery(ctx context.Context, queryCo ...@@ -100,7 +101,10 @@ func (e *CloudWatchExecutor) executeTimeSeriesQuery(ctx context.Context, queryCo
query, err := parseQuery(queryContext.Queries[i].Model) query, err := parseQuery(queryContext.Queries[i].Model)
if err != nil { if err != nil {
return nil, err result.Results[query.RefId] = &tsdb.QueryResult{
Error: err,
}
return result, nil
} }
query.RefId = queryContext.Queries[i].RefId query.RefId = queryContext.Queries[i].RefId
...@@ -113,15 +117,21 @@ func (e *CloudWatchExecutor) executeTimeSeriesQuery(ctx context.Context, queryCo ...@@ -113,15 +117,21 @@ func (e *CloudWatchExecutor) executeTimeSeriesQuery(ctx context.Context, queryCo
} }
if query.Id == "" && query.Expression != "" { if query.Id == "" && query.Expression != "" {
return nil, fmt.Errorf("Invalid query: id should be set if using expression") result.Results[query.RefId] = &tsdb.QueryResult{
Error: fmt.Errorf("Invalid query: id should be set if using expression"),
}
return result, nil
} }
eg.Go(func() error { eg.Go(func() error {
queryRes, err := e.executeQuery(ectx, query, queryContext) queryRes, err := e.executeQuery(ectx, query, queryContext)
if err != nil { if ae, ok := err.(awserr.Error); ok && ae.Code() == "500" {
return err return err
} }
result.Results[queryRes.RefId] = queryRes result.Results[queryRes.RefId] = queryRes
if err != nil {
result.Results[queryRes.RefId].Error = err
}
return nil return nil
}) })
} }
...@@ -131,11 +141,14 @@ func (e *CloudWatchExecutor) executeTimeSeriesQuery(ctx context.Context, queryCo ...@@ -131,11 +141,14 @@ func (e *CloudWatchExecutor) executeTimeSeriesQuery(ctx context.Context, queryCo
q := getMetricDataQuery q := getMetricDataQuery
eg.Go(func() error { eg.Go(func() error {
queryResponses, err := e.executeGetMetricDataQuery(ectx, region, q, queryContext) queryResponses, err := e.executeGetMetricDataQuery(ectx, region, q, queryContext)
if err != nil { if ae, ok := err.(awserr.Error); ok && ae.Code() == "500" {
return err return err
} }
for _, queryRes := range queryResponses { for _, queryRes := range queryResponses {
result.Results[queryRes.RefId] = queryRes result.Results[queryRes.RefId] = queryRes
if err != nil {
result.Results[queryRes.RefId].Error = err
}
} }
return nil return nil
}) })
......
Markdown is supported
0% or
You are about to add 0 people to the discussion. Proceed with caution.
Finish editing this message first!
Please register or to comment