Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

[Index Management] Support data retention on Data Streams tab #165263

Merged
Show file tree
Hide file tree
Changes from all commits
Commits
Show all changes
22 commits
Select commit Hold shift + click to select a range
1cd71e3
add data retention to data streams table
alisonelizabeth Aug 30, 2023
d0226d6
add data retention to details panel
alisonelizabeth Sep 5, 2023
79cb0ab
Merge branch 'main' of github.com:elastic/kibana into index_managemen…
alisonelizabeth Sep 5, 2023
c41885c
[CI] Auto-commit changed files from 'node scripts/eslint --no-cache -…
kibanamachine Sep 5, 2023
5dc856a
Merge branch 'main' of github.com:elastic/kibana into index_managemen…
alisonelizabeth Sep 6, 2023
71552af
fix details panel logic
alisonelizabeth Sep 6, 2023
002ae7c
fix jest tests
alisonelizabeth Sep 6, 2023
86a4468
fix API integration tests
alisonelizabeth Sep 6, 2023
de09ecc
add tooltip to table
alisonelizabeth Sep 6, 2023
9ba7c0b
Merge branch 'main' into index_management/data_stream_lifecycle
kibanamachine Sep 7, 2023
7fb90b5
fix i18n
alisonelizabeth Sep 7, 2023
e9c01a9
remove unused translation
alisonelizabeth Sep 7, 2023
44e72f8
Merge branch 'main' of github.com:elastic/kibana into index_managemen…
alisonelizabeth Sep 7, 2023
6a5c9e5
update readme
alisonelizabeth Sep 7, 2023
bdd649f
remove ternary
alisonelizabeth Sep 7, 2023
a9cb16d
fix test
alisonelizabeth Sep 7, 2023
d4c1f4d
fix test
alisonelizabeth Sep 8, 2023
26541e5
Merge branch 'main' of github.com:elastic/kibana into index_managemen…
alisonelizabeth Sep 8, 2023
cc150bc
Merge branch 'main' of github.com:elastic/kibana into index_managemen…
alisonelizabeth Sep 14, 2023
f48949b
address initial copy feedback
alisonelizabeth Sep 14, 2023
5a678dc
Merge branch 'main' of github.com:elastic/kibana into index_managemen…
alisonelizabeth Sep 18, 2023
264952a
update tooltip text
alisonelizabeth Sep 18, 2023
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
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 {
Copy link
Contributor Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

I refactored some of the server-side code to leverage the types from @elastic/elasticsearch rather than our own custom interfaces

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
Loading