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
Changes from 1 commit
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
Prev Previous commit
Next Next commit
Move default profile ad hoc data views to internal state
davismcphee committed Jan 22, 2025

Verified

This commit was created on GitHub.com and signed with GitHub’s verified signature.
commit deae60bf2fcf83130761aa2f1fff9356dc923d36
Original file line number Diff line number Diff line change
@@ -28,6 +28,7 @@ export interface InternalState {
isDataViewLoading: boolean;
savedDataViews: DataViewListItem[];
adHocDataViews: DataView[];
defaultProfileAdHocDataViewIds: string[];
expandedDoc: DataTableRecord | undefined;
customFilters: Filter[];
overriddenVisContextAfterInvalidation: UnifiedHistogramVisContext | {} | undefined; // it will be used during saved search saving
@@ -46,10 +47,12 @@ export interface InternalStateTransitions {
setIsDataViewLoading: (state: InternalState) => (isLoading: boolean) => InternalState;
setSavedDataViews: (state: InternalState) => (dataView: DataViewListItem[]) => InternalState;
setAdHocDataViews: (state: InternalState) => (dataViews: DataView[]) => InternalState;
setDefaultProfileAdHocDataViews: (
state: InternalState
) => (dataViews: DataView[]) => InternalState;
appendAdHocDataViews: (
state: InternalState
) => (dataViews: DataView | DataView[]) => InternalState;
removeAdHocDataViewById: (state: InternalState) => (id: string) => InternalState;
replaceAdHocDataViewWithId: (
state: InternalState
) => (id: string, dataView: DataView) => InternalState;
@@ -90,6 +93,7 @@ export function getInternalStateContainer() {
dataView: undefined,
isDataViewLoading: false,
adHocDataViews: [],
defaultProfileAdHocDataViewIds: [],
savedDataViews: [],
expandedDoc: undefined,
customFilters: [],
@@ -126,6 +130,22 @@ export function getInternalStateContainer() {
...prevState,
adHocDataViews: newAdHocDataViewList,
}),
setDefaultProfileAdHocDataViews:
(prevState: InternalState) => (defaultProfileAdHocDataViews: DataView[]) => {
const adHocDataViews = prevState.adHocDataViews
.filter((dataView) => !prevState.defaultProfileAdHocDataViewIds.includes(dataView.id!))
.concat(defaultProfileAdHocDataViews);

const defaultProfileAdHocDataViewIds = defaultProfileAdHocDataViews.map(
(dataView) => dataView.id!
);

return {
...prevState,
adHocDataViews,
defaultProfileAdHocDataViewIds,
};
},
appendAdHocDataViews:
(prevState: InternalState) => (dataViewsAdHoc: DataView | DataView[]) => {
// check for already existing data views
@@ -142,17 +162,24 @@ export function getInternalStateContainer() {
adHocDataViews: prevState.adHocDataViews.concat(dataViewsAdHoc),
};
},
removeAdHocDataViewById: (prevState: InternalState) => (id: string) => ({
...prevState,
adHocDataViews: prevState.adHocDataViews.filter((dataView) => dataView.id !== id),
}),
replaceAdHocDataViewWithId:
(prevState: InternalState) => (prevId: string, newDataView: DataView) => ({
...prevState,
adHocDataViews: prevState.adHocDataViews.map((dataView) =>
dataView.id === prevId ? newDataView : dataView
),
}),
(prevState: InternalState) => (prevId: string, newDataView: DataView) => {
let defaultProfileAdHocDataViewIds = prevState.defaultProfileAdHocDataViewIds;

if (defaultProfileAdHocDataViewIds.includes(prevId)) {
defaultProfileAdHocDataViewIds = defaultProfileAdHocDataViewIds.map((id) =>
id === prevId ? newDataView.id! : id
);
}

return {
...prevState,
adHocDataViews: prevState.adHocDataViews.map((dataView) =>
dataView.id === prevId ? newDataView : dataView
),
defaultProfileAdHocDataViewIds,
};
},
setExpandedDoc: (prevState: InternalState) => (expandedDoc: DataTableRecord | undefined) => ({
...prevState,
expandedDoc,
Original file line number Diff line number Diff line change
@@ -22,36 +22,33 @@ export const useDefaultAdHocDataViews = ({
rootProfileState: RootProfileState;
}) => {
const { dataViews } = useDiscoverServices();
const [prevProfileDataViewIds, setPrevProfileDataViewIds] = useState<string[]>([]);
const { internalState } = stateContainer;

const initializeDataViews = useLatest(async () => {
if (rootProfileState.rootProfileLoading) {
return;
}

// Clear the cache of old data views before creating
// the new ones to avoid cache hits on duplicate IDs
for (const prevId of internalState.get().defaultProfileAdHocDataViewIds) {
dataViews.clearInstanceCache(prevId);
}

const profileDataViewSpecs = rootProfileState.getDefaultAdHocDataViews();
const profileDataViews = await Promise.all(
profileDataViewSpecs.map((spec) => dataViews.create(spec, true))
);
const currentDataViews = stateContainer.internalState.getState().adHocDataViews;
const newDataViews = currentDataViews
.filter((dataView) => !prevProfileDataViewIds.includes(dataView.id!))
.concat(profileDataViews);

for (const prevId of prevProfileDataViewIds) {
dataViews.clearInstanceCache(prevId);
}

setPrevProfileDataViewIds(profileDataViews.map((dataView) => dataView.id!));
stateContainer.internalState.transitions.setAdHocDataViews(newDataViews);
internalState.transitions.setDefaultProfileAdHocDataViews(profileDataViews);
Copy link
Contributor

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Would be great to later also add these data views to ES|QL source autocomplete if possible.

Copy link
Contributor Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

In general having index patterns from data views in ES|QL autocomplete seems useful, but I don't think we support that at all yet. We have an issue for something similar with default ES|QL queries in Discover profiles, but it's not exactly the same: #186000.

});

// This approach allows us to return a callback with a stable reference
const [initializeProfileDataViews] = useState(() => () => initializeDataViews.current());

// Make sure to clean up on unmount
useUnmount(() => {
for (const prevId of prevProfileDataViewIds) {
for (const prevId of internalState.get().defaultProfileAdHocDataViewIds) {
dataViews.clearInstanceCache(prevId);
}
});