Skip to content

Commit

Permalink
[Index Management] Add data streams tests for serverless (elastic#171926
Browse files Browse the repository at this point in the history
)

## Summary

This PR adds data streams api integration tests for serverless. The
helpers code was extracted to a service for re-use in stateful and
serverless tests.


### 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)

---------

Co-authored-by: kibanamachine <42973632+kibanamachine@users.noreply.github.com>
  • Loading branch information
yuliacech and kibanamachine authored Nov 28, 2023
1 parent a658233 commit 5031231
Show file tree
Hide file tree
Showing 6 changed files with 437 additions and 74 deletions.
Original file line number Diff line number Diff line change
Expand Up @@ -9,85 +9,21 @@ import expect from '@kbn/expect';

import { DataStream } from '@kbn/index-management-plugin/common';
import { FtrProviderContext } from '../../../ftr_provider_context';
// @ts-ignore
import { API_BASE_PATH } from './constants';
import { datastreamsHelpers } from './lib/datastreams.helpers';

export default function ({ getService }: FtrProviderContext) {
const supertest = getService('supertest');
const es = getService('es');

const createDataStream = async (name: string) => {
// A data stream requires an index template before it can be created.
await es.indices.putIndexTemplate({
name,
body: {
// We need to match the names of backing indices with this template.
index_patterns: [name + '*'],
template: {
mappings: {
properties: {
'@timestamp': {
type: 'date',
},
},
},
lifecycle: {
// @ts-expect-error @elastic/elasticsearch enabled prop is not typed yet
enabled: true,
},
},
data_stream: {},
},
});

await es.indices.createDataStream({ name });
};

const updateIndexTemplateMappings = async (name: string, mappings: any) => {
await es.indices.putIndexTemplate({
name,
body: {
// We need to match the names of backing indices with this template.
index_patterns: [name + '*'],
template: {
mappings,
},
data_stream: {},
},
});
};

const getDatastream = async (name: string) => {
const {
data_streams: [datastream],
} = await es.indices.getDataStream({ name });
return datastream;
};

const getMapping = async (name: string) => {
const res = await es.indices.getMapping({ index: name });

return Object.values(res)[0]!.mappings;
};

const deleteComposableIndexTemplate = async (name: string) => {
await es.indices.deleteIndexTemplate({ name });
};

const deleteDataStream = async (name: string) => {
await es.indices.deleteDataStream({ name });
await deleteComposableIndexTemplate(name);
};

const assertDataStreamStorageSizeExists = (storageSize: string, storageSizeBytes: number) => {
// Storage size of a document doesn't look like it would be deterministic (could vary depending
// on how ES, Lucene, and the file system interact), so we'll just assert its presence and
// type.
expect(storageSize).to.be.ok();
expect(typeof storageSize).to.be('string');
expect(storageSizeBytes).to.be.ok();
expect(typeof storageSizeBytes).to.be('number');
};
const {
createDataStream,
deleteDataStream,
assertDataStreamStorageSizeExists,
deleteComposableIndexTemplate,
updateIndexTemplateMappings,
getMapping,
getDatastream,
} = datastreamsHelpers(getService);

describe('Data streams', function () {
describe('Get', () => {
Expand Down
Original file line number Diff line number Diff line change
@@ -0,0 +1,96 @@
/*
* 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 expect from '@kbn/expect';
import { FtrProviderContext } from '../../../../ftr_provider_context';

export function datastreamsHelpers(getService: FtrProviderContext['getService']) {
const es = getService('es');

const createDataStream = async (name: string) => {
// A data stream requires an index template before it can be created.
await es.indices.putIndexTemplate({
name,
body: {
// We need to match the names of backing indices with this template.
index_patterns: [name + '*'],
template: {
mappings: {
properties: {
'@timestamp': {
type: 'date',
},
},
},
lifecycle: {
// @ts-expect-error @elastic/elasticsearch enabled prop is not typed yet
enabled: true,
},
},
data_stream: {},
},
});

await es.indices.createDataStream({ name });
};

const updateIndexTemplateMappings = async (name: string, mappings: any) => {
await es.indices.putIndexTemplate({
name,
body: {
// We need to match the names of backing indices with this template.
index_patterns: [name + '*'],
template: {
mappings,
},
data_stream: {},
},
});
};

const getDatastream = async (name: string) => {
const {
data_streams: [datastream],
} = await es.indices.getDataStream({ name });
return datastream;
};

const getMapping = async (name: string) => {
const res = await es.indices.getMapping({ index: name });

return Object.values(res)[0]!.mappings;
};

const deleteComposableIndexTemplate = async (name: string) => {
await es.indices.deleteIndexTemplate({ name });
};

const deleteDataStream = async (name: string) => {
await es.indices.deleteDataStream({ name });
await deleteComposableIndexTemplate(name);
};

const assertDataStreamStorageSizeExists = (storageSize: string, storageSizeBytes: number) => {
// Storage size of a document doesn't look like it would be deterministic (could vary depending
// on how ES, Lucene, and the file system interact), so we'll just assert its presence and
// type.
expect(storageSize).to.be.ok();
expect(typeof storageSize).to.be('string');
expect(storageSizeBytes).to.be.ok();
expect(typeof storageSizeBytes).to.be('number');
};

return {
createDataStream,
updateIndexTemplateMappings,
getDatastream,
getMapping,
deleteComposableIndexTemplate,
deleteDataStream,
assertDataStreamStorageSizeExists,
};
}
4 changes: 4 additions & 0 deletions x-pack/test/api_integration/services/index_management.ts
Original file line number Diff line number Diff line change
Expand Up @@ -9,13 +9,17 @@ import { FtrProviderContext } from '../ftr_provider_context';
import { indicesApi } from '../apis/management/index_management/lib/indices.api';
import { mappingsApi } from '../apis/management/index_management/lib/mappings.api';
import { indicesHelpers } from '../apis/management/index_management/lib/indices.helpers';
import { datastreamsHelpers } from '../apis/management/index_management/lib/datastreams.helpers';

export function IndexManagementProvider({ getService }: FtrProviderContext) {
return {
indices: {
api: indicesApi(getService),
helpers: indicesHelpers(getService),
},
datastreams: {
helpers: datastreamsHelpers(getService),
},
mappings: {
api: mappingsApi(getService),
},
Expand Down
Loading

0 comments on commit 5031231

Please sign in to comment.