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

[7.x] [Logs UI] Fix the LogStream story to work with KIPs (#100862) #101415

Merged
merged 1 commit into from
Jun 4, 2021
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
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
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: [],
}),
};
};