Elasticsearch and Cloudwatch: Replace deprecated experimental/errorsource (#97363)

* Update elasticsearch

* Update azure monitor

* Update test

* Revert "Update azure monitor"

This reverts commit 21b53845b8.

* Update cloudwatch
This commit is contained in:
Ivana Huckova
2024-12-12 10:12:03 +01:00
committed by GitHub
parent ded90fa28d
commit 7de65b39b5
12 changed files with 47 additions and 49 deletions
+5 -6
View File
@@ -11,7 +11,6 @@ import (
"github.com/aws/aws-sdk-go/service/cloudwatch"
"github.com/grafana/grafana-plugin-sdk-go/backend"
"github.com/grafana/grafana-plugin-sdk-go/data"
"github.com/grafana/grafana-plugin-sdk-go/experimental/errorsource"
"github.com/grafana/grafana/pkg/tsdb/cloudwatch/kinds/dataquery"
"github.com/grafana/grafana/pkg/tsdb/cloudwatch/utils"
)
@@ -36,7 +35,7 @@ func (e *cloudWatchExecutor) executeAnnotationQuery(ctx context.Context, pluginC
if model.Period != nil && *model.Period != "" {
p, err := strconv.ParseInt(*model.Period, 10, 64)
if err != nil {
return nil, errorsource.DownstreamError(fmt.Errorf("query period must be an int"), false)
return nil, backend.DownstreamError(fmt.Errorf("query period must be an int"))
}
period = p
}
@@ -82,13 +81,13 @@ func (e *cloudWatchExecutor) executeAnnotationQuery(ctx context.Context, pluginC
}
resp, err := cli.DescribeAlarms(params)
if err != nil {
result = errorsource.AddDownstreamErrorToResponse(query.RefID, result, fmt.Errorf("%v: %w", "failed to call cloudwatch:DescribeAlarms", err))
result.Responses[query.RefID] = backend.ErrorResponseWithErrorSource(backend.DownstreamError(fmt.Errorf("%v: %w", "failed to call cloudwatch:DescribeAlarms", err)))
return result, nil
}
alarmNames = filterAlarms(resp, utils.Depointerizer(model.Namespace), metricName, dimensions, statistic, period)
} else {
if model.Region == nil || model.Namespace == nil || metricName == "" || statistic == "" {
return result, errorsource.DownstreamError(errors.New("invalid annotations query"), false)
return result, backend.DownstreamError(errors.New("invalid annotations query"))
}
var qd []*cloudwatch.Dimension
@@ -113,7 +112,7 @@ func (e *cloudWatchExecutor) executeAnnotationQuery(ctx context.Context, pluginC
}
resp, err := cli.DescribeAlarmsForMetric(params)
if err != nil {
result = errorsource.AddDownstreamErrorToResponse(query.RefID, result, fmt.Errorf("%v: %w", "failed to call cloudwatch:DescribeAlarmsForMetric", err))
result.Responses[query.RefID] = backend.ErrorResponseWithErrorSource(backend.DownstreamError(fmt.Errorf("%v: %w", "failed to call cloudwatch:DescribeAlarmsForMetric", err)))
return result, nil
}
for _, alarm := range resp.MetricAlarms {
@@ -131,7 +130,7 @@ func (e *cloudWatchExecutor) executeAnnotationQuery(ctx context.Context, pluginC
}
resp, err := cli.DescribeAlarmHistory(params)
if err != nil {
result = errorsource.AddDownstreamErrorToResponse(query.RefID, result, fmt.Errorf("%v: %w", "failed to call cloudwatch:DescribeAlarmHistory", err))
result.Responses[query.RefID] = backend.ErrorResponseWithErrorSource(backend.DownstreamError(fmt.Errorf("%v: %w", "failed to call cloudwatch:DescribeAlarmHistory", err)))
return result, nil
}
for _, history := range resp.AlarmHistoryItems {
@@ -7,7 +7,7 @@ import (
"github.com/aws/aws-sdk-go/aws"
"github.com/aws/aws-sdk-go/service/cloudwatch"
"github.com/aws/aws-sdk-go/service/cloudwatch/cloudwatchiface"
"github.com/grafana/grafana-plugin-sdk-go/experimental/errorsource"
"github.com/grafana/grafana-plugin-sdk-go/backend"
"github.com/grafana/grafana/pkg/tsdb/cloudwatch/features"
"github.com/grafana/grafana/pkg/tsdb/cloudwatch/utils"
)
@@ -28,7 +28,7 @@ func (e *cloudWatchExecutor) executeRequest(ctx context.Context, client cloudwat
resp, err := client.GetMetricDataWithContext(ctx, metricDataInput)
if err != nil {
return mdo, errorsource.DownstreamError(err, false)
return mdo, backend.DownstreamError(err)
}
mdo = append(mdo, resp)
+8 -9
View File
@@ -17,7 +17,6 @@ import (
"github.com/aws/aws-sdk-go/service/cloudwatchlogs/cloudwatchlogsiface"
"github.com/grafana/grafana-plugin-sdk-go/backend"
"github.com/grafana/grafana-plugin-sdk-go/data"
"github.com/grafana/grafana-plugin-sdk-go/experimental/errorsource"
"golang.org/x/sync/errgroup"
"github.com/grafana/grafana/pkg/tsdb/cloudwatch/features"
@@ -101,7 +100,7 @@ func (e *cloudWatchExecutor) executeLogActions(ctx context.Context, req *backend
dataframe, err := e.executeLogAction(ectx, logsQuery, query, req.PluginContext)
if err != nil {
resultChan <- backend.Responses{
query.RefID: errorsource.Response(err),
query.RefID: backend.ErrorResponseWithErrorSource(err),
}
return nil
}
@@ -182,12 +181,12 @@ func (e *cloudWatchExecutor) handleGetLogEvents(ctx context.Context, logsClient
}
if logsQuery.LogGroupName == "" {
return nil, errorsource.DownstreamError(fmt.Errorf("Error: Parameter 'logGroupName' is required"), false)
return nil, backend.DownstreamError(fmt.Errorf("Error: Parameter 'logGroupName' is required"))
}
queryRequest.SetLogGroupName(logsQuery.LogGroupName)
if logsQuery.LogStreamName == "" {
return nil, errorsource.DownstreamError(fmt.Errorf("Error: Parameter 'logStreamName' is required"), false)
return nil, backend.DownstreamError(fmt.Errorf("Error: Parameter 'logStreamName' is required"))
}
queryRequest.SetLogStreamName(logsQuery.LogStreamName)
@@ -201,7 +200,7 @@ func (e *cloudWatchExecutor) handleGetLogEvents(ctx context.Context, logsClient
logEvents, err := logsClient.GetLogEventsWithContext(ctx, queryRequest)
if err != nil {
return nil, errorsource.DownstreamError(err, false)
return nil, backend.DownstreamError(err)
}
messages := make([]*string, 0)
@@ -230,7 +229,7 @@ func (e *cloudWatchExecutor) executeStartQuery(ctx context.Context, logsClient c
endTime := timeRange.To
if !startTime.Before(endTime) {
return nil, errorsource.DownstreamError(fmt.Errorf("invalid time range: start time must be before end time"), false)
return nil, backend.DownstreamError(fmt.Errorf("invalid time range: start time must be before end time"))
}
if logsQuery.QueryLanguage == nil {
cwli := dataquery.LogsQueryLanguageCWLI
@@ -290,7 +289,7 @@ func (e *cloudWatchExecutor) executeStartQuery(ctx context.Context, logsClient c
e.logger.FromContext(ctx).Debug("ExecuteStartQuery rate exceeded", "err", awsErr)
err = &AWSError{Code: throttlingException, Message: err.Error()}
}
err = errorsource.DownstreamError(err, false)
err = backend.DownstreamError(err)
}
return resp, err
}
@@ -335,7 +334,7 @@ func (e *cloudWatchExecutor) executeStopQuery(ctx context.Context, logsClient cl
response = &cloudwatchlogs.StopQueryOutput{Success: aws.Bool(false)}
err = nil
} else {
err = errorsource.DownstreamError(err, false)
err = backend.DownstreamError(err)
}
}
@@ -365,7 +364,7 @@ func (e *cloudWatchExecutor) executeGetQueryResults(ctx context.Context, logsCli
if errors.As(err, &awsErr) {
err = &AWSError{Code: awsErr.Code(), Message: err.Error()}
}
err = errorsource.DownstreamError(err, false)
err = backend.DownstreamError(err)
}
return getQueryResultsResponse, err
}
+2 -3
View File
@@ -11,7 +11,6 @@ import (
"github.com/aws/aws-sdk-go/service/cloudwatchlogs/cloudwatchlogsiface"
"github.com/grafana/grafana-plugin-sdk-go/backend"
"github.com/grafana/grafana-plugin-sdk-go/data"
"github.com/grafana/grafana-plugin-sdk-go/experimental/errorsource"
"github.com/grafana/grafana/pkg/tsdb/cloudwatch/kinds/dataquery"
"github.com/grafana/grafana/pkg/tsdb/cloudwatch/models"
"github.com/grafana/grafana/pkg/tsdb/cloudwatch/utils"
@@ -56,9 +55,9 @@ var executeSyncLogQuery = func(ctx context.Context, e *cloudWatchExecutor, req *
}
getQueryResultsOutput, err := e.syncQuery(ctx, logsClient, q, logsQuery, instance.Settings.LogsTimeout.Duration)
var sourceError errorsource.Error
var sourceError backend.ErrorWithSource
if errors.As(err, &sourceError) {
errorsource.AddErrorToResponse(refId, resp, sourceError)
resp.Responses[refId] = backend.ErrorResponseWithErrorSource(sourceError)
continue
}
if err != nil {
@@ -16,7 +16,6 @@ import (
"github.com/grafana/grafana-plugin-sdk-go/backend"
"github.com/grafana/grafana-plugin-sdk-go/backend/log"
"github.com/grafana/grafana-plugin-sdk-go/experimental/errorsource"
"github.com/grafana/grafana/pkg/tsdb/cloudwatch/kinds/dataquery"
"github.com/grafana/grafana/pkg/tsdb/cloudwatch/utils"
)
@@ -311,7 +310,7 @@ func (q *CloudWatchQuery) migrateLegacyQuery(query metricsDataQuery) {
func (q *CloudWatchQuery) validateAndSetDefaults(refId string, metricsDataQuery metricsDataQuery, startTime, endTime time.Time,
defaultRegionValue string, crossAccountQueryingEnabled bool) error {
if metricsDataQuery.Statistic == nil && metricsDataQuery.Statistics == nil {
return errorsource.DownstreamError(fmt.Errorf("query must have either statistic or statistics field"), false)
return backend.DownstreamError(fmt.Errorf("query must have either statistic or statistics field"))
}
var err error
+3 -4
View File
@@ -8,7 +8,6 @@ import (
"golang.org/x/sync/errgroup"
"github.com/grafana/grafana-plugin-sdk-go/backend"
"github.com/grafana/grafana-plugin-sdk-go/experimental/errorsource"
"github.com/grafana/grafana/pkg/tsdb/cloudwatch/features"
"github.com/grafana/grafana/pkg/tsdb/cloudwatch/models"
"github.com/grafana/grafana/pkg/tsdb/cloudwatch/utils"
@@ -24,13 +23,13 @@ func (e *cloudWatchExecutor) executeTimeSeriesQuery(ctx context.Context, req *ba
resp := backend.NewQueryDataResponse()
if len(req.Queries) == 0 {
return nil, errorsource.DownstreamError(fmt.Errorf("request contains no queries"), false)
return nil, backend.DownstreamError(fmt.Errorf("request contains no queries"))
}
// startTime and endTime are always the same for all queries
startTime := req.Queries[0].TimeRange.From
endTime := req.Queries[0].TimeRange.To
if !startTime.Before(endTime) {
return nil, errorsource.DownstreamError(fmt.Errorf("invalid time range: start time must be before end time"), false)
return nil, backend.DownstreamError(fmt.Errorf("invalid time range: start time must be before end time"))
}
instance, err := e.getInstance(ctx, req.PluginContext)
@@ -129,7 +128,7 @@ func (e *cloudWatchExecutor) executeTimeSeriesQuery(ctx context.Context, req *ba
}
if err := eg.Wait(); err != nil {
dataResponse := errorsource.Response(fmt.Errorf("metric request error: %w", err))
dataResponse := backend.ErrorResponseWithErrorSource(fmt.Errorf("metric request error: %w", err))
resultChan <- &responseWrapper{
RefId: getQueryRefIdFromErrorString(err.Error(), requestQueries),
DataResponse: &dataResponse,