Skip to content

Commit

Permalink
[ML] APM Latency Correlations: Code consolidation. (#110790)
Browse files Browse the repository at this point in the history
Code deduplication:
- combine 3 existing client side hooks into useSearchStrategy
- combine server side multiple search strategy files into shared search_strategy_provider.ts
- Clarified naming (client/server params, strategy naming etc.), improved types.
- None of the actual deeper internal logic changed, larger chunks of code that show up as new lines is mostly just moved code + additional types (e.g. function overloads) to support the different search strategies with the same server side code and client side hook.
  • Loading branch information
walterra authored and kibanamachine committed Sep 8, 2021
1 parent d6e5827 commit dcb7f7a
Show file tree
Hide file tree
Showing 78 changed files with 1,392 additions and 1,708 deletions.
14 changes: 14 additions & 0 deletions x-pack/plugins/apm/common/search_strategies/constants.ts
Original file line number Diff line number Diff line change
@@ -0,0 +1,14 @@
/*
* 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.
*/

export const APM_SEARCH_STRATEGIES = {
APM_FAILED_TRANSACTIONS_CORRELATIONS: 'apmFailedTransactionsCorrelations',
APM_LATENCY_CORRELATIONS: 'apmLatencyCorrelations',
} as const;
export type ApmSearchStrategies = typeof APM_SEARCH_STRATEGIES[keyof typeof APM_SEARCH_STRATEGIES];

export const DEFAULT_PERCENTILE_THRESHOLD = 95;
63 changes: 0 additions & 63 deletions x-pack/plugins/apm/common/search_strategies/correlations/types.ts

This file was deleted.

Original file line number Diff line number Diff line change
Expand Up @@ -7,9 +7,6 @@

import { i18n } from '@kbn/i18n';

export const FAILED_TRANSACTIONS_CORRELATION_SEARCH_STRATEGY =
'apmFailedTransactionsCorrelationsSearchStrategy';

export const FAILED_TRANSACTIONS_IMPACT_THRESHOLD = {
HIGH: i18n.translate(
'xpack.apm.correlations.failedTransactions.highImpactText',
Expand Down
Original file line number Diff line number Diff line change
@@ -0,0 +1,34 @@
/*
* 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 {
FieldValuePair,
RawResponseBase,
SearchStrategyClientParams,
} from '../types';

import { FAILED_TRANSACTIONS_IMPACT_THRESHOLD } from './constants';

export interface FailedTransactionsCorrelation extends FieldValuePair {
doc_count: number;
bg_count: number;
score: number;
pValue: number | null;
normalizedScore: number;
failurePercentage: number;
successPercentage: number;
}

export type FailedTransactionsCorrelationsImpactThreshold = typeof FAILED_TRANSACTIONS_IMPACT_THRESHOLD[keyof typeof FAILED_TRANSACTIONS_IMPACT_THRESHOLD];

export type FailedTransactionsCorrelationsParams = SearchStrategyClientParams;

export interface FailedTransactionsCorrelationsRawResponse
extends RawResponseBase {
log: string[];
failedTransactionsCorrelations: FailedTransactionsCorrelation[];
}

This file was deleted.

Original file line number Diff line number Diff line change
@@ -0,0 +1,40 @@
/*
* 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 {
FieldValuePair,
HistogramItem,
RawResponseBase,
SearchStrategyClientParams,
} from '../types';

export interface LatencyCorrelation extends FieldValuePair {
correlation: number;
histogram: HistogramItem[];
ksTest: number;
}

export interface LatencyCorrelationSearchServiceProgress {
started: number;
loadedHistogramStepsize: number;
loadedOverallHistogram: number;
loadedFieldCandidates: number;
loadedFieldValuePairs: number;
loadedHistograms: number;
}

export interface LatencyCorrelationsParams extends SearchStrategyClientParams {
percentileThreshold: number;
analyzeCorrelations: boolean;
}

export interface LatencyCorrelationsRawResponse extends RawResponseBase {
log: string[];
overallHistogram?: HistogramItem[];
percentileThresholdValue?: number;
latencyCorrelations?: LatencyCorrelation[];
}
50 changes: 50 additions & 0 deletions x-pack/plugins/apm/common/search_strategies/types.ts
Original file line number Diff line number Diff line change
@@ -0,0 +1,50 @@
/*
* 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.
*/

export interface FieldValuePair {
fieldName: string;
// For dynamic fieldValues we only identify fields as `string`,
// 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;
}

export interface HistogramItem {
key: number;
doc_count: number;
}

export interface ResponseHitSource {
[s: string]: unknown;
}

export interface ResponseHit {
_source: ResponseHitSource;
}

export interface RawResponseBase {
ccsWarning: boolean;
took: number;
}

export interface SearchStrategyClientParams {
environment: string;
kuery: string;
serviceName?: string;
transactionName?: string;
transactionType?: string;
start?: string;
end?: string;
}

export interface SearchStrategyServerParams {
index: string;
includeFrozen?: boolean;
}

export type SearchStrategyParams = SearchStrategyClientParams &
SearchStrategyServerParams;
Original file line number Diff line number Diff line change
Expand Up @@ -14,36 +14,31 @@ import type { Criteria } from '@elastic/eui/src/components/basic_table/basic_tab
import { FETCH_STATUS } from '../../../hooks/use_fetcher';
import { useUiTracker } from '../../../../../observability/public';
import { useTheme } from '../../../hooks/use_theme';
import type { CorrelationsTerm } from '../../../../common/search_strategies/failure_correlations/types';
import type { FieldValuePair } from '../../../../common/search_strategies/types';

const PAGINATION_SIZE_OPTIONS = [5, 10, 20, 50];

export type SelectedCorrelationTerm<T extends CorrelationsTerm> = Pick<
T,
'fieldName' | 'fieldValue'
>;

interface Props<T> {
interface CorrelationsTableProps<T extends FieldValuePair> {
significantTerms?: T[];
status: FETCH_STATUS;
percentageColumnName?: string;
setSelectedSignificantTerm: (term: T | null) => void;
selectedTerm?: { fieldName: string; fieldValue: string };
selectedTerm?: FieldValuePair;
onFilter?: () => void;
columns: Array<EuiBasicTableColumn<T>>;
onTableChange: (c: Criteria<T>) => void;
sorting?: EuiTableSortingType<T>;
}

export function CorrelationsTable<T extends CorrelationsTerm>({
export function CorrelationsTable<T extends FieldValuePair>({
significantTerms,
status,
setSelectedSignificantTerm,
columns,
selectedTerm,
onTableChange,
sorting,
}: Props<T>) {
}: CorrelationsTableProps<T>) {
const euiTheme = useTheme();
const trackApmEvent = useUiTracker({ app: 'apm' });
const trackSelectSignificantCorrelationTerm = useCallback(
Expand Down
Loading

0 comments on commit dcb7f7a

Please sign in to comment.