Skip to content

Commit

Permalink
[8.x] [One Discover] Breakdown by log.level for logs sources (elastic…
Browse files Browse the repository at this point in the history
…#200584) (elastic#202105)

# Backport

This will backport the following commits from `main` to `8.x`:
- [[One Discover] Breakdown by log.level for logs sources
(elastic#200584)](elastic#200584)

<!--- Backport version: 8.9.8 -->

### Questions ?
Please refer to the [Backport tool
documentation](https://github.com/sqren/backport)

<!--BACKPORT [{"author":{"name":"Marco Antonio
Ghiani","email":"marcoantonio.ghiani01@gmail.com"},"sourceCommit":{"committedDate":"2024-11-28T08:12:47Z","message":"[One
Discover] Breakdown by log.level for logs sources (elastic#200584)\n\n## 📓
Summary\r\n\r\nCloses elastic#183498 \r\n\r\nThis work sets the Breakdown
selector for the Histogram to the\r\n`log.level` field once a logs data
source is resolved.\r\nIt also applies to ES|QL queries, the change is
applied/removed on each\r\nsource
change.\r\n\r\n---------\r\n\r\nCo-authored-by: Marco Antonio Ghiani
<marcoantonio.ghiani@elastic.co>\r\nCo-authored-by: Davis McPhee
<davis.mcphee@elastic.co>","sha":"ac6025eaa1b5e0e733bab0110b60928e27ee6860","branchLabelMapping":{"^v9.0.0$":"main","^v8.18.0$":"8.x","^v(\\d+).(\\d+).\\d+$":"$1.$2"}},"sourcePullRequest":{"labels":["release_note:skip","v9.0.0","Team:DataDiscovery","backport:prev-minor","Team:obs-ux-logs","Project:OneDiscover"],"number":200584,"url":"https://github.com/elastic/kibana/pull/200584","mergeCommit":{"message":"[One
Discover] Breakdown by log.level for logs sources (elastic#200584)\n\n## 📓
Summary\r\n\r\nCloses elastic#183498 \r\n\r\nThis work sets the Breakdown
selector for the Histogram to the\r\n`log.level` field once a logs data
source is resolved.\r\nIt also applies to ES|QL queries, the change is
applied/removed on each\r\nsource
change.\r\n\r\n---------\r\n\r\nCo-authored-by: Marco Antonio Ghiani
<marcoantonio.ghiani@elastic.co>\r\nCo-authored-by: Davis McPhee
<davis.mcphee@elastic.co>","sha":"ac6025eaa1b5e0e733bab0110b60928e27ee6860"}},"sourceBranch":"main","suggestedTargetBranches":[],"targetPullRequestStates":[{"branch":"main","label":"v9.0.0","labelRegex":"^v9.0.0$","isSourceBranch":true,"state":"MERGED","url":"https://github.com/elastic/kibana/pull/200584","number":200584,"mergeCommit":{"message":"[One
Discover] Breakdown by log.level for logs sources (elastic#200584)\n\n## 📓
Summary\r\n\r\nCloses elastic#183498 \r\n\r\nThis work sets the Breakdown
selector for the Histogram to the\r\n`log.level` field once a logs data
source is resolved.\r\nIt also applies to ES|QL queries, the change is
applied/removed on each\r\nsource
change.\r\n\r\n---------\r\n\r\nCo-authored-by: Marco Antonio Ghiani
<marcoantonio.ghiani@elastic.co>\r\nCo-authored-by: Davis McPhee
<davis.mcphee@elastic.co>","sha":"ac6025eaa1b5e0e733bab0110b60928e27ee6860"}}]}]
BACKPORT-->
  • Loading branch information
tonyghiani authored Nov 28, 2024
1 parent f27ff7b commit 2850e29
Show file tree
Hide file tree
Showing 33 changed files with 557 additions and 370 deletions.
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

0 comments on commit 2850e29

Please sign in to comment.