From c6940c111c38916c26cb02fa63a76ab1f6b1a7de Mon Sep 17 00:00:00 2001 From: Quynh Nguyen Date: Mon, 16 Aug 2021 13:19:35 -0500 Subject: [PATCH] [ML] Add unit test for getFailedTransactionsCorrelationImpactLabel --- .../failure_correlations/constants.ts | 2 +- ...nsactions_correlation_impact_label.test.ts | 51 +++++++++++++++++++ ..._transactions_correlation_impact_label.ts} | 11 ++-- 3 files changed, 58 insertions(+), 6 deletions(-) create mode 100644 x-pack/plugins/apm/public/components/app/correlations/utils/get_failed_transactions_correlation_impact_label.test.ts rename x-pack/plugins/apm/public/components/app/correlations/utils/{get_failure_correlation_impact_label.ts => get_failed_transactions_correlation_impact_label.ts} (67%) diff --git a/x-pack/plugins/apm/common/search_strategies/failure_correlations/constants.ts b/x-pack/plugins/apm/common/search_strategies/failure_correlations/constants.ts index 22b59f91af7ddb..a80918f0e399e2 100644 --- a/x-pack/plugins/apm/common/search_strategies/failure_correlations/constants.ts +++ b/x-pack/plugins/apm/common/search_strategies/failure_correlations/constants.ts @@ -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', { diff --git a/x-pack/plugins/apm/public/components/app/correlations/utils/get_failed_transactions_correlation_impact_label.test.ts b/x-pack/plugins/apm/public/components/app/correlations/utils/get_failed_transactions_correlation_impact_label.test.ts new file mode 100644 index 00000000000000..e448b23bcc4908 --- /dev/null +++ b/x-pack/plugins/apm/public/components/app/correlations/utils/get_failed_transactions_correlation_impact_label.test.ts @@ -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 + ); + }); +}); diff --git a/x-pack/plugins/apm/public/components/app/correlations/utils/get_failure_correlation_impact_label.ts b/x-pack/plugins/apm/public/components/app/correlations/utils/get_failed_transactions_correlation_impact_label.ts similarity index 67% rename from x-pack/plugins/apm/public/components/app/correlations/utils/get_failure_correlation_impact_label.ts rename to x-pack/plugins/apm/public/components/app/correlations/utils/get_failed_transactions_correlation_impact_label.ts index ef66162f871366..6fcaec52cb5602 100644 --- a/x-pack/plugins/apm/public/components/app/correlations/utils/get_failure_correlation_impact_label.ts +++ b/x-pack/plugins/apm/public/components/app/correlations/utils/get_failed_transactions_correlation_impact_label.ts @@ -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; }