-
Notifications
You must be signed in to change notification settings - Fork 8.3k
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
[elasticsearch/healthCheck] ensure that multi.allow_explicit_index=tr…
…ue (#10855) * [elasticsearch/healthCheck] ensure that multi.allow_explicit_index=true * [elasticsearch/healthCheck] fix tests
- Loading branch information
Showing
4 changed files
with
115 additions
and
1 deletion.
There are no files selected for viewing
75 changes: 75 additions & 0 deletions
75
src/core_plugins/elasticsearch/lib/__tests__/ensure_allow_explicit_index.js
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,75 @@ | ||
import sinon from 'sinon'; | ||
import expect from 'expect.js'; | ||
|
||
import { ensureAllowExplicitIndex } from '../ensure_allow_explicit_index'; | ||
|
||
const createStubCallWithInternal = responders => ( | ||
sinon.spy(async (params) => { | ||
if (responders.length) { | ||
return await responders.shift()(params); | ||
} | ||
|
||
throw new Error('Unexpected client.mget call'); | ||
}) | ||
); | ||
|
||
const createStubConfig = () => ({ | ||
get: sinon.spy((key) => { | ||
switch (key) { | ||
case 'kibana.index': return '.kibana'; | ||
case 'pkg.version': return '0.0.0'; | ||
default: throw new Error(`Unexpected config.get('${key}') call`); | ||
} | ||
}) | ||
}); | ||
|
||
describe('ensureAllowExplicitIndex()', () => { | ||
it('attempts an mget with index in request', async () => { | ||
const config = createStubConfig(); | ||
const callWithInternalUser = createStubCallWithInternal([ | ||
() => ({ ok: true }) | ||
]); | ||
|
||
const resp = await ensureAllowExplicitIndex(callWithInternalUser, config); | ||
expect(resp).to.be(true); | ||
}); | ||
|
||
it(`reports "illegal_argument_exception" that mentions "explicit index"`, async () => { | ||
const config = createStubConfig(); | ||
const callWithInternalUser = createStubCallWithInternal([ | ||
() => ({ | ||
error: { | ||
type: 'illegal_argument_exception', | ||
reason: 'explicit index not supported' | ||
} | ||
}) | ||
]); | ||
|
||
try { | ||
await ensureAllowExplicitIndex(callWithInternalUser, config); | ||
throw new Error('expected ensureAllowExplicitIndex() to throw error'); | ||
} catch (error) { | ||
expect(error.message).to.contain('rest.action.multi.allow_explicit_index'); | ||
} | ||
}); | ||
|
||
it('reports unexpected errors', async () => { | ||
const config = createStubConfig(); | ||
const callWithInternalUser = createStubCallWithInternal([ | ||
() => ({ | ||
error: { | ||
type: 'foo', | ||
reason: 'bar' | ||
} | ||
}) | ||
]); | ||
|
||
try { | ||
await ensureAllowExplicitIndex(callWithInternalUser, config); | ||
throw new Error('expected ensureAllowExplicitIndex() to throw error'); | ||
} catch (error) { | ||
expect(error.message).to.contain('[foo]'); | ||
expect(error.message).to.contain('bar'); | ||
} | ||
}); | ||
}); |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
36 changes: 36 additions & 0 deletions
36
src/core_plugins/elasticsearch/lib/ensure_allow_explicit_index.js
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,36 @@ | ||
export async function ensureAllowExplicitIndex(callWithInternalUser, config) { | ||
const resp = await callWithInternalUser('mget', { | ||
ignore: [400], | ||
body: { | ||
docs: [ | ||
{ | ||
_index: config.get('kibana.index'), | ||
_type: 'config', | ||
_id: config.get('pkg.version'), | ||
}, | ||
], | ||
}, | ||
}); | ||
|
||
if (!resp.error) { | ||
return true; | ||
} | ||
|
||
const error = resp.error || {}; | ||
const errorReason = error.reason || ''; | ||
|
||
const isArgError = error.type === 'illegal_argument_exception'; | ||
const isExplicitIndexException = isArgError && errorReason.includes('explicit index'); | ||
|
||
if (isExplicitIndexException) { | ||
throw new Error( | ||
'Kibana must be able to specify the index within Elasticsearch multi-requests ' + | ||
'(rest.action.multi.allow_explicit_index=true).' | ||
); | ||
} | ||
|
||
throw new Error( | ||
'Unable to ensure that rest.action.multi.allow_explicit_index=true: ' + | ||
`[${error.type}] ${errorReason}` | ||
); | ||
} |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters