-
Notifications
You must be signed in to change notification settings - Fork 66
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
Autoinstrumentation improvements #1066
Merged
Merged
Changes from 4 commits
Commits
Show all changes
5 commits
Select commit
Hold shift + click to select a range
File filter
Filter by extension
Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
There are no files selected for viewing
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change | ||||||
---|---|---|---|---|---|---|---|---|
|
@@ -29,78 +29,59 @@ func (a *dataSDKAdapter) QueryData(ctx context.Context, req *pluginv2.QueryDataR | |||||||
var innerErr error | ||||||||
resp, innerErr = a.queryDataHandler.QueryData(ctx, parsedReq) | ||||||||
|
||||||||
if resp == nil || len(resp.Responses) == 0 { | ||||||||
return RequestStatusFromError(innerErr), innerErr | ||||||||
} | ||||||||
|
||||||||
if isCancelledError(innerErr) { | ||||||||
return RequestStatusCancelled, nil | ||||||||
} | ||||||||
|
||||||||
if isHTTPTimeoutError(innerErr) { | ||||||||
return RequestStatusError, nil | ||||||||
status := RequestStatusFromQueryDataResponse(resp, innerErr) | ||||||||
if innerErr != nil { | ||||||||
return status, innerErr | ||||||||
} else if resp == nil { | ||||||||
return RequestStatusError, fmt.Errorf("both response and error are nil, but one must be provided") | ||||||||
marefr marked this conversation as resolved.
Show resolved
Hide resolved
|
||||||||
} | ||||||||
ctxLogger := Logger.FromContext(ctx) | ||||||||
|
||||||||
// Set downstream status source in the context if there's at least one response with downstream status source, | ||||||||
// and if there's no plugin error | ||||||||
var hasPluginError bool | ||||||||
var hasDownstreamError bool | ||||||||
var hasCancelledError bool | ||||||||
var hasHTTPTimeoutError bool | ||||||||
for _, r := range resp.Responses { | ||||||||
var hasPluginError, hasDownstreamError bool | ||||||||
for refID, r := range resp.Responses { | ||||||||
if r.Error == nil { | ||||||||
continue | ||||||||
} | ||||||||
|
||||||||
if isCancelledError(r.Error) { | ||||||||
hasCancelledError = true | ||||||||
// if error source not set and the error is a downstream error, set error source to downstream. | ||||||||
if !r.ErrorSource.IsValid() && IsDownstreamError(r.Error) { | ||||||||
r.ErrorSource = ErrorSourceDownstream | ||||||||
} | ||||||||
if isHTTPTimeoutError(r.Error) { | ||||||||
hasHTTPTimeoutError = true | ||||||||
|
||||||||
if !r.Status.IsValid() { | ||||||||
There was a problem hiding this comment. Choose a reason for hiding this commentThe reason will be displayed to describe this comment to others. Learn more. This one I copied from grafana-plugin-sdk-go/backend/convert_to_protobuf.go Lines 218 to 220 in e1e82c0
|
||||||||
r.Status = statusFromError(r.Error) | ||||||||
} | ||||||||
|
||||||||
if r.ErrorSource == ErrorSourceDownstream { | ||||||||
hasDownstreamError = true | ||||||||
} else { | ||||||||
hasPluginError = true | ||||||||
} | ||||||||
} | ||||||||
|
||||||||
if hasCancelledError { | ||||||||
if err := WithDownstreamErrorSource(ctx); err != nil { | ||||||||
return RequestStatusError, fmt.Errorf("failed to set downstream status source: %w", errors.Join(innerErr, err)) | ||||||||
logParams := []any{ | ||||||||
"refID", refID, | ||||||||
"status", int(r.Status), | ||||||||
"error", r.Error, | ||||||||
"statusSource", string(r.ErrorSource), | ||||||||
} | ||||||||
return RequestStatusCancelled, nil | ||||||||
} | ||||||||
|
||||||||
if hasHTTPTimeoutError { | ||||||||
if err := WithDownstreamErrorSource(ctx); err != nil { | ||||||||
return RequestStatusError, fmt.Errorf("failed to set downstream status source: %w", errors.Join(innerErr, err)) | ||||||||
} | ||||||||
return RequestStatusError, nil | ||||||||
ctxLogger.Error("Partial data response error", logParams...) | ||||||||
} | ||||||||
|
||||||||
// A plugin error has higher priority than a downstream error, | ||||||||
// so set to downstream only if there's no plugin error | ||||||||
if hasDownstreamError && !hasPluginError { | ||||||||
if err := WithDownstreamErrorSource(ctx); err != nil { | ||||||||
return RequestStatusError, fmt.Errorf("failed to set downstream status source: %w", errors.Join(innerErr, err)) | ||||||||
} | ||||||||
return RequestStatusError, nil | ||||||||
} | ||||||||
|
||||||||
if hasPluginError { | ||||||||
if err := WithErrorSource(ctx, ErrorSourcePlugin); err != nil { | ||||||||
return RequestStatusError, fmt.Errorf("failed to set plugin status source: %w", errors.Join(innerErr, err)) | ||||||||
} | ||||||||
return RequestStatusError, nil | ||||||||
} | ||||||||
|
||||||||
if innerErr != nil { | ||||||||
return RequestStatusFromError(innerErr), innerErr | ||||||||
} else if hasDownstreamError { | ||||||||
if err := WithDownstreamErrorSource(ctx); err != nil { | ||||||||
return RequestStatusError, fmt.Errorf("failed to set downstream status source: %w", errors.Join(innerErr, err)) | ||||||||
} | ||||||||
} | ||||||||
|
||||||||
return RequestStatusOK, nil | ||||||||
return status, nil | ||||||||
}) | ||||||||
if err != nil { | ||||||||
return nil, err | ||||||||
|
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Add this suggestion to a batch that can be applied as a single commit.
This suggestion is invalid because no changes were made to the code.
Suggestions cannot be applied while the pull request is closed.
Suggestions cannot be applied while viewing a subset of changes.
Only one suggestion per line can be applied in a batch.
Add this suggestion to a batch that can be applied as a single commit.
Applying suggestions on deleted lines is not supported.
You must change the existing code in this line in order to create a valid suggestion.
Outdated suggestions cannot be applied.
This suggestion has been applied or marked resolved.
Suggestions cannot be applied from pending reviews.
Suggestions cannot be applied on multi-line comments.
Suggestions cannot be applied while the pull request is queued to merge.
Suggestion cannot be applied right now. Please check back later.
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
This is iterating the data responses and we do that below as well, but feels like much cleaner code doing it this way
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
It looks like that check
if resp == nil || len(resp.Responses) == 0 {
was needed also for code bellow, because now, if we return nil response, we get panic infor refID, r := range resp.Responses
codeThere was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
That's correct, but I still get a separate panic even after adding back the same
if resp == nil || len(resp.Responses) == 0 {
check.This time the panic is here:
grafana-plugin-sdk-go/backend/data_adapter.go
Line 109 in e1e82c0
grafana-plugin-sdk-go/backend/convert_to_protobuf.go
Line 197 in 6158ec5
I also get it on the latest main:
So this section needs better error handling in general :)
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
Are you returning both a nil response and a nil error in your datasource?
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
I can see the test doing that, but was referring to your datasource @ivanahuckova
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
No, I was returning nil response and error. You can see it in the screenshot as well.
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
Pushed some changes: