mirror of
https://github.com/elastic/kibana.git
synced 2025-04-24 01:38:56 -04:00
Fix branch frozen indices (#29970)
* Adds frozen index param to ES queries * Added include frozen setting to debug output * Updates tests with new request method
This commit is contained in:
parent
beee5f8a0e
commit
674a6aa2ef
3 changed files with 28 additions and 12 deletions
|
@ -19,28 +19,36 @@ describe('setupRequest', () => {
|
|||
config: () => 'myConfig',
|
||||
plugins: {
|
||||
elasticsearch: {
|
||||
getCluster: () => ({
|
||||
callWithRequest: callWithRequestSpy
|
||||
})
|
||||
getCluster: () => ({ callWithRequest: callWithRequestSpy })
|
||||
}
|
||||
}
|
||||
}
|
||||
},
|
||||
getUiSettingsService: jest.fn(() => ({
|
||||
get: jest.fn(() => Promise.resolve(false))
|
||||
}))
|
||||
};
|
||||
|
||||
const setup = setupRequest(mockReq);
|
||||
setup.client('myType', { body: 'foo' });
|
||||
});
|
||||
|
||||
it('should call callWithRequest with correct args', () => {
|
||||
it('should call callWithRequest with correct args', async () => {
|
||||
const setup = setupRequest(mockReq);
|
||||
await setup.client('myType', { body: 'foo' });
|
||||
expect(callWithRequestSpy).toHaveBeenCalledWith(mockReq, 'myType', {
|
||||
body: 'foo',
|
||||
ignore_throttled: true,
|
||||
rest_total_hits_as_int: true
|
||||
});
|
||||
});
|
||||
|
||||
it('should update params with rest_total_hits_as_int', () => {
|
||||
expect(callWithRequestSpy.mock.calls[0][2]).toEqual({
|
||||
it('should set ignore_throttled to false if includeFrozen is true', async () => {
|
||||
// mock includeFrozen to return true
|
||||
mockReq.getUiSettingsService.mockImplementation(() => ({
|
||||
get: jest.fn(() => Promise.resolve(true))
|
||||
}));
|
||||
const setup = setupRequest(mockReq);
|
||||
await setup.client('myType', { body: 'foo' });
|
||||
expect(callWithRequestSpy).toHaveBeenCalledWith(mockReq, 'myType', {
|
||||
body: 'foo',
|
||||
ignore_throttled: false,
|
||||
rest_total_hits_as_int: true
|
||||
});
|
||||
});
|
||||
|
|
|
@ -40,10 +40,14 @@ interface APMRequestQuery {
|
|||
export function setupRequest(req: Legacy.Request): Setup {
|
||||
const query = (req.query as unknown) as APMRequestQuery;
|
||||
const cluster = req.server.plugins.elasticsearch.getCluster('data');
|
||||
const uiSettings = req.getUiSettingsService();
|
||||
|
||||
const client: ESClient = async (type, params) => {
|
||||
const includeFrozen = await uiSettings.get('search:includeFrozen');
|
||||
|
||||
const client: ESClient = (type, params) => {
|
||||
if (query._debug) {
|
||||
console.log(`DEBUG ES QUERY:`);
|
||||
console.log({ includeFrozen });
|
||||
console.log(
|
||||
`${req.method.toUpperCase()} ${req.url.pathname} ${JSON.stringify(
|
||||
query
|
||||
|
@ -55,6 +59,7 @@ export function setupRequest(req: Legacy.Request): Setup {
|
|||
|
||||
const nextParams = {
|
||||
...params,
|
||||
ignore_throttled: !includeFrozen,
|
||||
rest_total_hits_as_int: true // ensure that ES returns accurate hits.total with pre-6.6 format
|
||||
};
|
||||
return cluster.callWithRequest(req, type, nextParams);
|
||||
|
|
|
@ -35,7 +35,10 @@ describe('route handlers should fail with a Boom error', () => {
|
|||
getCluster: () => mockCluster
|
||||
}
|
||||
}
|
||||
}
|
||||
},
|
||||
getUiSettingsService: jest.fn(() => ({
|
||||
get: jest.fn()
|
||||
}))
|
||||
};
|
||||
|
||||
const routes = flatten(mockServer.route.mock.calls);
|
||||
|
|
Loading…
Add table
Add a link
Reference in a new issue