-
Notifications
You must be signed in to change notification settings - Fork 8.3k
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
[ML] Fix time range adjustment for the swim lane causing the infinite…
… loop update (#86461) * [ML] fix swim lane time selection adjustment * [ML] fix adjustment * [ML] fix tooManyBuckets condition * [ML] fix typo
- Loading branch information
Showing
6 changed files
with
219 additions
and
42 deletions.
There are no files selected for viewing
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
|
@@ -5,3 +5,4 @@ | |
*/ | ||
|
||
export { useMlKibana } from './kibana_context'; | ||
export { useTimefilter } from './use_timefilter'; |
40 changes: 40 additions & 0 deletions
40
x-pack/plugins/ml/public/application/contexts/kibana/__mocks__/use_timefilter.ts
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,40 @@ | ||
/* | ||
* Copyright Elasticsearch B.V. and/or licensed to Elasticsearch B.V. under one | ||
* or more contributor license agreements. Licensed under the Elastic License; | ||
* you may not use this file except in compliance with the Elastic License. | ||
*/ | ||
|
||
import { TimefilterContract } from '../../../../../../../../src/plugins/data/public'; | ||
import { Observable } from 'rxjs'; | ||
|
||
/** | ||
* Copy from {@link '../../../../../../../../src/plugins/data/public/query/timefilter/timefilter_service.mock'} | ||
*/ | ||
const timefilterMock: jest.Mocked<TimefilterContract> = { | ||
isAutoRefreshSelectorEnabled: jest.fn(), | ||
isTimeRangeSelectorEnabled: jest.fn(), | ||
isTimeTouched: jest.fn(), | ||
getEnabledUpdated$: jest.fn(), | ||
getTimeUpdate$: jest.fn(), | ||
getRefreshIntervalUpdate$: jest.fn(), | ||
getAutoRefreshFetch$: jest.fn(() => new Observable<unknown>()), | ||
getFetch$: jest.fn(), | ||
getTime: jest.fn(), | ||
setTime: jest.fn(), | ||
setRefreshInterval: jest.fn(), | ||
getRefreshInterval: jest.fn(), | ||
getActiveBounds: jest.fn(), | ||
disableAutoRefreshSelector: jest.fn(), | ||
disableTimeRangeSelector: jest.fn(), | ||
enableAutoRefreshSelector: jest.fn(), | ||
enableTimeRangeSelector: jest.fn(), | ||
getBounds: jest.fn(), | ||
calculateBounds: jest.fn(), | ||
createFilter: jest.fn(), | ||
getRefreshIntervalDefaults: jest.fn(), | ||
getTimeDefaults: jest.fn(), | ||
}; | ||
|
||
export const useTimefilter = jest.fn(() => { | ||
return timefilterMock; | ||
}); |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
133 changes: 133 additions & 0 deletions
133
x-pack/plugins/ml/public/application/explorer/hooks/use_selected_cells.test.ts
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,133 @@ | ||
/* | ||
* Copyright Elasticsearch B.V. and/or licensed to Elasticsearch B.V. under one | ||
* or more contributor license agreements. Licensed under the Elastic License; | ||
* you may not use this file except in compliance with the Elastic License. | ||
*/ | ||
|
||
import moment from 'moment'; | ||
import { renderHook } from '@testing-library/react-hooks'; | ||
import { useSelectedCells } from './use_selected_cells'; | ||
import { ExplorerAppState } from '../../../../common/types/ml_url_generator'; | ||
import { TimefilterContract } from '../../../../../../../src/plugins/data/public'; | ||
|
||
import { useTimefilter } from '../../contexts/kibana'; | ||
|
||
jest.mock('../../contexts/kibana'); | ||
|
||
describe('useSelectedCells', () => { | ||
test('should not set state when the cell selection is correct', () => { | ||
(useTimefilter() as jest.Mocked<TimefilterContract>).getBounds.mockReturnValue({ | ||
min: moment(1498824778 * 1000), | ||
max: moment(1502366798 * 1000), | ||
}); | ||
|
||
const urlState = { | ||
mlExplorerSwimlane: { | ||
selectedType: 'overall', | ||
selectedLanes: ['Overall'], | ||
selectedTimes: [1498780800, 1498867200], | ||
showTopFieldValues: true, | ||
viewByFieldName: 'apache2.access.remote_ip', | ||
viewByFromPage: 1, | ||
viewByPerPage: 10, | ||
}, | ||
mlExplorerFilter: {}, | ||
} as ExplorerAppState; | ||
|
||
const setUrlState = jest.fn(); | ||
|
||
const bucketInterval = 86400; | ||
|
||
renderHook(() => useSelectedCells(urlState, setUrlState, bucketInterval)); | ||
|
||
expect(setUrlState).not.toHaveBeenCalled(); | ||
}); | ||
|
||
test('should reset cell selection when it is completely out of range', () => { | ||
(useTimefilter() as jest.Mocked<TimefilterContract>).getBounds.mockReturnValue({ | ||
min: moment(1501071178 * 1000), | ||
max: moment(1502366798 * 1000), | ||
}); | ||
|
||
const urlState = { | ||
mlExplorerSwimlane: { | ||
selectedType: 'overall', | ||
selectedLanes: ['Overall'], | ||
selectedTimes: [1498780800, 1498867200], | ||
showTopFieldValues: true, | ||
viewByFieldName: 'apache2.access.remote_ip', | ||
viewByFromPage: 1, | ||
viewByPerPage: 10, | ||
}, | ||
mlExplorerFilter: {}, | ||
} as ExplorerAppState; | ||
|
||
const setUrlState = jest.fn(); | ||
|
||
const bucketInterval = 86400; | ||
|
||
const { result } = renderHook(() => useSelectedCells(urlState, setUrlState, bucketInterval)); | ||
|
||
expect(result.current[0]).toEqual({ | ||
lanes: ['Overall'], | ||
showTopFieldValues: true, | ||
times: [1498780800, 1498867200], | ||
type: 'overall', | ||
viewByFieldName: 'apache2.access.remote_ip', | ||
}); | ||
|
||
expect(setUrlState).toHaveBeenCalledWith({ | ||
mlExplorerSwimlane: { | ||
viewByFieldName: 'apache2.access.remote_ip', | ||
viewByFromPage: 1, | ||
viewByPerPage: 10, | ||
}, | ||
}); | ||
}); | ||
|
||
test('should adjust cell selection time boundaries based on the main time range', () => { | ||
(useTimefilter() as jest.Mocked<TimefilterContract>).getBounds.mockReturnValue({ | ||
min: moment(1501071178 * 1000), | ||
max: moment(1502366798 * 1000), | ||
}); | ||
|
||
const urlState = { | ||
mlExplorerSwimlane: { | ||
selectedType: 'overall', | ||
selectedLanes: ['Overall'], | ||
selectedTimes: [1498780800, 1502366798], | ||
showTopFieldValues: true, | ||
viewByFieldName: 'apache2.access.remote_ip', | ||
viewByFromPage: 1, | ||
viewByPerPage: 10, | ||
}, | ||
mlExplorerFilter: {}, | ||
} as ExplorerAppState; | ||
|
||
const setUrlState = jest.fn(); | ||
|
||
const bucketInterval = 86400; | ||
|
||
const { result } = renderHook(() => useSelectedCells(urlState, setUrlState, bucketInterval)); | ||
|
||
expect(result.current[0]).toEqual({ | ||
lanes: ['Overall'], | ||
showTopFieldValues: true, | ||
times: [1498780800, 1502366798], | ||
type: 'overall', | ||
viewByFieldName: 'apache2.access.remote_ip', | ||
}); | ||
|
||
expect(setUrlState).toHaveBeenCalledWith({ | ||
mlExplorerSwimlane: { | ||
selectedLanes: ['Overall'], | ||
selectedTimes: [1500984778, 1502366798], | ||
selectedType: 'overall', | ||
showTopFieldValues: true, | ||
viewByFieldName: 'apache2.access.remote_ip', | ||
viewByFromPage: 1, | ||
viewByPerPage: 10, | ||
}, | ||
}); | ||
}); | ||
}); |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters