-
Notifications
You must be signed in to change notification settings - Fork 8.1k
New issue
Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.
By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.
Already on GitHub? Sign in to your account
[APM] Service maps anomaly detection status in popover #65217
Merged
ogupte
merged 6 commits into
elastic:master
from
ogupte:apm-64205-service-maps-anomaly-popover
May 5, 2020
Merged
Changes from all commits
Commits
Show all changes
6 commits
Select commit
Hold shift + click to select a range
4358232
Adds ML status to the service maps popover. Modifies the query a bit to
ogupte 7751307
fixed failures and updated tests
ogupte ccf4bb8
component clean up
ogupte d56debc
makes the ML link open in a new window
ogupte 2f8f296
- Closes #64278 by removing the framework badge.
ogupte 56b81f0
- Closes #65244 by displaying a message for services without anomalie…
ogupte 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
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 |
---|---|---|
|
@@ -8,14 +8,23 @@ import { | |
EuiFlexGroup, | ||
EuiFlexItem, | ||
EuiHorizontalRule, | ||
EuiTitle | ||
EuiTitle, | ||
EuiIconTip, | ||
EuiHealth | ||
} from '@elastic/eui'; | ||
import theme from '@elastic/eui/dist/eui_theme_light.json'; | ||
import { i18n } from '@kbn/i18n'; | ||
import cytoscape from 'cytoscape'; | ||
import React from 'react'; | ||
import { SERVICE_FRAMEWORK_NAME } from '../../../../../common/elasticsearch_fieldnames'; | ||
import styled from 'styled-components'; | ||
import { fontSize, px } from '../../../../style/variables'; | ||
import { Buttons } from './Buttons'; | ||
import { Info } from './Info'; | ||
import { ServiceMetricFetcher } from './ServiceMetricFetcher'; | ||
import { MLJobLink } from '../../../shared/Links/MachineLearningLinks/MLJobLink'; | ||
import { getSeverityColor } from '../cytoscapeOptions'; | ||
import { asInteger } from '../../../../utils/formatters'; | ||
import { getMetricChangeDescription } from '../../../../../../ml/public'; | ||
|
||
const popoverMinWidth = 280; | ||
|
||
|
@@ -27,6 +36,31 @@ interface ContentsProps { | |
selectedNodeServiceName: string; | ||
} | ||
|
||
const HealthStatusTitle = styled(EuiTitle)` | ||
display: inline; | ||
text-transform: uppercase; | ||
`; | ||
|
||
const VerticallyCentered = styled.div` | ||
display: flex; | ||
align-items: center; | ||
`; | ||
|
||
const SubduedText = styled.span` | ||
color: ${theme.euiTextSubduedColor}; | ||
`; | ||
|
||
const EnableText = styled.section` | ||
color: ${theme.euiTextSubduedColor}; | ||
line-height: 1.4; | ||
font-size: ${fontSize}; | ||
width: ${px(popoverMinWidth)}; | ||
`; | ||
|
||
export const ContentLine = styled.section` | ||
line-height: 2; | ||
`; | ||
|
||
// IE 11 does not handle flex properties as expected. With browser detection, | ||
// we can use regular div elements to render contents that are almost identical. | ||
// | ||
|
@@ -51,14 +85,61 @@ const FlexColumnGroup = (props: { | |
const FlexColumnItem = (props: { children: React.ReactNode }) => | ||
isIE11 ? <div {...props} /> : <EuiFlexItem {...props} />; | ||
|
||
const ANOMALY_DETECTION_TITLE = i18n.translate( | ||
'xpack.apm.serviceMap.anomalyDetectionPopoverTitle', | ||
{ defaultMessage: 'Anomaly Detection' } | ||
); | ||
|
||
const ANOMALY_DETECTION_INFO = i18n.translate( | ||
'xpack.apm.serviceMap.anomalyDetectionPopoverInfo', | ||
{ | ||
defaultMessage: | ||
'Display the health of your service by enabling the anomaly detection feature in Machine Learning.' | ||
} | ||
); | ||
|
||
const ANOMALY_DETECTION_SCORE_METRIC = i18n.translate( | ||
'xpack.apm.serviceMap.anomalyDetectionPopoverScoreMetric', | ||
{ defaultMessage: 'Score (max.)' } | ||
); | ||
|
||
const ANOMALY_DETECTION_LINK = i18n.translate( | ||
'xpack.apm.serviceMap.anomalyDetectionPopoverLink', | ||
{ defaultMessage: 'View anomalies' } | ||
); | ||
|
||
const ANOMALY_DETECTION_ENABLE_TEXT = i18n.translate( | ||
'xpack.apm.serviceMap.anomalyDetectionPopoverEnable', | ||
{ | ||
defaultMessage: | ||
'Enable anomaly detection from the Integrations menu in the Service details view.' | ||
} | ||
); | ||
|
||
export function Contents({ | ||
selectedNodeData, | ||
isService, | ||
label, | ||
onFocusClick, | ||
selectedNodeServiceName | ||
}: ContentsProps) { | ||
const frameworkName = selectedNodeData[SERVICE_FRAMEWORK_NAME]; | ||
sorenlouv marked this conversation as resolved.
Show resolved
Hide resolved
|
||
// Anomaly Detection | ||
const severity = selectedNodeData.severity; | ||
const maxScore = selectedNodeData.max_score; | ||
const actualValue = selectedNodeData.actual_value; | ||
const typicalValue = selectedNodeData.typical_value; | ||
const jobId = selectedNodeData.job_id; | ||
There was a problem hiding this comment. Choose a reason for hiding this commentThe reason will be displayed to describe this comment to others. Learn more. These are all selectedNodeData: cytoscape.NodeDataDefinition; Should be changed to something like: selectedNodeData: ServiceNode; where type ServiceNode = cytoscape.NodeDataDefinition & TypeWithAnomalyDetectionFields I expect interface TypeWithAnomalyDetectionFields {
severity?: string;
maxScore?: string;
...
} (or perhaps it can be inferred from a ReturnType) |
||
const hasAnomalyDetection = [ | ||
severity, | ||
maxScore, | ||
actualValue, | ||
typicalValue, | ||
jobId | ||
].every(value => value !== undefined); | ||
const anomalyDescription = hasAnomalyDetection | ||
? getMetricChangeDescription(actualValue, typicalValue).message | ||
: null; | ||
|
||
return ( | ||
<FlexColumnGroup | ||
direction="column" | ||
|
@@ -71,12 +152,50 @@ export function Contents({ | |
</EuiTitle> | ||
<EuiHorizontalRule margin="xs" /> | ||
</FlexColumnItem> | ||
{isService && ( | ||
<FlexColumnItem> | ||
<section> | ||
<HealthStatusTitle size="xxs"> | ||
<h3>{ANOMALY_DETECTION_TITLE}</h3> | ||
</HealthStatusTitle> | ||
| ||
<EuiIconTip type="iInCircle" content={ANOMALY_DETECTION_INFO} /> | ||
</section> | ||
{hasAnomalyDetection ? ( | ||
<> | ||
<ContentLine> | ||
<EuiFlexGroup> | ||
<EuiFlexItem> | ||
<VerticallyCentered> | ||
<EuiHealth color={getSeverityColor(severity)} /> | ||
<SubduedText> | ||
{ANOMALY_DETECTION_SCORE_METRIC} | ||
</SubduedText> | ||
</VerticallyCentered> | ||
</EuiFlexItem> | ||
<EuiFlexItem grow={false}> | ||
<div> | ||
{asInteger(maxScore)} | ||
<SubduedText> ({anomalyDescription})</SubduedText> | ||
</div> | ||
</EuiFlexItem> | ||
</EuiFlexGroup> | ||
</ContentLine> | ||
<ContentLine> | ||
<MLJobLink external jobId={jobId}> | ||
{ANOMALY_DETECTION_LINK} | ||
</MLJobLink> | ||
</ContentLine> | ||
</> | ||
) : ( | ||
<EnableText>{ANOMALY_DETECTION_ENABLE_TEXT}</EnableText> | ||
)} | ||
<EuiHorizontalRule margin="xs" /> | ||
</FlexColumnItem> | ||
)} | ||
<FlexColumnItem> | ||
{isService ? ( | ||
<ServiceMetricFetcher | ||
frameworkName={frameworkName} | ||
serviceName={selectedNodeServiceName} | ||
/> | ||
<ServiceMetricFetcher serviceName={selectedNodeServiceName} /> | ||
) : ( | ||
<Info {...selectedNodeData} /> | ||
)} | ||
|
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
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.
This was necessary to add since the
data
of each node wasn't being updated when existing elements were re-added. Before adding this, the displayed anomaly data was stale after updating date ranges.