[Logs UI] Fix the LogStream story to work with KIPs (#100862)
Co-authored-by: Kibana Machine <42973632+kibanamachine@users.noreply.github.com>
This commit is contained in:
parent
7b4b713237
commit
081cf98f61
|
@ -3,10 +3,11 @@ import { defer, of, Subject } from 'rxjs';
|
||||||
import { delay } from 'rxjs/operators';
|
import { delay } from 'rxjs/operators';
|
||||||
|
|
||||||
import { I18nProvider } from '@kbn/i18n/react';
|
import { I18nProvider } from '@kbn/i18n/react';
|
||||||
|
import { KBN_FIELD_TYPES } from '../../../../../../src/plugins/data/public';
|
||||||
import { EuiThemeProvider } from '../../../../../../src/plugins/kibana_react/common';
|
import { EuiThemeProvider } from '../../../../../../src/plugins/kibana_react/common';
|
||||||
import { KibanaContextProvider } from '../../../../../../src/plugins/kibana_react/public';
|
import { KibanaContextProvider } from '../../../../../../src/plugins/kibana_react/public';
|
||||||
|
|
||||||
import { LOG_ENTRIES_SEARCH_STRATEGY } from '../../../common/search_strategies/log_entries/log_entries';
|
import { LOG_ENTRIES_SEARCH_STRATEGY } from '../../../common/search_strategies/log_entries/log_entries';
|
||||||
|
import { createIndexPatternMock, createIndexPatternsMock } from '../../hooks/use_kibana_index_patterns.mock';
|
||||||
import { DEFAULT_SOURCE_CONFIGURATION } from '../../test_utils/source_configuration';
|
import { DEFAULT_SOURCE_CONFIGURATION } from '../../test_utils/source_configuration';
|
||||||
import { generateFakeEntries, ENTRIES_EMPTY } from '../../test_utils/entries';
|
import { generateFakeEntries, ENTRIES_EMPTY } from '../../test_utils/entries';
|
||||||
|
|
||||||
|
@ -18,6 +19,45 @@ export const startTimestamp = 1595145600000;
|
||||||
export const endTimestamp = startTimestamp + 15 * 60 * 1000;
|
export const endTimestamp = startTimestamp + 15 * 60 * 1000;
|
||||||
|
|
||||||
export const dataMock = {
|
export const dataMock = {
|
||||||
|
indexPatterns: createIndexPatternsMock(500, [
|
||||||
|
createIndexPatternMock({
|
||||||
|
id: 'some-test-id',
|
||||||
|
title: 'mock-index-pattern-*',
|
||||||
|
timeFieldName: '@timestamp',
|
||||||
|
fields: [
|
||||||
|
{
|
||||||
|
name: '@timestamp',
|
||||||
|
type: KBN_FIELD_TYPES.DATE,
|
||||||
|
searchable: true,
|
||||||
|
aggregatable: true,
|
||||||
|
},
|
||||||
|
{
|
||||||
|
name: 'event.dataset',
|
||||||
|
type: KBN_FIELD_TYPES.STRING,
|
||||||
|
searchable: true,
|
||||||
|
aggregatable: true,
|
||||||
|
},
|
||||||
|
{
|
||||||
|
name: 'host.name',
|
||||||
|
type: KBN_FIELD_TYPES.STRING,
|
||||||
|
searchable: true,
|
||||||
|
aggregatable: true,
|
||||||
|
},
|
||||||
|
{
|
||||||
|
name: 'log.level',
|
||||||
|
type: KBN_FIELD_TYPES.STRING,
|
||||||
|
searchable: true,
|
||||||
|
aggregatable: true,
|
||||||
|
},
|
||||||
|
{
|
||||||
|
name: 'message',
|
||||||
|
type: KBN_FIELD_TYPES.STRING,
|
||||||
|
searchable: true,
|
||||||
|
aggregatable: true,
|
||||||
|
},
|
||||||
|
],
|
||||||
|
})
|
||||||
|
]),
|
||||||
search: {
|
search: {
|
||||||
search: ({ params }, options) => {
|
search: ({ params }, options) => {
|
||||||
return defer(() => {
|
return defer(() => {
|
||||||
|
@ -68,10 +108,16 @@ export const dataMock = {
|
||||||
};
|
};
|
||||||
|
|
||||||
|
|
||||||
export const fetch = function (url, params) {
|
export const fetch = async function (url, params) {
|
||||||
switch (url) {
|
switch (url) {
|
||||||
case '/api/infra/log_source_configurations/default':
|
case '/api/infra/log_source_configurations/default':
|
||||||
return DEFAULT_SOURCE_CONFIGURATION;
|
return DEFAULT_SOURCE_CONFIGURATION;
|
||||||
|
case '/api/infra/log_source_configurations/default/status':
|
||||||
|
return {
|
||||||
|
data: {
|
||||||
|
logIndexStatus: 'available',
|
||||||
|
}
|
||||||
|
};
|
||||||
default:
|
default:
|
||||||
return {};
|
return {};
|
||||||
}
|
}
|
||||||
|
|
|
@ -21,7 +21,7 @@ import { Pick2 } from '../../common/utility_types';
|
||||||
|
|
||||||
type MockIndexPattern = Pick<
|
type MockIndexPattern = Pick<
|
||||||
IndexPattern,
|
IndexPattern,
|
||||||
'id' | 'title' | 'type' | 'getTimeField' | 'isTimeBased' | 'getFieldByName'
|
'id' | 'title' | 'type' | 'getTimeField' | 'isTimeBased' | 'getFieldByName' | 'getComputedFields'
|
||||||
>;
|
>;
|
||||||
export type MockIndexPatternSpec = Pick<
|
export type MockIndexPatternSpec = Pick<
|
||||||
IIndexPattern,
|
IIndexPattern,
|
||||||
|
@ -35,23 +35,7 @@ export const MockIndexPatternsKibanaContextProvider: React.FC<{
|
||||||
mockIndexPatterns: MockIndexPatternSpec[];
|
mockIndexPatterns: MockIndexPatternSpec[];
|
||||||
}> = ({ asyncDelay, children, mockIndexPatterns }) => {
|
}> = ({ asyncDelay, children, mockIndexPatterns }) => {
|
||||||
const indexPatterns = useMemo(
|
const indexPatterns = useMemo(
|
||||||
() =>
|
() => createIndexPatternsMock(asyncDelay, mockIndexPatterns.map(createIndexPatternMock)),
|
||||||
createIndexPatternsMock(
|
|
||||||
asyncDelay,
|
|
||||||
mockIndexPatterns.map(({ id, title, type = undefined, fields, timeFieldName }) => {
|
|
||||||
const indexPatternFields = fields.map((fieldSpec) => new IndexPatternField(fieldSpec));
|
|
||||||
|
|
||||||
return {
|
|
||||||
id,
|
|
||||||
title,
|
|
||||||
type,
|
|
||||||
getTimeField: () => indexPatternFields.find(({ name }) => name === timeFieldName),
|
|
||||||
isTimeBased: () => timeFieldName != null,
|
|
||||||
getFieldByName: (fieldName) =>
|
|
||||||
indexPatternFields.find(({ name }) => name === fieldName),
|
|
||||||
};
|
|
||||||
})
|
|
||||||
),
|
|
||||||
[asyncDelay, mockIndexPatterns]
|
[asyncDelay, mockIndexPatterns]
|
||||||
);
|
);
|
||||||
|
|
||||||
|
@ -71,7 +55,7 @@ export const MockIndexPatternsKibanaContextProvider: React.FC<{
|
||||||
);
|
);
|
||||||
};
|
};
|
||||||
|
|
||||||
const createIndexPatternsMock = (
|
export const createIndexPatternsMock = (
|
||||||
asyncDelay: number,
|
asyncDelay: number,
|
||||||
indexPatterns: MockIndexPattern[]
|
indexPatterns: MockIndexPattern[]
|
||||||
): {
|
): {
|
||||||
|
@ -93,3 +77,36 @@ const createIndexPatternsMock = (
|
||||||
},
|
},
|
||||||
};
|
};
|
||||||
};
|
};
|
||||||
|
|
||||||
|
export const createIndexPatternMock = ({
|
||||||
|
id,
|
||||||
|
title,
|
||||||
|
type = undefined,
|
||||||
|
fields,
|
||||||
|
timeFieldName,
|
||||||
|
}: MockIndexPatternSpec): MockIndexPattern => {
|
||||||
|
const indexPatternFields = fields.map((fieldSpec) => new IndexPatternField(fieldSpec));
|
||||||
|
|
||||||
|
return {
|
||||||
|
id,
|
||||||
|
title,
|
||||||
|
type,
|
||||||
|
getTimeField: () => indexPatternFields.find(({ name }) => name === timeFieldName),
|
||||||
|
isTimeBased: () => timeFieldName != null,
|
||||||
|
getFieldByName: (fieldName) => indexPatternFields.find(({ name }) => name === fieldName),
|
||||||
|
getComputedFields: () => ({
|
||||||
|
docvalueFields: [],
|
||||||
|
runtimeFields: indexPatternFields.reduce((accumulatedRuntimeFields, field) => {
|
||||||
|
if (field.runtimeField != null) {
|
||||||
|
return {
|
||||||
|
...accumulatedRuntimeFields,
|
||||||
|
[field.name]: field.runtimeField,
|
||||||
|
};
|
||||||
|
}
|
||||||
|
return accumulatedRuntimeFields;
|
||||||
|
}, {}),
|
||||||
|
scriptFields: {},
|
||||||
|
storedFields: [],
|
||||||
|
}),
|
||||||
|
};
|
||||||
|
};
|
||||||
|
|
Loading…
Reference in a new issue