diff --git a/pkg/infinity/client.go b/pkg/infinity/client.go index fd43635f..b8a41b5e 100644 --- a/pkg/infinity/client.go +++ b/pkg/infinity/client.go @@ -20,7 +20,6 @@ import ( "github.com/grafana/grafana-plugin-sdk-go/backend" "github.com/grafana/grafana-plugin-sdk-go/backend/proxy" "github.com/grafana/grafana-plugin-sdk-go/backend/tracing" - "github.com/grafana/grafana-plugin-sdk-go/experimental/errorsource" "github.com/icholy/digest" "golang.org/x/oauth2" ) @@ -198,15 +197,15 @@ func (client *Client) req(ctx context.Context, url string, body io.Reader, setti defer span.End() req, err := GetRequest(ctx, settings, body, query, requestHeaders, true) if err != nil { - return nil, http.StatusInternalServerError, 0, errorsource.DownstreamError(fmt.Errorf("error preparing request. %w", err), false) + return nil, http.StatusInternalServerError, 0, backend.DownstreamError(fmt.Errorf("error preparing request. %w", err)) } if req == nil { - return nil, http.StatusInternalServerError, 0, errorsource.DownstreamError(errors.New("error preparing request. invalid request constructed"), false) + return nil, http.StatusInternalServerError, 0, backend.DownstreamError(errors.New("error preparing request. invalid request constructed")) } startTime := time.Now() if !CanAllowURL(req.URL.String(), settings.AllowedHosts) { logger.Debug("url is not in the allowed list. make sure to match the base URL with the settings", "url", req.URL.String()) - return nil, http.StatusUnauthorized, 0, errorsource.DownstreamError(errors.New("requested URL is not allowed. To allow this URL, update the datasource config Security -> Allowed Hosts section"), false) + return nil, http.StatusUnauthorized, 0, backend.DownstreamError(errors.New("requested URL is not allowed. To allow this URL, update the datasource config Security -> Allowed Hosts section")) } logger.Debug("requesting URL", "host", req.URL.Hostname(), "url_path", req.URL.Path, "method", req.Method, "type", query.Type) res, err := client.HttpClient.Do(req) @@ -220,29 +219,29 @@ func (client *Client) req(ctx context.Context, url string, body io.Reader, setti logger.Debug("error getting response from server", "url", url, "method", req.Method, "error", err.Error(), "status code", res.StatusCode) // Infinity can query anything and users are responsible for ensuring that endpoint/auth is correct // therefore any incoming error is considered downstream - return nil, res.StatusCode, duration, errorsource.DownstreamError(fmt.Errorf("error getting response from %s", url), false) + return nil, res.StatusCode, duration, backend.DownstreamError(fmt.Errorf("error getting response from %s", url)) } if errors.Is(err, context.Canceled) { logger.Debug("request cancelled", "url", url, "method", req.Method) - return nil, http.StatusInternalServerError, duration, errorsource.DownstreamError(err, false) + return nil, http.StatusInternalServerError, duration, backend.DownstreamError(err) } logger.Debug("error getting response from server. no response received", "url", url, "error", err.Error()) - return nil, http.StatusInternalServerError, duration, errorsource.DownstreamError(fmt.Errorf("error getting response from url %s. no response received. Error: %w", url, err), false) + return nil, http.StatusInternalServerError, duration, backend.DownstreamError(fmt.Errorf("error getting response from url %s. no response received. Error: %w", url, err)) } if res == nil { logger.Debug("invalid response from server and also no error", "url", url, "method", req.Method) - return nil, http.StatusInternalServerError, duration, errorsource.DownstreamError(fmt.Errorf("invalid response received for the URL %s", url), false) + return nil, http.StatusInternalServerError, duration, backend.DownstreamError(fmt.Errorf("invalid response received for the URL %s", url)) } if res.StatusCode >= http.StatusBadRequest { err = fmt.Errorf("%w. %s", ErrUnsuccessfulHTTPResponseStatus, res.Status) // Infinity can query anything and users are responsible for ensuring that endpoint/auth is correct // therefore any incoming error is considered downstream - return nil, res.StatusCode, duration, errorsource.DownstreamError(err, false) + return nil, res.StatusCode, duration, backend.DownstreamError(err) } bodyBytes, err := io.ReadAll(res.Body) if err != nil { logger.Debug("error reading response body", "url", url, "error", err.Error()) - return nil, res.StatusCode, duration, errorsource.DownstreamError(err, false) + return nil, res.StatusCode, duration, backend.DownstreamError(err) } bodyBytes = removeBOMContent(bodyBytes) if CanParseAsJSON(query.Type, res.Header) { @@ -250,7 +249,7 @@ func (client *Client) req(ctx context.Context, url string, body io.Reader, setti err := json.Unmarshal(bodyBytes, &out) if err != nil { err = fmt.Errorf("%w. %w", ErrParsingResponseBodyAsJson, err) - err = errorsource.DownstreamError(err, false) + err = backend.DownstreamError(err) logger.Debug("error un-marshaling JSON response", "url", url, "error", err.Error()) } return out, res.StatusCode, duration, err @@ -267,19 +266,19 @@ func (client *Client) GetResults(ctx context.Context, query models.Query, reques logger := backend.Logger.FromContext(ctx) if query.Source == "azure-blob" { if strings.TrimSpace(query.AzBlobContainerName) == "" || strings.TrimSpace(query.AzBlobName) == "" { - return nil, http.StatusBadRequest, 0, errorsource.DownstreamError(errors.New("invalid/empty container name/blob name"), false) + return nil, http.StatusBadRequest, 0, backend.DownstreamError(errors.New("invalid/empty container name/blob name")) } if client.AzureBlobClient == nil { - return nil, http.StatusInternalServerError, 0, errorsource.PluginError(errors.New("invalid azure blob client"), false) + return nil, http.StatusInternalServerError, 0, backend.PluginError(errors.New("invalid azure blob client")) } blobDownloadResponse, err := client.AzureBlobClient.DownloadStream(ctx, strings.TrimSpace(query.AzBlobContainerName), strings.TrimSpace(query.AzBlobName), nil) if err != nil { - return nil, http.StatusInternalServerError, 0, errorsource.DownstreamError(err, false) + return nil, http.StatusInternalServerError, 0, backend.DownstreamError(err) } reader := blobDownloadResponse.Body bodyBytes, err := io.ReadAll(reader) if err != nil { - return nil, http.StatusInternalServerError, 0, errorsource.PluginError(fmt.Errorf("error reading blob content. %w", err), false) + return nil, http.StatusInternalServerError, 0, backend.PluginError(fmt.Errorf("error reading blob content. %w", err)) } bodyBytes = removeBOMContent(bodyBytes) if CanParseAsJSON(query.Type, http.Header{}) { @@ -287,7 +286,7 @@ func (client *Client) GetResults(ctx context.Context, query models.Query, reques err := json.Unmarshal(bodyBytes, &out) if err != nil { logger.Error("error un-marshaling blob content", "error", err.Error()) - err = errorsource.PluginError(err, false) + err = backend.PluginError(err) } return out, http.StatusOK, duration, err } diff --git a/pkg/infinity/csvBackend.go b/pkg/infinity/csvBackend.go index e771af25..4998c7d6 100644 --- a/pkg/infinity/csvBackend.go +++ b/pkg/infinity/csvBackend.go @@ -5,9 +5,9 @@ import ( "errors" "github.com/grafana/grafana-infinity-datasource/pkg/models" + "github.com/grafana/grafana-plugin-sdk-go/backend" "github.com/grafana/grafana-plugin-sdk-go/backend/tracing" "github.com/grafana/grafana-plugin-sdk-go/data" - "github.com/grafana/grafana-plugin-sdk-go/experimental/errorsource" "github.com/grafana/infinity-libs/lib/go/csvframer" "github.com/grafana/infinity-libs/lib/go/gframer" ) @@ -48,9 +48,9 @@ func GetCSVBackendResponse(ctx context.Context, responseString string, query mod } if err != nil { if errors.Is(err, csvframer.ErrEmptyCsv) || errors.Is(err, csvframer.ErrReadingCsvResponse) { - err = errorsource.DownstreamError(err, false) + err = backend.DownstreamError(err) } else { - err = errorsource.PluginError(err , false) + err = backend.PluginError(err) } } return frame, err diff --git a/pkg/infinity/googleSheets.go b/pkg/infinity/googleSheets.go index 223a3d25..4cbe76d9 100644 --- a/pkg/infinity/googleSheets.go +++ b/pkg/infinity/googleSheets.go @@ -10,7 +10,6 @@ import ( "github.com/grafana/grafana-infinity-datasource/pkg/models" "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/infinity-libs/lib/go/gframer" ) @@ -49,7 +48,7 @@ func GetGoogleSheetsResponse(ctx context.Context, urlResponseObject any, query m Query: query, Error: "invalid response received from google sheets", } - return frame, errorsource.DownstreamError(errors.New("invalid response received from google sheets"), false) + return frame, backend.DownstreamError(errors.New("invalid response received from google sheets")) } sheet := &Spreadsheet{} if err := json.Unmarshal([]byte(sheetsString), &sheet); err != nil { @@ -58,7 +57,7 @@ func GetGoogleSheetsResponse(ctx context.Context, urlResponseObject any, query m Query: query, Error: "invalid response received from google sheets", } - return frame, errorsource.DownstreamError(errors.New("invalid response received from google sheets"), false) + return frame, backend.DownstreamError(errors.New("invalid response received from google sheets")) } if sheet != nil && len(sheet.Sheets) > 0 && len(sheet.Sheets[0].Data) > 0 { parsedCSV := [][]string{} diff --git a/pkg/infinity/inline.go b/pkg/infinity/inline.go index 48d4c9da..a2864eda 100644 --- a/pkg/infinity/inline.go +++ b/pkg/infinity/inline.go @@ -6,8 +6,8 @@ import ( "fmt" "github.com/grafana/grafana-infinity-datasource/pkg/models" + "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/infinity-libs/lib/go/jsonframer" ) @@ -49,7 +49,7 @@ func GetFrameForInlineSources(ctx context.Context, query models.Query) (*data.Fr }) if err != nil { if errors.Is(err, jsonframer.ErrInvalidRootSelector) || errors.Is(err, jsonframer.ErrInvalidJSONContent) || errors.Is(err, jsonframer.ErrEvaluatingJSONata) { - return frame, errorsource.DownstreamError(fmt.Errorf("error converting json data to frame: %w", err), false) + return frame, backend.DownstreamError(fmt.Errorf("error converting json data to frame: %w", err)) } return frame, err } diff --git a/pkg/infinity/jsonBackend.go b/pkg/infinity/jsonBackend.go index b92e1e3d..a8b4a6a0 100644 --- a/pkg/infinity/jsonBackend.go +++ b/pkg/infinity/jsonBackend.go @@ -10,7 +10,6 @@ import ( "github.com/grafana/grafana-plugin-sdk-go/backend" "github.com/grafana/grafana-plugin-sdk-go/backend/tracing" "github.com/grafana/grafana-plugin-sdk-go/data" - "github.com/grafana/grafana-plugin-sdk-go/experimental/errorsource" "github.com/grafana/infinity-libs/lib/go/jsonframer" ) @@ -23,7 +22,7 @@ func GetJSONBackendResponse(ctx context.Context, urlResponseObject any, query mo if err != nil { logger.Error("error json parsing root data", "error", err.Error()) frame.Meta.Custom = &CustomMeta{Query: query, Error: err.Error()} - return frame, errorsource.PluginError(fmt.Errorf("error parsing json root data"), false) + return frame, backend.PluginError(fmt.Errorf("error parsing json root data")) } columns := []jsonframer.ColumnSelector{} for _, c := range query.Columns { @@ -42,9 +41,9 @@ func GetJSONBackendResponse(ctx context.Context, urlResponseObject any, query mo if err != nil { if errors.Is(err, jsonframer.ErrInvalidRootSelector) || errors.Is(err, jsonframer.ErrInvalidJSONContent) || errors.Is(err, jsonframer.ErrEvaluatingJSONata) { - return frame, errorsource.DownstreamError(fmt.Errorf("error converting json data to frame: %w", err), false) + return frame, backend.DownstreamError(fmt.Errorf("error converting json data to frame: %w", err)) } - return frame, errorsource.PluginError(fmt.Errorf("error converting json data to frame: %w", err), false) + return frame, backend.PluginError(fmt.Errorf("error converting json data to frame: %w", err)) } if newFrame != nil { frame.Fields = append(frame.Fields, newFrame.Fields...) diff --git a/pkg/infinity/meta.go b/pkg/infinity/meta.go index 543cf9c5..5254fdc8 100644 --- a/pkg/infinity/meta.go +++ b/pkg/infinity/meta.go @@ -7,9 +7,9 @@ import ( "time" "github.com/grafana/grafana-infinity-datasource/pkg/models" + "github.com/grafana/grafana-plugin-sdk-go/backend" "github.com/grafana/grafana-plugin-sdk-go/backend/tracing" "github.com/grafana/grafana-plugin-sdk-go/data" - "github.com/grafana/grafana-plugin-sdk-go/experimental/errorsource" ) type CustomMeta struct { @@ -47,7 +47,7 @@ func WrapMetaForInlineQuery(ctx context.Context, frame *data.Frame, err error, q customMeta := &CustomMeta{Query: query, Data: query.Data, ResponseCodeFromServer: 0} if err != nil { customMeta.Error = err.Error() - err = errorsource.PluginError(err, false) + err = backend.PluginError(err) } frame.Meta = &data.FrameMeta{ ExecutedQueryString: "This feature is not available for this type of query yet", diff --git a/pkg/infinity/postprocess.go b/pkg/infinity/postprocess.go index 07175db4..338734fc 100644 --- a/pkg/infinity/postprocess.go +++ b/pkg/infinity/postprocess.go @@ -10,7 +10,6 @@ import ( "github.com/grafana/grafana-plugin-sdk-go/backend" "github.com/grafana/grafana-plugin-sdk-go/backend/tracing" "github.com/grafana/grafana-plugin-sdk-go/data" - "github.com/grafana/grafana-plugin-sdk-go/experimental/errorsource" "github.com/grafana/infinity-libs/lib/go/framesql" t "github.com/grafana/infinity-libs/lib/go/transformations" ) @@ -27,7 +26,7 @@ func PostProcessFrame(ctx context.Context, frame *data.Frame, query models.Query if err != nil { logger.Error("error getting computed column", "error", err.Error()) frame.Meta.Custom = &CustomMeta{Query: query, Error: err.Error()} - return frame, errorsource.PluginError(err, false) + return frame, backend.PluginError(err) } frame, err = t.ApplyFilter(frame, query.FilterExpression) if err != nil { @@ -78,8 +77,8 @@ func addErrorSourceToTransformError(err error) error { for _, e := range downstreamErrors { if errors.Is(err, e) { - return errorsource.DownstreamError(err, false) + return backend.DownstreamError(err) } } - return errorsource.PluginError(err, false) + return backend.PluginError(err) } \ No newline at end of file diff --git a/pkg/infinity/reference.go b/pkg/infinity/reference.go index 7dd67670..5f06e9a0 100644 --- a/pkg/infinity/reference.go +++ b/pkg/infinity/reference.go @@ -6,7 +6,7 @@ import ( "strings" "github.com/grafana/grafana-infinity-datasource/pkg/models" - "github.com/grafana/grafana-plugin-sdk-go/experimental/errorsource" + "github.com/grafana/grafana-plugin-sdk-go/backend" ) func UpdateQueryWithReferenceData(ctx context.Context, query models.Query, settings models.InfinitySettings) (models.Query, error) { @@ -18,7 +18,7 @@ func UpdateQueryWithReferenceData(ctx context.Context, query models.Query, setti return query, nil } } - return query, errorsource.DownstreamError(errors.New("error getting reference data. Either empty or not defined"), false) + return query, backend.DownstreamError(errors.New("error getting reference data. Either empty or not defined")) } return query, nil } diff --git a/pkg/infinity/remote.go b/pkg/infinity/remote.go index 24ee28d6..a6875e78 100644 --- a/pkg/infinity/remote.go +++ b/pkg/infinity/remote.go @@ -11,7 +11,6 @@ import ( "github.com/grafana/grafana-plugin-sdk-go/backend" "github.com/grafana/grafana-plugin-sdk-go/backend/tracing" "github.com/grafana/grafana-plugin-sdk-go/data" - "github.com/grafana/grafana-plugin-sdk-go/experimental/errorsource" "github.com/grafana/infinity-libs/lib/go/jsonframer" "github.com/grafana/infinity-libs/lib/go/transformations" ) @@ -214,11 +213,11 @@ func GetFrameForURLSourcesWithPostProcessing(ctx context.Context, query models.Q if query.PageMode == models.PaginationModeCursor && strings.TrimSpace(query.PageParamCursorFieldExtractionPath) != "" { body, err := json.Marshal(urlResponseObject) if err != nil { - return frame, cursor, errorsource.PluginError(errors.New("error while finding the cursor value"), false) + return frame, cursor, backend.PluginError(errors.New("error while finding the cursor value")) } cursor, err = jsonframer.GetRootData(string(body), query.PageParamCursorFieldExtractionPath) if err != nil { - return frame, cursor, errorsource.PluginError(errors.New("error while extracting the cursor value"), false) + return frame, cursor, backend.PluginError(errors.New("error while extracting the cursor value")) } } return frame, cursor, nil diff --git a/pkg/infinity/transformations.go b/pkg/infinity/transformations.go index fdc3e174..303f05b4 100644 --- a/pkg/infinity/transformations.go +++ b/pkg/infinity/transformations.go @@ -6,7 +6,6 @@ import ( "github.com/grafana/grafana-infinity-datasource/pkg/models" "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/infinity-libs/lib/go/transformations" ) @@ -28,7 +27,7 @@ func ApplyTransformations(query models.Query, input *backend.QueryDataResponse) } response, err = ApplyTransformation(query, t, response) if err != nil { - return response, errorsource.PluginError(err, false) + return response, backend.PluginError(err) } } for k := range response.Responses { diff --git a/pkg/infinity/xmlBackend.go b/pkg/infinity/xmlBackend.go index 6078d81d..6c6c5d33 100644 --- a/pkg/infinity/xmlBackend.go +++ b/pkg/infinity/xmlBackend.go @@ -4,9 +4,9 @@ import ( "context" "github.com/grafana/grafana-infinity-datasource/pkg/models" + "github.com/grafana/grafana-plugin-sdk-go/backend" "github.com/grafana/grafana-plugin-sdk-go/backend/tracing" "github.com/grafana/grafana-plugin-sdk-go/data" - "github.com/grafana/grafana-plugin-sdk-go/experimental/errorsource" "github.com/grafana/infinity-libs/lib/go/jsonframer" "github.com/grafana/infinity-libs/lib/go/xmlframer" ) @@ -33,7 +33,7 @@ func GetXMLBackendResponse(ctx context.Context, inputString string, query models frame.Fields = append(frame.Fields, newFrame.Fields...) } if err != nil { - err = errorsource.PluginError(err, false) + err = backend.PluginError(err) } return frame, err } diff --git a/pkg/models/macros.go b/pkg/models/macros.go index 91eaf8bb..4cc6e27a 100644 --- a/pkg/models/macros.go +++ b/pkg/models/macros.go @@ -9,7 +9,6 @@ import ( "github.com/grafana/grafana-plugin-sdk-go/backend" "github.com/grafana/grafana-plugin-sdk-go/backend/gtime" - "github.com/grafana/grafana-plugin-sdk-go/experimental/errorsource" m "github.com/grafana/infinity-libs/lib/go/macros" ) @@ -19,7 +18,7 @@ func getMatches(macroName, input string) ([][]string, error) { macroRegex := fmt.Sprintf("\\$__%s\\b(?:\\((.*?)\\))?", macroName) rgx, err := regexp.Compile(macroRegex) if err != nil { - return nil, errorsource.PluginError(err, false) + return nil, backend.PluginError(err) } return rgx.FindAllStringSubmatch(input, -1), nil } @@ -38,7 +37,7 @@ func InterPolateMacros(queryString string, timeRange backend.TimeRange, pluginCo macros := map[string]macroFunc{ "combineValues": func(query string, args []string) (string, error) { if len(args) <= 3 { - return query, errorsource.DownstreamError(errors.New("insufficient arguments to combineValues macro"), false) + return query, backend.DownstreamError(errors.New("insufficient arguments to combineValues macro")) } if len(args) == 4 && args[3] == "*" { return "", nil @@ -57,7 +56,7 @@ func InterPolateMacros(queryString string, timeRange backend.TimeRange, pluginCo }, "customInterval": func(query string, args []string) (string, error) { if len(args) == 0 { - return query, errorsource.DownstreamError(errors.New("insufficient arguments to customInterval macro"), false) + return query, backend.DownstreamError(errors.New("insufficient arguments to customInterval macro")) } for argI := range args { if argI == len(args)-1 { @@ -66,7 +65,7 @@ func InterPolateMacros(queryString string, timeRange backend.TimeRange, pluginCo if argI%2 != 0 { duration, err := gtime.ParseDuration(args[argI-1]) if err != nil { - return query, errorsource.DownstreamError(errors.New("invalid customInterval macro"), false) + return query, backend.DownstreamError(errors.New("invalid customInterval macro")) } if timeRangeInMilliSeconds <= duration.Milliseconds() { return args[argI], nil @@ -79,7 +78,7 @@ func InterPolateMacros(queryString string, timeRange backend.TimeRange, pluginCo for key, macro := range macros { matches, err := getMatches(key, queryString) if err != nil { - return queryString, errorsource.PluginError(err, false) + return queryString, err } for _, match := range matches { if len(match) == 0 { @@ -91,7 +90,7 @@ func InterPolateMacros(queryString string, timeRange backend.TimeRange, pluginCo } res, err := macro(queryString, args) if err != nil { - return queryString, errorsource.PluginError(err, false) + return queryString, err } queryString = strings.Replace(queryString, match[0], res, -1) } diff --git a/pkg/models/macros_test.go b/pkg/models/macros_test.go index 33d59746..d6221fb7 100644 --- a/pkg/models/macros_test.go +++ b/pkg/models/macros_test.go @@ -8,7 +8,6 @@ import ( "github.com/grafana/grafana-infinity-datasource/pkg/models" "github.com/grafana/grafana-plugin-sdk-go/backend" - "github.com/grafana/grafana-plugin-sdk-go/experimental/errorsource" "github.com/stretchr/testify/assert" "github.com/stretchr/testify/require" ) @@ -22,9 +21,9 @@ func TestInterPolateCombineValueMacros(t *testing.T) { wantError error }{ {query: "foo", want: "foo"}, - {query: "$__combineValues", wantError: errorsource.DownstreamError(errors.New("insufficient arguments to combineValues macro"), false)}, - {query: "$__combineValues()", wantError: errorsource.DownstreamError(errors.New("insufficient arguments to combineValues macro"), false)}, - {query: "$__combineValues(a,b,c)", wantError: errorsource.DownstreamError(errors.New("insufficient arguments to combineValues macro"), false)}, + {query: "$__combineValues", wantError: backend.DownstreamError(errors.New("insufficient arguments to combineValues macro"))}, + {query: "$__combineValues()", wantError: backend.DownstreamError(errors.New("insufficient arguments to combineValues macro"))}, + {query: "$__combineValues(a,b,c)", wantError: backend.DownstreamError(errors.New("insufficient arguments to combineValues macro"))}, {query: "$__combineValues(a,b,c,*)", want: ""}, {query: "$__combineValues(a,b,c,d)", want: "adb"}, {query: "$__combineValues(a,b,__space,d,e)", want: "adb aeb"}, @@ -108,7 +107,7 @@ func TestInterPolateCustomIntervalMacros(t *testing.T) { {query: "$__customInterval(1d)", want: "1d"}, {query: "$__customInterval(1m,1 MIN)", want: "1 MIN"}, {query: "$__customInterval(1m,1 MIN,1d)", want: "1d"}, - {query: "$__customInterval(1min,1 MIN,1d)", wantError: errorsource.DownstreamError(errors.New("invalid customInterval macro"), false)}, + {query: "$__customInterval(1min,1 MIN,1d)", wantError: backend.DownstreamError(errors.New("invalid customInterval macro"))}, {query: "$__customInterval(2d,2 DAYS,1d)", want: "2 DAYS"}, {query: "$__customInterval(5m,5 MINUTES,1d,1 DAY,10d,10 days,1d)", want: "1 DAY"}, {query: "foo $__customInterval(5m,5 MINUTES,1d,1 DAY,10d,10 days,1d) $__customInterval(2d,2 DAYS,1d) bar", want: "foo 1 DAY 2 DAYS bar"}, diff --git a/pkg/models/query.go b/pkg/models/query.go index 95b4947f..1e5f3701 100644 --- a/pkg/models/query.go +++ b/pkg/models/query.go @@ -8,7 +8,6 @@ import ( "strings" "github.com/grafana/grafana-plugin-sdk-go/backend" - "github.com/grafana/grafana-plugin-sdk-go/experimental/errorsource" ) type QueryType string @@ -303,12 +302,12 @@ func LoadQuery(ctx context.Context, backendQuery backend.DataQuery, pluginContex var query Query err := json.Unmarshal(backendQuery.JSON, &query) if err != nil { - return query, errorsource.DownstreamError(fmt.Errorf("error while parsing the query json. %w", err), false) + return query, backend.DownstreamError(fmt.Errorf("error while parsing the query json. %w", err)) } query = ApplyDefaultsToQuery(ctx, query, settings) if query.PageMode == PaginationModeList && strings.TrimSpace(query.PageParamListFieldName) == "" { // Downstream error as user input is not correct - return query, errorsource.DownstreamError(errors.New("pagination_param_list_field_name cannot be empty"), false) + return query, backend.DownstreamError(errors.New("pagination_param_list_field_name cannot be empty")) } return ApplyMacros(ctx, query, backendQuery.TimeRange, pluginContext) } diff --git a/pkg/pluginhost/handler_querydata.go b/pkg/pluginhost/handler_querydata.go index 05c82136..60eaaafa 100644 --- a/pkg/pluginhost/handler_querydata.go +++ b/pkg/pluginhost/handler_querydata.go @@ -10,7 +10,6 @@ import ( "github.com/grafana/grafana-plugin-sdk-go/backend" "github.com/grafana/grafana-plugin-sdk-go/backend/tracing" "github.com/grafana/grafana-plugin-sdk-go/data" - "github.com/grafana/grafana-plugin-sdk-go/experimental/errorsource" "go.opentelemetry.io/otel/attribute" "go.opentelemetry.io/otel/trace" ) @@ -22,7 +21,7 @@ func (ds *DataSource) QueryData(ctx context.Context, req *backend.QueryDataReque defer span.End() response := backend.NewQueryDataResponse() if ds.client == nil { - return response, errorsource.PluginError(errors.New("invalid infinity client"), false) + return response, backend.PluginError(errors.New("invalid infinity client")) } for _, q := range req.Queries { query, err := models.LoadQuery(ctx, q, req.PluginContext, ds.client.Settings) @@ -30,7 +29,7 @@ func (ds *DataSource) QueryData(ctx context.Context, req *backend.QueryDataReque span.RecordError(err) logger.Error("error un-marshaling the query", "error", err.Error()) // Here we are using error source from the original error and if it does not have any source we are using the plugin error as the default source - errorRes := errorsource.Response(errorsource.SourceError(backend.ErrorSourcePlugin, fmt.Errorf("%s: %w", "error un-marshaling the query", err), false)) + errorRes := backend.ErrorResponseWithErrorSource(backend.PluginError(fmt.Errorf("%s: %w", "error un-marshaling the query", err))) response.Responses[q.RefID] = errorRes continue } @@ -41,7 +40,7 @@ func (ds *DataSource) QueryData(ctx context.Context, req *backend.QueryDataReque span.RecordError(err) span.SetStatus(500, err.Error()) // We should have error source from the original error, but in a case it is not there, we are using the plugin error as the default source - return response, errorsource.PluginError(fmt.Errorf("%s: %w", "error applying infinity query transformation", err), false) + return response, backend.PluginError(fmt.Errorf("%s: %w", "error applying infinity query transformation", err)) } response = response1 continue @@ -82,7 +81,7 @@ func QueryDataQuery(ctx context.Context, query models.Query, infClient infinity. sheetRange = sheetName + "!" + sheetRange } if sheetId == "" { - return errorsource.Response(errorsource.DownstreamError(errors.New("invalid or empty sheet ID"), false)) + return backend.ErrorResponseWithErrorSource(backend.DownstreamError(errors.New("invalid or empty sheet ID"))) } query.URL = fmt.Sprintf("https://sheets.googleapis.com/v4/spreadsheets/%s?includeGridData=true&ranges=%s", sheetId, sheetRange) frame, err := infinity.GetFrameForURLSources(ctx, query, infClient, requestHeaders) @@ -93,7 +92,11 @@ func QueryDataQuery(ctx context.Context, query models.Query, infClient infinity. wrappedError := fmt.Errorf("%s: %w", "error getting data frame from google sheets", err) response.Error = wrappedError // We should have error source from the original error, but in a case it is not there, we are using the plugin error as the default source - response.ErrorSource = errorsource.SourceError(backend.ErrorSourcePlugin, wrappedError, false).Source() + if backend.IsDownstreamError(err) { + response.ErrorSource = backend.ErrorSourceDownstream + } else { + response.ErrorSource = backend.ErrorSourcePlugin + } return response } if frame != nil { @@ -127,7 +130,11 @@ func QueryDataQuery(ctx context.Context, query models.Query, infClient infinity. response.Frames = append(response.Frames, frame) } response.Error = fmt.Errorf("error while performing the infinity query. %w", err) - response.ErrorSource = errorsource.SourceError(backend.ErrorSourcePlugin, err, false).Source() + if backend.IsDownstreamError(err) { + response.ErrorSource = backend.ErrorSourceDownstream + } else { + response.ErrorSource = backend.ErrorSourcePlugin + } return response } if frame != nil && infClient.Settings.AuthenticationMethod != models.AuthenticationMethodAzureBlob && infClient.Settings.AuthenticationMethod != models.AuthenticationMethodNone && infClient.Settings.AuthenticationMethod != "" && len(infClient.Settings.AllowedHosts) < 1 { @@ -149,7 +156,11 @@ func QueryDataQuery(ctx context.Context, query models.Query, infClient infinity. response.Frames = append(response.Frames, frame) response.Error = fmt.Errorf("error while performing the infinity inline query. %w", err) // We should have error source from the original error, but in a case it is not there, we are using the plugin error as the default source - response.ErrorSource = errorsource.SourceError(backend.ErrorSourcePlugin, err, false).Source() + if backend.IsDownstreamError(err) { + response.ErrorSource = backend.ErrorSourceDownstream + } else { + response.ErrorSource = backend.ErrorSourcePlugin + } return response } if frame != nil {