Skip to content

Commit

Permalink
Move getSeverity
Browse files Browse the repository at this point in the history
  • Loading branch information
sorenlouv committed Jul 20, 2020
1 parent 335203d commit 53437de
Show file tree
Hide file tree
Showing 7 changed files with 74 additions and 74 deletions.
41 changes: 0 additions & 41 deletions x-pack/plugins/apm/common/anomaly_detection.test.ts

This file was deleted.

23 changes: 0 additions & 23 deletions x-pack/plugins/apm/common/anomaly_detection.ts
Original file line number Diff line number Diff line change
Expand Up @@ -13,29 +13,6 @@ export interface ServiceAnomalyStats {
jobId?: string;
}

export enum severity {
critical = 'critical',
major = 'major',
minor = 'minor',
warning = 'warning',
}

export function getSeverity(score?: number) {
if (typeof score !== 'number') {
return undefined;
} else if (score < 25) {
return severity.warning;
} else if (score >= 25 && score < 50) {
return severity.minor;
} else if (score >= 50 && score < 75) {
return severity.major;
} else if (score >= 75) {
return severity.critical;
} else {
return undefined;
}
}

export const MLErrorMessages: Record<ErrorCode, string> = {
INSUFFICIENT_LICENSE: i18n.translate(
'xpack.apm.anomaly_detection.error.insufficient_license',
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -20,10 +20,8 @@ import { asInteger, asDuration } from '../../../../utils/formatters';
import { MLJobLink } from '../../../shared/Links/MachineLearningLinks/MLJobLink';
import { getSeverityColor, popoverWidth } from '../cytoscapeOptions';
import { TRANSACTION_REQUEST } from '../../../../../common/transaction_types';
import {
ServiceAnomalyStats,
getSeverity,
} from '../../../../../common/anomaly_detection';
import { ServiceAnomalyStats } from '../../../../../common/anomaly_detection';
import { getSeverity } from './getSeverity';

const HealthStatusTitle = styled(EuiTitle)`
display: inline;
Expand Down
Original file line number Diff line number Diff line change
@@ -0,0 +1,39 @@
/*
* Copyright Elasticsearch B.V. and/or licensed to Elasticsearch B.V. under one
* or more contributor license agreements. Licensed under the Elastic License;
* you may not use this file except in compliance with the Elastic License.
*/

import { getSeverity } from './getSeverity';

describe('getSeverity', () => {
describe('when score is undefined', () => {
it('returns undefined', () => {
expect(getSeverity(undefined)).toEqual(undefined);
});
});

describe('when score < 25', () => {
it('returns warning', () => {
expect(getSeverity(10)).toEqual(severity.warning);
});
});

describe('when score is between 25 and 50', () => {
it('returns minor', () => {
expect(getSeverity(40)).toEqual(severity.minor);
});
});

describe('when score is between 50 and 75', () => {
it('returns major', () => {
expect(getSeverity(60)).toEqual(severity.major);
});
});

describe('when score is 75 or more', () => {
it('returns critical', () => {
expect(getSeverity(100)).toEqual(severity.critical);
});
});
});
Original file line number Diff line number Diff line change
@@ -0,0 +1,30 @@
/*
* Copyright Elasticsearch B.V. and/or licensed to Elasticsearch B.V. under one
* or more contributor license agreements. Licensed under the Elastic License;
* you may not use this file except in compliance with the Elastic License.
*/

export enum severity {
critical = 'critical',
major = 'major',
minor = 'minor',
warning = 'warning',
}

// TODO: Replace with `getSeverity` from:
// https://github.com/elastic/kibana/blob/0f964f66916480f2de1f4b633e5afafc08cf62a0/x-pack/plugins/ml/common/util/anomaly_utils.ts#L129
export function getSeverity(score?: number) {
if (typeof score !== 'number') {
return undefined;
} else if (score < 25) {
return severity.warning;
} else if (score >= 25 && score < 50) {
return severity.minor;
} else if (score >= 50 && score < 75) {
return severity.major;
} else if (score >= 75) {
return severity.critical;
} else {
return undefined;
}
}
Original file line number Diff line number Diff line change
Expand Up @@ -11,11 +11,8 @@ import {
} from '../../../../common/elasticsearch_fieldnames';
import { EuiTheme } from '../../../../../observability/public';
import { defaultIcon, iconForNode } from './icons';
import {
ServiceAnomalyStats,
severity,
getSeverity,
} from '../../../../common/anomaly_detection';
import { ServiceAnomalyStats } from '../../../../common/anomaly_detection';
import { severity, getSeverity } from './Popover/getSeverity';

export const popoverWidth = 280;

Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -143,7 +143,7 @@ function getNoItemsMessage({
return <LoadingStatePrompt />;
}

// A known erorr occured. Show specific error message
// A known error occured. Show specific error message
if (errorCode) {
return MLErrorMessages[errorCode];
}
Expand Down

0 comments on commit 53437de

Please sign in to comment.