Skip to content

Commit

Permalink
Use a real DataView reference with derivedDataView
Browse files Browse the repository at this point in the history
  • Loading branch information
Kerry350 committed Oct 20, 2022
1 parent 96d17b0 commit a395d27
Show file tree
Hide file tree
Showing 7 changed files with 24 additions and 15 deletions.
Original file line number Diff line number Diff line change
Expand Up @@ -10,6 +10,13 @@ import { createStubDataView } from '@kbn/data-views-plugin/common/stubs';
import { defaultLogViewsStaticConfig } from './defaults';
import { ResolvedLogView, resolveLogView } from './resolved_log_view';
import { LogViewAttributes } from './types';
import { DataView } from '@kbn/data-views-plugin/common';

const dataViewMock = {
id: 'log-view-data-view-mock',
title: 'log-view-data-view-mock-title',
fields: [],
} as unknown as DataView;

export const createResolvedLogViewMock = (
resolvedLogViewOverrides: Partial<ResolvedLogView> = {}
Expand Down Expand Up @@ -41,6 +48,7 @@ export const createResolvedLogViewMock = (
messageColumn: { id: 'MESSAGE_COLUMN_ID' },
},
],
dataViewReference: dataViewMock,
...resolvedLogViewOverrides,
});

Expand Down
9 changes: 9 additions & 0 deletions x-pack/plugins/infra/common/log_views/resolved_log_view.ts
Original file line number Diff line number Diff line change
Expand Up @@ -23,6 +23,7 @@ export interface ResolvedLogView {
fields: ResolvedLogViewField[];
runtimeMappings: estypes.MappingRuntimeFields;
columns: LogViewColumnConfiguration[];
dataViewReference: DataView;
}

export const resolveLogView = async (
Expand Down Expand Up @@ -60,6 +61,12 @@ const resolveLegacyReference = async (
);
});

const dataViewReference = await dataViewsService.create({
id: '___InfraLogsLegacyLogViewReference___',
title: logViewAttributes.logIndices.indexName,
timeFieldName: TIMESTAMP_FIELD,
});

return {
indices: logViewAttributes.logIndices.indexName,
timestampField: TIMESTAMP_FIELD,
Expand All @@ -70,6 +77,7 @@ const resolveLegacyReference = async (
columns: logViewAttributes.logColumns,
name: logViewAttributes.name,
description: logViewAttributes.description,
dataViewReference,
};
};

Expand Down Expand Up @@ -97,6 +105,7 @@ const resolveDataViewReference = async (
columns: logViewAttributes.logColumns,
name: logViewAttributes.name,
description: logViewAttributes.description,
dataViewReference: dataView,
};
};

Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -7,11 +7,11 @@

import { buildEsQuery, Filter, Query } from '@kbn/es-query';
import { JsonValue } from '@kbn/utility-types';
import { noop } from 'lodash';
import React, { useCallback, useEffect, useMemo } from 'react';
import { DataPublicPluginStart } from '@kbn/data-plugin/public';
import { euiStyled } from '@kbn/kibana-react-plugin/common';
import { useKibana } from '@kbn/kibana-react-plugin/public';
import { noop } from 'lodash';
import { LogEntryCursor } from '../../../common/log_entry';
import { defaultLogViewsStaticConfig } from '../../../common/log_views';
import { BuiltEsQuery, useLogStream } from '../../containers/logs/log_stream';
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -53,7 +53,7 @@ const unsupportedLanguageError = i18n.translate(
}
);

export const useLogFilterState = ({ indexPattern }: { indexPattern: DataViewBase }) => {
export const useLogFilterState = ({ indexPattern }: { indexPattern?: DataViewBase }) => {
const {
notifications: { toasts },
data: {
Expand Down
5 changes: 1 addition & 4 deletions x-pack/plugins/infra/public/hooks/use_log_view.mock.ts
Original file line number Diff line number Diff line change
Expand Up @@ -17,10 +17,7 @@ const defaultLogViewId = 'default';
export const createUninitializedUseLogViewMock =
(logViewId: string = defaultLogViewId) =>
(): IUseLogView => ({
derivedDataView: {
fields: [],
title: 'unknown',
},
derivedDataView: undefined,
hasFailedLoading: false,
hasFailedLoadingLogView: false,
hasFailedLoadingLogViewStatus: false,
Expand Down
10 changes: 3 additions & 7 deletions x-pack/plugins/infra/public/hooks/use_log_view.ts
Original file line number Diff line number Diff line change
Expand Up @@ -63,13 +63,9 @@ export const useLogView = ({
[logViews]
);

const derivedDataView = useMemo(
() => ({
fields: resolvedLogView?.fields ?? [],
title: resolvedLogView?.indices ?? 'unknown',
}),
[resolvedLogView]
);
const derivedDataView = useMemo(() => {
return resolvedLogView?.dataViewReference;
}, [resolvedLogView]);

const isLoadingLogView = loadLogViewRequest.state === 'pending';
const isResolvingLogView = resolveLogViewRequest.state === 'pending';
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -8,7 +8,6 @@
import { EuiFlexGroup, EuiFlexItem } from '@elastic/eui';
import { i18n } from '@kbn/i18n';
import React from 'react';
import { DataView } from '@kbn/data-views-plugin/public';
import { euiStyled } from '@kbn/kibana-react-plugin/common';
import { useKibanaContextForPlugin } from '../../../hooks/use_kibana';
import { LogCustomizationMenu } from '../../../components/logging/log_customization_menu';
Expand Down Expand Up @@ -62,7 +61,7 @@ export const LogsToolbar = () => {
defaultMessage: 'Search for log entries… (e.g. host.name:host-1)',
})}
useDefaultBehaviors={true}
indexPatterns={[derivedDataView as DataView]}
indexPatterns={derivedDataView ? [derivedDataView] : undefined}
showQueryInput={true}
showQueryMenu={false}
showFilterBar={false}
Expand Down

0 comments on commit a395d27

Please sign in to comment.