Skip to content

Commit

Permalink
[ML] Add unit test for getFailedTransactionsCorrelationImpactLabel
Browse files Browse the repository at this point in the history
  • Loading branch information
qn895 committed Aug 16, 2021
1 parent 5ceed16 commit c6940c1
Show file tree
Hide file tree
Showing 3 changed files with 58 additions and 6 deletions.
Expand Up @@ -10,7 +10,7 @@ import { i18n } from '@kbn/i18n';
export const FAILED_TRANSACTIONS_CORRELATION_SEARCH_STRATEGY =
'apmFailedTransactionsCorrelationsSearchStrategy';

export const FAILURE_CORRELATION_IMPACT_THRESHOLD = {
export const FAILED_TRANSACTIONS_IMPACT_THRESHOLD = {
HIGH: i18n.translate(
'xpack.apm.correlations.failedTransactions.highImpactText',
{
Expand Down
@@ -0,0 +1,51 @@
/*
* Copyright Elasticsearch B.V. and/or licensed to Elasticsearch B.V. under one
* or more contributor license agreements. Licensed under the Elastic License
* 2.0; you may not use this file except in compliance with the Elastic License
* 2.0.
*/

import { getFailedTransactionsCorrelationImpactLabel } from './get_failed_transactions_correlation_impact_label';
import { FAILED_TRANSACTIONS_IMPACT_THRESHOLD } from '../../../../../common/search_strategies/failure_correlations/constants';

describe('getFailedTransactionsCorrelationImpactLabel', () => {
it('returns null if value is invalid ', () => {
expect(getFailedTransactionsCorrelationImpactLabel(-0.03)).toBe(null);
expect(getFailedTransactionsCorrelationImpactLabel(NaN)).toBe(null);
expect(getFailedTransactionsCorrelationImpactLabel(Infinity)).toBe(null);
});

it('returns null if value is greater than threshold ', () => {
expect(getFailedTransactionsCorrelationImpactLabel(0.1)).toBe(null);
});

it('returns High if value is within [0, 1e-6) ', () => {
expect(getFailedTransactionsCorrelationImpactLabel(0)).toBe(
FAILED_TRANSACTIONS_IMPACT_THRESHOLD.HIGH
);
expect(getFailedTransactionsCorrelationImpactLabel(1e-7)).toBe(
FAILED_TRANSACTIONS_IMPACT_THRESHOLD.HIGH
);
});

it('returns Medium if value is within [1e-6, 1e-3) ', () => {
expect(getFailedTransactionsCorrelationImpactLabel(1e-6)).toBe(
FAILED_TRANSACTIONS_IMPACT_THRESHOLD.MEDIUM
);
expect(getFailedTransactionsCorrelationImpactLabel(1e-5)).toBe(
FAILED_TRANSACTIONS_IMPACT_THRESHOLD.MEDIUM
);
expect(getFailedTransactionsCorrelationImpactLabel(1e-4)).toBe(
FAILED_TRANSACTIONS_IMPACT_THRESHOLD.MEDIUM
);
});

it('returns Low if value is within [1e-3, 0.02) ', () => {
expect(getFailedTransactionsCorrelationImpactLabel(1e-3)).toBe(
FAILED_TRANSACTIONS_IMPACT_THRESHOLD.LOW
);
expect(getFailedTransactionsCorrelationImpactLabel(0.02)).toBe(
FAILED_TRANSACTIONS_IMPACT_THRESHOLD.LOW
);
});
});
Expand Up @@ -6,17 +6,18 @@
*/

import { FailureCorrelationImpactThreshold } from '../../../../../common/search_strategies/failure_correlations/types';
import { FAILURE_CORRELATION_IMPACT_THRESHOLD } from '../../../../../common/search_strategies/failure_correlations/constants';
import { FAILED_TRANSACTIONS_IMPACT_THRESHOLD } from '../../../../../common/search_strategies/failure_correlations/constants';

export function getFailedTransactionsCorrelationImpactLabel(
pValue: number
): FailureCorrelationImpactThreshold | null {
if (pValue > 0 && pValue < 1e-6)
return FAILURE_CORRELATION_IMPACT_THRESHOLD.HIGH;
// The lower the p value, the higher the impact
if (pValue >= 0 && pValue < 1e-6)
return FAILED_TRANSACTIONS_IMPACT_THRESHOLD.HIGH;
if (pValue >= 1e-6 && pValue < 0.001)
return FAILURE_CORRELATION_IMPACT_THRESHOLD.MEDIUM;
return FAILED_TRANSACTIONS_IMPACT_THRESHOLD.MEDIUM;
if (pValue >= 0.001 && pValue <= 0.02)
return FAILURE_CORRELATION_IMPACT_THRESHOLD.LOW;
return FAILED_TRANSACTIONS_IMPACT_THRESHOLD.LOW;

return null;
}

0 comments on commit c6940c1

Please sign in to comment.