Skip to content

Commit

Permalink
Merge branch 'main' into chore/cypress-flaky-tests-runner
Browse files Browse the repository at this point in the history
  • Loading branch information
patrykkopycinski authored Aug 8, 2023
2 parents a7c947d + b8841bc commit f51f4b3
Show file tree
Hide file tree
Showing 48 changed files with 2,729 additions and 274 deletions.
1 change: 1 addition & 0 deletions .buildkite/ftr_configs.yml
Original file line number Diff line number Diff line change
Expand Up @@ -328,6 +328,7 @@ enabled:
- x-pack/test/functional/config_security_basic.ts
- x-pack/test/functional/config.ccs.ts
- x-pack/test/functional/config.firefox.js
- x-pack/test/functional/config.upgrade_assistant.ts
- x-pack/test/functional_cloud/config.ts
- x-pack/test/kubernetes_security/basic/config.ts
- x-pack/test/licensing_plugin/config.public.ts
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -56,14 +56,10 @@ Predicting the buffer required to account for actions depends heavily on the rul

experimental[]

Alerts and actions log activity in a set of "event log" indices. These indices are configured with an index lifecycle management (ILM) policy, which you can customize. The default policy rolls over the index when it reaches 50GB, or after 30 days. Indices over 90 days old are deleted.
Alerts and actions log activity in a set of "event log" data streams, one per Kibana version, named `.kibana-event-log-{VERSION}`. These data streams are configured with a lifecycle data retention of 90 days. This can be updated to other values via the standard data stream lifecycle APIs. Note that the event log data contains the data shown in the alerting pages in {kib}, so reducing the data retention period will result in less data being available to view.

The name of the index policy is `kibana-event-log-policy`. {kib} creates the index policy on startup, if it doesn't already exist. The index policy can be customized for your environment, but {kib} never modifies the index policy after creating it.

Because {kib} uses the documents to display historic data, you should set the delete phase longer than you would like the historic data to be shown. For example, if you would like to see one month's worth of historic data, you should set the delete phase to at least one month.

For more information on index lifecycle management, see:
{ref}/index-lifecycle-management.html[Index Lifecycle Policies].
For more information on data stream lifecycle management, see:
{ref}/data-stream-lifecycle.html[Data stream lifecycle].

[float]
[[alerting-circuit-breakers]]
Expand Down
1 change: 1 addition & 0 deletions packages/kbn-doc-links/src/get_doc_links.ts
Original file line number Diff line number Diff line change
Expand Up @@ -319,6 +319,7 @@ export const getDocLinks = ({ kibanaBranch }: GetDocLinkOptions): DocLinks => {
overview: `${KIBANA_DOCS}upgrade-assistant.html`,
batchReindex: `${KIBANA_DOCS}batch-start-resume-reindex.html`,
remoteReindex: `${ELASTICSEARCH_DOCS}docs-reindex.html#reindex-from-remote`,
reindexWithPipeline: `${ELASTICSEARCH_DOCS}docs-reindex.html#reindex-with-an-ingest-pipeline`,
},
rollupJobs: `${KIBANA_DOCS}data-rollups.html`,
elasticsearch: {
Expand Down
1 change: 1 addition & 0 deletions packages/kbn-doc-links/src/types.ts
Original file line number Diff line number Diff line change
Expand Up @@ -298,6 +298,7 @@ export interface DocLinks {
readonly overview: string;
readonly batchReindex: string;
readonly remoteReindex: string;
readonly reindexWithPipeline: string;
};
readonly rollupJobs: string;
readonly elasticsearch: Record<string, string>;
Expand Down
3 changes: 2 additions & 1 deletion test/functional/apps/visualize/group5/_tsvb_time_series.ts
Original file line number Diff line number Diff line change
Expand Up @@ -23,7 +23,8 @@ export default function ({ getPageObjects, getService }: FtrProviderContext) {
const browser = getService('browser');
const kibanaServer = getService('kibanaServer');

describe('visual builder', function describeIndexTests() {
// Failing: See https://github.com/elastic/kibana/issues/162995
describe.skip('visual builder', function describeIndexTests() {
before(async () => {
await security.testUser.setRoles([
'kibana_admin',
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -11,8 +11,6 @@ const createClusterClientMock = () => {
const mock: jest.Mocked<IClusterClientAdapter> = {
indexDocument: jest.fn(),
indexDocuments: jest.fn(),
doesIlmPolicyExist: jest.fn(),
createIlmPolicy: jest.fn(),
doesIndexTemplateExist: jest.fn(),
createIndexTemplate: jest.fn(),
doesDataStreamExist: jest.fn(),
Expand Down
50 changes: 0 additions & 50 deletions x-pack/plugins/event_log/server/es/cluster_client_adapter.test.ts
Original file line number Diff line number Diff line change
Expand Up @@ -165,56 +165,6 @@ describe('buffering documents', () => {
});
});

describe('doesIlmPolicyExist', () => {
// ElasticsearchError can be a bit random in shape, we need an any here
// eslint-disable-next-line @typescript-eslint/no-explicit-any
const notFoundError = new Error('Not found') as any;
notFoundError.statusCode = 404;

test('should call cluster with proper arguments', async () => {
await clusterClientAdapter.doesIlmPolicyExist('foo');
expect(clusterClient.transport.request).toHaveBeenCalledWith({
method: 'GET',
path: '/_ilm/policy/foo',
});
});

test('should return false when 404 error is returned by Elasticsearch', async () => {
clusterClient.transport.request.mockRejectedValue(notFoundError);
await expect(clusterClientAdapter.doesIlmPolicyExist('foo')).resolves.toEqual(false);
});

test('should throw error when error is not 404', async () => {
clusterClient.transport.request.mockRejectedValue(new Error('Fail'));
await expect(
clusterClientAdapter.doesIlmPolicyExist('foo')
).rejects.toThrowErrorMatchingInlineSnapshot(`"error checking existance of ilm policy: Fail"`);
});

test('should return true when no error is thrown', async () => {
await expect(clusterClientAdapter.doesIlmPolicyExist('foo')).resolves.toEqual(true);
});
});

describe('createIlmPolicy', () => {
test('should call cluster client with given policy', async () => {
clusterClient.transport.request.mockResolvedValue({ success: true });
await clusterClientAdapter.createIlmPolicy('foo', { args: true });
expect(clusterClient.transport.request).toHaveBeenCalledWith({
method: 'PUT',
path: '/_ilm/policy/foo',
body: { args: true },
});
});

test('should throw error when call cluster client throws', async () => {
clusterClient.transport.request.mockRejectedValue(new Error('Fail'));
await expect(
clusterClientAdapter.createIlmPolicy('foo', { args: true })
).rejects.toThrowErrorMatchingInlineSnapshot(`"error creating ilm policy: Fail"`);
});
});

describe('doesIndexTemplateExist', () => {
test('should call cluster with proper arguments', async () => {
await clusterClientAdapter.doesIndexTemplateExist('foo');
Expand Down
30 changes: 0 additions & 30 deletions x-pack/plugins/event_log/server/es/cluster_client_adapter.ts
Original file line number Diff line number Diff line change
Expand Up @@ -178,36 +178,6 @@ export class ClusterClientAdapter<TDoc extends { body: AliasAny; index: string }
}
}

public async doesIlmPolicyExist(policyName: string): Promise<boolean> {
const request = {
method: 'GET',
path: `/_ilm/policy/${policyName}`,
};
try {
const esClient = await this.elasticsearchClientPromise;
await esClient.transport.request(request);
} catch (err) {
if (err.statusCode === 404) return false;
throw new Error(`error checking existance of ilm policy: ${err.message}`);
}
return true;
}

public async createIlmPolicy(policyName: string, policy: Record<string, unknown>): Promise<void> {
this.logger.info(`Installing ILM policy ${policyName}`);
const request = {
method: 'PUT',
path: `/_ilm/policy/${policyName}`,
body: policy,
};
try {
const esClient = await this.elasticsearchClientPromise;
await esClient.transport.request(request);
} catch (err) {
throw new Error(`error creating ilm policy: ${err.message}`);
}
}

public async doesIndexTemplateExist(name: string): Promise<boolean> {
try {
const esClient = await this.elasticsearchClientPromise;
Expand Down
10 changes: 2 additions & 8 deletions x-pack/plugins/event_log/server/es/context.test.ts
Original file line number Diff line number Diff line change
Expand Up @@ -57,13 +57,12 @@ describe('createEsContext', () => {
expect(esNames).toStrictEqual({
base: 'test-index',
dataStream: 'test-index-event-log-1.2.3',
ilmPolicy: 'test-index-event-log-policy',
indexPattern: 'test-index-event-log-*',
indexTemplate: 'test-index-event-log-1.2.3-template',
});
});

test('should return exist false for esAdapter ilm policy, index template and data stream before initialize', async () => {
test('should return exist false for esAdapter index template and data stream before initialize', async () => {
const context = createEsContext({
logger,
indexNameRoot: 'test1',
Expand All @@ -84,7 +83,7 @@ describe('createEsContext', () => {
expect(doesIndexTemplateExist).toBeFalsy();
});

test('should return exist true for esAdapter ilm policy, index template and data stream after initialize', async () => {
test('should return exist true for esAdapter index template and data stream after initialize', async () => {
const context = createEsContext({
logger,
indexNameRoot: 'test2',
Expand All @@ -94,11 +93,6 @@ describe('createEsContext', () => {
elasticsearchClient.indices.existsTemplate.mockResponse(true);
context.initialize();

const doesIlmPolicyExist = await context.esAdapter.doesIlmPolicyExist(
context.esNames.ilmPolicy
);
expect(doesIlmPolicyExist).toBeTruthy();

elasticsearchClient.indices.getDataStream.mockResolvedValue(GetDataStreamsResponse);
const doesDataStreamExist = await context.esAdapter.doesDataStreamExist(
context.esNames.dataStream
Expand Down
13 changes: 1 addition & 12 deletions x-pack/plugins/event_log/server/es/documents.test.ts
Original file line number Diff line number Diff line change
Expand Up @@ -5,19 +5,9 @@
* 2.0.
*/

import { getIndexTemplate, getIlmPolicy } from './documents';
import { getIndexTemplate } from './documents';
import { getEsNames } from './names';

describe('getIlmPolicy()', () => {
test('returns the basic structure of an ilm policy', () => {
expect(getIlmPolicy()).toMatchObject({
policy: {
phases: {},
},
});
});
});

describe('getIndexTemplate()', () => {
const kibanaVersion = '1.2.3';
const esNames = getEsNames('XYZ', kibanaVersion);
Expand All @@ -27,7 +17,6 @@ describe('getIndexTemplate()', () => {
expect(indexTemplate.index_patterns).toEqual([esNames.dataStream]);
expect(indexTemplate.template.settings.number_of_shards).toBeGreaterThanOrEqual(0);
expect(indexTemplate.template.settings.auto_expand_replicas).toBe('0-1');
expect(indexTemplate.template.settings['index.lifecycle.name']).toBe(esNames.ilmPolicy);
expect(indexTemplate.template.mappings).toMatchObject({});
});
});
34 changes: 3 additions & 31 deletions x-pack/plugins/event_log/server/es/documents.ts
Original file line number Diff line number Diff line change
Expand Up @@ -25,41 +25,13 @@ export function getIndexTemplate(esNames: EsNames) {
hidden: true,
number_of_shards: 1,
auto_expand_replicas: '0-1',
'index.lifecycle.name': esNames.ilmPolicy,
},
lifecycle: {
data_retention: '90d',
},
mappings,
},
};

return indexTemplateBody;
}

// returns the body of an ilm policy used in an ES PUT _ilm/policy call
export function getIlmPolicy() {
return {
policy: {
_meta: {
description:
'ilm policy the Kibana event log, created initially by Kibana, but updated by the user, not Kibana',
managed: false,
},
phases: {
hot: {
actions: {
rollover: {
max_size: '50GB',
max_age: '30d',
// max_docs: 1, // you know, for testing
},
},
},
delete: {
min_age: '90d',
actions: {
delete: {},
},
},
},
},
};
}
44 changes: 0 additions & 44 deletions x-pack/plugins/event_log/server/es/init.test.ts
Original file line number Diff line number Diff line change
Expand Up @@ -83,7 +83,6 @@ describe('initializeEs', () => {
`error getting existing index templates - Fail`
);
expect(esContext.esAdapter.setLegacyIndexTemplateToHidden).not.toHaveBeenCalled();
expect(esContext.esAdapter.doesIlmPolicyExist).toHaveBeenCalled();
});

test(`should continue initialization if updating existing index templates throws an error`, async () => {
Expand Down Expand Up @@ -124,7 +123,6 @@ describe('initializeEs', () => {
expect(esContext.logger.error).toHaveBeenCalledWith(
`error setting existing \"foo-bar-template\" index template to hidden - Fail`
);
expect(esContext.esAdapter.doesIlmPolicyExist).toHaveBeenCalled();
});

test(`should update existing index settings if any exist and are not hidden`, async () => {
Expand Down Expand Up @@ -207,7 +205,6 @@ describe('initializeEs', () => {
expect(esContext.esAdapter.getExistingIndices).toHaveBeenCalled();
expect(esContext.logger.error).toHaveBeenCalledWith(`error getting existing indices - Fail`);
expect(esContext.esAdapter.setIndexToHidden).not.toHaveBeenCalled();
expect(esContext.esAdapter.doesIlmPolicyExist).toHaveBeenCalled();
});

test(`should continue initialization if updating existing index settings throws an error`, async () => {
Expand Down Expand Up @@ -251,7 +248,6 @@ describe('initializeEs', () => {
expect(esContext.logger.error).toHaveBeenCalledWith(
`error setting existing \"foo-bar-000001\" index to hidden - Fail`
);
expect(esContext.esAdapter.doesIlmPolicyExist).toHaveBeenCalled();
});

test(`should update existing index aliases if any exist and are not hidden`, async () => {
Expand Down Expand Up @@ -300,7 +296,6 @@ describe('initializeEs', () => {
`error getting existing index aliases - Fail`
);
expect(esContext.esAdapter.setIndexAliasToHidden).not.toHaveBeenCalled();
expect(esContext.esAdapter.doesIlmPolicyExist).toHaveBeenCalled();
});

test(`should continue initialization if updating existing index aliases throws an error`, async () => {
Expand Down Expand Up @@ -336,23 +331,6 @@ describe('initializeEs', () => {
expect(esContext.logger.error).toHaveBeenCalledWith(
`error setting existing \"foo-bar\" index aliases - Fail`
);
expect(esContext.esAdapter.doesIlmPolicyExist).toHaveBeenCalled();
});

test(`should create ILM policy if it doesn't exist`, async () => {
esContext.esAdapter.doesIlmPolicyExist.mockResolvedValue(false);

await initializeEs(esContext);
expect(esContext.esAdapter.doesIlmPolicyExist).toHaveBeenCalled();
expect(esContext.esAdapter.createIlmPolicy).toHaveBeenCalled();
});

test(`shouldn't create ILM policy if it exists`, async () => {
esContext.esAdapter.doesIlmPolicyExist.mockResolvedValue(true);

await initializeEs(esContext);
expect(esContext.esAdapter.doesIlmPolicyExist).toHaveBeenCalled();
expect(esContext.esAdapter.createIlmPolicy).not.toHaveBeenCalled();
});

test(`should create index template if it doesn't exist`, async () => {
Expand Down Expand Up @@ -463,30 +441,10 @@ describe('retries', () => {
esContext.esAdapter.getExistingLegacyIndexTemplates.mockResolvedValue({});
esContext.esAdapter.getExistingIndices.mockResolvedValue({});
esContext.esAdapter.getExistingIndexAliases.mockResolvedValue({});
esContext.esAdapter.doesIlmPolicyExist.mockResolvedValue(true);
esContext.esAdapter.doesIndexTemplateExist.mockResolvedValue(true);
esContext.esAdapter.doesDataStreamExist.mockResolvedValue(true);
});

test('createIlmPolicyIfNotExists with 1 retry', async () => {
esContext.esAdapter.doesIlmPolicyExist.mockRejectedValueOnce(new Error('retry 1'));

const timeStart = performance.now();
await initializeEs(esContext);
const timeElapsed = Math.ceil(performance.now() - timeStart);

expect(timeElapsed).toBeGreaterThanOrEqual(MOCK_RETRY_DELAY);

expect(esContext.esAdapter.getExistingLegacyIndexTemplates).toHaveBeenCalledTimes(1);
expect(esContext.esAdapter.doesIlmPolicyExist).toHaveBeenCalledTimes(2);
expect(esContext.esAdapter.doesIndexTemplateExist).toHaveBeenCalledTimes(1);
expect(esContext.esAdapter.doesDataStreamExist).toHaveBeenCalledTimes(1);

const prefix = `eventLog initialization operation failed and will be retried: createIlmPolicyIfNotExists`;
expect(esContext.logger.warn).toHaveBeenCalledTimes(1);
expect(esContext.logger.warn).toHaveBeenCalledWith(`${prefix}; 4 more times; error: retry 1`);
});

test('createIndexTemplateIfNotExists with 2 retries', async () => {
esContext.esAdapter.doesIndexTemplateExist.mockRejectedValueOnce(new Error('retry 2a'));
esContext.esAdapter.doesIndexTemplateExist.mockRejectedValueOnce(new Error('retry 2b'));
Expand All @@ -498,7 +456,6 @@ describe('retries', () => {
expect(timeElapsed).toBeGreaterThanOrEqual(MOCK_RETRY_DELAY * (1 + 2));

expect(esContext.esAdapter.getExistingLegacyIndexTemplates).toHaveBeenCalledTimes(1);
expect(esContext.esAdapter.doesIlmPolicyExist).toHaveBeenCalledTimes(1);
expect(esContext.esAdapter.doesIndexTemplateExist).toHaveBeenCalledTimes(3);
expect(esContext.esAdapter.doesDataStreamExist).toHaveBeenCalledTimes(1);

Expand All @@ -524,7 +481,6 @@ describe('retries', () => {
expect(timeElapsed).toBeGreaterThanOrEqual(MOCK_RETRY_DELAY * (1 + 2 + 4 + 8));

expect(esContext.esAdapter.getExistingLegacyIndexTemplates).toHaveBeenCalledTimes(1);
expect(esContext.esAdapter.doesIlmPolicyExist).toHaveBeenCalledTimes(1);
expect(esContext.esAdapter.doesIndexTemplateExist).toHaveBeenCalledTimes(1);
expect(esContext.esAdapter.doesDataStreamExist).toHaveBeenCalledTimes(5);
expect(esContext.esAdapter.createDataStream).toHaveBeenCalledTimes(0);
Expand Down
Loading

0 comments on commit f51f4b3

Please sign in to comment.