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

[Discover] Add a default "All logs" temporary data view in the Observability Solution view #205991

Merged
Merged
Show file tree
Hide file tree
Changes from 30 commits
Commits
Show all changes
33 commits
Select commit Hold shift + click to select a range
8cd7089
Initial getDefaultAdHocDataViews extension
davismcphee Jan 9, 2025
c146fac
Finish initial implementation
davismcphee Jan 10, 2025
79f0ec0
Fix types
davismcphee Jan 10, 2025
13db01c
Add useDefaultAdHocDataViews hook
davismcphee Jan 10, 2025
deae60b
Move default profile ad hoc data views to internal state
davismcphee Jan 10, 2025
0e8f21c
Fix types and tests
davismcphee Jan 13, 2025
3f9bdba
Fix broken test
davismcphee Jan 17, 2025
255fff2
Fix broken test
davismcphee Jan 18, 2025
7770cc0
Update default o11y logs data view
davismcphee Jan 18, 2025
f79ef92
Fix Jest test
davismcphee Jan 20, 2025
f3d14f0
Remove CCS special handling
davismcphee Jan 20, 2025
dfdbf94
Update implementation and add tests
davismcphee Jan 20, 2025
e45a53a
Fix profile data view fields loading, and clean up resolve_data_view
davismcphee Jan 21, 2025
a411d60
Duplicate default profile data view on saved search change
davismcphee Jan 22, 2025
c3d1bd6
Add Jest test
davismcphee Jan 22, 2025
5ac5cfc
Add more tests
davismcphee Jan 22, 2025
1f372b2
Fix missing fields when changing data view
davismcphee Jan 22, 2025
c430307
Add functional tests
davismcphee Jan 22, 2025
3db6ffb
Fix test skips
davismcphee Jan 22, 2025
c665e5c
Updating comments
davismcphee Jan 22, 2025
76e11f4
Merge branch 'main' into discover-ad-hoc-data-views-extension
davismcphee Jan 23, 2025
c2328cd
Merge branch 'main' into discover-ad-hoc-data-views-extension
davismcphee Jan 23, 2025
0d803a7
Use Discover session title instead of 'copy' for cloned default profi…
davismcphee Jan 23, 2025
ad21e3d
Clean up logic around no data page check
davismcphee Jan 23, 2025
0b7d4ee
Allow overwriting default profile data views with spec in location state
davismcphee Jan 24, 2025
ebd3cb6
Update filter references when saving session with default profiel dat…
davismcphee Jan 24, 2025
c4d8168
Fix type
davismcphee Jan 24, 2025
751f366
Add support for showing managed data views in the data view picker
davismcphee Jan 25, 2025
af6171f
Merge branch 'main' into discover-ad-hoc-data-views-extension
davismcphee Jan 25, 2025
641c013
Fix Jest tests
davismcphee Jan 25, 2025
ed79553
Merge branch 'main' into discover-ad-hoc-data-views-extension
davismcphee Jan 27, 2025
991548e
Allow sidebar URL tracking for default profile data views
davismcphee Jan 27, 2025
7306fc1
Add test for getDefaultAdHocDataViews
davismcphee Jan 27, 2025
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 @@ -10,5 +10,8 @@
import { DEFAULT_ALLOWED_LOGS_BASE_PATTERNS_REGEXP, getLogsContextService } from '../data_types';

export const createLogsContextServiceMock = () => {
return getLogsContextService([DEFAULT_ALLOWED_LOGS_BASE_PATTERNS_REGEXP]);
return getLogsContextService({
allLogsIndexPattern: 'logs-*',
allowedDataSources: [DEFAULT_ALLOWED_LOGS_BASE_PATTERNS_REGEXP],
});
};
Original file line number Diff line number Diff line change
Expand Up @@ -11,6 +11,7 @@ import { createRegExpPatternFrom, testPatternAgainstAllowedList } from '@kbn/dat
import type { LogsDataAccessPluginStart } from '@kbn/logs-data-access-plugin/public';

export interface LogsContextService {
getAllLogsIndexPattern(): string | undefined;
isLogsIndexPattern(indexPattern: unknown): boolean;
}

Expand All @@ -32,34 +33,45 @@ export const DEFAULT_ALLOWED_LOGS_BASE_PATTERNS_REGEXP = createRegExpPatternFrom
'data'
);

export const createLogsContextService = async ({ logsDataAccess }: LogsContextServiceDeps) => {
export const createLogsContextService = async ({
logsDataAccess,
}: LogsContextServiceDeps): Promise<LogsContextService> => {
let allLogsIndexPattern: string | undefined;
let logSources: string[] | undefined;

if (logsDataAccess) {
const logSourcesService = logsDataAccess.services.logSourcesService;
logSources = (await logSourcesService.getLogSources())
allLogsIndexPattern = (await logSourcesService.getLogSources())
.map((logSource) => logSource.indexPattern)
.join(',') // TODO: Will be replaced by helper in: https://github.com/elastic/kibana/pull/192003
.split(',');
.join(','); // TODO: Will be replaced by helper in: https://github.com/elastic/kibana/pull/192003
logSources = allLogsIndexPattern.split(',');
}

const ALLOWED_LOGS_DATA_SOURCES = [
DEFAULT_ALLOWED_LOGS_BASE_PATTERNS_REGEXP,
...(logSources ? logSources : []),
];

return getLogsContextService(ALLOWED_LOGS_DATA_SOURCES);
return getLogsContextService({
allLogsIndexPattern,
allowedDataSources: ALLOWED_LOGS_DATA_SOURCES,
});
};

export const getLogsContextService = (allowedDataSources: Array<string | RegExp>) => {
export const getLogsContextService = ({
allLogsIndexPattern,
allowedDataSources,
}: {
allLogsIndexPattern: string | undefined;
allowedDataSources: Array<string | RegExp>;
}): LogsContextService => {
const getAllLogsIndexPattern = () => allLogsIndexPattern;
const isLogsIndexPattern = (indexPattern: unknown) => {
return (
typeof indexPattern === 'string' &&
testPatternAgainstAllowedList(allowedDataSources)(indexPattern)
);
};

return {
isLogsIndexPattern,
};
return { getAllLogsIndexPattern, isLogsIndexPattern };
};
1 change: 1 addition & 0 deletions src/platform/packages/shared/kbn-es-query/index.ts
Original file line number Diff line number Diff line change
Expand Up @@ -104,6 +104,7 @@ export {
uniqFilters,
unpinFilter,
updateFilter,
updateFilterReferences,
extractTimeFilter,
extractTimeRange,
convertRangeFilterToTimeRange,
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -15,4 +15,5 @@ export * from './meta_filter';
export * from './only_disabled';
export * from './extract_time_filter';
export * from './convert_range_filter';
export * from './update_filter_references';
export * from './types';
Original file line number Diff line number Diff line change
@@ -0,0 +1,30 @@
/*
* Copyright Elasticsearch B.V. and/or licensed to Elasticsearch B.V. under one
* or more contributor license agreements. Licensed under the "Elastic License
* 2.0", the "GNU Affero General Public License v3.0 only", and the "Server Side
* Public License v 1"; you may not use this file except in compliance with, at
* your election, the "Elastic License 2.0", the "GNU Affero General Public
* License v3.0 only", or the "Server Side Public License, v 1".
*/

import { Filter } from '..';

export function updateFilterReferences(
filters: Filter[],
fromDataView: string,
toDataView: string | undefined
) {
return (filters || []).map((filter) => {
if (filter.meta.index === fromDataView) {
return {
...filter,
meta: {
...filter.meta,
index: toDataView,
},
};
} else {
return filter;
}
});
}
Original file line number Diff line number Diff line change
Expand Up @@ -31,6 +31,7 @@ export {
extractTimeFilter,
extractTimeRange,
convertRangeFilterToTimeRange,
updateFilterReferences,
} from './helpers';

export {
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -34,6 +34,7 @@ import { buildDataTableRecord } from '@kbn/discover-utils';
import type { DataTableRecord } from '@kbn/discover-utils/types';
import type { DiscoverCustomizationId } from '../../../../customizations/customization_service';
import { FieldListCustomization, SearchBarCustomization } from '../../../../customizations';
import { InternalStateProvider } from '../../state_management/discover_internal_state_container';

const mockSearchBarCustomization: SearchBarCustomization = {
id: 'search_bar',
Expand Down Expand Up @@ -177,13 +178,13 @@ function getCompProps(options?: { hits?: DataTableRecord[] }): DiscoverSidebarRe
};
}

function getAppStateContainer({ query }: { query?: Query | AggregateQuery }) {
const appStateContainer = getDiscoverStateMock({ isTimeBased: true }).appState;
appStateContainer.set({
function getStateContainer({ query }: { query?: Query | AggregateQuery }) {
const stateContainer = getDiscoverStateMock({ isTimeBased: true });
stateContainer.appState.set({
query: query ?? { query: '', language: 'lucene' },
filters: [],
});
return appStateContainer;
return stateContainer;
}

async function mountComponent(
Expand All @@ -192,7 +193,7 @@ async function mountComponent(
services?: DiscoverServices
): Promise<ReactWrapper<DiscoverSidebarResponsiveProps>> {
let comp: ReactWrapper<DiscoverSidebarResponsiveProps>;
const appState = getAppStateContainer(appStateParams);
const { appState, internalState } = getStateContainer(appStateParams);
const mockedServices = services ?? createMockServices();
mockedServices.data.dataViews.getIdsWithTitle = jest.fn(async () =>
props.selectedDataView
Expand All @@ -208,7 +209,9 @@ async function mountComponent(
comp = mountWithIntl(
<KibanaContextProvider services={mockedServices}>
<DiscoverAppStateProvider value={appState}>
<DiscoverSidebarResponsive {...props} />
<InternalStateProvider value={internalState}>
<DiscoverSidebarResponsive {...props} />
</InternalStateProvider>
</DiscoverAppStateProvider>
</KibanaContextProvider>
);
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -37,6 +37,10 @@ import {
import { useDiscoverCustomization } from '../../../../customizations';
import { useAdditionalFieldGroups } from '../../hooks/sidebar/use_additional_field_groups';
import { useIsEsqlMode } from '../../hooks/use_is_esql_mode';
import {
selectDataViewsForPicker,
useInternalStateSelector,
} from '../../state_management/discover_internal_state_container';

const EMPTY_FIELD_COUNTS = {};

Expand Down Expand Up @@ -172,6 +176,8 @@ export function DiscoverSidebarResponsive(props: DiscoverSidebarResponsiveProps)
);
const selectedDataViewRef = useRef<DataView | null | undefined>(selectedDataView);
const showFieldList = sidebarState.status !== DiscoverSidebarReducerStatus.INITIAL;
const { savedDataViews, managedDataViews, adHocDataViews } =
useInternalStateSelector(selectDataViewsForPicker);

useEffect(() => {
const subscription = props.documents$.subscribe((documentState) => {
Expand Down Expand Up @@ -326,6 +332,9 @@ export function DiscoverSidebarResponsive(props: DiscoverSidebarResponsiveProps)
) : (
<DataViewPicker
currentDataViewId={selectedDataView.id}
adHocDataViews={adHocDataViews}
managedDataViews={managedDataViews}
savedDataViews={savedDataViews}
onChangeDataView={onChangeDataView}
onAddField={createField}
onDataViewCreated={createNewDataView}
Expand All @@ -338,7 +347,16 @@ export function DiscoverSidebarResponsive(props: DiscoverSidebarResponsiveProps)
/>
)
) : null;
}, [selectedDataView, createNewDataView, onChangeDataView, createField, CustomDataViewPicker]);
}, [
selectedDataView,
CustomDataViewPicker,
adHocDataViews,
managedDataViews,
savedDataViews,
onChangeDataView,
createField,
createNewDataView,
]);

const onAddFieldToWorkspace = useCallback(
(field: DataViewField) => {
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -15,7 +15,10 @@ import { TextBasedLanguages } from '@kbn/esql-utils';
import { DiscoverFlyouts, dismissAllFlyoutsExceptFor } from '@kbn/discover-utils';
import { useSavedSearchInitial } from '../../state_management/discover_state_provider';
import { ESQL_TRANSITION_MODAL_KEY } from '../../../../../common/constants';
import { useInternalStateSelector } from '../../state_management/discover_internal_state_container';
import {
selectDataViewsForPicker,
useInternalStateSelector,
} from '../../state_management/discover_internal_state_container';
import { useDiscoverServices } from '../../../../hooks/use_discover_services';
import type { DiscoverStateContainer } from '../../state_management/discover_state';
import { onSaveSearch } from './on_save_search';
Expand Down Expand Up @@ -49,9 +52,9 @@ export const DiscoverTopNav = ({
const { dataViewEditor, navigation, dataViewFieldEditor, data, uiSettings, setHeaderActionMenu } =
services;
const query = useAppStateSelector((state) => state.query);
const adHocDataViews = useInternalStateSelector((state) => state.adHocDataViews);
const { savedDataViews, managedDataViews, adHocDataViews } =
useInternalStateSelector(selectDataViewsForPicker);
const dataView = useInternalStateSelector((state) => state.dataView!);
const savedDataViews = useInternalStateSelector((state) => state.savedDataViews);
const isESQLToDataViewTransitionModalVisible = useInternalStateSelector(
(state) => state.isESQLToDataViewTransitionModalVisible
);
Expand Down Expand Up @@ -180,9 +183,7 @@ export const DiscoverTopNav = ({

const dataViewPickerProps: DataViewPickerProps = useMemo(() => {
const isESQLModeEnabled = uiSettings.get(ENABLE_ESQL);
const supportedTextBasedLanguages: DataViewPickerProps['textBasedLanguages'] = isESQLModeEnabled
? [TextBasedLanguages.ESQL]
: [];
const supportedTextBasedLanguages = isESQLModeEnabled ? [TextBasedLanguages.ESQL] : [];

return {
trigger: {
Expand All @@ -197,6 +198,7 @@ export const DiscoverTopNav = ({
onChangeDataView: stateContainer.actions.onChangeDataView,
textBasedLanguages: supportedTextBasedLanguages,
adHocDataViews,
managedDataViews,
savedDataViews,
onEditDataView: stateContainer.actions.onDataViewEdited,
};
Expand All @@ -205,6 +207,7 @@ export const DiscoverTopNav = ({
addField,
createNewDataView,
dataView,
managedDataViews,
savedDataViews,
stateContainer,
uiSettings,
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -72,6 +72,7 @@ describe('test fetchAll', () => {
isDataViewLoading: false,
savedDataViews: [],
adHocDataViews: [],
defaultProfileAdHocDataViewIds: [],
expandedDoc: undefined,
customFilters: [],
overriddenVisContextAfterInvalidation: undefined,
Expand Down Expand Up @@ -265,6 +266,7 @@ describe('test fetchAll', () => {
isDataViewLoading: false,
savedDataViews: [],
adHocDataViews: [],
defaultProfileAdHocDataViewIds: [],
expandedDoc: undefined,
customFilters: [],
overriddenVisContextAfterInvalidation: undefined,
Expand Down Expand Up @@ -389,6 +391,7 @@ describe('test fetchAll', () => {
isDataViewLoading: false,
savedDataViews: [],
adHocDataViews: [],
defaultProfileAdHocDataViewIds: [],
expandedDoc: undefined,
customFilters: [],
overriddenVisContextAfterInvalidation: undefined,
Expand Down
Loading