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 (