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

Fix wrong 503 error response code #2493

Merged
merged 1 commit into from
Feb 5, 2024

Conversation

vmmusings
Copy link
Member

@vmmusings vmmusings commented Jan 31, 2024

Description

1.Request

###
POST {{baseUrl}}/_plugins/_async_query
content-type: application/json

{
    "lang" : "sql",
    "datasource" : "safdsf",
    "query" : "create index clientip_year4 on my_glue.default.http_logs (clientip, year) WITH (auto_refresh=true)"
}

1.Response

{
  "status": 400,
  "error": {
    "type": "DataSourceNotFoundException",
    "reason": "Invalid Request",
    "details": "DataSource with name safdsf doesn\u0027t exist."
  }
}

Earlier the response was 503.

  1. Request
GET {{baseUrl}}/_plugins/_async_query/00fdo6u94n7abo0q
Content-Type: application/json

2.Response

{
  "status": 400,
  "error": {
    "type": "AsyncQueryNotFoundException",
    "reason": "Invalid Request",
    "details": "Invalid queryId: 00fdo6u94n7abo0q"
  }
}

Earlier the status code was 503 and messaging was internal problem in backend.
3. Request

###
DELETE {{baseUrl}}/_plugins/_async_query/00fdo6u94n7abo0q
Content-Type: application/json

3.Response

{
  "status": 400,
  "error": {
    "type": "AsyncQueryNotFoundException",
    "reason": "Invalid Request",
    "details": "Invalid queryId: 00fdo6u94n7abo0q"
  }
}

Earlier the status code was 503 and messaging was internal problem in backend.

  1. Request
###
POST {{baseUrl}}/_plugins/_sql

Content-Type: application/json 
{
  "query": "SELECT * from I_THINK/IM/A_URL"
}

4.Response

{
  "error": {
    "reason": "Invalid SQL query",
    "details": "Left side of the expression [I_THINK / IM] is expected to be an identifier",
    "type": "ParserException"
  },
  "status": 400
}

Earlier the response was 503.

  1. Request
###
POST {{baseUrl}}/_plugins/_async_query
content-type: application/json

{
    "lang" : "sql",
    "datasource" : "safdsf",
    "datasource" : "daf"
    "query" : "create index clientip_year4 on my_glue.default.http_logs (clientip, year) WITH (auto_refresh=true)"
}

5.Response


  "status": 400,
  "error": {
    "type": "IllegalArgumentException",
    "reason": "Invalid Request",
    "details": "Error while parsing the request body: Duplicate field \u0027datasource\u0027\n at [Source: REDACTED (`StreamReadFeature.INCLUDE_SOURCE_IN_LOCATION` disabled); line: 4, column: 17]"
  }
}
  1. Old Resposne
{"error":{"root_cause":[{"type":"json_parse_exception","reason":"Duplicate field 'datasource'\n at [Source: (org.opensearch.core.common.io.stream.InputStreamStreamInput); line: 1, column: 38]"}],"type":"json_parse_exception","reason":"Duplicate field 'datasource'\n at [Source: (org.opensearch.core.common.io.stream.InputStreamStreamInput); line: 1, column: 38]"},"status":400}
Verbose Error Response
  1. Request
###
POST {{baseUrl}}/_plugins/_async_query
content-type: application/json

{
    "lang" : "sql",
    "datasource" : ["daf", "afds"],
    "query" : "create index clientip_year4 on my_glue.default.http_logs (clientip, year) WITH (auto_refresh=true)"
}

6.Response

{
  "status": 400,
  "error": {
    "type": "IllegalArgumentException",
    "reason": "Invalid Request",
    "details": "Error while parsing the request body: Can\u0027t get text on a START_ARRAY at 3:20"
  }
}
  1. OldResponse

{"error":{"root_cause":[{"type":"illegal_state_exception","reason":"Can't get text on a START_ARRAY at 1:16"}],"type":"illegal_state_exception","reason":"Can't get text on a START_ARRAY at 1:16"},"status":500}
500 Error Response

7.Request

###
GET {{baseUrl}}/_plugins/_query/_datasources
Authorization: Basic test:Test2@1234
content-type: application/json

7.Response

{
  "status": 403,
  "error": {
    "type": "OpenSearchSecurityException",
    "reason": "There was internal problem at backend",
    "details": "no permissions for [cluster:admin/opensearch/ql/datasources/read] and User [name\u003dtest, backend_roles\u003d[], requestedTenant\u003dnull]"
  }
}
 ###
GET {{baseUrl}}/_plugins/_ppl/stats
Content-Type: application/json
 "datasource_failed_request_count_cuserr": 8,

Now the customer error is increasing with authorization errors.

Issues Resolved

#2391
#2035

Check List

  • New functionality includes testing.
    • All tests pass, including unit test, integration test and doctest
  • New functionality has been documented.
    • New functionality has javadoc added
    • New functionality has user manual doc added
  • Commits are signed per the DCO using --signoff

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.

Copy link

codecov bot commented Jan 31, 2024

Codecov Report

Attention: 17 lines in your changes are missing coverage. Please review.

Comparison is base (94bd664) 95.43% compared to head (67a1f90) 95.40%.

❗ Current head 67a1f90 differs from pull request most recent head 19a4a3e. Consider uploading reports for the commit 19a4a3e to get more accurate results

Files Patch % Lines
...sql/spark/rest/RestAsyncQueryManagementAction.java 0.00% 10 Missing ⚠️
...ql/datasources/rest/RestDataSourceQueryAction.java 0.00% 5 Missing ⚠️
.../sql/spark/rest/model/CreateAsyncQueryRequest.java 88.88% 1 Missing and 1 partial ⚠️
Additional details and impacted files
@@             Coverage Diff              @@
##               main    #2493      +/-   ##
============================================
- Coverage     95.43%   95.40%   -0.04%     
- Complexity     5024     5025       +1     
============================================
  Files           483      483              
  Lines         13989    14005      +16     
  Branches        943      944       +1     
============================================
+ Hits          13350    13361      +11     
- Misses          617      622       +5     
  Partials         22       22              
Flag Coverage Δ
sql-engine 95.40% <58.53%> (-0.04%) ⬇️

Flags with carried forward coverage won't be shown. Click here to find out more.

☔ View full report in Codecov by Sentry.
📢 Have feedback on the report? Share it here.

@vmmusings vmmusings force-pushed the 503-fixes branch 5 times, most recently from 1213b54 to 1ba04e1 Compare February 1, 2024 00:14
@vmmusings vmmusings self-assigned this Feb 1, 2024
@vmmusings vmmusings added backport 2.x bug Something isn't working labels Feb 1, 2024
@vmmusings vmmusings force-pushed the 503-fixes branch 7 times, most recently from fd9c878 to 305f729 Compare February 2, 2024 00:40
@vmmusings vmmusings force-pushed the 503-fixes branch 4 times, most recently from f6ea526 to 807f564 Compare February 2, 2024 19:27
@vmmusings vmmusings marked this pull request as ready for review February 2, 2024 19:29
AsyncQueryId queryId = new AsyncQueryId(qid);
return StateStore.getJobMetaData(stateStore, queryId.getDataSourceName())
.apply(queryId.docId());
} catch (Exception e) {
Copy link
Collaborator

Choose a reason for hiding this comment

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

should we move this to

  public static QueryId queryId() {
    return new QueryId(RandomStringUtils.random(10, true, true));
  }

@vmmusings vmmusings merged commit 70d94e6 into opensearch-project:main Feb 5, 2024
18 of 20 checks passed
opensearch-trigger-bot bot pushed a commit that referenced this pull request Feb 5, 2024
Signed-off-by: Vamsi Manohar <[email protected]>
(cherry picked from commit 70d94e6)
Signed-off-by: github-actions[bot] <github-actions[bot]@users.noreply.github.com>
vmmusings pushed a commit that referenced this pull request Feb 5, 2024
(cherry picked from commit 70d94e6)

Signed-off-by: Vamsi Manohar <[email protected]>
Signed-off-by: github-actions[bot] <github-actions[bot]@users.noreply.github.com>
Co-authored-by: github-actions[bot] <github-actions[bot]@users.noreply.github.com>
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
backport 2.x bug Something isn't working
Projects
None yet
Development

Successfully merging this pull request may close these issues.

3 participants