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

Add errorsource to errors #449

Merged
merged 5 commits into from
Sep 9, 2024
Merged

Add errorsource to errors #449

merged 5 commits into from
Sep 9, 2024

Conversation

iwysiu
Copy link
Contributor

@iwysiu iwysiu commented Sep 4, 2024

What this PR does / why we need it:
Adds errorsource to the opensearch datasource.

Which issue(s) this PR fixes:

Fixes https://github.com/grafana/oss-plugin-partnerships/issues/1014

Special notes for your reviewer:

// the Stats query can be created later.
func handleServiceMapPrefetch(ctx context.Context, osClient client.Client, req *backend.QueryDataRequest) (string, error) {
// the Stats query can be created later. Returns true if the serviceMap was fetched
func handleServiceMapPrefetch(ctx context.Context, osClient client.Client, req *backend.QueryDataRequest) *backend.QueryDataResponse {
Copy link
Contributor Author

Choose a reason for hiding this comment

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

There wasn't really a better way to handle the fact that execute is now returning the error as part of the response and still wrap the other errors

}

func wrapError(response *backend.QueryDataResponse, err error) (*backend.QueryDataResponse, error) {
var invalidQueryTypeError invalidQueryTypeError
Copy link
Contributor Author

Choose a reason for hiding this comment

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

now the error gets wrapped earlier, so we don't need this

@iwysiu iwysiu marked this pull request as ready for review September 5, 2024 13:53
@iwysiu iwysiu requested a review from a team as a code owner September 5, 2024 13:53
@iwysiu iwysiu requested review from kevinwcyu, nmarrs and njvrzm and removed request for a team September 5, 2024 13:53
Copy link

@nmarrs nmarrs left a comment

Choose a reason for hiding this comment

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

nice!! just left some nooby go questions haha

}

res, err := h.client.ExecuteMultisearch(ctx, req)
if err != nil {
return nil, err
// We are returning the error containing the source that was added through errorsource.Middleware
return errorsource.AddErrorToResponse(h.queries[0].RefID, response, err), nil
Copy link

Choose a reason for hiding this comment

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

Should we maybe draw out the h.queries[0].RefID into a defined reusable var in this case?

Copy link
Contributor Author

Choose a reason for hiding this comment

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

done!

}

query := newQueryRequest(osClient, req.Queries, req.PluginContext.DataSourceInstanceSettings)
response, err := wrapError(query.execute(ctx))
response, err = wrapError(query.execute(ctx))
Copy link

Choose a reason for hiding this comment

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

what is context of removing the := to =? (I am a bit of a Go noob btw)

Copy link

Choose a reason for hiding this comment

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

also should we keep this version of wrapError around vs using the newer wrap for this error? or in this case are we confident that this is an error owned by us

Copy link
Contributor Author

Choose a reason for hiding this comment

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

The difference is that := initializes and sets a variable and = sets an existing variable. Since response and err have now both been already initialized in this function, we only need to set it (and the compiler will yell at us if we do otherwise). It was able to use := before because while err had been initialized, response hadn't.

This is the same wrapError as it was before (line 128), it just used to also handle invalidQueryTypeError which we're now handling earlier.

Copy link

@nmarrs nmarrs left a comment

Choose a reason for hiding this comment

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

🚢

Copy link
Contributor

@njvrzm njvrzm left a comment

Choose a reason for hiding this comment

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

Looks solid! I like the lots of tests, I don't think we've been doing much of that with the errorsource work so far. One optional suggestion.

pkg/opensearch/opensearch.go Outdated Show resolved Hide resolved
iwysiu and others added 2 commits September 9, 2024 11:15
Co-authored-by: Nathan Vērzemnieks <njvrzm@gmail.com>
@iwysiu iwysiu merged commit dde12ed into main Sep 9, 2024
4 checks passed
@iwysiu iwysiu deleted the iwysiu/errorsourcewq branch September 9, 2024 15:51
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
None yet
Projects
None yet
Development

Successfully merging this pull request may close these issues.

3 participants