Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Error source HTTP client middleware #1106

Merged
merged 9 commits into from
Oct 11, 2024
Merged

Error source HTTP client middleware #1106

merged 9 commits into from
Oct 11, 2024

Conversation

marefr
Copy link
Contributor

@marefr marefr commented Oct 10, 2024

Alternative to #1102

Moves backend.ErrorSource related implementation to a new package status. This tries to keep backward compatibility by keeping type aliases in the backend package referencing the new status package.

The main motivation behind this change is that having the backend.ErrorSource makes it basically impossible for any other package to make use of this if that package is imported by the backend package since it creates a circular dependency.

Seems like gorelease doesn't agree these type alias changes are compatible. In my head they should be 🤔

# github.com/grafana/grafana-plugin-sdk-go/backend
## incompatible changes
DataResponse.ErrorSource: changed from ErrorSource to github.com/grafana/grafana-plugin-sdk-go/experimental/status.Source
DefaultErrorSource: changed from ErrorSource to github.com/grafana/grafana-plugin-sdk-go/experimental/status.Source
ErrDataResponseWithSource: changed from func(Status, ErrorSource, string) DataResponse to func(Status, github.com/grafana/grafana-plugin-sdk-go/experimental/status.Source, string) DataResponse
ErrorSource: changed from ErrorSource to github.com/grafana/grafana-plugin-sdk-go/experimental/status.Source
ErrorSourceDownstream: changed from ErrorSource to github.com/grafana/grafana-plugin-sdk-go/experimental/status.Source
ErrorSourceFromHTTPStatus: changed from func(int) ErrorSource to func(int) github.com/grafana/grafana-plugin-sdk-go/experimental/status.Source
ErrorSourcePlugin: changed from ErrorSource to github.com/grafana/grafana-plugin-sdk-go/experimental/status.Source
FrameResponseWithErrorAndSource: changed from func(github.com/grafana/grafana-plugin-sdk-go/data.Framer, error, ErrorSource) *DataResponse to func(github.com/grafana/grafana-plugin-sdk-go/data.Framer, error, github.com/grafana/grafana-plugin-sdk-go/experimental/status.Source) *DataResponse
WithErrorSource: changed from func(context.Context, ErrorSource) error to func(context.Context, github.com/grafana/grafana-plugin-sdk-go/experimental/status.Source) error
## compatible changes
ErrorSourceFromHTTPError: added
IsDownstreamHTTPError: added

# github.com/grafana/grafana-plugin-sdk-go/backend/httpclient
## compatible changes
ErrorSourceMiddleware: added
ErrorSourceMiddlewareName: added

# github.com/grafana/grafana-plugin-sdk-go/experimental/errorsource
## incompatible changes
Error.ErrorSource: changed from func() github.com/grafana/grafana-plugin-sdk-go/backend.ErrorSource to func() github.com/grafana/grafana-plugin-sdk-go/experimental/status.Source
Error.Source: changed from func() github.com/grafana/grafana-plugin-sdk-go/backend.ErrorSource to func() github.com/grafana/grafana-plugin-sdk-go/experimental/status.Source
FromStatus: changed from func(github.com/grafana/grafana-plugin-sdk-go/backend.Status) github.com/grafana/grafana-plugin-sdk-go/backend.ErrorSource to func(github.com/grafana/grafana-plugin-sdk-go/backend.Status) github.com/grafana/grafana-plugin-sdk-go/experimental/status.Source
New: changed from func(error, github.com/grafana/grafana-plugin-sdk-go/backend.ErrorSource, github.com/grafana/grafana-plugin-sdk-go/backend.Status) Error to func(error, github.com/grafana/grafana-plugin-sdk-go/experimental/status.Source, github.com/grafana/grafana-plugin-sdk-go/backend.Status) Error
SourceError: changed from func(github.com/grafana/grafana-plugin-sdk-go/backend.ErrorSource, error, bool) Error to func(github.com/grafana/grafana-plugin-sdk-go/experimental/status.Source, error, bool) Error

# github.com/grafana/grafana-plugin-sdk-go/experimental/slo
## incompatible changes
FromStatus: changed from func(github.com/grafana/grafana-plugin-sdk-go/backend.Status) github.com/grafana/grafana-plugin-sdk-go/backend.ErrorSource to func(github.com/grafana/grafana-plugin-sdk-go/backend.Status) github.com/grafana/grafana-plugin-sdk-go/experimental/status.Source

# github.com/grafana/grafana-plugin-sdk-go/experimental/status
## compatible changes
package added

# summary
Inferred base version: v0.2[5](https://github.com/grafana/grafana-plugin-sdk-go/actions/runs/11290062261/job/31401119632?pr=1106#step:5:6)2.0
Suggested version: v0.253.0

@marefr marefr self-assigned this Oct 10, 2024
@marefr marefr marked this pull request as ready for review October 10, 2024 13:25
@marefr marefr requested a review from a team as a code owner October 10, 2024 13:25
@marefr marefr requested review from wbrowne, andresmgot, oshirohugo and ivanahuckova and removed request for a team October 10, 2024 13:25
Copy link
Member

@ivanahuckova ivanahuckova left a comment

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Awesome cleanup! Left some comments.

backend/status/status_source.go Outdated Show resolved Hide resolved
backend/status/status_source.go Outdated Show resolved Hide resolved
@ivanahuckova ivanahuckova self-requested a review October 10, 2024 14:29
Copy link
Member

@ivanahuckova ivanahuckova left a comment

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

LGTM! Things that we need to improve in follow up:

  • We should probably export errorWithSourceImpl and use it in experimental/errorsource instead of Error to ensure that all methods are working as intended with a new middleware. Specifically we need Response to work.
  • We should add methods/options that add error source, but will not override it if it exists
  • Deprecate experimental/errorsource and point plugin developers use non-experimental versions of functions.
  • In pkg/infra/httpclient/httpclientprovider/http_client_provider.go we need to add ErrorSource middleaware so built in plugin case use it. Done in Plugins: Auto instrumentation improvements grafana#94193

Copy link
Member

@ivanahuckova ivanahuckova left a comment

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Left couple more comments and questions

backend/status/status_source.go Outdated Show resolved Hide resolved
backend/status/status_source.go Outdated Show resolved Hide resolved
Copy link
Member

@wbrowne wbrowne left a comment

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

LGTM

@marefr marefr merged commit 64eea53 into main Oct 11, 2024
2 of 3 checks passed
@marefr marefr deleted the 1102-alternative branch October 11, 2024 13:22
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
None yet
Projects
Development

Successfully merging this pull request may close these issues.

3 participants