Skip to content

Commit

Permalink
[Index Management] Support data retention on Data Streams tab (elasti…
Browse files Browse the repository at this point in the history
  • Loading branch information
alisonelizabeth authored Sep 18, 2023
1 parent a6c25b1 commit be01217
Show file tree
Hide file tree
Showing 13 changed files with 239 additions and 154 deletions.
29 changes: 27 additions & 2 deletions x-pack/plugins/index_management/README.md
Original file line number Diff line number Diff line change
Expand Up @@ -49,11 +49,34 @@ POST %25%7B%5B%40metadata%5D%5Bbeat%5D%7D-%25%7B%5B%40metadata%5D%5Bversion%5D%7
}
```

Create a data stream configured with data stream lifecyle.

```
PUT _index_template/my-index-template
{
"index_patterns": ["my-data-stream*"],
"data_stream": { },
"priority": 500,
"template": {
"lifecycle": {
"data_retention": "7d"
}
},
"_meta": {
"description": "Template with data stream lifecycle"
}
}
```

```
PUT _data_stream/my-data-stream
```

## Index templates tab

### Quick steps for testing

**Legacy index templates** are only shown in the UI on stateful *and* if a user has existing legacy index templates. You can test this functionality by creating one in Console:
**Legacy index templates** are only shown in the UI on stateful _and_ if a user has existing legacy index templates. You can test this functionality by creating one in Console:

```
PUT _template/template_1
Expand All @@ -67,6 +90,7 @@ On serverless, Elasticsearch does not support legacy index templates and therefo
To test **Cloud-managed templates**:

1. Add `cluster.metadata.managed_index_templates` setting via Dev Tools:

```
PUT /_cluster/settings
{
Expand All @@ -77,6 +101,7 @@ PUT /_cluster/settings
```

2. Create a template with the format: `.cloud-<template_name>` via Dev Tools.

```
PUT _template/.cloud-example
{
Expand All @@ -101,4 +126,4 @@ In 7.x, the UI supports types defined as part of the mappings for legacy index t
}
}
}
```
```
Original file line number Diff line number Diff line change
Expand Up @@ -8,7 +8,6 @@
import { act } from 'react-dom/test-utils';
import { ReactWrapper } from 'enzyme';

import { EuiDescriptionListDescription } from '@elastic/eui';
import {
registerTestBed,
TestBed,
Expand Down Expand Up @@ -43,8 +42,9 @@ export interface DataStreamsTabTestBed extends TestBed<TestSubjects> {
findDetailPanelTitle: () => string;
findEmptyPromptIndexTemplateLink: () => ReactWrapper;
findDetailPanelIlmPolicyLink: () => ReactWrapper;
findDetailPanelIlmPolicyName: () => ReactWrapper;
findDetailPanelIlmPolicyDetail: () => ReactWrapper;
findDetailPanelIndexTemplateLink: () => ReactWrapper;
findDetailPanelDataRetentionDetail: () => ReactWrapper;
}

export const setup = async (
Expand Down Expand Up @@ -211,10 +211,14 @@ export const setup = async (
return find('indexTemplateLink');
};

const findDetailPanelIlmPolicyName = () => {
const descriptionList = testBed.component.find(EuiDescriptionListDescription);
// ilm policy is the last in the details list
return descriptionList.last();
const findDetailPanelIlmPolicyDetail = () => {
const { find } = testBed;
return find('ilmPolicyDetail');
};

const findDetailPanelDataRetentionDetail = () => {
const { find } = testBed;
return find('dataRetentionDetail');
};

return {
Expand All @@ -240,8 +244,9 @@ export const setup = async (
findDetailPanelTitle,
findEmptyPromptIndexTemplateLink,
findDetailPanelIlmPolicyLink,
findDetailPanelIlmPolicyName,
findDetailPanelIlmPolicyDetail,
findDetailPanelIndexTemplateLink,
findDetailPanelDataRetentionDetail,
};
};

Expand All @@ -264,6 +269,9 @@ export const createDataStreamPayload = (dataStream: Partial<DataStream>): DataSt
delete_index: true,
},
hidden: false,
lifecycle: {
data_retention: '7d',
},
...dataStream,
});

Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -170,8 +170,8 @@ describe('Data Streams tab', () => {
const { tableCellsValues } = table.getMetaData('dataStreamTable');

expect(tableCellsValues).toEqual([
['', 'dataStream1', 'green', '1', 'Delete'],
['', 'dataStream2', 'green', '1', 'Delete'],
['', 'dataStream1', 'green', '1', '7d', 'Delete'],
['', 'dataStream2', 'green', '1', '7d', 'Delete'],
]);
});

Expand Down Expand Up @@ -209,8 +209,8 @@ describe('Data Streams tab', () => {
// The table renders with the stats columns though.
const { tableCellsValues } = table.getMetaData('dataStreamTable');
expect(tableCellsValues).toEqual([
['', 'dataStream1', 'green', 'December 31st, 1969 7:00:00 PM', '5b', '1', 'Delete'],
['', 'dataStream2', 'green', 'December 31st, 1969 7:00:00 PM', '1kb', '1', 'Delete'],
['', 'dataStream1', 'green', 'December 31st, 1969 7:00:00 PM', '5b', '1', '7d', 'Delete'],
['', 'dataStream2', 'green', 'December 31st, 1969 7:00:00 PM', '1kb', '1', '7d', 'Delete'],
]);
});

Expand All @@ -229,8 +229,8 @@ describe('Data Streams tab', () => {
// the human-readable string values.
const { tableCellsValues } = table.getMetaData('dataStreamTable');
expect(tableCellsValues).toEqual([
['', 'dataStream1', 'green', 'December 31st, 1969 7:00:00 PM', '5b', '1', 'Delete'],
['', 'dataStream2', 'green', 'December 31st, 1969 7:00:00 PM', '1kb', '1', 'Delete'],
['', 'dataStream1', 'green', 'December 31st, 1969 7:00:00 PM', '5b', '1', '7d', 'Delete'],
['', 'dataStream2', 'green', 'December 31st, 1969 7:00:00 PM', '1kb', '1', '7d', 'Delete'],
]);
});

Expand Down Expand Up @@ -335,6 +335,12 @@ describe('Data Streams tab', () => {
expect(find('summaryTab').exists()).toBeTruthy();
expect(find('title').text().trim()).toBe('indexTemplate');
});

test('shows data retention detail when configured', async () => {
const { actions, findDetailPanelDataRetentionDetail } = testBed;
await actions.clickNameAt(0);
expect(findDetailPanelDataRetentionDetail().exists()).toBeTruthy();
});
});
});

Expand Down Expand Up @@ -423,10 +429,10 @@ describe('Data Streams tab', () => {
});
testBed.component.update();

const { actions, findDetailPanelIlmPolicyLink, findDetailPanelIlmPolicyName } = testBed;
const { actions, findDetailPanelIlmPolicyLink, findDetailPanelIlmPolicyDetail } = testBed;
await actions.clickNameAt(0);
expect(findDetailPanelIlmPolicyLink().exists()).toBeFalsy();
expect(findDetailPanelIlmPolicyName().contains('None')).toBeTruthy();
expect(findDetailPanelIlmPolicyDetail().exists()).toBeFalsy();
});

test('without an ILM url locator and with an ILM policy', async () => {
Expand All @@ -453,10 +459,10 @@ describe('Data Streams tab', () => {
});
testBed.component.update();

const { actions, findDetailPanelIlmPolicyLink, findDetailPanelIlmPolicyName } = testBed;
const { actions, findDetailPanelIlmPolicyLink, findDetailPanelIlmPolicyDetail } = testBed;
await actions.clickNameAt(0);
expect(findDetailPanelIlmPolicyLink().exists()).toBeFalsy();
expect(findDetailPanelIlmPolicyName().contains('my_ilm_policy')).toBeTruthy();
expect(findDetailPanelIlmPolicyDetail().contains('my_ilm_policy')).toBeTruthy();
});
});

Expand Down Expand Up @@ -489,8 +495,8 @@ describe('Data Streams tab', () => {
const { tableCellsValues } = table.getMetaData('dataStreamTable');

expect(tableCellsValues).toEqual([
['', `managed-data-stream${nonBreakingSpace}Fleet-managed`, 'green', '1', 'Delete'],
['', 'non-managed-data-stream', 'green', '1', 'Delete'],
['', `managed-data-stream${nonBreakingSpace}Fleet-managed`, 'green', '1', '7d', 'Delete'],
['', 'non-managed-data-stream', 'green', '1', '7d', 'Delete'],
]);
});

Expand All @@ -499,14 +505,16 @@ describe('Data Streams tab', () => {
let { tableCellsValues } = table.getMetaData('dataStreamTable');

expect(tableCellsValues).toEqual([
['', `managed-data-stream${nonBreakingSpace}Fleet-managed`, 'green', '1', 'Delete'],
['', 'non-managed-data-stream', 'green', '1', 'Delete'],
['', `managed-data-stream${nonBreakingSpace}Fleet-managed`, 'green', '1', '7d', 'Delete'],
['', 'non-managed-data-stream', 'green', '1', '7d', 'Delete'],
]);

actions.toggleViewFilterAt(0);

({ tableCellsValues } = table.getMetaData('dataStreamTable'));
expect(tableCellsValues).toEqual([['', 'non-managed-data-stream', 'green', '1', 'Delete']]);
expect(tableCellsValues).toEqual([
['', 'non-managed-data-stream', 'green', '1', '7d', 'Delete'],
]);
});
});

Expand Down Expand Up @@ -537,7 +545,7 @@ describe('Data Streams tab', () => {
const { tableCellsValues } = table.getMetaData('dataStreamTable');

expect(tableCellsValues).toEqual([
['', `hidden-data-stream${nonBreakingSpace}Hidden`, 'green', '1', 'Delete'],
['', `hidden-data-stream${nonBreakingSpace}Hidden`, 'green', '1', '7d', 'Delete'],
]);
});
});
Expand Down Expand Up @@ -570,8 +578,8 @@ describe('Data Streams tab', () => {
const { tableCellsValues } = table.getMetaData('dataStreamTable');

expect(tableCellsValues).toEqual([
['', 'dataStreamNoDelete', 'green', '1', ''],
['', 'dataStreamWithDelete', 'green', '1', 'Delete'],
['', 'dataStreamNoDelete', 'green', '1', '7d', ''],
['', 'dataStreamWithDelete', 'green', '1', '7d', 'Delete'],
]);
});

Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -5,9 +5,9 @@
* 2.0.
*/

import { DataStream, DataStreamFromEs, Health } from '../types';
import { DataStream, EnhancedDataStreamFromEs, Health } from '../types';

export function deserializeDataStream(dataStreamFromEs: DataStreamFromEs): DataStream {
export function deserializeDataStream(dataStreamFromEs: EnhancedDataStreamFromEs): DataStream {
const {
name,
timestamp_field: timeStampField,
Expand All @@ -22,6 +22,7 @@ export function deserializeDataStream(dataStreamFromEs: DataStreamFromEs): DataS
_meta,
privileges,
hidden,
lifecycle,
} = dataStreamFromEs;

return {
Expand All @@ -44,9 +45,12 @@ export function deserializeDataStream(dataStreamFromEs: DataStreamFromEs): DataS
_meta,
privileges,
hidden,
lifecycle,
};
}

export function deserializeDataStreamList(dataStreamsFromEs: DataStreamFromEs[]): DataStream[] {
export function deserializeDataStreamList(
dataStreamsFromEs: EnhancedDataStreamFromEs[]
): DataStream[] {
return dataStreamsFromEs.map((dataStream) => deserializeDataStream(dataStream));
}
42 changes: 18 additions & 24 deletions x-pack/plugins/index_management/common/types/data_streams.ts
Original file line number Diff line number Diff line change
Expand Up @@ -5,20 +5,20 @@
* 2.0.
*/

import {
ByteSize,
IndicesDataLifecycleWithRollover,
IndicesDataStream,
IndicesDataStreamsStatsDataStreamsStatsItem,
Metadata,
} from '@elastic/elasticsearch/lib/api/types';

interface TimestampFieldFromEs {
name: string;
}

type TimestampField = TimestampFieldFromEs;

interface MetaFromEs {
managed_by: string;
package: any;
managed: boolean;
}

type Meta = MetaFromEs;

interface PrivilegesFromEs {
delete_index: boolean;
}
Expand All @@ -27,20 +27,13 @@ type Privileges = PrivilegesFromEs;

export type HealthFromEs = 'GREEN' | 'YELLOW' | 'RED';

export interface DataStreamFromEs {
name: string;
timestamp_field: TimestampFieldFromEs;
indices: DataStreamIndexFromEs[];
generation: number;
_meta?: MetaFromEs;
status: HealthFromEs;
template: string;
ilm_policy?: string;
store_size?: string;
store_size_bytes?: number;
maximum_timestamp?: number;
privileges: PrivilegesFromEs;
hidden: boolean;
export interface EnhancedDataStreamFromEs extends IndicesDataStream {
store_size?: IndicesDataStreamsStatsDataStreamsStatsItem['store_size'];
store_size_bytes?: IndicesDataStreamsStatsDataStreamsStatsItem['store_size_bytes'];
maximum_timestamp?: IndicesDataStreamsStatsDataStreamsStatsItem['maximum_timestamp'];
privileges: {
delete_index: boolean;
};
}

export interface DataStreamIndexFromEs {
Expand All @@ -58,12 +51,13 @@ export interface DataStream {
health: Health;
indexTemplateName: string;
ilmPolicyName?: string;
storageSize?: string;
storageSize?: ByteSize;
storageSizeBytes?: number;
maxTimeStamp?: number;
_meta?: Meta;
_meta?: Metadata;
privileges: Privileges;
hidden: boolean;
lifecycle?: IndicesDataLifecycleWithRollover;
}

export interface DataStreamIndex {
Expand Down
2 changes: 1 addition & 1 deletion x-pack/plugins/index_management/common/types/index.ts
Original file line number Diff line number Diff line change
Expand Up @@ -13,7 +13,7 @@ export * from './mappings';

export * from './templates';

export type { DataStreamFromEs, Health, DataStream, DataStreamIndex } from './data_streams';
export type { EnhancedDataStreamFromEs, Health, DataStream, DataStreamIndex } from './data_streams';

export * from './component_templates';

Expand Down
Loading

0 comments on commit be01217

Please sign in to comment.