Skip to content

Commit 081cf98

Browse files
[Logs UI] Fix the LogStream story to work with KIPs (#100862)
Co-authored-by: Kibana Machine <42973632+kibanamachine@users.noreply.github.com>
1 parent 7b4b713 commit 081cf98

File tree

2 files changed

+84
-21
lines changed

2 files changed

+84
-21
lines changed

x-pack/plugins/infra/public/components/log_stream/log_stream.stories.mdx

Lines changed: 48 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -3,10 +3,11 @@ import { defer, of, Subject } from 'rxjs';
33
import { delay } from 'rxjs/operators';
44

55
import { I18nProvider } from '@kbn/i18n/react';
6+
import { KBN_FIELD_TYPES } from '../../../../../../src/plugins/data/public';
67
import { EuiThemeProvider } from '../../../../../../src/plugins/kibana_react/common';
78
import { KibanaContextProvider } from '../../../../../../src/plugins/kibana_react/public';
8-
99
import { LOG_ENTRIES_SEARCH_STRATEGY } from '../../../common/search_strategies/log_entries/log_entries';
10+
import { createIndexPatternMock, createIndexPatternsMock } from '../../hooks/use_kibana_index_patterns.mock';
1011
import { DEFAULT_SOURCE_CONFIGURATION } from '../../test_utils/source_configuration';
1112
import { generateFakeEntries, ENTRIES_EMPTY } from '../../test_utils/entries';
1213

@@ -18,6 +19,45 @@ export const startTimestamp = 1595145600000;
1819
export const endTimestamp = startTimestamp + 15 * 60 * 1000;
1920

2021
export const dataMock = {
22+
indexPatterns: createIndexPatternsMock(500, [
23+
createIndexPatternMock({
24+
id: 'some-test-id',
25+
title: 'mock-index-pattern-*',
26+
timeFieldName: '@timestamp',
27+
fields: [
28+
{
29+
name: '@timestamp',
30+
type: KBN_FIELD_TYPES.DATE,
31+
searchable: true,
32+
aggregatable: true,
33+
},
34+
{
35+
name: 'event.dataset',
36+
type: KBN_FIELD_TYPES.STRING,
37+
searchable: true,
38+
aggregatable: true,
39+
},
40+
{
41+
name: 'host.name',
42+
type: KBN_FIELD_TYPES.STRING,
43+
searchable: true,
44+
aggregatable: true,
45+
},
46+
{
47+
name: 'log.level',
48+
type: KBN_FIELD_TYPES.STRING,
49+
searchable: true,
50+
aggregatable: true,
51+
},
52+
{
53+
name: 'message',
54+
type: KBN_FIELD_TYPES.STRING,
55+
searchable: true,
56+
aggregatable: true,
57+
},
58+
],
59+
})
60+
]),
2161
search: {
2262
search: ({ params }, options) => {
2363
return defer(() => {
@@ -68,10 +108,16 @@ export const dataMock = {
68108
};
69109

70110

71-
export const fetch = function (url, params) {
111+
export const fetch = async function (url, params) {
72112
switch (url) {
73113
case '/api/infra/log_source_configurations/default':
74114
return DEFAULT_SOURCE_CONFIGURATION;
115+
case '/api/infra/log_source_configurations/default/status':
116+
return {
117+
data: {
118+
logIndexStatus: 'available',
119+
}
120+
};
75121
default:
76122
return {};
77123
}

x-pack/plugins/infra/public/hooks/use_kibana_index_patterns.mock.tsx

Lines changed: 36 additions & 19 deletions
Original file line numberDiff line numberDiff line change
@@ -21,7 +21,7 @@ import { Pick2 } from '../../common/utility_types';
2121

2222
type MockIndexPattern = Pick<
2323
IndexPattern,
24-
'id' | 'title' | 'type' | 'getTimeField' | 'isTimeBased' | 'getFieldByName'
24+
'id' | 'title' | 'type' | 'getTimeField' | 'isTimeBased' | 'getFieldByName' | 'getComputedFields'
2525
>;
2626
export type MockIndexPatternSpec = Pick<
2727
IIndexPattern,
@@ -35,23 +35,7 @@ export const MockIndexPatternsKibanaContextProvider: React.FC<{
3535
mockIndexPatterns: MockIndexPatternSpec[];
3636
}> = ({ asyncDelay, children, mockIndexPatterns }) => {
3737
const indexPatterns = useMemo(
38-
() =>
39-
createIndexPatternsMock(
40-
asyncDelay,
41-
mockIndexPatterns.map(({ id, title, type = undefined, fields, timeFieldName }) => {
42-
const indexPatternFields = fields.map((fieldSpec) => new IndexPatternField(fieldSpec));
43-
44-
return {
45-
id,
46-
title,
47-
type,
48-
getTimeField: () => indexPatternFields.find(({ name }) => name === timeFieldName),
49-
isTimeBased: () => timeFieldName != null,
50-
getFieldByName: (fieldName) =>
51-
indexPatternFields.find(({ name }) => name === fieldName),
52-
};
53-
})
54-
),
38+
() => createIndexPatternsMock(asyncDelay, mockIndexPatterns.map(createIndexPatternMock)),
5539
[asyncDelay, mockIndexPatterns]
5640
);
5741

@@ -71,7 +55,7 @@ export const MockIndexPatternsKibanaContextProvider: React.FC<{
7155
);
7256
};
7357

74-
const createIndexPatternsMock = (
58+
export const createIndexPatternsMock = (
7559
asyncDelay: number,
7660
indexPatterns: MockIndexPattern[]
7761
): {
@@ -93,3 +77,36 @@ const createIndexPatternsMock = (
9377
},
9478
};
9579
};
80+
81+
export const createIndexPatternMock = ({
82+
id,
83+
title,
84+
type = undefined,
85+
fields,
86+
timeFieldName,
87+
}: MockIndexPatternSpec): MockIndexPattern => {
88+
const indexPatternFields = fields.map((fieldSpec) => new IndexPatternField(fieldSpec));
89+
90+
return {
91+
id,
92+
title,
93+
type,
94+
getTimeField: () => indexPatternFields.find(({ name }) => name === timeFieldName),
95+
isTimeBased: () => timeFieldName != null,
96+
getFieldByName: (fieldName) => indexPatternFields.find(({ name }) => name === fieldName),
97+
getComputedFields: () => ({
98+
docvalueFields: [],
99+
runtimeFields: indexPatternFields.reduce((accumulatedRuntimeFields, field) => {
100+
if (field.runtimeField != null) {
101+
return {
102+
...accumulatedRuntimeFields,
103+
[field.name]: field.runtimeField,
104+
};
105+
}
106+
return accumulatedRuntimeFields;
107+
}, {}),
108+
scriptFields: {},
109+
storedFields: [],
110+
}),
111+
};
112+
};

0 commit comments

Comments
 (0)