[data.search] Use versioned router (#158520)

## Summary

Step 1 of https://github.com/elastic/kibana/issues/157095.

Uses the new versioned router capabilities for the search routes (`POST`
and `DELETE`).

### Checklist

- [x] [Unit or functional
tests](https://www.elastic.co/guide/en/kibana/master/development-tests.html)
were updated or added to match the most common scenarios

### For maintainers

- [x] This was checked for breaking API changes and was [labeled
appropriately](https://www.elastic.co/guide/en/kibana/master/contributing.html#kibana-release-notes-process)

---------

Co-authored-by: kibanamachine <42973632+kibanamachine@users.noreply.github.com>
Co-authored-by: Matthias Wilhelm <matthias.wilhelm@elastic.co>
This commit is contained in:
Lukas Olson 2023-06-07 01:33:39 -07:00 committed by GitHub
parent b8b4f75145
commit 34ada8a9a6
No known key found for this signature in database
GPG key ID: 4AEE18F83AFDEB23
14 changed files with 235 additions and 78 deletions

View file

@ -6,6 +6,7 @@
* Side Public License, v 1.
*/
import { ELASTIC_HTTP_VERSION_HEADER } from '@kbn/core-http-common';
import expect from '@kbn/expect';
import { FtrProviderContext } from '../../ftr_provider_context';
import { painlessErrReq } from './painless_err_req';
@ -28,6 +29,7 @@ export default function ({ getService }: FtrProviderContext) {
it('should return 200 when correctly formatted searches are provided', async () => {
const resp = await supertest
.post(`/internal/search/es`)
.set(ELASTIC_HTTP_VERSION_HEADER, '1')
.send({
params: {
body: {
@ -43,11 +45,13 @@ export default function ({ getService }: FtrProviderContext) {
expect(resp.body.isPartial).to.be(false);
expect(resp.body.isRunning).to.be(false);
expect(resp.body).to.have.property('rawResponse');
expect(resp.header).to.have.property(ELASTIC_HTTP_VERSION_HEADER, '1');
});
it('should return 200 if terminated early', async () => {
const resp = await supertest
.post(`/internal/search/es`)
.set(ELASTIC_HTTP_VERSION_HEADER, '1')
.send({
params: {
terminateAfter: 1,
@ -66,11 +70,13 @@ export default function ({ getService }: FtrProviderContext) {
expect(resp.body.isPartial).to.be(false);
expect(resp.body.isRunning).to.be(false);
expect(resp.body.rawResponse.terminated_early).to.be(true);
expect(resp.header).to.have.property(ELASTIC_HTTP_VERSION_HEADER, '1');
});
it('should return 404 when if no strategy is provided', async () => {
const resp = await supertest
.post(`/internal/search`)
.set(ELASTIC_HTTP_VERSION_HEADER, '1')
.send({
body: {
query: {
@ -86,6 +92,7 @@ export default function ({ getService }: FtrProviderContext) {
it('should return 404 when if unknown strategy is provided', async () => {
const resp = await supertest
.post(`/internal/search/banana`)
.set(ELASTIC_HTTP_VERSION_HEADER, '1')
.send({
body: {
query: {
@ -97,11 +104,13 @@ export default function ({ getService }: FtrProviderContext) {
verifyErrorResponse(resp.body, 404);
expect(resp.body.message).to.contain('banana not found');
expect(resp.header).to.have.property(ELASTIC_HTTP_VERSION_HEADER, '1');
});
it('should return 400 with illegal ES argument', async () => {
const resp = await supertest
.post(`/internal/search/es`)
.set(ELASTIC_HTTP_VERSION_HEADER, '1')
.send({
params: {
timeout: 1, // This should be a time range string!
@ -122,6 +131,7 @@ export default function ({ getService }: FtrProviderContext) {
it('should return 400 with a bad body', async () => {
const resp = await supertest
.post(`/internal/search/es`)
.set(ELASTIC_HTTP_VERSION_HEADER, '1')
.send({
params: {
body: {
@ -136,7 +146,11 @@ export default function ({ getService }: FtrProviderContext) {
});
it('should return 400 for a painless error', async () => {
const resp = await supertest.post(`/internal/search/es`).send(painlessErrReq).expect(400);
const resp = await supertest
.post(`/internal/search/es`)
.set(ELASTIC_HTTP_VERSION_HEADER, '1')
.send(painlessErrReq)
.expect(400);
verifyErrorResponse(resp.body, 400, 'search_phase_execution_exception', true);
});
@ -144,14 +158,23 @@ export default function ({ getService }: FtrProviderContext) {
describe('delete', () => {
it('should return 404 when no search id provided', async () => {
const resp = await supertest.delete(`/internal/search/es`).send().expect(404);
const resp = await supertest
.delete(`/internal/search/es`)
.set(ELASTIC_HTTP_VERSION_HEADER, '1')
.send()
.expect(404);
verifyErrorResponse(resp.body, 404);
});
it('should return 400 when trying a delete on a non supporting strategy', async () => {
const resp = await supertest.delete(`/internal/search/es/123`).send().expect(400);
const resp = await supertest
.delete(`/internal/search/es/123`)
.set(ELASTIC_HTTP_VERSION_HEADER, '1')
.send()
.expect(400);
verifyErrorResponse(resp.body, 400);
expect(resp.body.message).to.contain("Search strategy es doesn't support cancellations");
expect(resp.header).to.have.property(ELASTIC_HTTP_VERSION_HEADER, '1');
});
});
});

View file

@ -7,6 +7,7 @@
*/
import expect from '@kbn/expect';
import { ELASTIC_HTTP_VERSION_HEADER } from '@kbn/core-http-common';
import { FtrProviderContext } from '../../ftr_provider_context';
export default function ({ getService }: FtrProviderContext) {
@ -28,6 +29,7 @@ export default function ({ getService }: FtrProviderContext) {
it('should return 200 when correctly formatted searches are provided', async () => {
const resp = await supertest
.post(`/internal/search/sql`)
.set(ELASTIC_HTTP_VERSION_HEADER, '1')
.send({
params: {
query: sqlQuery,
@ -39,11 +41,13 @@ export default function ({ getService }: FtrProviderContext) {
expect(resp.body).to.have.property('isPartial');
expect(resp.body).to.have.property('isRunning');
expect(resp.body).to.have.property('rawResponse');
expect(resp.header).to.have.property(ELASTIC_HTTP_VERSION_HEADER, '1');
});
it('should fetch search results by id', async () => {
const resp1 = await supertest
.post(`/internal/search/sql`)
.set(ELASTIC_HTTP_VERSION_HEADER, '1')
.send({
params: {
query: sqlQuery,
@ -53,13 +57,17 @@ export default function ({ getService }: FtrProviderContext) {
.expect(200);
const id = resp1.body.id;
const resp2 = await supertest.post(`/internal/search/sql/${id}`).send({});
const resp2 = await supertest
.post(`/internal/search/sql/${id}`)
.set(ELASTIC_HTTP_VERSION_HEADER, '1')
.send({});
expect(resp2.status).to.be(200);
expect(resp2.body.id).to.be(id);
expect(resp2.body).to.have.property('isPartial');
expect(resp2.body).to.have.property('isRunning');
expect(resp2.body).to.have.property('rawResponse');
expect(resp2.header).to.have.property(ELASTIC_HTTP_VERSION_HEADER, '1');
});
});
@ -67,6 +75,7 @@ export default function ({ getService }: FtrProviderContext) {
it('should delete search', async () => {
const resp1 = await supertest
.post(`/internal/search/sql`)
.set(ELASTIC_HTTP_VERSION_HEADER, '1')
.send({
params: {
query: sqlQuery,
@ -77,13 +86,25 @@ export default function ({ getService }: FtrProviderContext) {
const id = resp1.body.id;
// confirm it was saved
await supertest.post(`/internal/search/sql/${id}`).send({}).expect(200);
await supertest
.post(`/internal/search/sql/${id}`)
.set(ELASTIC_HTTP_VERSION_HEADER, '1')
.send({})
.expect(200);
// delete it
await supertest.delete(`/internal/search/sql/${id}`).send().expect(200);
await supertest
.delete(`/internal/search/sql/${id}`)
.set(ELASTIC_HTTP_VERSION_HEADER, '1')
.send()
.expect(200);
// check it was deleted
await supertest.post(`/internal/search/sql/${id}`).send({}).expect(404);
await supertest
.post(`/internal/search/sql/${id}`)
.set(ELASTIC_HTTP_VERSION_HEADER, '1')
.send({})
.expect(404);
});
});
});