Skip to content

Commit

Permalink
- Closes elastic#65244 by displaying a message for services without a…
Browse files Browse the repository at this point in the history
…nomalies detected

- removes unecessary service framework name in service map queries
- adds date range filter for anomaly detection
  • Loading branch information
ogupte committed May 5, 2020
1 parent 2f8f296 commit 56b81f0
Show file tree
Hide file tree
Showing 7 changed files with 67 additions and 72 deletions.
2 changes: 0 additions & 2 deletions x-pack/plugins/apm/common/service_map.ts
Original file line number Diff line number Diff line change
Expand Up @@ -9,7 +9,6 @@ import { ILicense } from '../../licensing/public';
import {
AGENT_NAME,
SERVICE_ENVIRONMENT,
SERVICE_FRAMEWORK_NAME,
SERVICE_NAME,
SPAN_SUBTYPE,
SPAN_TYPE,
Expand All @@ -19,7 +18,6 @@ import {
export interface ServiceConnectionNode {
[SERVICE_NAME]: string;
[SERVICE_ENVIRONMENT]: string | null;
[SERVICE_FRAMEWORK_NAME]: string | null;
[AGENT_NAME]: string;
}
export interface ExternalConnectionNode {
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -134,6 +134,11 @@ export function Cytoscape({
);
cy.remove(absentElements);
cy.add(elements);
// ensure all elements get latest data properties
elements.forEach(elementDefinition => {
const el = cy.getElementById(elementDefinition.data.id as string);
el.data(elementDefinition.data);
});
cy.trigger('data');
}
}, [cy, elements]);
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -17,6 +17,7 @@ import { i18n } from '@kbn/i18n';
import cytoscape from 'cytoscape';
import React from 'react';
import styled from 'styled-components';
import { fontSize, px } from '../../../../style/variables';
import { Buttons } from './Buttons';
import { Info } from './Info';
import { ServiceMetricFetcher } from './ServiceMetricFetcher';
Expand Down Expand Up @@ -49,6 +50,13 @@ 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;
`;
Expand Down Expand Up @@ -100,6 +108,14 @@ const ANOMALY_DETECTION_LINK = i18n.translate(
{ 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,
Expand Down Expand Up @@ -136,7 +152,7 @@ export function Contents({
</EuiTitle>
<EuiHorizontalRule margin="xs" />
</FlexColumnItem>
{hasAnomalyDetection && (
{isService && (
<FlexColumnItem>
<section>
<HealthStatusTitle size="xxs">
Expand All @@ -145,27 +161,35 @@ export function Contents({
&nbsp;
<EuiIconTip type="iInCircle" content={ANOMALY_DETECTION_INFO} />
</section>
<ContentLine>
<EuiFlexGroup>
<EuiFlexItem>
<VerticallyCentered>
<EuiHealth color={getSeverityColor(severity)} />
<SubduedText>{ANOMALY_DETECTION_SCORE_METRIC}</SubduedText>
</VerticallyCentered>
</EuiFlexItem>
<EuiFlexItem grow={false}>
<div>
{asInteger(maxScore)}
<SubduedText>&nbsp;({anomalyDescription})</SubduedText>
</div>
</EuiFlexItem>
</EuiFlexGroup>
</ContentLine>
<ContentLine>
<MLJobLink external jobId={jobId}>
{ANOMALY_DETECTION_LINK}
</MLJobLink>
</ContentLine>
{hasAnomalyDetection ? (
<>
<ContentLine>
<EuiFlexGroup>
<EuiFlexItem>
<VerticallyCentered>
<EuiHealth color={getSeverityColor(severity)} />
<SubduedText>
{ANOMALY_DETECTION_SCORE_METRIC}
</SubduedText>
</VerticallyCentered>
</EuiFlexItem>
<EuiFlexItem grow={false}>
<div>
{asInteger(maxScore)}
<SubduedText>&nbsp;({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>
)}
Expand Down
8 changes: 6 additions & 2 deletions x-pack/plugins/apm/server/lib/helpers/range_filter.ts
Original file line number Diff line number Diff line change
Expand Up @@ -4,9 +4,13 @@
* you may not use this file except in compliance with the Elastic License.
*/

export function rangeFilter(start: number, end: number) {
export function rangeFilter(
start: number,
end: number,
timestampField = '@timestamp'
) {
return {
'@timestamp': {
[timestampField]: {
gte: start,
lte: end,
format: 'epoch_millis'
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -9,7 +9,6 @@ import {
SPAN_DESTINATION_SERVICE_RESOURCE,
SERVICE_NAME,
SERVICE_ENVIRONMENT,
SERVICE_FRAMEWORK_NAME,
AGENT_NAME,
SPAN_TYPE,
SPAN_SUBTYPE
Expand All @@ -19,7 +18,6 @@ import { dedupeConnections } from './';
const nodejsService = {
[SERVICE_NAME]: 'opbeans-node',
[SERVICE_ENVIRONMENT]: 'production',
[SERVICE_FRAMEWORK_NAME]: null,
[AGENT_NAME]: 'nodejs'
};

Expand All @@ -32,7 +30,6 @@ const nodejsExternal = {
const javaService = {
[SERVICE_NAME]: 'opbeans-java',
[SERVICE_ENVIRONMENT]: 'production',
[SERVICE_FRAMEWORK_NAME]: null,
[AGENT_NAME]: 'java'
};

Expand Down
45 changes: 8 additions & 37 deletions x-pack/plugins/apm/server/lib/service_map/get_service_map.ts
Original file line number Diff line number Diff line change
Expand Up @@ -7,7 +7,6 @@ import { chunk } from 'lodash';
import {
AGENT_NAME,
SERVICE_ENVIRONMENT,
SERVICE_FRAMEWORK_NAME,
SERVICE_NAME
} from '../../../common/elasticsearch_fieldnames';
import { getServicesProjection } from '../../../common/projections/services';
Expand All @@ -19,6 +18,7 @@ import { getServiceMapFromTraceIds } from './get_service_map_from_trace_ids';
import { getTraceSampleIds } from './get_trace_sample_ids';
import { addAnomaliesToServicesData } from './ml_helpers';
import { getMlIndex } from '../../../common/ml_job_constants';
import { rangeFilter } from '../helpers/range_filter';

export interface IEnvOptions {
setup: Setup & SetupTimeRange;
Expand Down Expand Up @@ -107,11 +107,6 @@ async function getServicesData(options: IEnvOptions) {
terms: {
field: AGENT_NAME
}
},
service_framework_name: {
terms: {
field: SERVICE_FRAMEWORK_NAME
}
}
}
}
Expand All @@ -129,55 +124,31 @@ async function getServicesData(options: IEnvOptions) {
[SERVICE_NAME]: bucket.key as string,
[AGENT_NAME]:
(bucket.agent_name.buckets[0]?.key as string | undefined) || '',
[SERVICE_ENVIRONMENT]: options.environment || null,
[SERVICE_FRAMEWORK_NAME]:
(bucket.service_framework_name.buckets[0]?.key as
| string
| undefined) || null
[SERVICE_ENVIRONMENT]: options.environment || null
};
}) || []
);
}

function getAnomaliesData(options: IEnvOptions) {
const { client } = options.setup;
const { start, end, client } = options.setup;
const rangeQuery = { range: rangeFilter(start, end, 'timestamp') };

const params = {
index: getMlIndex('*'),
body: {
size: 0,
query: {
bool: {
filter: {
term: {
result_type: 'record'
}
}
}
bool: { filter: [{ term: { result_type: 'record' } }, rangeQuery] }
},
aggs: {
jobs: {
terms: {
field: 'job_id',
size: 10
},
terms: { field: 'job_id', size: 10 },
aggs: {
top_score_hits: {
top_hits: {
sort: [
{
record_score: {
order: 'desc' as const
}
}
],
_source: [
'job_id',
'record_score',
'typical',
'actual',
'field_name'
],
sort: [{ record_score: { order: 'desc' as const } }],
_source: ['job_id', 'record_score', 'typical', 'actual'],
size: 1
}
}
Expand Down
8 changes: 2 additions & 6 deletions x-pack/plugins/apm/server/lib/service_map/ml_helpers.test.ts
Original file line number Diff line number Diff line change
Expand Up @@ -13,14 +13,12 @@ describe('addAnomaliesToServicesData', () => {
{
'service.name': 'opbeans-ruby',
'agent.name': 'ruby',
'service.environment': null,
'service.framework.name': 'Ruby on Rails'
'service.environment': null
},
{
'service.name': 'opbeans-java',
'agent.name': 'java',
'service.environment': null,
'service.framework.name': null
'service.environment': null
}
];

Expand Down Expand Up @@ -72,7 +70,6 @@ describe('addAnomaliesToServicesData', () => {
'service.name': 'opbeans-ruby',
'agent.name': 'ruby',
'service.environment': null,
'service.framework.name': 'Ruby on Rails',
max_score: 50,
severity: 'major',
actual_value: 2000,
Expand All @@ -83,7 +80,6 @@ describe('addAnomaliesToServicesData', () => {
'service.name': 'opbeans-java',
'agent.name': 'java',
'service.environment': null,
'service.framework.name': null,
max_score: 100,
severity: 'critical',
actual_value: 9000,
Expand Down

0 comments on commit 56b81f0

Please sign in to comment.