[APM] Add rest_total_hits_as_int to all ES requests (#26462)
This commit is contained in:
parent
15636c4f6b
commit
d3330a6ea9
47
x-pack/plugins/apm/server/lib/helpers/setup_request.test.ts
Normal file
47
x-pack/plugins/apm/server/lib/helpers/setup_request.test.ts
Normal file
|
@ -0,0 +1,47 @@
|
|||
/*
|
||||
* 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 { setupRequest } from './setup_request';
|
||||
|
||||
describe('setupRequest', () => {
|
||||
let callWithRequestSpy: jest.Mock;
|
||||
let mockReq: any;
|
||||
|
||||
beforeEach(() => {
|
||||
callWithRequestSpy = jest.fn();
|
||||
mockReq = {
|
||||
params: {},
|
||||
query: {},
|
||||
server: {
|
||||
config: () => 'myConfig',
|
||||
plugins: {
|
||||
elasticsearch: {
|
||||
getCluster: () => ({
|
||||
callWithRequest: callWithRequestSpy
|
||||
})
|
||||
}
|
||||
}
|
||||
}
|
||||
};
|
||||
|
||||
const setup = setupRequest(mockReq);
|
||||
setup.client('myType', { body: 'foo' });
|
||||
});
|
||||
|
||||
it('should call callWithRequest with correct args', () => {
|
||||
expect(callWithRequestSpy).toHaveBeenCalledWith(mockReq, 'myType', {
|
||||
body: 'foo',
|
||||
rest_total_hits_as_int: true
|
||||
});
|
||||
});
|
||||
|
||||
it('should update params with rest_total_hits_as_int', () => {
|
||||
expect(callWithRequestSpy.mock.calls[0][2]).toEqual({
|
||||
body: 'foo',
|
||||
rest_total_hits_as_int: true
|
||||
});
|
||||
});
|
||||
});
|
|
@ -63,7 +63,12 @@ export function setupRequest(req: Request): Setup {
|
|||
console.log(`GET ${params.index}/_search`);
|
||||
console.log(JSON.stringify(params.body, null, 4));
|
||||
}
|
||||
return cluster.callWithRequest(req, type, params);
|
||||
|
||||
const nextParams = {
|
||||
...params,
|
||||
rest_total_hits_as_int: true // ensure that ES returns accurate hits.total with pre-6.6 format
|
||||
};
|
||||
return cluster.callWithRequest(req, type, nextParams);
|
||||
};
|
||||
|
||||
return {
|
||||
|
|
Loading…
Reference in a new issue