Skip to content

Commit

Permalink
[Logs UI] Fix the LogStream story to work with KIPs (#100862)
Browse files Browse the repository at this point in the history
Co-authored-by: Kibana Machine <42973632+kibanamachine@users.noreply.github.com>
  • Loading branch information
weltenwort and kibanamachine authored Jun 4, 2021
1 parent 7b4b713 commit 081cf98
Show file tree
Hide file tree
Showing 2 changed files with 84 additions and 21 deletions.
Original file line number Diff line number Diff line change
Expand Up @@ -3,10 +3,11 @@ import { defer, of, Subject } from 'rxjs';
import { delay } from 'rxjs/operators';

import { I18nProvider } from '@kbn/i18n/react';
import { KBN_FIELD_TYPES } from '../../../../../../src/plugins/data/public';
import { EuiThemeProvider } from '../../../../../../src/plugins/kibana_react/common';
import { KibanaContextProvider } from '../../../../../../src/plugins/kibana_react/public';

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 { generateFakeEntries, ENTRIES_EMPTY } from '../../test_utils/entries';

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

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: ({ params }, options) => {
return defer(() => {
Expand Down Expand Up @@ -68,10 +108,16 @@ export const dataMock = {
};


export const fetch = function (url, params) {
export const fetch = async function (url, params) {
switch (url) {
case '/api/infra/log_source_configurations/default':
return DEFAULT_SOURCE_CONFIGURATION;
case '/api/infra/log_source_configurations/default/status':
return {
data: {
logIndexStatus: 'available',
}
};
default:
return {};
}
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -21,7 +21,7 @@ import { Pick2 } from '../../common/utility_types';

type MockIndexPattern = Pick<
IndexPattern,
'id' | 'title' | 'type' | 'getTimeField' | 'isTimeBased' | 'getFieldByName'
'id' | 'title' | 'type' | 'getTimeField' | 'isTimeBased' | 'getFieldByName' | 'getComputedFields'
>;
export type MockIndexPatternSpec = Pick<
IIndexPattern,
Expand All @@ -35,23 +35,7 @@ export const MockIndexPatternsKibanaContextProvider: React.FC<{
mockIndexPatterns: MockIndexPatternSpec[];
}> = ({ asyncDelay, children, mockIndexPatterns }) => {
const indexPatterns = useMemo(
() =>
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),
};
})
),
() => createIndexPatternsMock(asyncDelay, mockIndexPatterns.map(createIndexPatternMock)),
[asyncDelay, mockIndexPatterns]
);

Expand All @@ -71,7 +55,7 @@ export const MockIndexPatternsKibanaContextProvider: React.FC<{
);
};

const createIndexPatternsMock = (
export const createIndexPatternsMock = (
asyncDelay: number,
indexPatterns: MockIndexPattern[]
): {
Expand All @@ -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: [],
}),
};
};

0 comments on commit 081cf98

Please sign in to comment.