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

[Query enhancements] use status 503 if search strategy throws 500 #8876

Open
wants to merge 2 commits into
base: main
Choose a base branch
from

Conversation

joshuali925
Copy link
Member

@joshuali925 joshuali925 commented Nov 15, 2024

Description

use status 503 if search strategy throws 500 to indicate downstream service failure

Issues Resolved

Screenshot

Testing the changes

when opensearch is down, send a request to enhancements api:
before

❯ curl -X POST 'http://localhost:5601/api/enhancements/search/sql' -H 'Content-Type: application/json' -H 'osd-xsrf: osd-fetch' -d '{"query":{ "query": "b", "language": "language", "format": "format" }}'
{"statusCode":500,"error":"Internal Server Error","message":"An internal server error occurred."}%

after

❯ curl -X POST 'http://localhost:5601/api/enhancements/search/sql' -H 'Content-Type: application/json' -H 'osd-xsrf: osd-fetch' -d '{"query":{ "query": "b", "language": "language", "format": "format" }}'
{"statusCode":503,"error":"Service Unavailable","message":"Error: No Living connections"}%

Changelog

Check List

  • All tests pass
    • yarn test:jest
    • yarn test:jest_integration
  • New functionality includes testing.
  • New functionality has been documented.
  • Update CHANGELOG.md
  • Commits are signed per the DCO using --signoff

Copy link
Contributor

❌ Empty Changelog Section

The Changelog section in your PR description is empty. Please add a valid changelog entry or entries. If you did add a changelog entry, check to make sure that it was not accidentally included inside the comment block in the Changelog section.

Copy link

codecov bot commented Nov 15, 2024

Codecov Report

Attention: Patch coverage is 75.00000% with 1 line in your changes missing coverage. Please review.

Project coverage is 60.88%. Comparing base (e993d24) to head (742da55).
Report is 3 commits behind head on main.

Files with missing lines Patch % Lines
.../plugins/query_enhancements/server/routes/index.ts 75.00% 1 Missing ⚠️
Additional details and impacted files
@@            Coverage Diff             @@
##             main    #8876      +/-   ##
==========================================
- Coverage   60.93%   60.88%   -0.06%     
==========================================
  Files        3800     3805       +5     
  Lines       90880    90963      +83     
  Branches    14324    14345      +21     
==========================================
+ Hits        55382    55387       +5     
- Misses      31969    32047      +78     
  Partials     3529     3529              
Flag Coverage Δ
Linux_1 29.01% <ø> (ø)
Linux_2 56.39% <ø> (ø)
Linux_3 37.92% <ø> (ø)
Linux_4 28.96% <75.00%> (-0.04%) ⬇️
Windows_1 29.02% <ø> (ø)
Windows_2 56.34% <ø> (ø)
Windows_3 37.92% <ø> (ø)
Windows_4 28.96% <75.00%> (-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.

Comment on lines 94 to 96
const statusCode = error.status || err.status;
return res.custom({
statusCode: error.status || err.status,
statusCode: statusCode === 500 ? 503 : statusCode || 503,
Copy link
Collaborator

Choose a reason for hiding this comment

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

can we validate this behavior in a test?

Copy link
Member Author

Choose a reason for hiding this comment

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

added a basic test

Signed-off-by: Joshua Li <[email protected]>
@kavilla
Copy link
Member

kavilla commented Nov 15, 2024

i think the test failures might be due to tests needing to be updated, or snapshots

@kavilla kavilla added discover for discover reinvent discover-next labels Nov 15, 2024
Copy link
Contributor

❌ Empty Changelog Section

The Changelog section in your PR description is empty. Please add a valid changelog entry or entries. If you did add a changelog entry, check to make sure that it was not accidentally included inside the comment block in the Changelog section.

@joshuali925
Copy link
Member Author

failure seems irrelevant, they passed on rerun

Summary of all failing tests
 FAIL  src/plugins/data/public/query/query_string/query_string_manager.test.ts
  ● QueryStringManager › clearQueryHistory clears the query history

    expect(received).toHaveLength(expected)

    Expected length: 2
    Received length: 1
    Received array:  [{"id": "8ffe6413-d2bf-45ae-863b-0b7a80208bcd", "query": {"language": "sql", "query": "test query 2"}, "time": 1731698469371}]

      109 |     service.addToQueryHistory({ query: 'test query 1', language: 'sql' });
      110 |     service.addToQueryHistory({ query: 'test query 2', language: 'sql' });
    > 111 |     expect(service.getQueryHistory()).toHaveLength(2);
          |                                       ^
      112 |
      113 |     service.clearQueryHistory();
      114 |     expect(service.getQueryHistory()).toHaveLength(0);

      at Object.<anonymous> (src/plugins/data/public/query/query_string/query_string_manager.test.ts:111:39)

  ● QueryStringManager › addToQueryHistory adds query to history

    expect(received).toHaveLength(expected)

    Expected length: 1
    Received length: 2
    Received array:  [{"id": "4714cdd6-cd94-4736-8a88-919c873419d1", "query": {"language": "sql", "query": "test query"}, "time": 1731698469376}, {"id": "8ffe6413-d2bf-45ae-863b-0b7a80208bcd", "query": {"language": "sql", "query": "test query 2"}, "time": 1731698469371}]

      119 |     service.addToQueryHistory(query);
      120 |     const history = service.getQueryHistory();
    > 121 |     expect(history).toHaveLength(1);
          |                     ^
      122 |     expect(history[0]).toHaveProperty('query', query);
      123 |   });
      124 |

      at Object.<anonymous> (src/plugins/data/public/query/query_string/query_string_manager.test.ts:121:21)

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Projects
None yet
Development

Successfully merging this pull request may close these issues.

4 participants