Skip to content
This repository has been archived by the owner on Aug 2, 2022. It is now read-only.

Commit

Permalink
Fix live chart pulling and other minor issues(#113)
Browse files Browse the repository at this point in the history
* Improve performance of fetching anomalies when there are too many anomaly results

* Fix detector stopped status message

* Fix unit test and pagination on Dashboard
  • Loading branch information
yizheliu-amazon committed May 8, 2020
1 parent bb66d0d commit 7c1b1ae
Show file tree
Hide file tree
Showing 5 changed files with 58 additions and 19 deletions.
17 changes: 15 additions & 2 deletions public/pages/Dashboard/Components/AnomaliesLiveChart.tsx
Original file line number Diff line number Diff line change
Expand Up @@ -91,16 +91,29 @@ export const AnomaliesLiveChart = (props: AnomaliesLiveChartProps) => {

const getLiveAnomalyResults = async () => {
setIsLoadingAnomalies(true);
const latestLiveAnomalyResult = await getLatestAnomalyResultsForDetectorsByTimeRange(
// check if there is any anomaly result in last 30mins
const latestSingleLiveAnomalyResult = await getLatestAnomalyResultsForDetectorsByTimeRange(
searchES,
props.selectedDetectors,
'30m',
dispatch,
-1,
1,
MAX_LIVE_DETECTORS
);

setHasLatestAnomalyResult(!isEmpty(latestSingleLiveAnomalyResult));

// get anomalies(anomaly_grade>0) in last 30mins
const latestLiveAnomalyResult = await getLatestAnomalyResultsForDetectorsByTimeRange(
searchES,
props.selectedDetectors,
'30m',
dispatch,
0,
MAX_ANOMALIES,
MAX_LIVE_DETECTORS
);
setHasLatestAnomalyResult(!isEmpty(latestLiveAnomalyResult));

const nonZeroAnomalyResult = latestLiveAnomalyResult.filter(
anomalyData => get(anomalyData, AD_DOC_FIELDS.ANOMALY_GRADE, 0) > 0
Expand Down
5 changes: 4 additions & 1 deletion public/pages/Dashboard/Components/AnomalousDetectorsList.tsx
Original file line number Diff line number Diff line change
Expand Up @@ -47,7 +47,10 @@ export const AnomalousDetectorsList = (props: AnomalousDetectorsListProps) => {
pageSizeOptions: [5, 10, 20, 50],
};

useEffect(() => {});
useEffect(() => {
setIndexOfPage(0);
}, [props.selectedDetectors]);

const handleTableChange = ({ page: tablePage = {}, sort = {} }: any) => {
const { index: page, size } = tablePage;
const { field: sortField, direction: direction } = sort;
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -50,22 +50,36 @@ import { toString } from '../MetaData';
import { DATA_TYPES } from '../../../../utils/constants';
import { OPERATORS_MAP } from '../../../createDetector/components/DataFilters/utils/constant';
import { displayText } from '../../../createDetector/components/DataFilters/utils/helpers';
import { mockedStore, initialState } from '../../../../redux/utils/testUtils';

const renderWithRouter = (detector: Detector) => ({
...render(
<Router>
<Switch>
<Route
render={(props: RouteComponentProps) => (
<DetectorConfig
detector={detector}
detectorId={detector.id}
{...props}
/>
)}
/>
</Switch>
</Router>
<Provider
store={mockedStore({
...initialState,
ad: {
...initialState.ad,
detectors: {
[detector.id]: detector,
},
},
})}
>
<Router>
<Switch>
<Route
render={(props: RouteComponentProps) => (
<DetectorConfig
detectorId={detector.id}
onEditDetector={jest.fn()}
onEditFeatures={jest.fn()}
{...props}
/>
)}
/>
</Switch>
</Router>
</Provider>
),
});

Expand Down Expand Up @@ -229,7 +243,10 @@ describe('<DetectorConfig /> spec', () => {
});

describe('test 1 simple feature enabled/disabled', () => {
test.each([[true, 'Enabled'], [false, 'Disabled']])(
test.each([
[true, 'Enabled'],
[false, 'Disabled'],
])(
'renders 1 simple feature enabled/disabled',
async (enabledInDef, enabledInRender) => {
const randomDetector = {
Expand Down
2 changes: 1 addition & 1 deletion public/pages/DetectorDetail/containers/DetectorDetail.tsx
Original file line number Diff line number Diff line change
Expand Up @@ -291,7 +291,7 @@ export const DetectorDetail = (props: DetectorDetailProps) => {
? `Stopped at ${moment(detector.disabledTime).format(
'MM/DD/YY h:mm A'
)}`
: 'Detector is not started'
: 'Detector is stopped'
: 'Feature required to start the detector'}
</EuiHealth>
)}
Expand Down
8 changes: 7 additions & 1 deletion public/redux/reducers/__tests__/utils.ts
Original file line number Diff line number Diff line change
Expand Up @@ -10,6 +10,7 @@ import {
Monitor,
} from '../../../models/interfaces';
import moment from 'moment';
import { DETECTOR_STATE } from '../../../utils/constants';

const detectorFaker = new chance('seed');

Expand Down Expand Up @@ -103,10 +104,15 @@ export const getRandomDetector = (isCreate: boolean = true): Detector => {
disabledTime: moment(1586823218000)
.subtract(1, 'days')
.valueOf(),
curState: DETECTOR_STATE.INIT,
initializationError: '',
};
};

export const getRandomMonitor = (detectorId: string, enabled: boolean = true): Monitor => {
export const getRandomMonitor = (
detectorId: string,
enabled: boolean = true
): Monitor => {
return {
id: detectorFaker.guid().slice(0, 20),
name: detectorFaker.word({ length: 10 }),
Expand Down

0 comments on commit 7c1b1ae

Please sign in to comment.