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

Commit e97c00c

Browse files
committed
address comments
1 parent 8d61193 commit e97c00c

File tree

26 files changed

+298
-69
lines changed

26 files changed

+298
-69
lines changed

.lintstagedrc

+1-1
Original file line numberDiff line numberDiff line change
@@ -1,4 +1,4 @@
11
{
2-
"*.{ts,tsx,js,jsx,json,css,md}": ["prettier --write", "git add"]
2+
"*.{js,jsx,json,css,md}": ["prettier --write", "git add"]
33
}
44

index.js

+2-2
Original file line numberDiff line numberDiff line change
@@ -22,7 +22,7 @@ import {
2222
MonitorService,
2323
AnomalyDetectorService,
2424
} from './server/services';
25-
import { createAlertingCluster, createAlertingAdCluster } from './server/clusters';
25+
import { createAlertingCluster, createAlertingADCluster } from './server/clusters';
2626
import { PLUGIN_NAME } from './utils/constants';
2727

2828
export default function(kibana) {
@@ -49,7 +49,7 @@ export default function(kibana) {
4949
init(server, options) {
5050
// Create clusters
5151
createAlertingCluster(server);
52-
createAlertingAdCluster(server);
52+
createAlertingADCluster(server);
5353

5454
// Initialize services
5555
const esDriver = server.plugins.elasticsearch;

public/pages/CreateMonitor/components/AnomalyDetectors/AnomaliesChart/AnomaliesChart.js

+2-4
Original file line numberDiff line numberDiff line change
@@ -15,7 +15,6 @@
1515

1616
import React from 'react';
1717
import PropTypes from 'prop-types';
18-
import DelayedLoader from '../../../../../components/DelayedLoader';
1918
import { EuiText, EuiSpacer } from '@elastic/eui';
2019
import {
2120
Chart,
@@ -30,14 +29,13 @@ import {
3029
LineAnnotation,
3130
} from '@elastic/charts';
3231
import { ChartContainer } from '../../../../../components/ChartContainer/ChartContainer';
32+
import DelayedLoader from '../../../../../components/DelayedLoader';
3333

3434
const getAxisTitle = (displayGrade, displayConfidence) => {
3535
if (displayGrade && displayConfidence) {
3636
return 'Anomaly grade / confidence';
37-
} else if (displayGrade) {
38-
return 'Anomaly grade';
3937
}
40-
return 'Anomaly confidence';
38+
return displayGrade ? 'Anomaly grade' : 'Anomaly confidence';
4139
};
4240

4341
const AnomaliesChart = props => {

public/pages/CreateMonitor/components/AnomalyDetectors/AnomaliesChart/AnomaliesChart.test.js

+1-1
Original file line numberDiff line numberDiff line change
@@ -15,8 +15,8 @@
1515

1616
import React from 'react';
1717
import { render } from 'enzyme';
18-
import { AnomaliesChart } from './AnomaliesChart';
1918
import moment from 'moment';
19+
import { AnomaliesChart } from './AnomaliesChart';
2020

2121
const startTime = moment('2018-10-25T09:30:00').valueOf();
2222
const endTime = moment('2018-10-29T09:30:00').valueOf();

public/pages/CreateMonitor/components/AnomalyDetectors/EmptyFeaturesMessage/EmptyFeaturesMessage.js

+2-2
Original file line numberDiff line numberDiff line change
@@ -36,8 +36,8 @@ const EmptyFeaturesMessage = props => (
3636
style={{ maxWidth: '45em' }}
3737
body={
3838
<EuiText>
39-
No features have been added to this anomaly detector. A feature is a metric that used
40-
for anomaly detection. A detector can discover anomalies across one or many features.
39+
No features have been added to this anomaly detector. A feature is a metric that is used
40+
for anomaly detection. A detector can discover anomalies across one or more features.
4141
</EuiText>
4242
}
4343
actions={[

public/pages/CreateMonitor/components/AnomalyDetectors/EmptyFeaturesMessage/__snapshots__/EmptyFeaturesMessage.test.js.snap

+1-1
Original file line numberDiff line numberDiff line change
@@ -17,7 +17,7 @@ exports[`EmptyFeaturesMessage renders 1`] = `
1717
<div
1818
class="euiText euiText--medium"
1919
>
20-
No features have been added to this anomaly detector. A feature is a metric that used for anomaly detection. A detector can discover anomalies across one or many features.
20+
No features have been added to this anomaly detector. A feature is a metric that is used for anomaly detection. A detector can discover anomalies across one or more features.
2121
</div>
2222
</div>
2323
</span>

public/pages/CreateMonitor/containers/AnomalyDetectors/AnomalyDetectorData.js

+2-10
Original file line numberDiff line numberDiff line change
@@ -17,6 +17,7 @@ import React from 'react';
1717
import PropTypes from 'prop-types';
1818
import moment from 'moment';
1919
import { AppContext } from '../../../../utils/AppContext';
20+
import { AD_PREVIEW_DAYS } from '../../../../utils/constants';
2021

2122
class AnomalyDetectorData extends React.Component {
2223
static contextType = AppContext;
@@ -39,15 +40,6 @@ class AnomalyDetectorData extends React.Component {
3940
async componentDidMount() {
4041
await this.getPreviewData();
4142
}
42-
componentDidUpdate(prevProps) {
43-
if (
44-
this.props.detectorId != prevProps.detectorId ||
45-
this.props.startTime != prevProps.startTime ||
46-
this.props.endTime != prevProps.endTime
47-
) {
48-
this.getPreviewData();
49-
}
50-
}
5143

5244
async getPreviewData() {
5345
const { detectorId, startTime, endTime } = this.props;
@@ -58,7 +50,7 @@ class AnomalyDetectorData extends React.Component {
5850
if (!detectorId) return;
5951
const requestParams = {
6052
startTime: moment()
61-
.subtract(5, 'd')
53+
.subtract(AD_PREVIEW_DAYS, 'd')
6254
.valueOf(),
6355
startTime: startTime,
6456
endTime: endTime,

public/pages/CreateMonitor/containers/AnomalyDetectors/AnomalyDetectors.js

-1
Original file line numberDiff line numberDiff line change
@@ -43,7 +43,6 @@ class AnomalyDetectors extends React.Component {
4343
label: detector.name,
4444
value: detector.id,
4545
features: detector.featureAttributes,
46-
//TODO::Temp hack until backend fix
4746
interval: detector.detectionInterval,
4847
}));
4948
this.setState({ detectorOptions });

public/pages/CreateMonitor/containers/AnomalyDetectors/__tests__/AnomalyDetector.test.js

-5
Original file line numberDiff line numberDiff line change
@@ -51,11 +51,6 @@ describe('AnomalyDetectors', () => {
5151
const wrapper = getMountWrapper();
5252
expect(wrapper).toMatchSnapshot();
5353
});
54-
// test('must call renderEmptyMessage initially', () => {
55-
// httpClientMock.post.mockResolvedValue({ data: { ok: true, detectors: [] } });
56-
// getMountWrapper();
57-
// expect(renderEmptyMessage).toHaveBeenCalled();
58-
// });
5954

6055
test('should be able to select the detector', done => {
6156
httpClientMock.post.mockResolvedValueOnce({

public/pages/CreateMonitor/containers/AnomalyDetectors/__tests__/AnomalyDetectorPreviewData.test.js

-10
Original file line numberDiff line numberDiff line change
@@ -42,16 +42,6 @@ describe('AnomalyDetectorData', () => {
4242
expect(getPreviewData).toHaveBeenCalled();
4343
expect(getPreviewData).toHaveBeenCalledTimes(1);
4444
});
45-
test('calls preview api if detectorId changes', () => {
46-
const mockedRender = jest.fn().mockImplementation(() => null);
47-
const getPreviewData = jest.spyOn(AnomalyDetectorData.prototype, 'getPreviewData');
48-
const wrapper = getMountWrapper();
49-
wrapper.setProps({
50-
children: <AnomalyDetectorData detectorId="another" render={mockedRender} />,
51-
});
52-
wrapper.update();
53-
expect(getPreviewData).toHaveBeenCalledTimes(2);
54-
});
5545
test('calls render with anomalyResult', () => {
5646
const wrapper = getMountWrapper();
5747
expect(mockedRender).toHaveBeenCalled();

public/pages/CreateMonitor/containers/CreateMonitor/utils/formikToMonitor.js

-5
Original file line numberDiff line numberDiff line change
@@ -83,11 +83,6 @@ export function formikToAdQuery(values) {
8383
},
8484
},
8585
aggregations: {
86-
// max_confidence: {
87-
// max: {
88-
// field: "confidence",
89-
// },
90-
// },
9186
max_anomaly_grade: {
9287
max: {
9388
field: 'anomaly_grade',

public/pages/CreateMonitor/containers/CreateMonitor/utils/monitorToFormik.js

+1-3
Original file line numberDiff line numberDiff line change
@@ -51,9 +51,7 @@ export default function monitorToFormik(monitor) {
5151
fieldName: fieldName ? [{ label: fieldName }] : [],
5252
timezone: timezone ? [{ label: timezone }] : [],
5353

54-
detectorId: isAD //&& _.get(inputs, '0.search.indices.0') === '.opendistro-anomaly-results*'
55-
? _.get(inputs, INPUTS_DETECTOR_ID)
56-
: undefined,
54+
detectorId: isAD ? _.get(inputs, INPUTS_DETECTOR_ID) : undefined,
5755
index: inputs[0].search.indices.map(index => ({ label: index })),
5856
query: JSON.stringify(inputs[0].search.query, null, 4),
5957
};

public/pages/CreateTrigger/containers/CreateTrigger/utils/formikToTrigger.js

-1
Original file line numberDiff line numberDiff line change
@@ -90,7 +90,6 @@ export function getADCondition(values) {
9090
return {
9191
script: {
9292
lang: 'painless',
93-
//TODO:: Check null check is required or not confirm with backend
9493
source: `return ${ANOMALY_GRADE_RESULT_PATH} != null && ${ANOMALY_GRADE_RESULT_PATH} ${anomalyGradeOperator} ${anomalyDetector.anomalyGradeThresholdValue} && ${ANOMALY_CONFIDENCE_RESULT_PATH} ${anomalyConfidenceOperator} ${anomalyDetector.anomalyConfidenceThresholdValue}`,
9594
},
9695
};

public/pages/Dashboard/containers/Dashboard.js

+13-12
Original file line numberDiff line numberDiff line change
@@ -314,23 +314,24 @@ export default class Dashboard extends Component {
314314
selectable ? undefined : 'Only Active Alerts are Acknowledgeable',
315315
};
316316

317+
const actions = () => {
318+
const actions = [<EuiButton onClick={this.acknowledgeAlert}>Acknowledge</EuiButton>];
319+
if (detectorIds.length) {
320+
actions.unshift(
321+
<EuiButton href={`${ES_AD_PLUGIN}#/detectors/${detectorIds[0]}`} target="_blank">
322+
View detector <EuiIcon type="popout" />
323+
</EuiButton>
324+
);
325+
}
326+
return actions;
327+
};
328+
317329
return (
318330
<ContentPanel
319331
title="Alerts"
320332
titleSize={monitorIds.length ? 's' : 'l'}
321333
bodyStyles={{ padding: 'initial' }}
322-
actions={
323-
detectorIds.length ? (
324-
[
325-
<EuiButtonEmpty href={`${ES_AD_PLUGIN}#/detectors/${detectorIds[0]}`} target="_blank">
326-
View detector <EuiIcon type="popout" />
327-
</EuiButtonEmpty>,
328-
<EuiButton onClick={this.acknowledgeAlert}>Acknowledge</EuiButton>,
329-
]
330-
) : (
331-
<EuiButton onClick={this.acknowledgeAlert}>Acknowledge</EuiButton>
332-
)
333-
}
334+
actions={actions()}
334335
>
335336
<DashboardControls
336337
activePage={page}

public/pages/MonitorDetails/containers/AnomalyHistory/AnomalyHistory.js

+15
Original file line numberDiff line numberDiff line change
@@ -1,3 +1,18 @@
1+
/*
2+
* Copyright 2020 Amazon.com, Inc. or its affiliates. All Rights Reserved.
3+
*
4+
* Licensed under the Apache License, Version 2.0 (the "License").
5+
* You may not use this file except in compliance with the License.
6+
* A copy of the License is located at
7+
*
8+
* http://www.apache.org/licenses/LICENSE-2.0
9+
*
10+
* or in the "license" file accompanying this file. This file is distributed
11+
* on an "AS IS" BASIS, WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either
12+
* express or implied. See the License for the specific language governing
13+
* permissions and limitations under the License.
14+
*/
15+
116
import React, { Component } from 'react';
217
import moment from 'moment';
318
import { get } from 'lodash';

public/pages/MonitorDetails/containers/MonitorDetails.js

+1-1
Original file line numberDiff line numberDiff line change
@@ -291,7 +291,7 @@ export default class MonitorDetails extends Component {
291291
{detector ? (
292292
<EuiFlexItem grow={false}>
293293
<EuiText size="s">
294-
Created from detector{' '}
294+
Created from detector:{' '}
295295
<EuiLink
296296
href={`${ES_AD_PLUGIN}#/detectors/${detectorId}`}
297297
external="true"

public/pages/MonitorDetails/containers/utils/__tests__/helper.test.js

+15
Original file line numberDiff line numberDiff line change
@@ -1,3 +1,18 @@
1+
/*
2+
* Copyright 2020 Amazon.com, Inc. or its affiliates. All Rights Reserved.
3+
*
4+
* Licensed under the Apache License, Version 2.0 (the "License").
5+
* You may not use this file except in compliance with the License.
6+
* A copy of the License is located at
7+
*
8+
* http://www.apache.org/licenses/LICENSE-2.0
9+
*
10+
* or in the "license" file accompanying this file. This file is distributed
11+
* on an "AS IS" BASIS, WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either
12+
* express or implied. See the License for the specific language governing
13+
* permissions and limitations under the License.
14+
*/
15+
116
import { migrateTriggerMetadata } from '../helpers';
217

318
describe('helpers', () => {

public/pages/MonitorDetails/containers/utils/helpers.js

+15
Original file line numberDiff line numberDiff line change
@@ -1,3 +1,18 @@
1+
/*
2+
* Copyright 2020 Amazon.com, Inc. or its affiliates. All Rights Reserved.
3+
*
4+
* Licensed under the Apache License, Version 2.0 (the "License").
5+
* You may not use this file except in compliance with the License.
6+
* A copy of the License is located at
7+
*
8+
* http://www.apache.org/licenses/LICENSE-2.0
9+
*
10+
* or in the "license" file accompanying this file. This file is distributed
11+
* on an "AS IS" BASIS, WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either
12+
* express or implied. See the License for the specific language governing
13+
* permissions and limitations under the License.
14+
*/
15+
116
import { get, isEmpty } from 'lodash';
217
export const migrateTriggerMetadata = monitor => {
318
const uiMetadata = get(monitor, 'ui_metadata', {});

public/utils/AppContext.js

+15
Original file line numberDiff line numberDiff line change
@@ -1,3 +1,18 @@
1+
/*
2+
* Copyright 2020 Amazon.com, Inc. or its affiliates. All Rights Reserved.
3+
*
4+
* Licensed under the Apache License, Version 2.0 (the "License").
5+
* You may not use this file except in compliance with the License.
6+
* A copy of the License is located at
7+
*
8+
* http://www.apache.org/licenses/LICENSE-2.0
9+
*
10+
* or in the "license" file accompanying this file. This file is distributed
11+
* on an "AS IS" BASIS, WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either
12+
* express or implied. See the License for the specific language governing
13+
* permissions and limitations under the License.
14+
*/
15+
116
import React from 'react';
217

318
export const AppContext = React.createContext({});

public/utils/constants.js

+2-2
Original file line numberDiff line numberDiff line change
@@ -54,10 +54,10 @@ export const DATA_TYPES = {
5454
KEYWORD: 'keyword',
5555
};
5656

57-
export const AD_PLUGIN_ID = 'aes-ad-plugin';
58-
5957
export const ES_AD_PLUGIN = 'opendistro-anomaly-detection';
6058

6159
export const INPUTS_DETECTOR_ID = '0.search.query.query.bool.filter[1].term.detector_id.value';
6260

6361
export const MONITOR_INPUT_DETECTOR_ID = `inputs.${INPUTS_DETECTOR_ID}`;
62+
63+
export const AD_PREVIEW_DAYS = 7;

public/utils/validate.js

+1-1
Original file line numberDiff line numberDiff line change
@@ -93,7 +93,7 @@ export const ILLEGAL_CHARACTERS = ['\\', '/', '?', '"', '<', '>', '|', ',', ' ']
9393
export const validateDetector = (detectorId, selectedDetector) => {
9494
if (!detectorId) return 'Must select detector';
9595
if (selectedDetector && selectedDetector.features.length === 0)
96-
return 'Detector with no features.';
96+
return 'Must choose detector which has features';
9797
};
9898

9999
export const validateIndex = options => {

server/clusters/alerting/createAlertingAdCluster.js

+1-1
Original file line numberDiff line numberDiff line change
@@ -16,7 +16,7 @@
1616
import alertingADPlugin from './adPlugin';
1717
import { CLUSTER, DEFAULT_HEADERS } from '../../services/utils/constants';
1818

19-
export default function createAlertingAdCluster(server) {
19+
export default function createAlertingADCluster(server) {
2020
const { customHeaders, ...rest } = server.config().get('elasticsearch');
2121
server.plugins.elasticsearch.createCluster(CLUSTER.AD_ALERTING, {
2222
plugins: [alertingADPlugin],

server/clusters/index.js

+2-2
Original file line numberDiff line numberDiff line change
@@ -14,6 +14,6 @@
1414
*/
1515

1616
import createAlertingCluster from './alerting/createAlertingCluster';
17-
import createAlertingAdCluster from './alerting/createAlertingAdCluster';
17+
import createAlertingADCluster from './alerting/createAlertingADCluster';
1818

19-
export { createAlertingCluster, createAlertingAdCluster };
19+
export { createAlertingCluster, createAlertingADCluster };

server/services/MonitorService.js

-4
Original file line numberDiff line numberDiff line change
@@ -31,10 +31,6 @@ export default class MonitorService {
3131
return { ok: true, resp: createResponse };
3232
} catch (err) {
3333
console.error('Alerting - MonitorService - createMonitor:', err);
34-
//FIXME: This is temporary as backend should send error message inside message instead of body
35-
if (err.statusCode === 400) {
36-
return { ok: false, resp: err.body };
37-
}
3834
return { ok: false, resp: err.message };
3935
}
4036
};

0 commit comments

Comments
 (0)