Skip to content

Commit b2ccd0f

Browse files
authored
Surface data stream stats, index template, and ILM policy in the UI (#75107) (#75713)
* Add Index Management README and quick testing steps for data streams. * Surface data stream health in Data Streams tab (table and detail panel). - Extract out DataHealth component for use in both Data Streams and Indices tabs. - Refactor detail panel to use data structure & algo to build component. - Refactor detail panel to use i18n.translate instead of FormattedMessage. * Render index template name and index lifecycle policy name in the detail panel. * Render storage size and max timestamp information in table and detail panel. - Add 'Include stats' switch. - Add humanizeTimeStamp service, localized to data streams.
1 parent 2baabec commit b2ccd0f

File tree

20 files changed

+568
-225
lines changed

20 files changed

+568
-225
lines changed

docs/developer/architecture/code-exploration.asciidoc

Lines changed: 2 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -426,9 +426,9 @@ You can test that the Frozen badge, phase filtering, and lifecycle information i
426426
Index Management by running this series of requests in Console:
427427
428428
429-
- {kib-repo}blob/{branch}/x-pack/plugins/index_management[indexManagement]
429+
- {kib-repo}blob/{branch}/x-pack/plugins/index_management/README.md[indexManagement]
430430
431-
WARNING: Missing README.
431+
Create a data stream using Console and you'll be able to view it in the UI:
432432
433433
434434
- {kib-repo}blob/{branch}/x-pack/plugins/infra/README.md[infra]
Lines changed: 22 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,22 @@
1+
# Index Management UI
2+
3+
## Data streams tab
4+
5+
### Quick steps for testing
6+
7+
Create a data stream using Console and you'll be able to view it in the UI:
8+
9+
```
10+
# Configure template for creating a data stream
11+
PUT _index_template/ds
12+
{
13+
"index_patterns": ["ds"],
14+
"data_stream": {}
15+
}
16+
17+
# Add a document to the data stream
18+
POST ds/_doc
19+
{
20+
"@timestamp": "2020-01-27"
21+
}
22+
```

x-pack/plugins/index_management/__jest__/client_integration/helpers/test_subjects.ts

Lines changed: 4 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -20,6 +20,7 @@ export type TestSubjects =
2020
| 'documentationLink'
2121
| 'emptyPrompt'
2222
| 'filterList.filterItem'
23+
| 'includeStatsSwitch'
2324
| 'indexTable'
2425
| 'indexTableIncludeHiddenIndicesToggle'
2526
| 'indexTableIndexNameLink'
@@ -28,16 +29,17 @@ export type TestSubjects =
2829
| 'legacyTemplateTable'
2930
| 'manageTemplateButton'
3031
| 'mappingsTabContent'
31-
| 'previewTabContent'
3232
| 'noAliasesCallout'
3333
| 'noMappingsCallout'
3434
| 'noSettingsCallout'
35+
| 'previewTabContent'
3536
| 'reloadButton'
3637
| 'reloadIndicesButton'
3738
| 'row'
3839
| 'sectionError'
3940
| 'sectionLoading'
4041
| 'settingsTabContent'
42+
| 'simulateTemplatePreview'
4143
| 'summaryTab'
4244
| 'summaryTitle'
4345
| 'systemTemplatesSwitch'
@@ -49,5 +51,4 @@ export type TestSubjects =
4951
| 'templateList'
5052
| 'templatesTab'
5153
| 'templateTable'
52-
| 'viewButton'
53-
| 'simulateTemplatePreview';
54+
| 'viewButton';

x-pack/plugins/index_management/__jest__/client_integration/home/data_streams_tab.helpers.ts

Lines changed: 11 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -22,6 +22,7 @@ export interface DataStreamsTabTestBed extends TestBed<TestSubjects> {
2222
actions: {
2323
goToDataStreamsList: () => void;
2424
clickEmptyPromptIndexTemplateLink: () => void;
25+
clickIncludeStatsSwitch: () => void;
2526
clickReloadButton: () => void;
2627
clickNameAt: (index: number) => void;
2728
clickIndicesAt: (index: number) => void;
@@ -74,6 +75,11 @@ export const setup = async (overridingDependencies: any = {}): Promise<DataStrea
7475
component.update();
7576
};
7677

78+
const clickIncludeStatsSwitch = () => {
79+
const { find } = testBed;
80+
find('includeStatsSwitch').simulate('click');
81+
};
82+
7783
const clickReloadButton = () => {
7884
const { find } = testBed;
7985
find('reloadButton').simulate('click');
@@ -149,6 +155,7 @@ export const setup = async (overridingDependencies: any = {}): Promise<DataStrea
149155
actions: {
150156
goToDataStreamsList,
151157
clickEmptyPromptIndexTemplateLink,
158+
clickIncludeStatsSwitch,
152159
clickReloadButton,
153160
clickNameAt,
154161
clickIndicesAt,
@@ -174,4 +181,8 @@ export const createDataStreamPayload = (name: string): DataStream => ({
174181
},
175182
],
176183
generation: 1,
184+
health: 'green',
185+
indexTemplateName: 'indexTemplate',
186+
storageSize: '1b',
187+
maxTimeStamp: 420,
177188
});

x-pack/plugins/index_management/__jest__/client_integration/home/data_streams_tab.test.ts

Lines changed: 35 additions & 9 deletions
Original file line numberDiff line numberDiff line change
@@ -78,7 +78,13 @@ describe('Data Streams tab', () => {
7878

7979
describe('when there are data streams', () => {
8080
beforeEach(async () => {
81-
httpRequestsMockHelpers.setLoadIndicesResponse([
81+
const {
82+
setLoadIndicesResponse,
83+
setLoadDataStreamsResponse,
84+
setLoadDataStreamResponse,
85+
} = httpRequestsMockHelpers;
86+
87+
setLoadIndicesResponse([
8288
{
8389
health: '',
8490
status: '',
@@ -105,20 +111,16 @@ describe('Data Streams tab', () => {
105111
]);
106112

107113
const dataStreamForDetailPanel = createDataStreamPayload('dataStream1');
108-
109-
httpRequestsMockHelpers.setLoadDataStreamsResponse([
114+
setLoadDataStreamsResponse([
110115
dataStreamForDetailPanel,
111116
createDataStreamPayload('dataStream2'),
112117
]);
113-
114-
httpRequestsMockHelpers.setLoadDataStreamResponse(dataStreamForDetailPanel);
118+
setLoadDataStreamResponse(dataStreamForDetailPanel);
115119

116120
testBed = await setup();
117-
118121
await act(async () => {
119122
testBed.actions.goToDataStreamsList();
120123
});
121-
122124
testBed.component.update();
123125
});
124126

@@ -127,8 +129,8 @@ describe('Data Streams tab', () => {
127129
const { tableCellsValues } = table.getMetaData('dataStreamTable');
128130

129131
expect(tableCellsValues).toEqual([
130-
['', 'dataStream1', '1', 'Delete'],
131-
['', 'dataStream2', '1', 'Delete'],
132+
['', 'dataStream1', 'green', '1', 'Delete'],
133+
['', 'dataStream2', 'green', '1', 'Delete'],
132134
]);
133135
});
134136

@@ -146,6 +148,30 @@ describe('Data Streams tab', () => {
146148
expect(server.requests[server.requests.length - 1].url).toBe(`${API_BASE_PATH}/data_streams`);
147149
});
148150

151+
test('has a switch that will reload the data streams with additional stats when clicked', async () => {
152+
const { exists, actions, table, component } = testBed;
153+
const totalRequests = server.requests.length;
154+
155+
expect(exists('includeStatsSwitch')).toBe(true);
156+
157+
// Changing the switch will automatically reload the data streams.
158+
await act(async () => {
159+
actions.clickIncludeStatsSwitch();
160+
});
161+
component.update();
162+
163+
// A request is sent, but sinon isn't capturing the query parameters for some reason.
164+
expect(server.requests.length).toBe(totalRequests + 1);
165+
expect(server.requests[server.requests.length - 1].url).toBe(`${API_BASE_PATH}/data_streams`);
166+
167+
// The table renders with the stats columns though.
168+
const { tableCellsValues } = table.getMetaData('dataStreamTable');
169+
expect(tableCellsValues).toEqual([
170+
['', 'dataStream1', 'green', 'December 31st, 1969 7:00:00 PM', '1b', '1', 'Delete'],
171+
['', 'dataStream2', 'green', 'December 31st, 1969 7:00:00 PM', '1b', '1', 'Delete'],
172+
]);
173+
});
174+
149175
test('clicking the indices count navigates to the backing indices', async () => {
150176
const { table, actions } = testBed;
151177
await actions.clickIndicesAt(0);

x-pack/plugins/index_management/common/lib/data_stream_serialization.ts

Lines changed: 17 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -4,10 +4,20 @@
44
* you may not use this file except in compliance with the Elastic License.
55
*/
66

7-
import { DataStream, DataStreamFromEs } from '../types';
7+
import { DataStream, DataStreamFromEs, Health } from '../types';
88

99
export function deserializeDataStream(dataStreamFromEs: DataStreamFromEs): DataStream {
10-
const { name, timestamp_field: timeStampField, indices, generation } = dataStreamFromEs;
10+
const {
11+
name,
12+
timestamp_field: timeStampField,
13+
indices,
14+
generation,
15+
status,
16+
template,
17+
ilm_policy: ilmPolicyName,
18+
store_size: storageSize,
19+
maximum_timestamp: maxTimeStamp,
20+
} = dataStreamFromEs;
1121

1222
return {
1323
name,
@@ -20,6 +30,11 @@ export function deserializeDataStream(dataStreamFromEs: DataStreamFromEs): DataS
2030
})
2131
),
2232
generation,
33+
health: status.toLowerCase() as Health, // ES typically returns status in all-caps
34+
indexTemplateName: template,
35+
ilmPolicyName,
36+
storageSize,
37+
maxTimeStamp,
2338
};
2439
}
2540

x-pack/plugins/index_management/common/types/data_streams.ts

Lines changed: 14 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -10,23 +10,37 @@ interface TimestampFieldFromEs {
1010

1111
type TimestampField = TimestampFieldFromEs;
1212

13+
export type HealthFromEs = 'GREEN' | 'YELLOW' | 'RED';
14+
1315
export interface DataStreamFromEs {
1416
name: string;
1517
timestamp_field: TimestampFieldFromEs;
1618
indices: DataStreamIndexFromEs[];
1719
generation: number;
20+
status: HealthFromEs;
21+
template: string;
22+
ilm_policy?: string;
23+
store_size?: string;
24+
maximum_timestamp?: number;
1825
}
1926

2027
export interface DataStreamIndexFromEs {
2128
index_name: string;
2229
index_uuid: string;
2330
}
2431

32+
export type Health = 'green' | 'yellow' | 'red';
33+
2534
export interface DataStream {
2635
name: string;
2736
timeStampField: TimestampField;
2837
indices: DataStreamIndex[];
2938
generation: number;
39+
health: Health;
40+
indexTemplateName: string;
41+
ilmPolicyName?: string;
42+
storageSize?: string;
43+
maxTimeStamp?: number;
3044
}
3145

3246
export interface DataStreamIndex {

x-pack/plugins/index_management/common/types/index.ts

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -12,6 +12,6 @@ export * from './mappings';
1212

1313
export * from './templates';
1414

15-
export { DataStreamFromEs, DataStream, DataStreamIndex } from './data_streams';
15+
export { DataStreamFromEs, Health, DataStream, DataStreamIndex } from './data_streams';
1616

1717
export * from './component_templates';

x-pack/plugins/index_management/public/application/services/health_to_color.ts renamed to x-pack/plugins/index_management/public/application/components/data_health.tsx

Lines changed: 13 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -4,7 +4,15 @@
44
* you may not use this file except in compliance with the Elastic License.
55
*/
66

7-
export const healthToColor = (health: 'green' | 'yellow' | 'red') => {
7+
import React from 'react';
8+
import { EuiHealth } from '@elastic/eui';
9+
import { Health } from '../../../common/types';
10+
11+
interface Props {
12+
health: Health;
13+
}
14+
15+
const healthToColor = (health: Health) => {
816
switch (health) {
917
case 'green':
1018
return 'success';
@@ -14,3 +22,7 @@ export const healthToColor = (health: 'green' | 'yellow' | 'red') => {
1422
return 'danger';
1523
}
1624
};
25+
26+
export const DataHealth: React.FunctionComponent<Props> = ({ health }) => (
27+
<EuiHealth color={healthToColor(health)}>{health}</EuiHealth>
28+
);

x-pack/plugins/index_management/public/application/components/index.ts

Lines changed: 1 addition & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -10,6 +10,7 @@ export { NoMatch } from './no_match';
1010
export { PageErrorForbidden } from './page_error';
1111
export { TemplateDeleteModal } from './template_delete_modal';
1212
export { TemplateForm } from './template_form';
13+
export { DataHealth } from './data_health';
1314
export * from './mappings_editor';
1415
export * from './component_templates';
1516
export * from './index_templates';

0 commit comments

Comments
 (0)