Skip to content

Commit

Permalink
[ML] Fix types, rename var
Browse files Browse the repository at this point in the history
  • Loading branch information
qn895 committed Aug 13, 2021
1 parent 63a10b8 commit 0633e88
Show file tree
Hide file tree
Showing 7 changed files with 44 additions and 32 deletions.
Original file line number Diff line number Diff line change
Expand Up @@ -9,7 +9,7 @@ import { i18n } from '@kbn/i18n';

export const APM_ERROR_CORRELATION_SEARCH_STRATEGY =
'apmErrorCorrelationsSearchStrategy';
export const FAILED_TRANSACTION_CORRELATION_IMPACT = {
export const FAILURE_CORRELATION_IMPACT_THRESHOLD = {
HIGH: i18n.translate(
'xpack.apm.correlations.failedTransactions.highImpactText',
{
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -5,14 +5,14 @@
* 2.0.
*/

import { FAILED_TRANSACTION_CORRELATION_IMPACT } from './constants';
import { FAILURE_CORRELATION_IMPACT_THRESHOLD } from './constants';

export interface ErrorCorrelationValue {
key: string;
doc_count: number;
bg_count: number;
score: number;
p_value: number | null;
pValue: number | null;
fieldName: string;
fieldValue: string;
}
Expand All @@ -30,4 +30,4 @@ export interface BaseSearchStrategyResponse {
cancelFetch: () => void;
}

export type FailedTransactionCorrelationImpact = typeof FAILED_TRANSACTION_CORRELATION_IMPACT[keyof typeof FAILED_TRANSACTION_CORRELATION_IMPACT]; // typeof JOB_FIELD_TYPES[keyof typeof JOB_FIELD_TYPES];
export type FailureCorrelationImpactThreshold = typeof FAILURE_CORRELATION_IMPACT_THRESHOLD[keyof typeof FAILURE_CORRELATION_IMPACT_THRESHOLD];
Original file line number Diff line number Diff line change
Expand Up @@ -33,16 +33,13 @@ import { useCorrelationsSearchStrategy } from './use_correlations_search_strateg
import {
BaseSearchStrategyResponse,
ErrorCorrelationValue,
FailedTransactionCorrelationImpact,
} from '../../../../common/search_strategies/error_correlations/types';
import { ImpactBar } from '../../shared/ImpactBar';
import {
APM_ERROR_CORRELATION_SEARCH_STRATEGY,
FAILED_TRANSACTION_CORRELATION_IMPACT,
} from '../../../../common/search_strategies/error_correlations/constants';
import { APM_ERROR_CORRELATION_SEARCH_STRATEGY } from '../../../../common/search_strategies/error_correlations/constants';
import { isErrorMessage } from './utils/is_error_message';
import { Summary } from '../../shared/Summary';
import { FETCH_STATUS } from '../../../hooks/use_fetcher';
import { getFailureCorrelationImpactLabel } from './utils/get_failure_correlation_impact_label';

interface Props {
onClose: () => void;
Expand All @@ -53,19 +50,6 @@ interface ErrorCorrelationSearchStrategyResult
values: ErrorCorrelationValue[];
}

export function getFailedTransactionsImpactLabel(
pValue: number
): FailedTransactionCorrelationImpact | null {
if (pValue > 0 && pValue < 1e-6)
return FAILED_TRANSACTION_CORRELATION_IMPACT.HIGH;
if (pValue >= 1e-6 && pValue < 0.001)
return FAILED_TRANSACTION_CORRELATION_IMPACT.MEDIUM;
if (pValue >= 0.001 && pValue <= 0.02)
return FAILED_TRANSACTION_CORRELATION_IMPACT.LOW;

return null;
}

export function MlFailureCorrelations({ onClose }: Props) {
const {
core: { notifications, uiSettings },
Expand Down Expand Up @@ -136,8 +120,8 @@ export function MlFailureCorrelations({ onClose }: Props) {
> = useMemo(
() => [
{
width: '125px',
field: 'normalized_score',
width: '116px',
field: 'normalizedScore',
name: (
<>
{i18n.translate(
Expand All @@ -158,7 +142,7 @@ export function MlFailureCorrelations({ onClose }: Props) {
},
{
width: '116px',
field: 'p_value',
field: 'pValue',
name: (
<>
{i18n.translate(
Expand All @@ -169,7 +153,7 @@ export function MlFailureCorrelations({ onClose }: Props) {
)}
</>
),
render: getFailedTransactionsImpactLabel,
render: getFailureCorrelationImpactLabel,
},
{
field: 'fieldName',
Expand Down Expand Up @@ -259,9 +243,9 @@ export function MlFailureCorrelations({ onClose }: Props) {
{`${selectedTerm.fieldName}: ${selectedTerm.key}`}
</EuiBadge>,
`p-value: ${
selectedTerm.p_value !== null && selectedTerm.p_value < 0.00001
selectedTerm.pValue !== null && selectedTerm.pValue < 0.00001
? '<.00001'
: asPreciseDecimal(selectedTerm.p_value, 4)
: asPreciseDecimal(selectedTerm.pValue, 4)
}`,
]}
/>
Expand Down
Original file line number Diff line number Diff line change
@@ -0,0 +1,6 @@
/*
* 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.
*/
Original file line number Diff line number Diff line change
@@ -0,0 +1,22 @@
/*
* 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 { FailureCorrelationImpactThreshold } from '../../../../../common/search_strategies/error_correlations/types';
import { FAILURE_CORRELATION_IMPACT_THRESHOLD } from '../../../../../common/search_strategies/error_correlations/constants';

export function getFailureCorrelationImpactLabel(
pValue: number
): FailureCorrelationImpactThreshold | null {
if (pValue > 0 && pValue < 1e-6)
return FAILURE_CORRELATION_IMPACT_THRESHOLD.HIGH;
if (pValue >= 1e-6 && pValue < 0.001)
return FAILURE_CORRELATION_IMPACT_THRESHOLD.MEDIUM;
if (pValue >= 0.001 && pValue <= 0.02)
return FAILURE_CORRELATION_IMPACT_THRESHOLD.LOW;

return null;
}
Original file line number Diff line number Diff line change
Expand Up @@ -67,8 +67,8 @@ export const asyncErrorCorrelationSearchServiceProvider = (
result.value.filter(
(record) =>
record &&
typeof record.p_value === 'number' &&
record.p_value < ERROR_CORRELATION_THRESHOLD
typeof record.pValue === 'number' &&
record.pValue < ERROR_CORRELATION_THRESHOLD
)
);
} else {
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -92,8 +92,8 @@ export const fetchFailedTransactionsCorrelationPValues = async (
...b,
fieldName,
fieldValue: b.key,
p_value: Math.exp(-score),
normalized_score: normalizedScore,
pValue: Math.exp(-score),
normalizedScore,
};
});

Expand Down

0 comments on commit 0633e88

Please sign in to comment.