-
Notifications
You must be signed in to change notification settings - Fork 2.5k
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
Return more detailed errors from ES storage (#5209)
## Which problem is this PR solving? - In many cases when ES operations fail, the only error returned to the UI or written to Jaeger log is `all shards fail`, which is pretty useless for the actual troubleshooting. - Meanwhile, the driver actually returns an error struct that contains a `RootCause` field. ## Description of the changes - Inspect the error and include root cause if present ## How was this change tested? Run all-in-one and `curl 'http://localhost:16686/api/services'` Before: `$ curl 'http://localhost:16686/api/services'` `{"data":null,"total":0,"limit":0,"offset":0,"errors":[{"code":500,"msg":"search services failed: elastic: Error 400 (Bad Request): all shards failed [type=search_phase_execution_exception]"}]}` After: `$ curl 'http://localhost:16686/api/services'` `{"data":null,"total":0,"limit":0,"offset":0,"errors":[{"code":500,"msg":"search services failed: elastic: Error 400 (Bad Request): all shards failed [type=search_phase_execution_exception]: RootCause[Fielddata is disabled on [serviceName] in [jaeger-service-]. Text fields are not optimised for operations that require per-document field data like aggregations and sorting, so these operations are disabled by default. Please use a keyword field instead. Alternatively, set fielddata=true on [serviceName] in order to load field data by uninverting the inverted index. Note that this can use significant memory. [type=illegal_argument_exception]]"}]}` --------- Signed-off-by: Yuri Shkuro <[email protected]>
- Loading branch information
1 parent
5375e1e
commit cdb8b3f
Showing
4 changed files
with
75 additions
and
4 deletions.
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 |
---|---|---|
@@ -0,0 +1,33 @@ | ||
// Copyright (c) 2024 The Jaeger Authors. | ||
// SPDX-License-Identifier: Apache-2.0 | ||
|
||
package es | ||
|
||
import ( | ||
"errors" | ||
"fmt" | ||
|
||
"github.com/olivere/elastic" | ||
) | ||
|
||
// DetailedError creates a more detailed error if the error stack contains elastic.Error. | ||
// This is useful because by default olivere/elastic returns errors that print like this: | ||
// | ||
// elastic: Error 400 (Bad Request): all shards failed [type=search_phase_execution_exception] | ||
// | ||
// This is pretty useless because it masks the underlying root cause. | ||
// DetailedError would instead return an error like this: | ||
// | ||
// <same as above>: RootCause[... detailed error message ...] | ||
func DetailedError(err error) error { | ||
var esErr *elastic.Error | ||
if errors.As(err, &esErr) { | ||
if esErr.Details != nil && len(esErr.Details.RootCause) > 0 { | ||
rc := esErr.Details.RootCause[0] | ||
if rc != nil { | ||
return fmt.Errorf("%w: RootCause[%s [type=%s]]", err, rc.Reason, rc.Type) | ||
} | ||
} | ||
} | ||
return 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
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,35 @@ | ||
// Copyright (c) 2024 The Jaeger Authors. | ||
// SPDX-License-Identifier: Apache-2.0 | ||
|
||
package es | ||
|
||
import ( | ||
"fmt" | ||
"testing" | ||
|
||
"github.com/olivere/elastic" | ||
"github.com/stretchr/testify/require" | ||
) | ||
|
||
func TestDetailedError(t *testing.T) { | ||
require.ErrorContains(t, fmt.Errorf("some err"), "some err", "no panic") | ||
|
||
esErr := &elastic.Error{ | ||
Status: 400, | ||
Details: &elastic.ErrorDetails{ | ||
Type: "type1", | ||
Reason: "useless reason, e.g. all shards failed", | ||
RootCause: []*elastic.ErrorDetails{ | ||
{ | ||
Type: "type2", | ||
Reason: "actual reason", | ||
}, | ||
}, | ||
}, | ||
} | ||
require.ErrorContains(t, DetailedError(esErr), "actual reason") | ||
|
||
esErr.Details.RootCause[0] = nil | ||
require.ErrorContains(t, DetailedError(esErr), "useless reason") | ||
require.NotContains(t, DetailedError(esErr).Error(), "actual reason") | ||
} |
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