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

[One Discover] Breakdown by log.level for logs sources #200584

Merged
merged 23 commits into from
Nov 28, 2024
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
Show all changes
23 commits
Select commit Hold shift + click to select a range
04b3b7a
feat(discover): logs sources breakdown by log level
Nov 18, 2024
06d6dea
refactor(discover): re-use default state util
Nov 18, 2024
a6d896a
test(discover): update tests for default state context awareness
Nov 18, 2024
4101ad1
test(discover): remove exclusive suite
Nov 18, 2024
7072fec
test(discover): fix linter on async
Nov 19, 2024
542ceb9
test(discover): fix tests
Nov 19, 2024
d9474a0
Merge branch 'main' into 183498-breakown-by-log-level
tonyghiani Nov 19, 2024
e596248
test(discover): update tests description
Nov 19, 2024
1c8f3d9
test(discover): remove exclusive suite
Nov 19, 2024
3b4234f
Fix issue where onFetchRecordsComplete is called twice, and ensure fe…
davismcphee Nov 20, 2024
ed520ba
Fix additional fetches when setting default breakdown field
davismcphee Nov 20, 2024
0961f5f
Fixing types and temp skipping some tests
davismcphee Nov 20, 2024
b3249d3
Fix Unified Histogram breakdown field handling
davismcphee Nov 20, 2024
51c32e0
Correctly reset ES|QL profile state
davismcphee Nov 20, 2024
7908e4c
Only set default profile breakdown field if present in data view
davismcphee Nov 21, 2024
bef877d
Fix Jest tests
davismcphee Nov 21, 2024
fe987ea
Comments and cleanup
davismcphee Nov 21, 2024
73d31a8
Revert breakdownField prop change that broke tests
davismcphee Nov 21, 2024
0825111
Merge pull request #3 from davismcphee/fix-default-app-state-pr
tonyghiani Nov 22, 2024
85fd4b8
Merge branch 'main' into 183498-breakown-by-log-level
tonyghiani Nov 22, 2024
652632c
Merge branch 'main' into 183498-breakown-by-log-level
tonyghiani Nov 25, 2024
5c95fe7
Merge branch 'main' into 183498-breakown-by-log-level
tonyghiani Nov 26, 2024
e73a4ad
Merge branch 'main' into 183498-breakown-by-log-level
tonyghiani Nov 27, 2024
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
2 changes: 2 additions & 0 deletions src/plugins/discover/public/__mocks__/services.ts
Original file line number Diff line number Diff line change
Expand Up @@ -14,6 +14,7 @@ import { uiActionsPluginMock } from '@kbn/ui-actions-plugin/public/mocks';
import { expressionsPluginMock } from '@kbn/expressions-plugin/public/mocks';
import { savedSearchPluginMock } from '@kbn/saved-search-plugin/public/mocks';
import {
analyticsServiceMock,
chromeServiceMock,
coreMock,
docLinksServiceMock,
Expand Down Expand Up @@ -149,6 +150,7 @@ export function createDiscoverServicesMock(): DiscoverServices {
corePluginMock.chrome.getActiveSolutionNavId$.mockReturnValue(new BehaviorSubject(null));

return {
analytics: analyticsServiceMock.createAnalyticsServiceStart(),
application: corePluginMock.application,
core: corePluginMock,
charts: chartPluginMock.createSetupContract(),
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -97,7 +97,6 @@ describe('useDiscoverHistogram', () => {
stateContainer.appState.update({
interval: 'auto',
hideChart: false,
breakdownField: 'extension',
});
const appState = stateContainer.appState;
const wrappedStateContainer = Object.create(appState);
Expand Down Expand Up @@ -166,7 +165,6 @@ describe('useDiscoverHistogram', () => {
expect(Object.keys(params?.initialState ?? {})).toEqual([
'chartHidden',
'timeInterval',
'breakdownField',
'totalHitsStatus',
'totalHitsResult',
]);
Expand Down Expand Up @@ -204,7 +202,6 @@ describe('useDiscoverHistogram', () => {
const state = {
timeInterval: '1m',
chartHidden: true,
breakdownField: 'test',
totalHitsStatus: UnifiedHistogramFetchStatus.loading,
totalHitsResult: undefined,
} as unknown as UnifiedHistogramState;
Expand All @@ -217,7 +214,6 @@ describe('useDiscoverHistogram', () => {
expect(stateContainer.appState.update).toHaveBeenCalledWith({
interval: state.timeInterval,
hideChart: state.chartHidden,
breakdownField: state.breakdownField,
});
});

Expand All @@ -228,7 +224,6 @@ describe('useDiscoverHistogram', () => {
const state = {
timeInterval: containerState.interval,
chartHidden: containerState.hideChart,
breakdownField: containerState.breakdownField,
totalHitsStatus: UnifiedHistogramFetchStatus.loading,
totalHitsResult: undefined,
} as unknown as UnifiedHistogramState;
Expand All @@ -254,18 +249,14 @@ describe('useDiscoverHistogram', () => {
api.setTimeInterval = jest.fn((timeInterval) => {
params = { ...params, timeInterval };
});
api.setBreakdownField = jest.fn((breakdownField) => {
params = { ...params, breakdownField };
});
act(() => {
hook.result.current.ref(api);
});
stateContainer.appState.update({ hideChart: true, interval: '1m', breakdownField: 'test' });
stateContainer.appState.update({ hideChart: true, interval: '1m' });
expect(api.setTotalHits).not.toHaveBeenCalled();
expect(api.setChartHidden).toHaveBeenCalled();
expect(api.setTimeInterval).toHaveBeenCalled();
expect(api.setBreakdownField).toHaveBeenCalled();
expect(Object.keys(params ?? {})).toEqual(['breakdownField', 'timeInterval', 'chartHidden']);
expect(Object.keys(params ?? {})).toEqual(['timeInterval', 'chartHidden']);
});

it('should exclude totalHitsStatus and totalHitsResult from Unified Histogram state updates', async () => {
Expand All @@ -275,7 +266,6 @@ describe('useDiscoverHistogram', () => {
const state = {
timeInterval: containerState.interval,
chartHidden: containerState.hideChart,
breakdownField: containerState.breakdownField,
totalHitsStatus: UnifiedHistogramFetchStatus.loading,
totalHitsResult: undefined,
} as unknown as UnifiedHistogramState;
Expand Down Expand Up @@ -310,7 +300,6 @@ describe('useDiscoverHistogram', () => {
const state = {
timeInterval: containerState.interval,
chartHidden: containerState.hideChart,
breakdownField: containerState.breakdownField,
totalHitsStatus: UnifiedHistogramFetchStatus.loading,
totalHitsResult: undefined,
} as unknown as UnifiedHistogramState;
Expand Down Expand Up @@ -355,7 +344,6 @@ describe('useDiscoverHistogram', () => {
const state = {
timeInterval: containerState.interval,
chartHidden: containerState.hideChart,
breakdownField: containerState.breakdownField,
totalHitsStatus: UnifiedHistogramFetchStatus.loading,
totalHitsResult: undefined,
} as unknown as UnifiedHistogramState;
Expand All @@ -381,63 +369,39 @@ describe('useDiscoverHistogram', () => {
});

it('should set isChartLoading to true for fetch start', async () => {
const fetch$ = new Subject<{
options: {
reset: boolean;
fetchMore: boolean;
};
searchSessionId: string;
}>();
const fetch$ = new Subject<void>();
const stateContainer = getStateContainer();
stateContainer.appState.update({ query: { esql: 'from *' } });
stateContainer.dataState.fetch$ = fetch$;
stateContainer.dataState.fetchChart$ = fetch$;
const { hook } = await renderUseDiscoverHistogram({ stateContainer });
act(() => {
fetch$.next({
options: { reset: false, fetchMore: false },
searchSessionId: '1234',
});
fetch$.next();
});
expect(hook.result.current.isChartLoading).toBe(true);
});
});

describe('refetching', () => {
it('should call refetch when savedSearchFetch$ is triggered', async () => {
const savedSearchFetch$ = new Subject<{
options: {
reset: boolean;
fetchMore: boolean;
};
searchSessionId: string;
}>();
const savedSearchFetch$ = new Subject<void>();
const stateContainer = getStateContainer();
stateContainer.dataState.fetch$ = savedSearchFetch$;
stateContainer.dataState.fetchChart$ = savedSearchFetch$;
const { hook } = await renderUseDiscoverHistogram({ stateContainer });
const api = createMockUnifiedHistogramApi();
act(() => {
hook.result.current.ref(api);
});
expect(api.refetch).toHaveBeenCalled();
act(() => {
savedSearchFetch$.next({
options: { reset: false, fetchMore: false },
searchSessionId: '1234',
});
savedSearchFetch$.next();
});
expect(api.refetch).toHaveBeenCalledTimes(2);
});

it('should skip the next refetch when hideChart changes from true to false', async () => {
const savedSearchFetch$ = new Subject<{
options: {
reset: boolean;
fetchMore: boolean;
};
searchSessionId: string;
}>();
const savedSearchFetch$ = new Subject<void>();
const stateContainer = getStateContainer();
stateContainer.dataState.fetch$ = savedSearchFetch$;
stateContainer.dataState.fetchChart$ = savedSearchFetch$;
const { hook, initialProps } = await renderUseDiscoverHistogram({ stateContainer });
const api = createMockUnifiedHistogramApi();
act(() => {
Expand All @@ -451,45 +415,9 @@ describe('useDiscoverHistogram', () => {
hook.rerender({ ...initialProps, hideChart: false });
});
act(() => {
savedSearchFetch$.next({
options: { reset: false, fetchMore: false },
searchSessionId: '1234',
});
});
expect(api.refetch).toHaveBeenCalledTimes(1);
});

it('should skip the next refetch when fetching more', async () => {
const savedSearchFetch$ = new Subject<{
options: {
reset: boolean;
fetchMore: boolean;
};
searchSessionId: string;
}>();
const stateContainer = getStateContainer();
stateContainer.dataState.fetch$ = savedSearchFetch$;
const { hook } = await renderUseDiscoverHistogram({ stateContainer });
const api = createMockUnifiedHistogramApi();
act(() => {
hook.result.current.ref(api);
});
expect(api.refetch).toHaveBeenCalledTimes(1);
act(() => {
savedSearchFetch$.next({
options: { reset: false, fetchMore: true },
searchSessionId: '1234',
});
savedSearchFetch$.next();
});
expect(api.refetch).toHaveBeenCalledTimes(1);

act(() => {
savedSearchFetch$.next({
options: { reset: false, fetchMore: false },
searchSessionId: '1234',
});
});
expect(api.refetch).toHaveBeenCalledTimes(2);
});
});

Expand Down
Loading