-
Notifications
You must be signed in to change notification settings - Fork 40
update error code if ES dial connection error #797
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
base: main
Are you sure you want to change the base?
Changes from all commits
File filter
Filter by extension
Conversations
Jump to
Diff view
Diff view
There are no files selected for viewing
Original file line number | Diff line number | Diff line change | ||||
---|---|---|---|---|---|---|
|
@@ -281,12 +281,18 @@ func (a *authenticator) Authenticate(ctx context.Context, headers map[string][]s | |||||
|
||||||
hasPrivileges, username, err := a.hasPrivileges(ctx, authHeaderValue) | ||||||
if err != nil { | ||||||
if elasticsearchErr, ok := err.(*types.ElasticsearchError); ok { | ||||||
if elasticsearchErr.Status == http.StatusUnauthorized || elasticsearchErr.Status == http.StatusForbidden { | ||||||
switch elasticsearchErr := err.(type) { | ||||||
case *types.ElasticsearchError: | ||||||
switch elasticsearchErr.Status { | ||||||
case http.StatusUnauthorized, http.StatusForbidden: | ||||||
return ctx, status.Error(codes.Unauthenticated, err.Error()) | ||||||
default: | ||||||
return ctx, status.Errorf(codes.Internal, "error checking privileges for API Key %q: %v", id, err) | ||||||
} | ||||||
default: | ||||||
// If no ES error type is found, it implies an error on the TCP connection level. | ||||||
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. Not exactly accurate. Reading the implementation of For example, a broken http proxy can return a body that cannot be parsed by hasPrivileges. It is not necessarily a TCP error. 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. Assuming we are both looking at the same method. It looks like we can also receive json.unmarshal errors. I would say a more general comment should suffice:
Suggested change
|
||||||
return ctx, errorWithDetails(codes.Unavailable, fmt.Sprintf("retryable server error %q: %v", id, err), nil) | ||||||
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. nit: why are we using errorWithDetails here instead of status.Errorf? 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 comes from a recommendation from @vigneshshanmugam in https://github.com/elastic/hosted-otel-collector/pull/1529#discussion_r2412175374 for consistency. 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. I'm not sure if I understand. Then why are we not using errorWithDetails on line 228 and 290? And what's the point of adding the domain with nil metadata as error info to the error? 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. It looks like the metadata is not used in the collector func map[string]string{
"component": "apikeyauthextension",
"api_key": id,
} |
||||||
} | ||||||
return ctx, status.Errorf(codes.Unauthenticated, "error checking privileges for API Key %q: %v", id, err) | ||||||
} | ||||||
if !hasPrivileges { | ||||||
cacheEntry := &cacheEntry{ | ||||||
|
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.
My ide is giving me this warning btw "Type switch on errors fails on wrapped errors". I do not see any error wrapping in
func (r HasPrivileges) Do
, so just providing a suggestion to be safe.