forked from elastic/kibana
-
Notifications
You must be signed in to change notification settings - Fork 0
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
[Index Management] Add serverless tests for indices routes (elastic#1…
…71773) ## Summary This PR adds api integration tests for indices routes that were missing for serverless ("reload" and "delete index"). To avoid copy-pasting the code, this PR also adds an index management service to re-use in serverless tests. Also some refactoring of js code into ts. ### Checklist Delete any items that are not applicable to this PR. - [ ] Any text added follows [EUI's writing guidelines](https://elastic.github.io/eui/#/guidelines/writing), uses sentence case text and includes [i18n support](https://github.com/elastic/kibana/blob/main/packages/kbn-i18n/README.md) - [ ] [Documentation](https://www.elastic.co/guide/en/kibana/master/development-documentation.html) was added for features that require explanation or tutorials - [ ] [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 - [ ] Any UI touched in this PR is usable by keyboard only (learn more about [keyboard accessibility](https://webaim.org/techniques/keyboard/)) - [ ] Any UI touched in this PR does not create any new axe failures (run axe in browser: [FF](https://addons.mozilla.org/en-US/firefox/addon/axe-devtools/), [Chrome](https://chrome.google.com/webstore/detail/axe-web-accessibility-tes/lhdoppojpmngadmnindnejefpokejbdd?hl=en-US)) - [ ] If a plugin configuration key changed, check if it needs to be allowlisted in the cloud and added to the [docker list](https://github.com/elastic/kibana/blob/main/src/dev/build/tasks/os_packages/docker_generator/resources/base/bin/kibana-docker) - [ ] This renders correctly on smaller devices using a responsive layout. (You can test this [in your browser](https://www.browserstack.com/guide/responsive-testing-on-local-server)) - [ ] This was checked for [cross-browser compatibility](https://www.elastic.co/support/matrix#matrix_browsers) ### Risk Matrix Delete this section if it is not applicable to this PR. Before closing this PR, invite QA, stakeholders, and other developers to identify risks that should be tested prior to the change/feature release. When forming the risk matrix, consider some of the following examples and how they may potentially impact the change: | Risk | Probability | Severity | Mitigation/Notes | |---------------------------|-------------|----------|-------------------------| | Multiple Spaces—unexpected behavior in non-default Kibana Space. | Low | High | Integration tests will verify that all features are still supported in non-default Kibana Space and when user switches between spaces. | | Multiple nodes—Elasticsearch polling might have race conditions when multiple Kibana nodes are polling for the same tasks. | High | Low | Tasks are idempotent, so executing them multiple times will not result in logical error, but will degrade performance. To test for this case we add plenty of unit tests around this logic and document manual testing procedure. | | Code should gracefully handle cases when feature X or plugin Y are disabled. | Medium | High | Unit tests will verify that any feature flag or plugin combination still results in our service operational. | | [See more potential risk examples](https://github.com/elastic/kibana/blob/main/RISK_MATRIX.mdx) | ### For maintainers - [ ] 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)
Showing
14 changed files
with
233 additions
and
158 deletions.
There are no files selected for viewing
53 changes: 0 additions & 53 deletions
53
x-pack/test/api_integration/apis/management/index_management/indices.helpers.js
This file was deleted.
Oops, something went wrong.
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
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
64 changes: 64 additions & 0 deletions
64
x-pack/test/api_integration/apis/management/index_management/lib/indices.api.ts
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,64 @@ | ||
/* | ||
* Copyright Elasticsearch B.V. and/or licensed to Elasticsearch B.V. under one | ||
* or more contributor license agreements. Licensed under the Elastic License | ||
* 2.0; you may not use this file except in compliance with the Elastic License | ||
* 2.0. | ||
*/ | ||
|
||
import { API_BASE_PATH } from '../constants'; | ||
import { FtrProviderContext } from '../../../../ftr_provider_context'; | ||
|
||
export function indicesApi(getService: FtrProviderContext['getService']) { | ||
const supertest = getService('supertest'); | ||
const executeActionOnIndices = ({ | ||
index, | ||
urlParam, | ||
args, | ||
}: { | ||
index?: string | string[]; | ||
urlParam: string; | ||
args?: any; | ||
}) => { | ||
const indices = Array.isArray(index) ? index : [index]; | ||
|
||
return supertest | ||
.post(`${API_BASE_PATH}/indices/${urlParam}`) | ||
.set('kbn-xsrf', 'xxx') | ||
.send({ indices, ...args }); | ||
}; | ||
|
||
const closeIndex = (index: string) => executeActionOnIndices({ index, urlParam: 'close' }); | ||
|
||
const openIndex = (index: string) => executeActionOnIndices({ index, urlParam: 'open' }); | ||
|
||
const deleteIndex = (index?: string) => executeActionOnIndices({ index, urlParam: 'delete' }); | ||
|
||
const flushIndex = (index: string) => executeActionOnIndices({ index, urlParam: 'flush' }); | ||
|
||
const refreshIndex = (index: string) => executeActionOnIndices({ index, urlParam: 'refresh' }); | ||
|
||
const forceMerge = (index: string, args?: { maxNumSegments: number }) => | ||
executeActionOnIndices({ index, urlParam: 'forcemerge', args }); | ||
|
||
const unfreeze = (index: string) => executeActionOnIndices({ index, urlParam: 'unfreeze' }); | ||
|
||
const clearCache = (index: string) => executeActionOnIndices({ index, urlParam: 'clear_cache' }); | ||
|
||
const list = () => supertest.get(`${API_BASE_PATH}/indices`); | ||
|
||
const reload = (indexNames?: string[]) => | ||
supertest.post(`${API_BASE_PATH}/indices/reload`).set('kbn-xsrf', 'xxx').send({ indexNames }); | ||
|
||
return { | ||
closeIndex, | ||
openIndex, | ||
deleteIndex, | ||
flushIndex, | ||
refreshIndex, | ||
forceMerge, | ||
unfreeze, | ||
list, | ||
reload, | ||
clearCache, | ||
}; | ||
} |
35 changes: 35 additions & 0 deletions
35
x-pack/test/api_integration/apis/management/index_management/lib/indices.helpers.ts
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,35 @@ | ||
/* | ||
* Copyright Elasticsearch B.V. and/or licensed to Elasticsearch B.V. under one | ||
* or more contributor license agreements. Licensed under the Elastic License | ||
* 2.0; you may not use this file except in compliance with the Elastic License | ||
* 2.0. | ||
*/ | ||
|
||
import { getRandomString } from './random'; | ||
import { FtrProviderContext } from '../../../../ftr_provider_context'; | ||
|
||
export function indicesHelpers(getService: FtrProviderContext['getService']) { | ||
const es = getService('es'); | ||
const esDeleteAllIndices = getService('esDeleteAllIndices'); | ||
|
||
let indicesCreated: string[] = []; | ||
|
||
const createIndex = async (index: string = getRandomString(), mappings?: any) => { | ||
indicesCreated.push(index); | ||
await es.indices.create({ index, mappings }); | ||
return index; | ||
}; | ||
|
||
const deleteAllIndices = async () => { | ||
await esDeleteAllIndices(indicesCreated); | ||
indicesCreated = []; | ||
}; | ||
|
||
const catIndex = (index?: string, h?: any) => | ||
es.cat.indices({ index, format: 'json', h }, { meta: true }); | ||
|
||
const indexStats = (index: string, metric: string) => | ||
es.indices.stats({ index, metric }, { meta: true }); | ||
|
||
return { createIndex, deleteAllIndices, catIndex, indexStats }; | ||
} |
File renamed without changes.
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
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
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
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
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
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,19 @@ | ||
/* | ||
* Copyright Elasticsearch B.V. and/or licensed to Elasticsearch B.V. under one | ||
* or more contributor license agreements. Licensed under the Elastic License | ||
* 2.0; you may not use this file except in compliance with the Elastic License | ||
* 2.0. | ||
*/ | ||
|
||
import { FtrProviderContext } from '../ftr_provider_context'; | ||
import { indicesApi } from '../apis/management/index_management/lib/indices.api'; | ||
import { indicesHelpers } from '../apis/management/index_management/lib/indices.helpers'; | ||
|
||
export function IndexManagementProvider({ getService }: FtrProviderContext) { | ||
return { | ||
indices: { | ||
api: indicesApi(getService), | ||
helpers: indicesHelpers(getService), | ||
}, | ||
}; | ||
} |
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
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