-
Notifications
You must be signed in to change notification settings - Fork 141
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
Improve Error Reporting for New SQL Engine #691
Improve Error Reporting for New SQL Engine #691
Conversation
LOG.warn("Caught an exception when anonymizing sensitive data"); | ||
resultQuery = query; | ||
LOG.warn("Caught an exception when anonymizing sensitive data."); | ||
LOG.debug("String {} failed anonymization.", query); |
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.
Why not combine with LOG.warn?
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.
For syntax errors, the query
variable contains the details of the failed query and is not anonymized (since the anonymization failed). This could, potentially, put sensitive data into the logs that we don't want to be included in production data. Setting it to debug level means that it doesn't go out to the logs by default.
docs/user/admin/settings.rst
Outdated
Query failed on both V1 and V2 SQL parser engines. V2 SQL parser error following: | ||
{ | ||
"error": { | ||
"reason": "Invalid SQL query", | ||
"details": "Failed to parse query due to offending symbol [DELETE] at: 'DELETE' <--- HERE... More details: Expecting tokens in {<EOF>, 'DESCRIBE', 'SELECT', 'SHOW', ';'}", | ||
"type": "SyntaxCheckException" | ||
}, | ||
"status": 400 | ||
} |
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.
1.Comparing with previous error message, the new one is misleading.
2.Why the V2 engine throw syntax exception? SQLFeatureDisabledException means user already disable sql plugin, then query will not executed in SQL engine.
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.
Good catch on this bug. Looks like the error string value for the V2 engine was being used from a previous error. I will update the test and clear the error message with each attempt at the V1 and V2 engines.
legacy/src/main/java/org/opensearch/sql/legacy/plugin/RestSQLQueryAction.java
Show resolved
Hide resolved
Codecov Report
@@ Coverage Diff @@
## main #691 +/- ##
=========================================
Coverage 94.74% 94.74%
Complexity 2857 2857
=========================================
Files 283 283
Lines 7676 7676
Branches 560 560
=========================================
Hits 7273 7273
Misses 349 349
Partials 54 54
Flags with carried forward coverage won't be shown. Click here to find out more. Help us with your feedback. Take ten seconds to tell us how you rate us. |
* This member variable and it's usage can be deleted once the | ||
* legacy SQL engine is deprecated. | ||
*/ | ||
private String errorStr; |
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.
You can use @Getter
and @Setter
annotations instead of creating setErrorStr
and getErrorStr
.
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.
Resolved under: 08981598f03df7da85f23fd547b70c1a08318c8c
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.
Just want to confirm is this class (or RestSqlAction
who create this) a singleton or created per request?
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.
do we really need errorStr? or Exception e? Could we use RestSqlAction produce the error message from e.
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.
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.
RestSqlAction is created per request.
legacy/src/main/java/org/opensearch/sql/legacy/plugin/RestSQLQueryAction.java
Outdated
Show resolved
Hide resolved
legacy/src/main/java/org/opensearch/sql/legacy/plugin/RestSQLQueryAction.java
Outdated
Show resolved
Hide resolved
*/ | ||
StringWriter sw = new StringWriter(); | ||
e.printStackTrace(new PrintWriter(sw)); | ||
String stackTrace = sw.toString(); |
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.
Can't his block (205-207) be with line 215? It'll be easier to follow.
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.
Resolved under: 08981598f03df7da85f23fd547b70c1a08318c8c
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 is for debug purpose, right? could it be wrap inside if (log.debug)?
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.
We want the stack trace to be logged under normal debug levels as error. So not for debugging purposes only but error reporting like prior to this new implementation. I could wrap this inside of a Log.Error if that is more of your liking.
Signed-off-by: forestmvey <[email protected]>
Signed-off-by: forestmvey <[email protected]>
Signed-off-by: forestmvey <[email protected]>
…race separately in log to avoid logging un-anonymized data. Added function comments Signed-off-by: forestmvey <[email protected]>
…ction Signed-off-by: forestmvey <[email protected]>
…Added more diagnostics for unsupported SQL requests. Updated documentation with fixes in the test that reflects V2 error message being used where it shouldn't Signed-off-by: forestmvey <[email protected]>
…es to log messages Signed-off-by: forestmvey <[email protected]>
eab8d62
to
0898159
Compare
@Override | ||
protected RestChannelConsumer prepareRequest(RestRequest request, NodeClient client) { | ||
Metrics.getInstance().getNumericalMetric(MetricName.REQ_TOTAL).increment(); | ||
Metrics.getInstance().getNumericalMetric(MetricName.REQ_COUNT_TOTAL).increment(); | ||
|
||
LogUtils.addRequestId(); | ||
newSqlQueryHandler.setErrorStr(""); |
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.
Is it necessary?
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.
Since this class is a singleton we can potentially re-use old error messages. This ensures we are starting with an empty error message.
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.
if it's singleton will errorStr handle concurrent errors?
@@ -234,7 +260,7 @@ private static boolean isExplainRequest(final RestRequest request) { | |||
return request.path().endsWith("/_explain"); | |||
} | |||
|
|||
private static boolean isClientError(Exception e) { | |||
public static boolean isClientError(Exception e) { |
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.
why change to public?
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 updated this function to public to allow RestSqlQueryAction
to output the same error format as this class. As well it seemed like a function that would be appropriately public.
private void reportError(final RestChannel channel, final Exception e, final RestStatus status, String v2SqlEngineError) { | ||
String errorMsg = ErrorMessageFactory.createErrorMessage(e, status.getStatus()).toString(); | ||
errorMsg += v2SqlEngineError.isEmpty() ? "" : | ||
"\nQuery failed on both V1 and V2 SQL parser engines. V2 SQL parser error following: \n" | ||
+ v2SqlEngineError; |
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.
Just discovered that you're concatenating 2 json objects here. In my test I'm getting
{
"error": {
"reason": "Invalid SQL query",
"details": "unsupported method: simple_query_string",
"type": "SqlParseException"
},
"status": 400
}
Query failed on both V1 and V2 SQL parser engines. V2 SQL parser error following:
{
"error": {
"reason": "Invalid SQL query",
"details": "Failed to parse query due to offending symbol [1] at: 'select `key`, str2 from calcs where simple_query_string([str2], one, analyzer = standard, 1' <--- HERE... More details: Expecting tokens in {'ALLOW_LEADING_WILDCARD', 'ANALYZER', 'ANALYZE_WILDCARD', 'AUTO_GENERATE_SYNONYMS_PHRASE_QUERY', 'BOOST', 'CUTOFF_FREQUENCY', 'DEFAULT_FIELD', 'DEFAULT_OPERATOR', 'ESCAPE', 'ENABLE_POSITION_INCREMENTS', 'FIELDS', 'FLAGS', 'FUZZINESS', 'FUZZY_MAX_EXPANSIONS', 'FUZZY_PREFIX_LENGTH', 'FUZZY_REWRITE', 'FUZZY_TRANSPOSITIONS', 'LENIENT', 'LOW_FREQ_OPERATOR', 'MAX_DETERMINIZED_STATES', 'MAX_EXPANSIONS', 'MINIMUM_SHOULD_MATCH', 'OPERATOR', 'PHRASE_SLOP', 'PREFIX_LENGTH', 'QUOTE_ANALYZER', 'QUOTE_FIELD_SUFFIX', 'REWRITE', 'SLOP', 'TIE_BREAKER', 'TIME_ZONE', 'TYPE', 'ZERO_TERMS_QUERY'}",
"type": "SyntaxCheckException"
},
"status": 400
}
You should update details
block of ErrorMessage
instead.
@@ -161,8 +172,9 @@ protected RestChannelConsumer prepareRequest(RestRequest request, NodeClient cli | |||
final QueryAction queryAction = explainRequest(client, sqlRequest, format); | |||
return channel -> executeSqlRequest(request, queryAction, client, channel); | |||
} catch (Exception e) { | |||
LOG.error(LogUtils.getRequestId() + " V2 SQL error during query execution", QueryDataAnonymizer.anonymizeData(newSqlQueryHandler.getErrorStr())); |
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.
errorStr
never holds the query, so call to anonymizer will always fail.
Description
When a query fails both legacy and new SQL engines, only the legacy engine error is reported to the user. On failure in both the legacy and new SQL engines, error messages from both should be reported to the end user. To avoid logging un-anonymized data, the anonymizer now returns a failure to anonymize string.
Check List
By submitting this pull request, I confirm that my contribution is made under the terms of the Apache 2.0 license.
For more information on following Developer Certificate of Origin and signing off your commits, please check here.