From 575f816907b2e05bda42843c8508b2585f17e730 Mon Sep 17 00:00:00 2001 From: Quynh Nguyen Date: Mon, 28 Feb 2022 13:35:41 -0600 Subject: [PATCH 01/11] Remove score column for failed transactions --- .../failed_transactions_correlations.tsx | 24 --------------- ...d_transactions_correlation_impact_label.ts | 30 +++++++++++++++++++ 2 files changed, 30 insertions(+), 24 deletions(-) diff --git a/x-pack/plugins/apm/public/components/app/correlations/failed_transactions_correlations.tsx b/x-pack/plugins/apm/public/components/app/correlations/failed_transactions_correlations.tsx index 6d20faae89a10..1e6c218f25dfb 100644 --- a/x-pack/plugins/apm/public/components/app/correlations/failed_transactions_correlations.tsx +++ b/x-pack/plugins/apm/public/components/app/correlations/failed_transactions_correlations.tsx @@ -36,8 +36,6 @@ import { useApmPluginContext } from '../../../context/apm_plugin/use_apm_plugin_ import { useLocalStorage } from '../../../hooks/use_local_storage'; import { FETCH_STATUS } from '../../../hooks/use_fetcher'; import { useTheme } from '../../../hooks/use_theme'; - -import { ImpactBar } from '../../shared/impact_bar'; import { push } from '../../shared/links/url_helpers'; import { CorrelationsTable } from './correlations_table'; @@ -225,28 +223,6 @@ export function FailedTransactionsCorrelations({ ] : []; return [ - { - width: '116px', - field: 'normalizedScore', - name: ( - <> - {i18n.translate( - 'xpack.apm.correlations.failedTransactions.correlationsTable.scoreLabel', - { - defaultMessage: 'Score', - } - )} - - ), - render: (_, { normalizedScore }) => { - return ( - <> - - - ); - }, - sortable: true, - }, { width: '116px', field: 'pValue', diff --git a/x-pack/plugins/apm/public/components/app/correlations/utils/get_failed_transactions_correlation_impact_label.ts b/x-pack/plugins/apm/public/components/app/correlations/utils/get_failed_transactions_correlation_impact_label.ts index d5d0fd4dcae51..93effa1e87f48 100644 --- a/x-pack/plugins/apm/public/components/app/correlations/utils/get_failed_transactions_correlation_impact_label.ts +++ b/x-pack/plugins/apm/public/components/app/correlations/utils/get_failed_transactions_correlation_impact_label.ts @@ -40,3 +40,33 @@ export function getFailedTransactionsCorrelationImpactLabel( return null; } + +export function getLatencyCorrelationImpactLabel( + pValue: FailedTransactionsCorrelation['pValue'] +): { + impact: FailedTransactionsCorrelationsImpactThreshold; + color: string; +} | null { + if (pValue === null) { + return null; + } + + // The lower the p value, the higher the impact + if (pValue >= 0 && pValue < 1e-6) + return { + impact: FAILED_TRANSACTIONS_IMPACT_THRESHOLD.HIGH, + color: 'danger', + }; + if (pValue >= 1e-6 && pValue < 0.001) + return { + impact: FAILED_TRANSACTIONS_IMPACT_THRESHOLD.MEDIUM, + color: 'warning', + }; + if (pValue >= 0.001 && pValue < 0.02) + return { + impact: FAILED_TRANSACTIONS_IMPACT_THRESHOLD.LOW, + color: 'default', + }; + + return null; +} From 0743eb4fa26bb2d51690fb010364174bde7dbc73 Mon Sep 17 00:00:00 2001 From: Quynh Nguyen Date: Thu, 27 Jan 2022 08:41:17 -0600 Subject: [PATCH 02/11] Show at least one correlated value --- .../latency_correlations/types.ts | 2 +- .../use_failed_transactions_correlations.ts | 6 +++ .../correlations/use_latency_correlations.ts | 23 +++++++++ .../query_correlation_with_histogram.ts | 43 +++++++++-------- .../correlations/queries/query_p_values.ts | 41 ++++++++++++---- .../queries/query_significant_correlations.ts | 48 +++++++++++++++++-- .../apm/server/routes/correlations/route.ts | 2 + 7 files changed, 131 insertions(+), 34 deletions(-) diff --git a/x-pack/plugins/apm/common/correlations/latency_correlations/types.ts b/x-pack/plugins/apm/common/correlations/latency_correlations/types.ts index 23c91554b6547..d493ac6e58838 100644 --- a/x-pack/plugins/apm/common/correlations/latency_correlations/types.ts +++ b/x-pack/plugins/apm/common/correlations/latency_correlations/types.ts @@ -10,7 +10,7 @@ import { FieldStats } from '../field_stats_types'; export interface LatencyCorrelation extends FieldValuePair { correlation: number; - histogram: HistogramItem[]; + histogram?: HistogramItem[]; ksTest: number; } diff --git a/x-pack/plugins/apm/public/components/app/correlations/use_failed_transactions_correlations.ts b/x-pack/plugins/apm/public/components/app/correlations/use_failed_transactions_correlations.ts index 41a2afada6e65..9018e1240194b 100644 --- a/x-pack/plugins/apm/public/components/app/correlations/use_failed_transactions_correlations.ts +++ b/x-pack/plugins/apm/public/components/app/correlations/use_failed_transactions_correlations.ts @@ -177,6 +177,12 @@ export function useFailedTransactionsCorrelations() { getFailedTransactionsCorrelationsSortedByScore([ ...failedTransactionsCorrelations, ]); + } else { + if (pValues.fallbackResult) { + responseUpdate.failedTransactionsCorrelations = [ + pValues.fallbackResult, + ]; + } } chunkLoadCounter++; diff --git a/x-pack/plugins/apm/public/components/app/correlations/use_latency_correlations.ts b/x-pack/plugins/apm/public/components/app/correlations/use_latency_correlations.ts index 0e166344d0dec..5693e25e0374c 100644 --- a/x-pack/plugins/apm/public/components/app/correlations/use_latency_correlations.ts +++ b/x-pack/plugins/apm/public/components/app/correlations/use_latency_correlations.ts @@ -177,6 +177,7 @@ export function useLatencyCorrelations() { chunkSize ); + const fallbackResults: LatencyCorrelation[] = []; for (const fieldValuePairChunk of fieldValuePairChunks) { const significantCorrelations = await callApmApi( 'POST /internal/apm/correlations/significant_correlations', @@ -197,6 +198,12 @@ export function useLatencyCorrelations() { ); responseUpdate.latencyCorrelations = getLatencyCorrelationsSortedByCorrelation([...latencyCorrelations]); + } else { + // If there's no correlation results that matches the criteria + // Consider the fallback results + if (significantCorrelations.fallbackResult) { + fallbackResults.push(significantCorrelations.fallbackResult); + } } chunkLoadCounter++; @@ -213,6 +220,22 @@ export function useLatencyCorrelations() { } } + if (latencyCorrelations.length === 0 && fallbackResults.length > 0) { + // Rank the fallback results and show at least one value + const sortedFallbackResults = fallbackResults.sort( + (a, b) => b.correlation - a.correlation + ); + + responseUpdate.latencyCorrelations = sortedFallbackResults.slice(0, 1); + + setResponse({ + ...responseUpdate, + loaded: + LOADED_FIELD_VALUE_PAIRS + + (chunkLoadCounter / fieldValuePairChunks.length) * + PROGRESS_STEP_CORRELATIONS, + }); + } setResponse.flush(); const { stats } = await callApmApi( diff --git a/x-pack/plugins/apm/server/routes/correlations/queries/query_correlation_with_histogram.ts b/x-pack/plugins/apm/server/routes/correlations/queries/query_correlation_with_histogram.ts index 03b28b28d521a..bb60c96eebbca 100644 --- a/x-pack/plugins/apm/server/routes/correlations/queries/query_correlation_with_histogram.ts +++ b/x-pack/plugins/apm/server/routes/correlations/queries/query_correlation_with_histogram.ts @@ -32,7 +32,9 @@ export async function fetchTransactionDurationCorrelationWithHistogram( histogramRangeSteps: number[], totalDocCount: number, fieldValuePair: FieldValuePair -): Promise { +): Promise< + LatencyCorrelation | Omit | undefined +> { const { correlation, ksTest } = await fetchTransactionDurationCorrelation( esClient, params, @@ -43,23 +45,26 @@ export async function fetchTransactionDurationCorrelationWithHistogram( [fieldValuePair] ); - if ( - correlation !== null && - correlation > CORRELATION_THRESHOLD && - ksTest !== null && - ksTest < KS_TEST_THRESHOLD - ) { - const logHistogram = await fetchTransactionDurationRanges( - esClient, - params, - histogramRangeSteps, - [fieldValuePair] - ); - return { - ...fieldValuePair, - correlation, - ksTest, - histogram: logHistogram, - }; + if (correlation !== null && ksTest !== null && !isNaN(ksTest)) { + if (correlation > CORRELATION_THRESHOLD && ksTest < KS_TEST_THRESHOLD) { + const logHistogram = await fetchTransactionDurationRanges( + esClient, + params, + histogramRangeSteps, + [fieldValuePair] + ); + return { + ...fieldValuePair, + correlation, + ksTest, + histogram: logHistogram, + }; + } else { + return { + ...fieldValuePair, + correlation, + ksTest, + }; + } } } diff --git a/x-pack/plugins/apm/server/routes/correlations/queries/query_p_values.ts b/x-pack/plugins/apm/server/routes/correlations/queries/query_p_values.ts index 7c471aebd0f7a..ba53880a0f053 100644 --- a/x-pack/plugins/apm/server/routes/correlations/queries/query_p_values.ts +++ b/x-pack/plugins/apm/server/routes/correlations/queries/query_p_values.ts @@ -41,18 +41,39 @@ export const fetchPValues = async ( ) ); - const failedTransactionsCorrelations: FailedTransactionsCorrelation[] = - fulfilled - .flat() - .filter( - (record) => - record && - typeof record.pValue === 'number' && - record.pValue < ERROR_CORRELATION_THRESHOLD - ); + const flattenedResults = fulfilled.flat(); + + const failedTransactionsCorrelations: FailedTransactionsCorrelation[] = []; + let fallbackResult: FailedTransactionsCorrelation | undefined; + + flattenedResults.forEach((record) => { + if ( + record && + typeof record.pValue === 'number' && + record.pValue < ERROR_CORRELATION_THRESHOLD + ) { + failedTransactionsCorrelations.push(record); + } else { + // If there's no result matching the criteria + // Find the next highest/closest result to the threshold + // to use as a fallback result + if (fallbackResult === null) { + fallbackResult = record; + } else { + if ( + record.pValue !== null && + fallbackResult && + fallbackResult.pValue !== null && + record.pValue < fallbackResult.pValue + ) { + fallbackResult = record; + } + } + } + }); const ccsWarning = rejected.length > 0 && paramsWithIndex?.index.includes(':'); - return { failedTransactionsCorrelations, ccsWarning }; + return { failedTransactionsCorrelations, ccsWarning, fallbackResult }; }; diff --git a/x-pack/plugins/apm/server/routes/correlations/queries/query_significant_correlations.ts b/x-pack/plugins/apm/server/routes/correlations/queries/query_significant_correlations.ts index ed5ad1c278143..1f2bac7adfdca 100644 --- a/x-pack/plugins/apm/server/routes/correlations/queries/query_significant_correlations.ts +++ b/x-pack/plugins/apm/server/routes/correlations/queries/query_significant_correlations.ts @@ -25,6 +25,7 @@ import { fetchTransactionDurationFractions, fetchTransactionDurationHistogramRangeSteps, fetchTransactionDurationPercentiles, + fetchTransactionDurationRanges, } from './index'; export const fetchSignificantCorrelations = async ( @@ -76,12 +77,51 @@ export const fetchSignificantCorrelations = async ( ) ); - const latencyCorrelations: LatencyCorrelation[] = fulfilled.filter( - (d): d is LatencyCorrelation => d !== undefined - ); + let fallbackResult: LatencyCorrelation | undefined; + const latencyCorrelations: LatencyCorrelation[] = []; + + fulfilled.forEach((d: LatencyCorrelation | undefined) => { + if (d === undefined) return; + if (Array.isArray(d.histogram)) { + latencyCorrelations.push(d); + } else { + if (!fallbackResult) { + fallbackResult = d; + } else { + if ( + d.ksTest > fallbackResult.ksTest && + d.correlation > fallbackResult.correlation + ) { + fallbackResult = d; + } + } + } + }); + + if (latencyCorrelations.length === 0 && fallbackResult) { + const { fieldName, fieldValue } = fallbackResult; + const logHistogram = await fetchTransactionDurationRanges( + esClient, + paramsWithIndex, + histogramRangeSteps, + [{ fieldName, fieldValue }] + ); + + if (typeof fallbackResult === 'object' && fallbackResult !== null) { + fallbackResult = { + ...(fallbackResult as LatencyCorrelation), + histogram: logHistogram, + }; + } + } const ccsWarning = rejected.length > 0 && paramsWithIndex?.index.includes(':'); - return { latencyCorrelations, ccsWarning, totalDocCount }; + return { + latencyCorrelations, + ccsWarning, + totalDocCount, + fallbackResult, + }; }; diff --git a/x-pack/plugins/apm/server/routes/correlations/route.ts b/x-pack/plugins/apm/server/routes/correlations/route.ts index fd0bce7a62ff8..b0735c7c57b36 100644 --- a/x-pack/plugins/apm/server/routes/correlations/route.ts +++ b/x-pack/plugins/apm/server/routes/correlations/route.ts @@ -257,6 +257,7 @@ const significantCorrelationsRoute = createApmServerRoute({ >; ccsWarning: boolean; totalDocCount: number; + fallbackResult?: import('./../../../common/correlations/latency_correlations/types').LatencyCorrelation; }> => { const { context } = resources; if (!isActivePlatinumLicense(context.licensing.license)) { @@ -314,6 +315,7 @@ const pValuesRoute = createApmServerRoute({ import('./../../../common/correlations/failed_transactions_correlations/types').FailedTransactionsCorrelation >; ccsWarning: boolean; + fallbackResult?: import('./../../../common/correlations/failed_transactions_correlations/types').FailedTransactionsCorrelation; }> => { const { context } = resources; if (!isActivePlatinumLicense(context.licensing.license)) { From dacd1bee9e64441c53484d72a57af43a1f30e068 Mon Sep 17 00:00:00 2001 From: Quynh Nguyen Date: Mon, 28 Feb 2022 16:07:14 -0600 Subject: [PATCH 03/11] Add very low badge for fallback transactions --- .../latency_correlations/types.ts | 1 + .../app/correlations/latency_correlations.tsx | 19 ++++++++++++++++++- .../correlations/use_latency_correlations.ts | 11 ++++++----- 3 files changed, 25 insertions(+), 6 deletions(-) diff --git a/x-pack/plugins/apm/common/correlations/latency_correlations/types.ts b/x-pack/plugins/apm/common/correlations/latency_correlations/types.ts index d493ac6e58838..cf20490774e18 100644 --- a/x-pack/plugins/apm/common/correlations/latency_correlations/types.ts +++ b/x-pack/plugins/apm/common/correlations/latency_correlations/types.ts @@ -12,6 +12,7 @@ export interface LatencyCorrelation extends FieldValuePair { correlation: number; histogram?: HistogramItem[]; ksTest: number; + isFallbackResult?: boolean; } export interface LatencyCorrelationsResponse { diff --git a/x-pack/plugins/apm/public/components/app/correlations/latency_correlations.tsx b/x-pack/plugins/apm/public/components/app/correlations/latency_correlations.tsx index 5b37a14b4e4e5..837a5d6a45748 100644 --- a/x-pack/plugins/apm/public/components/app/correlations/latency_correlations.tsx +++ b/x-pack/plugins/apm/public/components/app/correlations/latency_correlations.tsx @@ -17,12 +17,14 @@ import { EuiSpacer, EuiTitle, EuiToolTip, + EuiBadge, } from '@elastic/eui'; import { Direction } from '@elastic/eui/src/services/sort/sort_direction'; import { EuiTableSortingType } from '@elastic/eui/src/components/basic_table/table_types'; import { i18n } from '@kbn/i18n'; +import { FormattedMessage } from '@kbn/i18n-react'; import { useUiTracker } from '../../../../../observability/public'; import { asPreciseDecimal } from '../../../../common/utils/formatters'; @@ -49,6 +51,17 @@ import { useTheme } from '../../../hooks/use_theme'; import { ChartTitleToolTip } from './chart_title_tool_tip'; import { MIN_TAB_TITLE_HEIGHT } from '../transaction_details/distribution'; +export function FallbackCorrelationBadge() { + return ( + + + + ); +} + export function LatencyCorrelations({ onFilter }: { onFilter: () => void }) { const { core: { notifications }, @@ -146,7 +159,11 @@ export function LatencyCorrelations({ onFilter }: { onFilter: () => void }) { ), - render: (_, { correlation }) => { + render: (_, { correlation, isFallbackResult }) => { + if (isFallbackResult) { + return ; + } + return
{asPreciseDecimal(correlation, 2)}
; }, sortable: true, diff --git a/x-pack/plugins/apm/public/components/app/correlations/use_latency_correlations.ts b/x-pack/plugins/apm/public/components/app/correlations/use_latency_correlations.ts index 5693e25e0374c..428fdcda7cfc6 100644 --- a/x-pack/plugins/apm/public/components/app/correlations/use_latency_correlations.ts +++ b/x-pack/plugins/apm/public/components/app/correlations/use_latency_correlations.ts @@ -222,12 +222,13 @@ export function useLatencyCorrelations() { if (latencyCorrelations.length === 0 && fallbackResults.length > 0) { // Rank the fallback results and show at least one value - const sortedFallbackResults = fallbackResults.sort( - (a, b) => b.correlation - a.correlation - ); - - responseUpdate.latencyCorrelations = sortedFallbackResults.slice(0, 1); + const sortedFallbackResults = fallbackResults + .filter((r) => r.correlation > 0) + .sort((a, b) => b.correlation - a.correlation); + responseUpdate.latencyCorrelations = sortedFallbackResults + .slice(0, 1) + .map((r) => ({ ...r, isFallbackResult: true })); setResponse({ ...responseUpdate, loaded: From c7266d061647469c28cbf2471ef52e6007891c85 Mon Sep 17 00:00:00 2001 From: Quynh Nguyen Date: Tue, 1 Mar 2022 14:36:09 -0600 Subject: [PATCH 04/11] Match two columns --- .../constants.ts | 6 ++++ .../failed_transactions_correlations.tsx | 25 ++++++++++++- .../app/correlations/latency_correlations.tsx | 35 ++++++++++++++++--- ...d_transactions_correlation_impact_label.ts | 33 +++++++++++------ 4 files changed, 83 insertions(+), 16 deletions(-) diff --git a/x-pack/plugins/apm/common/correlations/failed_transactions_correlations/constants.ts b/x-pack/plugins/apm/common/correlations/failed_transactions_correlations/constants.ts index 09e3e22a1d352..099b6ae6fa4a3 100644 --- a/x-pack/plugins/apm/common/correlations/failed_transactions_correlations/constants.ts +++ b/x-pack/plugins/apm/common/correlations/failed_transactions_correlations/constants.ts @@ -26,4 +26,10 @@ export const FAILED_TRANSACTIONS_IMPACT_THRESHOLD = { defaultMessage: 'Low', } ), + VERY_LOW: i18n.translate( + 'xpack.apm.correlations.failedTransactions.veryLowImpactText', + { + defaultMessage: 'Very low', + } + ), } as const; diff --git a/x-pack/plugins/apm/public/components/app/correlations/failed_transactions_correlations.tsx b/x-pack/plugins/apm/public/components/app/correlations/failed_transactions_correlations.tsx index 1e6c218f25dfb..527da282dc336 100644 --- a/x-pack/plugins/apm/public/components/app/correlations/failed_transactions_correlations.tsx +++ b/x-pack/plugins/apm/public/components/app/correlations/failed_transactions_correlations.tsx @@ -28,7 +28,10 @@ import { i18n } from '@kbn/i18n'; import { useUiTracker } from '../../../../../observability/public'; -import { asPercent } from '../../../../common/utils/formatters'; +import { + asPercent, + asPreciseDecimal, +} from '../../../../common/utils/formatters'; import { FailedTransactionsCorrelation } from '../../../../common/correlations/failed_transactions_correlations/types'; import { FieldStats } from '../../../../common/correlations/field_stats_types'; @@ -36,6 +39,8 @@ import { useApmPluginContext } from '../../../context/apm_plugin/use_apm_plugin_ import { useLocalStorage } from '../../../hooks/use_local_storage'; import { FETCH_STATUS } from '../../../hooks/use_fetcher'; import { useTheme } from '../../../hooks/use_theme'; + +import { ImpactBar } from '../../shared/impact_bar'; import { push } from '../../shared/links/url_helpers'; import { CorrelationsTable } from './correlations_table'; @@ -223,6 +228,24 @@ export function FailedTransactionsCorrelations({ ] : []; return [ + { + width: '116px', + field: 'normalizedScore', + name: ( + <> + {i18n.translate( + 'xpack.apm.correlations.failedTransactions.correlationsTable.scoreLabel', + { + defaultMessage: 'Score', + } + )} + + ), + render: (_, { normalizedScore }) => { + return
{asPreciseDecimal(normalizedScore, 2)}
; + }, + sortable: true, + }, { width: '116px', field: 'pValue', diff --git a/x-pack/plugins/apm/public/components/app/correlations/latency_correlations.tsx b/x-pack/plugins/apm/public/components/app/correlations/latency_correlations.tsx index 837a5d6a45748..91bf115970e9b 100644 --- a/x-pack/plugins/apm/public/components/app/correlations/latency_correlations.tsx +++ b/x-pack/plugins/apm/public/components/app/correlations/latency_correlations.tsx @@ -50,6 +50,10 @@ import { getTransactionDistributionChartData } from './get_transaction_distribut import { useTheme } from '../../../hooks/use_theme'; import { ChartTitleToolTip } from './chart_title_tool_tip'; import { MIN_TAB_TITLE_HEIGHT } from '../transaction_details/distribution'; +import { + getFailedTransactionsCorrelationImpactLabel, + getLatencyCorrelationImpactLabel, +} from './utils/get_failed_transactions_correlation_impact_label'; export function FallbackCorrelationBadge() { return ( @@ -159,15 +163,36 @@ export function LatencyCorrelations({ onFilter }: { onFilter: () => void }) { ), - render: (_, { correlation, isFallbackResult }) => { - if (isFallbackResult) { - return ; - } - + render: (_, { correlation }) => { return
{asPreciseDecimal(correlation, 2)}
; }, sortable: true, }, + { + width: '116px', + field: 'pValue', + name: ( + <> + {i18n.translate( + 'xpack.apm.correlations.failedTransactions.correlationsTable.impactLabel', + { + defaultMessage: 'Impact', + } + )} + + ), + render: (_, { correlation, isFallbackResult }) => { + const label = getLatencyCorrelationImpactLabel( + correlation, + isFallbackResult + ); + return label ? ( + {label.impact} + ) : null; + }, + sortable: true, + }, + { field: 'fieldName', name: i18n.translate( diff --git a/x-pack/plugins/apm/public/components/app/correlations/utils/get_failed_transactions_correlation_impact_label.ts b/x-pack/plugins/apm/public/components/app/correlations/utils/get_failed_transactions_correlation_impact_label.ts index 93effa1e87f48..233bebfc5f6db 100644 --- a/x-pack/plugins/apm/public/components/app/correlations/utils/get_failed_transactions_correlation_impact_label.ts +++ b/x-pack/plugins/apm/public/components/app/correlations/utils/get_failed_transactions_correlation_impact_label.ts @@ -12,7 +12,8 @@ import { import { FAILED_TRANSACTIONS_IMPACT_THRESHOLD } from '../../../../../common/correlations/failed_transactions_correlations/constants'; export function getFailedTransactionsCorrelationImpactLabel( - pValue: FailedTransactionsCorrelation['pValue'] + pValue: FailedTransactionsCorrelation['pValue'], + isFallbackResult?: boolean ): { impact: FailedTransactionsCorrelationsImpactThreshold; color: string; @@ -21,6 +22,12 @@ export function getFailedTransactionsCorrelationImpactLabel( return null; } + if (isFallbackResult) + return { + impact: FAILED_TRANSACTIONS_IMPACT_THRESHOLD.VERY_LOW, + color: 'default', + }; + // The lower the p value, the higher the impact if (pValue >= 0 && pValue < 1e-6) return { @@ -42,30 +49,36 @@ export function getFailedTransactionsCorrelationImpactLabel( } export function getLatencyCorrelationImpactLabel( - pValue: FailedTransactionsCorrelation['pValue'] + correlation: FailedTransactionsCorrelation['pValue'], + isFallbackResult?: boolean ): { impact: FailedTransactionsCorrelationsImpactThreshold; color: string; } | null { - if (pValue === null) { + if (correlation === null || correlation < 0) { return null; } // The lower the p value, the higher the impact - if (pValue >= 0 && pValue < 1e-6) + if (isFallbackResult) return { - impact: FAILED_TRANSACTIONS_IMPACT_THRESHOLD.HIGH, - color: 'danger', + impact: FAILED_TRANSACTIONS_IMPACT_THRESHOLD.VERY_LOW, + color: 'default', }; - if (pValue >= 1e-6 && pValue < 0.001) + if (correlation < 0.4) + return { + impact: FAILED_TRANSACTIONS_IMPACT_THRESHOLD.LOW, + color: 'default', + }; + if (correlation < 0.6) return { impact: FAILED_TRANSACTIONS_IMPACT_THRESHOLD.MEDIUM, color: 'warning', }; - if (pValue >= 0.001 && pValue < 0.02) + if (correlation < 1) return { - impact: FAILED_TRANSACTIONS_IMPACT_THRESHOLD.LOW, - color: 'default', + impact: FAILED_TRANSACTIONS_IMPACT_THRESHOLD.HIGH, + color: 'danger', }; return null; From acef4cf47313dfe3d95e9192122abf573dc9a73a Mon Sep 17 00:00:00 2001 From: Quynh Nguyen Date: Tue, 1 Mar 2022 14:47:34 -0600 Subject: [PATCH 05/11] Update constants & i18n --- .../constants.ts | 38 +++++++------------ .../failed_transactions_correlations/types.ts | 4 +- ...nsactions_correlation_impact_label.test.ts | 8 ++-- ...d_transactions_correlation_impact_label.ts | 18 ++++----- .../translations/translations/ja-JP.json | 6 +-- .../translations/translations/zh-CN.json | 6 +-- 6 files changed, 34 insertions(+), 46 deletions(-) diff --git a/x-pack/plugins/apm/common/correlations/failed_transactions_correlations/constants.ts b/x-pack/plugins/apm/common/correlations/failed_transactions_correlations/constants.ts index 099b6ae6fa4a3..8a838360b3d44 100644 --- a/x-pack/plugins/apm/common/correlations/failed_transactions_correlations/constants.ts +++ b/x-pack/plugins/apm/common/correlations/failed_transactions_correlations/constants.ts @@ -7,29 +7,17 @@ import { i18n } from '@kbn/i18n'; -export const FAILED_TRANSACTIONS_IMPACT_THRESHOLD = { - HIGH: i18n.translate( - 'xpack.apm.correlations.failedTransactions.highImpactText', - { - defaultMessage: 'High', - } - ), - MEDIUM: i18n.translate( - 'xpack.apm.correlations.failedTransactions.mediumImpactText', - { - defaultMessage: 'Medium', - } - ), - LOW: i18n.translate( - 'xpack.apm.correlations.failedTransactions.lowImpactText', - { - defaultMessage: 'Low', - } - ), - VERY_LOW: i18n.translate( - 'xpack.apm.correlations.failedTransactions.veryLowImpactText', - { - defaultMessage: 'Very low', - } - ), +export const CORRELATIONS_IMPACT_THRESHOLD = { + HIGH: i18n.translate('xpack.apm.correlations.highImpactText', { + defaultMessage: 'High', + }), + MEDIUM: i18n.translate('xpack.apm.correlations.mediumImpactText', { + defaultMessage: 'Medium', + }), + LOW: i18n.translate('xpack.apm.correlations.lowImpactText', { + defaultMessage: 'Low', + }), + VERY_LOW: i18n.translate('xpack.apm.correlations.veryLowImpactText', { + defaultMessage: 'Very low', + }), } as const; diff --git a/x-pack/plugins/apm/common/correlations/failed_transactions_correlations/types.ts b/x-pack/plugins/apm/common/correlations/failed_transactions_correlations/types.ts index 8b09d45c1e1b6..52bb46b1d5bbf 100644 --- a/x-pack/plugins/apm/common/correlations/failed_transactions_correlations/types.ts +++ b/x-pack/plugins/apm/common/correlations/failed_transactions_correlations/types.ts @@ -7,7 +7,7 @@ import { FieldValuePair, HistogramItem } from '../types'; -import { FAILED_TRANSACTIONS_IMPACT_THRESHOLD } from './constants'; +import { CORRELATIONS_IMPACT_THRESHOLD } from './constants'; import { FieldStats } from '../field_stats_types'; export interface FailedTransactionsCorrelation extends FieldValuePair { @@ -22,7 +22,7 @@ export interface FailedTransactionsCorrelation extends FieldValuePair { } export type FailedTransactionsCorrelationsImpactThreshold = - typeof FAILED_TRANSACTIONS_IMPACT_THRESHOLD[keyof typeof FAILED_TRANSACTIONS_IMPACT_THRESHOLD]; + typeof CORRELATIONS_IMPACT_THRESHOLD[keyof typeof CORRELATIONS_IMPACT_THRESHOLD]; export interface FailedTransactionsCorrelationsResponse { ccsWarning: boolean; 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 index d35833295703f..b85121ea94a9c 100644 --- 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 @@ -6,19 +6,19 @@ */ import { getFailedTransactionsCorrelationImpactLabel } from './get_failed_transactions_correlation_impact_label'; -import { FAILED_TRANSACTIONS_IMPACT_THRESHOLD } from '../../../../../common/correlations/failed_transactions_correlations/constants'; +import { CORRELATIONS_IMPACT_THRESHOLD } from '../../../../../common/correlations/failed_transactions_correlations/constants'; const EXPECTED_RESULT = { HIGH: { - impact: FAILED_TRANSACTIONS_IMPACT_THRESHOLD.HIGH, + impact: CORRELATIONS_IMPACT_THRESHOLD.HIGH, color: 'danger', }, MEDIUM: { - impact: FAILED_TRANSACTIONS_IMPACT_THRESHOLD.MEDIUM, + impact: CORRELATIONS_IMPACT_THRESHOLD.MEDIUM, color: 'warning', }, LOW: { - impact: FAILED_TRANSACTIONS_IMPACT_THRESHOLD.LOW, + impact: CORRELATIONS_IMPACT_THRESHOLD.LOW, color: 'default', }, }; diff --git a/x-pack/plugins/apm/public/components/app/correlations/utils/get_failed_transactions_correlation_impact_label.ts b/x-pack/plugins/apm/public/components/app/correlations/utils/get_failed_transactions_correlation_impact_label.ts index 233bebfc5f6db..556c13d7467bb 100644 --- a/x-pack/plugins/apm/public/components/app/correlations/utils/get_failed_transactions_correlation_impact_label.ts +++ b/x-pack/plugins/apm/public/components/app/correlations/utils/get_failed_transactions_correlation_impact_label.ts @@ -9,7 +9,7 @@ import { FailedTransactionsCorrelation, FailedTransactionsCorrelationsImpactThreshold, } from '../../../../../common/correlations/failed_transactions_correlations/types'; -import { FAILED_TRANSACTIONS_IMPACT_THRESHOLD } from '../../../../../common/correlations/failed_transactions_correlations/constants'; +import { CORRELATIONS_IMPACT_THRESHOLD } from '../../../../../common/correlations/failed_transactions_correlations/constants'; export function getFailedTransactionsCorrelationImpactLabel( pValue: FailedTransactionsCorrelation['pValue'], @@ -24,24 +24,24 @@ export function getFailedTransactionsCorrelationImpactLabel( if (isFallbackResult) return { - impact: FAILED_TRANSACTIONS_IMPACT_THRESHOLD.VERY_LOW, + impact: CORRELATIONS_IMPACT_THRESHOLD.VERY_LOW, color: 'default', }; // The lower the p value, the higher the impact if (pValue >= 0 && pValue < 1e-6) return { - impact: FAILED_TRANSACTIONS_IMPACT_THRESHOLD.HIGH, + impact: CORRELATIONS_IMPACT_THRESHOLD.HIGH, color: 'danger', }; if (pValue >= 1e-6 && pValue < 0.001) return { - impact: FAILED_TRANSACTIONS_IMPACT_THRESHOLD.MEDIUM, + impact: CORRELATIONS_IMPACT_THRESHOLD.MEDIUM, color: 'warning', }; if (pValue >= 0.001 && pValue < 0.02) return { - impact: FAILED_TRANSACTIONS_IMPACT_THRESHOLD.LOW, + impact: CORRELATIONS_IMPACT_THRESHOLD.LOW, color: 'default', }; @@ -62,22 +62,22 @@ export function getLatencyCorrelationImpactLabel( // The lower the p value, the higher the impact if (isFallbackResult) return { - impact: FAILED_TRANSACTIONS_IMPACT_THRESHOLD.VERY_LOW, + impact: CORRELATIONS_IMPACT_THRESHOLD.VERY_LOW, color: 'default', }; if (correlation < 0.4) return { - impact: FAILED_TRANSACTIONS_IMPACT_THRESHOLD.LOW, + impact: CORRELATIONS_IMPACT_THRESHOLD.LOW, color: 'default', }; if (correlation < 0.6) return { - impact: FAILED_TRANSACTIONS_IMPACT_THRESHOLD.MEDIUM, + impact: CORRELATIONS_IMPACT_THRESHOLD.MEDIUM, color: 'warning', }; if (correlation < 1) return { - impact: FAILED_TRANSACTIONS_IMPACT_THRESHOLD.HIGH, + impact: CORRELATIONS_IMPACT_THRESHOLD.HIGH, color: 'danger', }; diff --git a/x-pack/plugins/translations/translations/ja-JP.json b/x-pack/plugins/translations/translations/ja-JP.json index 3a5bc5edfbb79..95afa858a3fa4 100644 --- a/x-pack/plugins/translations/translations/ja-JP.json +++ b/x-pack/plugins/translations/translations/ja-JP.json @@ -6949,9 +6949,9 @@ "xpack.apm.correlations.failedTransactions.helpPopover.performanceExplanation": "この分析は多数の属性に対して統計検索を実行します。広い時間範囲やトランザクションスループットが高いサービスでは、時間がかかる場合があります。パフォーマンスを改善するには、時間範囲を絞り込みます。", "xpack.apm.correlations.failedTransactions.helpPopover.tableExplanation": "表はスコア別に並べ替えられます。これは高、中、低影響度にマッピングされます。影響度が高い属性は、失敗したトランザクションの原因である可能性が高くなります。", "xpack.apm.correlations.failedTransactions.helpPopover.title": "失敗したトランザクションの相関関係", - "xpack.apm.correlations.failedTransactions.highImpactText": "高", - "xpack.apm.correlations.failedTransactions.lowImpactText": "低", - "xpack.apm.correlations.failedTransactions.mediumImpactText": "中", + "xpack.apm.correlations.highImpactText": "高", + "xpack.apm.correlations.lowImpactText": "低", + "xpack.apm.correlations.mediumImpactText": "中", "xpack.apm.correlations.failedTransactions.panelTitle": "失敗したトランザクションの遅延分布", "xpack.apm.correlations.failedTransactions.tableTitle": "相関関係", "xpack.apm.correlations.fieldContextPopover.addFilterAriaLabel": "{fieldName}のフィルター:\"{value}\"", diff --git a/x-pack/plugins/translations/translations/zh-CN.json b/x-pack/plugins/translations/translations/zh-CN.json index cd88c2b4b6a52..ba2e92630c20e 100644 --- a/x-pack/plugins/translations/translations/zh-CN.json +++ b/x-pack/plugins/translations/translations/zh-CN.json @@ -6964,9 +6964,9 @@ "xpack.apm.correlations.failedTransactions.helpPopover.performanceExplanation": "此分析会对大量属性执行统计搜索。对于较大时间范围和具有高事务吞吐量的服务,这可能需要些时间。减少时间范围以改善性能。", "xpack.apm.correlations.failedTransactions.helpPopover.tableExplanation": "表按分数排序,分数映射高、中或低影响级别。具有高影响级别的属性更可能造成事务失败。", "xpack.apm.correlations.failedTransactions.helpPopover.title": "失败事务相关性", - "xpack.apm.correlations.failedTransactions.highImpactText": "高", - "xpack.apm.correlations.failedTransactions.lowImpactText": "低", - "xpack.apm.correlations.failedTransactions.mediumImpactText": "中", + "xpack.apm.correlations.highImpactText": "高", + "xpack.apm.correlations.lowImpactText": "低", + "xpack.apm.correlations.mediumImpactText": "中", "xpack.apm.correlations.failedTransactions.panelTitle": "失败事务延迟分布", "xpack.apm.correlations.failedTransactions.tableTitle": "相关性", "xpack.apm.correlations.fieldContextPopover.addFilterAriaLabel": "筛留 {fieldName}:“{value}”", From afd96a9ebf3a2d25bd74c34f647dbe591df2ec33 Mon Sep 17 00:00:00 2001 From: Quynh Nguyen Date: Wed, 2 Mar 2022 09:12:46 -0600 Subject: [PATCH 06/11] Update failed transactions --- .../failed_transactions_correlations/types.ts | 1 + .../plugins/apm/common/correlations/types.ts | 1 + .../failed_transactions_correlations.tsx | 45 ++++++++++++------- ...get_transaction_distribution_chart_data.ts | 9 ++-- .../app/correlations/latency_correlations.tsx | 5 +-- .../use_failed_transactions_correlations.ts | 24 ++++++++-- .../correlations/queries/query_p_values.ts | 2 +- 7 files changed, 57 insertions(+), 30 deletions(-) diff --git a/x-pack/plugins/apm/common/correlations/failed_transactions_correlations/types.ts b/x-pack/plugins/apm/common/correlations/failed_transactions_correlations/types.ts index 52bb46b1d5bbf..e63d3d6faa92e 100644 --- a/x-pack/plugins/apm/common/correlations/failed_transactions_correlations/types.ts +++ b/x-pack/plugins/apm/common/correlations/failed_transactions_correlations/types.ts @@ -31,4 +31,5 @@ export interface FailedTransactionsCorrelationsResponse { overallHistogram?: HistogramItem[]; errorHistogram?: HistogramItem[]; fieldStats?: FieldStats[]; + fallbackResult?: FailedTransactionsCorrelation; } diff --git a/x-pack/plugins/apm/common/correlations/types.ts b/x-pack/plugins/apm/common/correlations/types.ts index 402750b72b2ab..6884d8c627fd0 100644 --- a/x-pack/plugins/apm/common/correlations/types.ts +++ b/x-pack/plugins/apm/common/correlations/types.ts @@ -11,6 +11,7 @@ export interface FieldValuePair { // but for example `http.response.status_code` which is part of // of the list of predefined field candidates is of type long/number. fieldValue: string | number; + isFallbackResult?: boolean; } export interface HistogramItem { diff --git a/x-pack/plugins/apm/public/components/app/correlations/failed_transactions_correlations.tsx b/x-pack/plugins/apm/public/components/app/correlations/failed_transactions_correlations.tsx index 527da282dc336..37b3f6376cbc6 100644 --- a/x-pack/plugins/apm/public/components/app/correlations/failed_transactions_correlations.tsx +++ b/x-pack/plugins/apm/public/components/app/correlations/failed_transactions_correlations.tsx @@ -39,8 +39,6 @@ import { useApmPluginContext } from '../../../context/apm_plugin/use_apm_plugin_ import { useLocalStorage } from '../../../hooks/use_local_storage'; import { FETCH_STATUS } from '../../../hooks/use_fetcher'; import { useTheme } from '../../../hooks/use_theme'; - -import { ImpactBar } from '../../shared/impact_bar'; import { push } from '../../shared/links/url_helpers'; import { CorrelationsTable } from './correlations_table'; @@ -259,8 +257,11 @@ export function FailedTransactionsCorrelations({ )} ), - render: (_, { pValue }) => { - const label = getFailedTransactionsCorrelationImpactLabel(pValue); + render: (_, { pValue, isFallbackResult }) => { + const label = getFailedTransactionsCorrelationImpactLabel( + pValue, + isFallbackResult + ); return label ? ( {label.impact} ) : null; @@ -376,18 +377,30 @@ export function FailedTransactionsCorrelations({ sort: { field: sortField, direction: sortDirection }, }; - const correlationTerms = useMemo( - () => - orderBy( - response.failedTransactionsCorrelations, - // The smaller the p value the higher the impact - // So we want to sort by the normalized score here - // which goes from 0 -> 1 - sortField === 'pValue' ? 'normalizedScore' : sortField, - sortDirection - ), - [response.failedTransactionsCorrelations, sortField, sortDirection] - ); + const correlationTerms = useMemo(() => { + if ( + progress.loaded === 1 && + response?.failedTransactionsCorrelations?.length === 0 && + response.fallbackResult !== undefined + ) { + return [{ ...response.fallbackResult, isFallbackResult: true }]; + } + + return orderBy( + response.failedTransactionsCorrelations, + // The smaller the p value the higher the impact + // So we want to sort by the normalized score here + // which goes from 0 -> 1 + sortField === 'pValue' ? 'normalizedScore' : sortField, + sortDirection + ); + }, [ + response.failedTransactionsCorrelations, + response.fallbackResult, + progress.loaded, + sortField, + sortDirection, + ]); const [pinnedSignificantTerm, setPinnedSignificantTerm] = useState(null); diff --git a/x-pack/plugins/apm/public/components/app/correlations/get_transaction_distribution_chart_data.ts b/x-pack/plugins/apm/public/components/app/correlations/get_transaction_distribution_chart_data.ts index 49ddd8aec0fe4..12799e5edc726 100644 --- a/x-pack/plugins/apm/public/components/app/correlations/get_transaction_distribution_chart_data.ts +++ b/x-pack/plugins/apm/public/components/app/correlations/get_transaction_distribution_chart_data.ts @@ -7,11 +7,10 @@ import { i18n } from '@kbn/i18n'; import { EuiTheme } from '../../../../../../../src/plugins/kibana_react/common'; -import type { - FieldValuePair, - HistogramItem, -} from '../../../../common/correlations/types'; +import type { HistogramItem } from '../../../../common/correlations/types'; import { TransactionDistributionChartData } from '../../shared/charts/transaction_distribution_chart'; +import { LatencyCorrelation } from '../../../../common/correlations/latency_correlations/types'; +import { FailedTransactionsCorrelation } from '../../../../common/correlations/failed_transactions_correlations/types'; export function getTransactionDistributionChartData({ euiTheme, @@ -22,7 +21,7 @@ export function getTransactionDistributionChartData({ euiTheme: EuiTheme; allTransactionsHistogram?: HistogramItem[]; failedTransactionsHistogram?: HistogramItem[]; - selectedTerm?: FieldValuePair & { histogram: HistogramItem[] }; + selectedTerm?: LatencyCorrelation | FailedTransactionsCorrelation | undefined; }) { const transactionDistributionChartData: TransactionDistributionChartData[] = []; diff --git a/x-pack/plugins/apm/public/components/app/correlations/latency_correlations.tsx b/x-pack/plugins/apm/public/components/app/correlations/latency_correlations.tsx index 91bf115970e9b..f3734dae5d247 100644 --- a/x-pack/plugins/apm/public/components/app/correlations/latency_correlations.tsx +++ b/x-pack/plugins/apm/public/components/app/correlations/latency_correlations.tsx @@ -50,10 +50,7 @@ import { getTransactionDistributionChartData } from './get_transaction_distribut import { useTheme } from '../../../hooks/use_theme'; import { ChartTitleToolTip } from './chart_title_tool_tip'; import { MIN_TAB_TITLE_HEIGHT } from '../transaction_details/distribution'; -import { - getFailedTransactionsCorrelationImpactLabel, - getLatencyCorrelationImpactLabel, -} from './utils/get_failed_transactions_correlation_impact_label'; +import { getLatencyCorrelationImpactLabel } from './utils/get_failed_transactions_correlation_impact_label'; export function FallbackCorrelationBadge() { return ( diff --git a/x-pack/plugins/apm/public/components/app/correlations/use_failed_transactions_correlations.ts b/x-pack/plugins/apm/public/components/app/correlations/use_failed_transactions_correlations.ts index 9018e1240194b..26f63e1ab0c59 100644 --- a/x-pack/plugins/apm/public/components/app/correlations/use_failed_transactions_correlations.ts +++ b/x-pack/plugins/apm/public/components/app/correlations/use_failed_transactions_correlations.ts @@ -77,6 +77,7 @@ export function useFailedTransactionsCorrelations() { // and histogram data for statistically significant results. const responseUpdate: FailedTransactionsCorrelationsResponse = { ccsWarning: false, + fallbackResult: undefined, }; const [overallHistogramResponse, errorHistogramRespone] = @@ -149,6 +150,7 @@ export function useFailedTransactionsCorrelations() { const failedTransactionsCorrelations: FailedTransactionsCorrelation[] = []; + let fallbackResult: FailedTransactionsCorrelation | undefined; const fieldsToSample = new Set(); const chunkSize = 10; let chunkLoadCounter = 0; @@ -178,10 +180,19 @@ export function useFailedTransactionsCorrelations() { ...failedTransactionsCorrelations, ]); } else { + // If there's no significant correlations found and there's a fallback result + // Update the highest ranked/scored fall back result if (pValues.fallbackResult) { - responseUpdate.failedTransactionsCorrelations = [ - pValues.fallbackResult, - ]; + if (!fallbackResult) { + fallbackResult = pValues.fallbackResult; + } else { + if ( + pValues.fallbackResult.normalizedScore > + fallbackResult.normalizedScore + ) { + fallbackResult = pValues.fallbackResult; + } + } } } @@ -215,7 +226,12 @@ export function useFailedTransactionsCorrelations() { ); responseUpdate.fieldStats = stats; - setResponse({ ...responseUpdate, loaded: LOADED_DONE, isRunning: false }); + setResponse({ + ...responseUpdate, + fallbackResult, + loaded: LOADED_DONE, + isRunning: false, + }); setResponse.flush(); } catch (e) { if (!abortCtrl.current.signal.aborted) { diff --git a/x-pack/plugins/apm/server/routes/correlations/queries/query_p_values.ts b/x-pack/plugins/apm/server/routes/correlations/queries/query_p_values.ts index ba53880a0f053..ee59925c47f27 100644 --- a/x-pack/plugins/apm/server/routes/correlations/queries/query_p_values.ts +++ b/x-pack/plugins/apm/server/routes/correlations/queries/query_p_values.ts @@ -57,7 +57,7 @@ export const fetchPValues = async ( // If there's no result matching the criteria // Find the next highest/closest result to the threshold // to use as a fallback result - if (fallbackResult === null) { + if (!fallbackResult) { fallbackResult = record; } else { if ( From dd2b011a2c34c8c5864b771d95259f349bb4c587 Mon Sep 17 00:00:00 2001 From: Quynh Nguyen Date: Wed, 2 Mar 2022 15:37:21 -0600 Subject: [PATCH 07/11] Fix types --- .../test/apm_api_integration/tests/correlations/latency.spec.ts | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/x-pack/test/apm_api_integration/tests/correlations/latency.spec.ts b/x-pack/test/apm_api_integration/tests/correlations/latency.spec.ts index e5062961e2f2c..1cdd59777c1c5 100644 --- a/x-pack/test/apm_api_integration/tests/correlations/latency.spec.ts +++ b/x-pack/test/apm_api_integration/tests/correlations/latency.spec.ts @@ -254,7 +254,7 @@ export default function ApiTest({ getService }: FtrProviderContext) { expect(correlation?.fieldValue).to.be('success'); expect(correlation?.correlation).to.be(0.6275246559191225); expect(correlation?.ksTest).to.be(4.806503252860024e-13); - expect(correlation?.histogram.length).to.be(101); + expect(correlation?.histogram?.length).to.be(101); const fieldStats = finalRawResponse?.fieldStats?.[0]; expect(typeof fieldStats).to.be('object'); From 9f57ca31de5d775db046dfc0b09fcf504fdba73f Mon Sep 17 00:00:00 2001 From: Quynh Nguyen Date: Tue, 15 Mar 2022 10:58:31 -0500 Subject: [PATCH 08/11] Change to immutable --- .../queries/query_significant_correlations.ts | 49 ++++++++++--------- 1 file changed, 26 insertions(+), 23 deletions(-) diff --git a/x-pack/plugins/apm/server/routes/correlations/queries/query_significant_correlations.ts b/x-pack/plugins/apm/server/routes/correlations/queries/query_significant_correlations.ts index 1f2bac7adfdca..1913a6c5dc19f 100644 --- a/x-pack/plugins/apm/server/routes/correlations/queries/query_significant_correlations.ts +++ b/x-pack/plugins/apm/server/routes/correlations/queries/query_significant_correlations.ts @@ -77,27 +77,30 @@ export const fetchSignificantCorrelations = async ( ) ); - let fallbackResult: LatencyCorrelation | undefined; - const latencyCorrelations: LatencyCorrelation[] = []; - - fulfilled.forEach((d: LatencyCorrelation | undefined) => { - if (d === undefined) return; - if (Array.isArray(d.histogram)) { - latencyCorrelations.push(d); - } else { - if (!fallbackResult) { - fallbackResult = d; - } else { - if ( - d.ksTest > fallbackResult.ksTest && - d.correlation > fallbackResult.correlation - ) { - fallbackResult = d; - } - } - } - }); - + const latencyCorrelations: LatencyCorrelation[] = fulfilled.filter( + (d) => d && 'histogram' in d + ); + let fallbackResult = + latencyCorrelations.length > 0 + ? undefined + : fulfilled + .filter((d) => !d?.histogram) + .reduce((d, result) => { + if (d?.correlation !== undefined) { + if (!result) { + result = d?.correlation > 0 ? d : undefined; + } else { + if ( + d.correlation > 0 && + d.ksTest > result.ksTest && + d.correlation > result.correlation + ) { + result = d; + } + } + } + return result; + }, undefined); if (latencyCorrelations.length === 0 && fallbackResult) { const { fieldName, fieldValue } = fallbackResult; const logHistogram = await fetchTransactionDurationRanges( @@ -107,9 +110,9 @@ export const fetchSignificantCorrelations = async ( [{ fieldName, fieldValue }] ); - if (typeof fallbackResult === 'object' && fallbackResult !== null) { + if (fallbackResult) { fallbackResult = { - ...(fallbackResult as LatencyCorrelation), + ...fallbackResult, histogram: logHistogram, }; } From abb1e2ac21926b99d1690af47675618a524d3c73 Mon Sep 17 00:00:00 2001 From: Quynh Nguyen Date: Tue, 15 Mar 2022 16:13:28 -0500 Subject: [PATCH 09/11] Add tooltip --- .../failed_transactions_correlations.tsx | 26 +++++++++++++++---- 1 file changed, 21 insertions(+), 5 deletions(-) diff --git a/x-pack/plugins/apm/public/components/app/correlations/failed_transactions_correlations.tsx b/x-pack/plugins/apm/public/components/app/correlations/failed_transactions_correlations.tsx index 37b3f6376cbc6..c970838f8b8c3 100644 --- a/x-pack/plugins/apm/public/components/app/correlations/failed_transactions_correlations.tsx +++ b/x-pack/plugins/apm/public/components/app/correlations/failed_transactions_correlations.tsx @@ -230,14 +230,30 @@ export function FailedTransactionsCorrelations({ width: '116px', field: 'normalizedScore', name: ( - <> - {i18n.translate( - 'xpack.apm.correlations.failedTransactions.correlationsTable.scoreLabel', + + > + <> + {i18n.translate( + 'xpack.apm.correlations.failedTransactions.correlationsTable.scoreLabel', + { + defaultMessage: 'Score', + } + )} + + + ), render: (_, { normalizedScore }) => { return
{asPreciseDecimal(normalizedScore, 2)}
; From eb7852501c53be5ee8900694c6d6452e58a7d6c9 Mon Sep 17 00:00:00 2001 From: Quynh Nguyen Date: Wed, 16 Mar 2022 12:22:12 -0500 Subject: [PATCH 10/11] [ML] Fix types --- .../queries/query_correlation_with_histogram.ts | 10 +++++----- .../queries/query_significant_correlations.ts | 10 +++++----- 2 files changed, 10 insertions(+), 10 deletions(-) diff --git a/x-pack/plugins/apm/server/routes/correlations/queries/query_correlation_with_histogram.ts b/x-pack/plugins/apm/server/routes/correlations/queries/query_correlation_with_histogram.ts index bb60c96eebbca..5c6b8f3594aa0 100644 --- a/x-pack/plugins/apm/server/routes/correlations/queries/query_correlation_with_histogram.ts +++ b/x-pack/plugins/apm/server/routes/correlations/queries/query_correlation_with_histogram.ts @@ -32,9 +32,7 @@ export async function fetchTransactionDurationCorrelationWithHistogram( histogramRangeSteps: number[], totalDocCount: number, fieldValuePair: FieldValuePair -): Promise< - LatencyCorrelation | Omit | undefined -> { +) { const { correlation, ksTest } = await fetchTransactionDurationCorrelation( esClient, params, @@ -58,13 +56,15 @@ export async function fetchTransactionDurationCorrelationWithHistogram( correlation, ksTest, histogram: logHistogram, - }; + } as LatencyCorrelation; } else { return { ...fieldValuePair, correlation, ksTest, - }; + } as Omit; } } + + return undefined; } diff --git a/x-pack/plugins/apm/server/routes/correlations/queries/query_significant_correlations.ts b/x-pack/plugins/apm/server/routes/correlations/queries/query_significant_correlations.ts index 1913a6c5dc19f..2fc1e69eab356 100644 --- a/x-pack/plugins/apm/server/routes/correlations/queries/query_significant_correlations.ts +++ b/x-pack/plugins/apm/server/routes/correlations/queries/query_significant_correlations.ts @@ -13,7 +13,7 @@ import type { FieldValuePair, CorrelationsParams, } from '../../../../common/correlations/types'; -import { LatencyCorrelation } from '../../../../common/correlations/latency_correlations/types'; +import type { LatencyCorrelation } from '../../../../common/correlations/latency_correlations/types'; import { computeExpectationsAndRanges, @@ -77,14 +77,14 @@ export const fetchSignificantCorrelations = async ( ) ); - const latencyCorrelations: LatencyCorrelation[] = fulfilled.filter( + const latencyCorrelations = fulfilled.filter( (d) => d && 'histogram' in d - ); - let fallbackResult = + ) as LatencyCorrelation[]; + let fallbackResult: LatencyCorrelation | undefined = latencyCorrelations.length > 0 ? undefined : fulfilled - .filter((d) => !d?.histogram) + .filter((d) => !(d as LatencyCorrelation)?.histogram) .reduce((d, result) => { if (d?.correlation !== undefined) { if (!result) { From e6324076338f33b54bb3e51668bf8369b4c91d69 Mon Sep 17 00:00:00 2001 From: Quynh Nguyen Date: Thu, 17 Mar 2022 09:51:42 -0500 Subject: [PATCH 11/11] [ML] Fix translation --- x-pack/plugins/translations/translations/fr-FR.json | 3 --- 1 file changed, 3 deletions(-) diff --git a/x-pack/plugins/translations/translations/fr-FR.json b/x-pack/plugins/translations/translations/fr-FR.json index db8cbd956e8fd..32cef97a5a49d 100644 --- a/x-pack/plugins/translations/translations/fr-FR.json +++ b/x-pack/plugins/translations/translations/fr-FR.json @@ -5920,9 +5920,6 @@ "xpack.apm.correlations.failedTransactions.correlationsTable.impactLabel": "Impact", "xpack.apm.correlations.failedTransactions.correlationsTable.pValueLabel": "Score", "xpack.apm.correlations.failedTransactions.errorTitle": "Une erreur est survenue lors de l'exécution de corrélations sur les transactions ayant échoué", - "xpack.apm.correlations.failedTransactions.highImpactText": "Élevé", - "xpack.apm.correlations.failedTransactions.lowImpactText": "Bas", - "xpack.apm.correlations.failedTransactions.mediumImpactText": "Moyen", "xpack.apm.correlations.failedTransactions.panelTitle": "Transactions ayant échoué", "xpack.apm.correlations.latencyCorrelations.correlationsTable.actionsLabel": "Filtre", "xpack.apm.correlations.latencyCorrelations.correlationsTable.correlationColumnDescription": "Score de corrélation [0-1] d'un attribut ; plus le score est élevé, plus un attribut augmente la latence.",