[Search Profiler] Migrate server to new es-js client (#88725)
This commit is contained in:
parent
4bc5f01428
commit
43db7e365f
|
@ -27,10 +27,6 @@ export const register = ({ router, getLicenseStatus, log }: RouteDependencies) =
|
||||||
});
|
});
|
||||||
}
|
}
|
||||||
|
|
||||||
const {
|
|
||||||
core: { elasticsearch },
|
|
||||||
} = ctx;
|
|
||||||
|
|
||||||
const {
|
const {
|
||||||
body: { query, index },
|
body: { query, index },
|
||||||
} = request;
|
} = request;
|
||||||
|
@ -46,21 +42,25 @@ export const register = ({ router, getLicenseStatus, log }: RouteDependencies) =
|
||||||
body: JSON.stringify(parsed, null, 2),
|
body: JSON.stringify(parsed, null, 2),
|
||||||
};
|
};
|
||||||
try {
|
try {
|
||||||
const resp = await elasticsearch.legacy.client.callAsCurrentUser('search', body);
|
const client = ctx.core.elasticsearch.client.asCurrentUser;
|
||||||
|
const resp = await client.search(body);
|
||||||
|
|
||||||
return response.ok({
|
return response.ok({
|
||||||
body: {
|
body: {
|
||||||
ok: true,
|
ok: true,
|
||||||
resp,
|
resp: resp.body,
|
||||||
},
|
},
|
||||||
});
|
});
|
||||||
} catch (err) {
|
} catch (err) {
|
||||||
log.error(err);
|
log.error(err);
|
||||||
|
const { statusCode, body: errorBody } = err;
|
||||||
|
|
||||||
return response.customError({
|
return response.customError({
|
||||||
statusCode: err.status || 500,
|
statusCode: statusCode || 500,
|
||||||
body: err.body
|
body: errorBody
|
||||||
? {
|
? {
|
||||||
message: err.message,
|
message: errorBody.error?.reason,
|
||||||
attributes: err.body,
|
attributes: errorBody,
|
||||||
}
|
}
|
||||||
: err,
|
: err,
|
||||||
});
|
});
|
||||||
|
|
|
@ -33,5 +33,6 @@ export default function ({ loadTestFile }: FtrProviderContext) {
|
||||||
loadTestFile(require.resolve('./transform'));
|
loadTestFile(require.resolve('./transform'));
|
||||||
loadTestFile(require.resolve('./lists'));
|
loadTestFile(require.resolve('./lists'));
|
||||||
loadTestFile(require.resolve('./upgrade_assistant'));
|
loadTestFile(require.resolve('./upgrade_assistant'));
|
||||||
|
loadTestFile(require.resolve('./searchprofiler'));
|
||||||
});
|
});
|
||||||
}
|
}
|
||||||
|
|
13
x-pack/test/api_integration/apis/searchprofiler/index.ts
Normal file
13
x-pack/test/api_integration/apis/searchprofiler/index.ts
Normal file
|
@ -0,0 +1,13 @@
|
||||||
|
/*
|
||||||
|
* Copyright Elasticsearch B.V. and/or licensed to Elasticsearch B.V. under one
|
||||||
|
* or more contributor license agreements. Licensed under the Elastic License;
|
||||||
|
* you may not use this file except in compliance with the Elastic License.
|
||||||
|
*/
|
||||||
|
|
||||||
|
import { FtrProviderContext } from '../../ftr_provider_context';
|
||||||
|
|
||||||
|
export default function ({ loadTestFile }: FtrProviderContext) {
|
||||||
|
describe('Search Profiler', () => {
|
||||||
|
loadTestFile(require.resolve('./searchprofiler'));
|
||||||
|
});
|
||||||
|
}
|
|
@ -0,0 +1,56 @@
|
||||||
|
/*
|
||||||
|
* Copyright Elasticsearch B.V. and/or licensed to Elasticsearch B.V. under one
|
||||||
|
* or more contributor license agreements. Licensed under the Elastic License;
|
||||||
|
* you may not use this file except in compliance with the Elastic License.
|
||||||
|
*/
|
||||||
|
|
||||||
|
import expect from '@kbn/expect';
|
||||||
|
import { FtrProviderContext } from '../../ftr_provider_context';
|
||||||
|
|
||||||
|
const API_BASE_PATH = '/api/searchprofiler';
|
||||||
|
|
||||||
|
export default function ({ getService }: FtrProviderContext) {
|
||||||
|
const supertest = getService('supertest');
|
||||||
|
|
||||||
|
describe('Profile', () => {
|
||||||
|
it('should return profile results for a valid index', async () => {
|
||||||
|
const payload = {
|
||||||
|
index: '_all',
|
||||||
|
query: {
|
||||||
|
query: {
|
||||||
|
match_all: {},
|
||||||
|
},
|
||||||
|
},
|
||||||
|
};
|
||||||
|
|
||||||
|
const { body } = await supertest
|
||||||
|
.post(`${API_BASE_PATH}/profile`)
|
||||||
|
.set('kbn-xsrf', 'xxx')
|
||||||
|
.set('Content-Type', 'application/json;charset=UTF-8')
|
||||||
|
.send(payload)
|
||||||
|
.expect(200);
|
||||||
|
|
||||||
|
expect(body.ok).to.eql(true);
|
||||||
|
});
|
||||||
|
|
||||||
|
it('should return error for invalid index', async () => {
|
||||||
|
const payloadWithInvalidIndex = {
|
||||||
|
index: 'index_does_not_exist',
|
||||||
|
query: {
|
||||||
|
query: {
|
||||||
|
match_all: {},
|
||||||
|
},
|
||||||
|
},
|
||||||
|
};
|
||||||
|
|
||||||
|
const { body } = await supertest
|
||||||
|
.post(`${API_BASE_PATH}/execute`)
|
||||||
|
.set('kbn-xsrf', 'xxx')
|
||||||
|
.set('Content-Type', 'application/json;charset=UTF-8')
|
||||||
|
.send(payloadWithInvalidIndex)
|
||||||
|
.expect(404);
|
||||||
|
|
||||||
|
expect(body.error).to.eql('Not Found');
|
||||||
|
});
|
||||||
|
});
|
||||||
|
}
|
Loading…
Reference in a new issue