This repository has been archived by the owner on Aug 2, 2022. It is now read-only.
-
Notifications
You must be signed in to change notification settings - Fork 62
anomaly detection changes. #123
Merged
ylwu-amzn
merged 5 commits into
opendistro-for-elasticsearch:master
from
ylwu-amzn:master
Apr 28, 2020
Merged
Changes from 2 commits
Commits
Show all changes
5 commits
Select commit
Hold shift + click to select a range
8d61193
anomaly detection changes.
ylwu-amzn e97c00c
address comments
ylwu-amzn 91205cd
remove anomaly detector option when create monitor if AD plugin not i…
ylwu-amzn feb3bf7
address comments: copyright, remove unused code,etc
ylwu-amzn c09034b
remove extra showLoader
ylwu-amzn File filter
Filter by extension
Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
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 |
---|---|---|
@@ -1,3 +1,4 @@ | ||
{ | ||
"*.{js,jsx,json,css,md}": ["prettier --write", "git add"] | ||
} | ||
|
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
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,41 @@ | ||
/* | ||
* Copyright 2019 Amazon.com, Inc. or its affiliates. All Rights Reserved. | ||
ylwu-amzn marked this conversation as resolved.
Show resolved
Hide resolved
|
||
* | ||
* Licensed under the Apache License, Version 2.0 (the "License"). | ||
* You may not use this file except in compliance with the License. | ||
* A copy of the License is located at | ||
* | ||
* http://www.apache.org/licenses/LICENSE-2.0 | ||
* | ||
* or in the "license" file accompanying this file. This file is distributed | ||
* on an "AS IS" BASIS, WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either | ||
* express or implied. See the License for the specific language governing | ||
* permissions and limitations under the License. | ||
*/ | ||
|
||
import PropTypes from 'prop-types'; | ||
import React from 'react'; | ||
|
||
const ChartContainer = ({ children, style }) => ( | ||
<div | ||
style={{ | ||
borderRadius: '5px', | ||
padding: '10px', | ||
border: '1px solid #D9D9D9', | ||
height: '250px', | ||
width: '100%', | ||
...style, | ||
}} | ||
> | ||
{children} | ||
</div> | ||
); | ||
ChartContainer.propTypes = { | ||
style: PropTypes.object, | ||
children: PropTypes.oneOfType([PropTypes.node, PropTypes.arrayOf([PropTypes.node])]).isRequired, | ||
}; | ||
ChartContainer.defaultPropTypes = { | ||
style: {}, | ||
}; | ||
|
||
export { ChartContainer }; |
Loading
Sorry, something went wrong. Reload?
Sorry, we cannot display this file.
Sorry, this file is invalid so it cannot be displayed.
134 changes: 134 additions & 0 deletions
134
public/pages/CreateMonitor/components/AnomalyDetectors/AnomaliesChart/AnomaliesChart.js
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,134 @@ | ||
/* | ||
* Copyright 2019 Amazon.com, Inc. or its affiliates. All Rights Reserved. | ||
* | ||
* Licensed under the Apache License, Version 2.0 (the "License"). | ||
* You may not use this file except in compliance with the License. | ||
* A copy of the License is located at | ||
* | ||
* http://www.apache.org/licenses/LICENSE-2.0 | ||
* | ||
* or in the "license" file accompanying this file. This file is distributed | ||
* on an "AS IS" BASIS, WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either | ||
* express or implied. See the License for the specific language governing | ||
* permissions and limitations under the License. | ||
*/ | ||
|
||
import React from 'react'; | ||
import PropTypes from 'prop-types'; | ||
import { EuiText, EuiSpacer } from '@elastic/eui'; | ||
import { | ||
Chart, | ||
getAxisId, | ||
Axis, | ||
getSpecId, | ||
LineSeries, | ||
niceTimeFormatter, | ||
Settings, | ||
Position, | ||
getAnnotationId, | ||
LineAnnotation, | ||
} from '@elastic/charts'; | ||
dbbaughe marked this conversation as resolved.
Show resolved
Hide resolved
|
||
import { ChartContainer } from '../../../../../components/ChartContainer/ChartContainer'; | ||
import DelayedLoader from '../../../../../components/DelayedLoader'; | ||
|
||
const getAxisTitle = (displayGrade, displayConfidence) => { | ||
ylwu-amzn marked this conversation as resolved.
Show resolved
Hide resolved
|
||
if (displayGrade && displayConfidence) { | ||
return 'Anomaly grade / confidence'; | ||
} | ||
return displayGrade ? 'Anomaly grade' : 'Anomaly confidence'; | ||
}; | ||
|
||
const AnomaliesChart = props => { | ||
const timeFormatter = niceTimeFormatter([props.startDateTime, props.endDateTime]); | ||
return ( | ||
<DelayedLoader isLoading={props.isLoading}> | ||
{showLoader => ( | ||
<React.Fragment> | ||
{props.showTitle ? ( | ||
<EuiText size="xs"> | ||
<strong>{props.title}</strong> | ||
</EuiText> | ||
) : null} | ||
<EuiSpacer size="s" /> | ||
<div> | ||
<ChartContainer | ||
style={{ height: '300px', width: '100%', opacity: showLoader ? 0.2 : 1 }} | ||
> | ||
<Chart> | ||
{props.showSettings ? ( | ||
<Settings | ||
showLegend | ||
legendPosition={Position.Bottom} | ||
showLegendDisplayValue={false} | ||
/> | ||
) : null} | ||
<Axis id={getAxisId('bottom')} position="bottom" tickFormat={timeFormatter} /> | ||
<Axis | ||
id={getAxisId('left')} | ||
title={getAxisTitle(props.displayGrade, props.displayConfidence)} | ||
position="left" | ||
domain={{ min: 0, max: 1 }} | ||
/> | ||
{props.annotationData ? ( | ||
<LineAnnotation | ||
annotationId={getAnnotationId('anomalyAnnotation')} | ||
domainType="yDomain" | ||
dataValues={props.annotationData} | ||
style={{ | ||
line: { | ||
strokeWidth: 1.5, | ||
stroke: '#f00', | ||
}, | ||
}} | ||
/> | ||
) : null} | ||
{props.displayGrade ? ( | ||
<LineSeries | ||
id={getSpecId('Anomaly grade')} | ||
xScaleType="time" | ||
yScaleType="linear" | ||
xAccessor={'plotTime'} | ||
yAccessors={['anomalyGrade']} | ||
data={props.anomalies} | ||
/> | ||
) : null} | ||
{props.displayConfidence ? ( | ||
<LineSeries | ||
id={getSpecId('Confidence')} | ||
xScaleType="time" | ||
yScaleType="linear" | ||
xAccessor={'plotTime'} | ||
yAccessors={['confidence']} | ||
data={props.anomalies} | ||
/> | ||
) : null} | ||
</Chart> | ||
</ChartContainer> | ||
</div> | ||
</React.Fragment> | ||
)} | ||
</DelayedLoader> | ||
); | ||
}; | ||
|
||
AnomaliesChart.propTypes = { | ||
startDateTime: PropTypes.number, | ||
endDateTime: PropTypes.number, | ||
endDate: PropTypes.number, | ||
isLoading: PropTypes.bool, | ||
showTitle: PropTypes.bool, | ||
showSettings: PropTypes.bool, | ||
annotationData: PropTypes.array, | ||
anomalies: PropTypes.array.isRequired, | ||
title: PropTypes.string, | ||
}; | ||
|
||
AnomaliesChart.defaultProps = { | ||
isLoading: false, | ||
showTitle: true, | ||
showSettings: true, | ||
anomalies: undefined, | ||
title: 'Sample preview for anomaly score', | ||
}; | ||
|
||
export { AnomaliesChart }; |
50 changes: 50 additions & 0 deletions
50
public/pages/CreateMonitor/components/AnomalyDetectors/AnomaliesChart/AnomaliesChart.test.js
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,50 @@ | ||
/* | ||
* Copyright 2019 Amazon.com, Inc. or its affiliates. All Rights Reserved. | ||
* | ||
* Licensed under the Apache License, Version 2.0 (the "License"). | ||
* You may not use this file except in compliance with the License. | ||
* A copy of the License is located at | ||
* | ||
* http://www.apache.org/licenses/LICENSE-2.0 | ||
* | ||
* or in the "license" file accompanying this file. This file is distributed | ||
* on an "AS IS" BASIS, WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either | ||
* express or implied. See the License for the specific language governing | ||
* permissions and limitations under the License. | ||
*/ | ||
|
||
import React from 'react'; | ||
import { render } from 'enzyme'; | ||
import moment from 'moment'; | ||
import { AnomaliesChart } from './AnomaliesChart'; | ||
|
||
const startTime = moment('2018-10-25T09:30:00').valueOf(); | ||
const endTime = moment('2018-10-29T09:30:00').valueOf(); | ||
|
||
describe('AnomaliesChart', () => { | ||
test('renders ', () => { | ||
const sampleData = [ | ||
{ | ||
anomalyGrade: 0.9983687181753063, | ||
anomalyScore: 0.8381447468893426, | ||
confidence: 0.42865659282252266, | ||
detectorId: 'temp', | ||
endTime: 1569097677667, | ||
plotTime: 1569097377667, | ||
startTime: 1569097077667, | ||
}, | ||
]; | ||
const component = ( | ||
<AnomaliesChart | ||
anomalies={sampleData} | ||
startDateTime={startTime} | ||
endDateTime={endTime} | ||
isLoading={false} | ||
displayGrade | ||
displayConfidence | ||
showTitle | ||
/> | ||
); | ||
expect(render(component)).toMatchSnapshot(); | ||
}); | ||
}); |
45 changes: 45 additions & 0 deletions
45
...itor/components/AnomalyDetectors/AnomaliesChart/__snapshots__/AnomaliesChart.test.js.snap
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,45 @@ | ||
// Jest Snapshot v1, https://goo.gl/fbAQLP | ||
|
||
exports[`AnomaliesChart renders 1`] = ` | ||
Array [ | ||
<div | ||
class="euiText euiText--extraSmall" | ||
> | ||
<strong> | ||
Sample preview for anomaly score | ||
</strong> | ||
</div>, | ||
<div | ||
class="euiSpacer euiSpacer--s" | ||
/>, | ||
<div> | ||
<div | ||
style="border-radius:5px;padding:10px;border:1px solid #D9D9D9;height:300px;width:100%;opacity:1" | ||
> | ||
<div | ||
class="echChart" | ||
> | ||
<div | ||
class="echChartStatus" | ||
data-ech-render-complete="false" | ||
data-ech-render-count="0" | ||
/> | ||
<div | ||
class="echChartResizer" | ||
/> | ||
<div | ||
class="echContainer" | ||
> | ||
<div | ||
class="echReactiveChart_unavailable" | ||
> | ||
<p> | ||
No data to display | ||
</p> | ||
</div> | ||
</div> | ||
</div> | ||
</div> | ||
</div>, | ||
] | ||
`; |
Oops, something went wrong.
Add this suggestion to a batch that can be applied as a single commit.
This suggestion is invalid because no changes were made to the code.
Suggestions cannot be applied while the pull request is closed.
Suggestions cannot be applied while viewing a subset of changes.
Only one suggestion per line can be applied in a batch.
Add this suggestion to a batch that can be applied as a single commit.
Applying suggestions on deleted lines is not supported.
You must change the existing code in this line in order to create a valid suggestion.
Outdated suggestions cannot be applied.
This suggestion has been applied or marked resolved.
Suggestions cannot be applied from pending reviews.
Suggestions cannot be applied on multi-line comments.
Suggestions cannot be applied while the pull request is queued to merge.
Suggestion cannot be applied right now. Please check back later.
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
I can't remember but I thought @mihirsoni already added some dark mode logic to Alerting before?
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
Not sure about that, @mihirsoni , can you confirm? Maybe you have reviewed this part before?
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
I think this could work out of the box. This could be needed.