Skip to content

Commit

Permalink
Update failed transactions
Browse files Browse the repository at this point in the history
  • Loading branch information
qn895 committed Mar 2, 2022
1 parent acef4cf commit afd96a9
Show file tree
Hide file tree
Showing 7 changed files with 57 additions and 30 deletions.
Original file line number Diff line number Diff line change
Expand Up @@ -31,4 +31,5 @@ export interface FailedTransactionsCorrelationsResponse {
overallHistogram?: HistogramItem[];
errorHistogram?: HistogramItem[];
fieldStats?: FieldStats[];
fallbackResult?: FailedTransactionsCorrelation;
}
1 change: 1 addition & 0 deletions x-pack/plugins/apm/common/correlations/types.ts
Original file line number Diff line number Diff line change
Expand Up @@ -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 {
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -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';
Expand Down Expand Up @@ -259,8 +257,11 @@ export function FailedTransactionsCorrelations({
)}
</>
),
render: (_, { pValue }) => {
const label = getFailedTransactionsCorrelationImpactLabel(pValue);
render: (_, { pValue, isFallbackResult }) => {
const label = getFailedTransactionsCorrelationImpactLabel(
pValue,
isFallbackResult
);
return label ? (
<EuiBadge color={label.color}>{label.impact}</EuiBadge>
) : null;
Expand Down Expand Up @@ -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<FailedTransactionsCorrelation | null>(null);
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -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,
Expand All @@ -22,7 +21,7 @@ export function getTransactionDistributionChartData({
euiTheme: EuiTheme;
allTransactionsHistogram?: HistogramItem[];
failedTransactionsHistogram?: HistogramItem[];
selectedTerm?: FieldValuePair & { histogram: HistogramItem[] };
selectedTerm?: LatencyCorrelation | FailedTransactionsCorrelation | undefined;
}) {
const transactionDistributionChartData: TransactionDistributionChartData[] =
[];
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -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 (
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -77,6 +77,7 @@ export function useFailedTransactionsCorrelations() {
// and histogram data for statistically significant results.
const responseUpdate: FailedTransactionsCorrelationsResponse = {
ccsWarning: false,
fallbackResult: undefined,
};

const [overallHistogramResponse, errorHistogramRespone] =
Expand Down Expand Up @@ -149,6 +150,7 @@ export function useFailedTransactionsCorrelations() {

const failedTransactionsCorrelations: FailedTransactionsCorrelation[] =
[];
let fallbackResult: FailedTransactionsCorrelation | undefined;
const fieldsToSample = new Set<string>();
const chunkSize = 10;
let chunkLoadCounter = 0;
Expand Down Expand Up @@ -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;
}
}
}
}

Expand Down Expand Up @@ -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) {
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -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 (
Expand Down

0 comments on commit afd96a9

Please sign in to comment.