diff --git a/x-pack/plugins/apm/common/search_strategies/latency_correlations/types.ts b/x-pack/plugins/apm/common/search_strategies/latency_correlations/types.ts index 7b297fa2b78e3..9710fdcd5dc37 100644 --- a/x-pack/plugins/apm/common/search_strategies/latency_correlations/types.ts +++ b/x-pack/plugins/apm/common/search_strategies/latency_correlations/types.ts @@ -39,7 +39,7 @@ export function isLatencyCorrelations( ); } -export interface AsyncSearchProviderProgress { +export interface LatencyCorrelationSearchServiceProgress { started: number; loadedHistogramStepsize: number; loadedOverallHistogram: number; diff --git a/x-pack/plugins/apm/server/lib/search_strategies/failed_transactions_correlations/async_search_service.ts b/x-pack/plugins/apm/server/lib/search_strategies/failed_transactions_correlations/failed_transactions_correlations_search_service.ts similarity index 88% rename from x-pack/plugins/apm/server/lib/search_strategies/failed_transactions_correlations/async_search_service.ts rename to x-pack/plugins/apm/server/lib/search_strategies/failed_transactions_correlations/failed_transactions_correlations_search_service.ts index 507f61ba61744..12f7902b51488 100644 --- a/x-pack/plugins/apm/server/lib/search_strategies/failed_transactions_correlations/async_search_service.ts +++ b/x-pack/plugins/apm/server/lib/search_strategies/failed_transactions_correlations/failed_transactions_correlations_search_service.ts @@ -22,18 +22,18 @@ import type { FailedTransactionsCorrelationsRawResponse, } from '../../../../common/search_strategies/failed_transactions_correlations/types'; import type { ApmIndicesConfig } from '../../settings/apm_indices/get_apm_indices'; -import { asyncSearchServiceLogProvider } from '../async_search_service_log'; +import { searchServiceLogProvider } from '../search_service_log'; import { fetchFailedTransactionsCorrelationPValues, fetchTransactionDurationFieldCandidates, } from '../queries'; -import type { AsyncSearchServiceProvider } from '../search_strategy_provider'; +import type { SearchServiceProvider } from '../search_strategy_provider'; -import { asyncFailedTransactionsCorrelationsSearchServiceStateProvider } from './async_search_service_state'; +import { failedTransactionsCorrelationsSearchServiceStateProvider } from './failed_transactions_correlations_search_service_state'; import { ERROR_CORRELATION_THRESHOLD } from '../constants'; -export type FailedTransactionsCorrelationsAsyncSearchServiceProvider = AsyncSearchServiceProvider< +export type FailedTransactionsCorrelationsSearchServiceProvider = SearchServiceProvider< FailedTransactionsCorrelationsParams, FailedTransactionsCorrelationsRawResponse >; @@ -43,15 +43,15 @@ export type FailedTransactionsCorrelationsSearchStrategy = ISearchStrategy< IKibanaSearchResponse >; -export const failedTransactionsCorrelationsAsyncSearchServiceProvider: FailedTransactionsCorrelationsAsyncSearchServiceProvider = ( +export const failedTransactionsCorrelationsSearchServiceProvider: FailedTransactionsCorrelationsSearchServiceProvider = ( esClient: ElasticsearchClient, getApmIndices: () => Promise, searchServiceParams: FailedTransactionsCorrelationsParams, includeFrozen: boolean ) => { - const { addLogMessage, getLogMessages } = asyncSearchServiceLogProvider(); + const { addLogMessage, getLogMessages } = searchServiceLogProvider(); - const state = asyncFailedTransactionsCorrelationsSearchServiceStateProvider(); + const state = failedTransactionsCorrelationsSearchServiceStateProvider(); async function fetchErrorCorrelations() { try { diff --git a/x-pack/plugins/apm/server/lib/search_strategies/failed_transactions_correlations/async_search_service_state.ts b/x-pack/plugins/apm/server/lib/search_strategies/failed_transactions_correlations/failed_transactions_correlations_search_service_state.ts similarity index 90% rename from x-pack/plugins/apm/server/lib/search_strategies/failed_transactions_correlations/async_search_service_state.ts rename to x-pack/plugins/apm/server/lib/search_strategies/failed_transactions_correlations/failed_transactions_correlations_search_service_state.ts index 2a1d20eeb1cc2..13cf752618537 100644 --- a/x-pack/plugins/apm/server/lib/search_strategies/failed_transactions_correlations/async_search_service_state.ts +++ b/x-pack/plugins/apm/server/lib/search_strategies/failed_transactions_correlations/failed_transactions_correlations_search_service_state.ts @@ -12,7 +12,7 @@ interface Progress { loadedFieldCandidates: number; loadedFailedTransactionsCorrelations: number; } -export const asyncFailedTransactionsCorrelationsSearchServiceStateProvider = () => { +export const failedTransactionsCorrelationsSearchServiceStateProvider = () => { let ccsWarning = false; function setCcsWarning(d: boolean) { ccsWarning = d; @@ -90,6 +90,6 @@ export const asyncFailedTransactionsCorrelationsSearchServiceStateProvider = () }; }; -export type AsyncSearchServiceState = ReturnType< - typeof asyncFailedTransactionsCorrelationsSearchServiceStateProvider +export type FailedTransactionsCorrelationsSearchServiceState = ReturnType< + typeof failedTransactionsCorrelationsSearchServiceStateProvider >; diff --git a/x-pack/plugins/apm/server/lib/search_strategies/failed_transactions_correlations/index.ts b/x-pack/plugins/apm/server/lib/search_strategies/failed_transactions_correlations/index.ts index 96244aaa6e937..ec91165cb481b 100644 --- a/x-pack/plugins/apm/server/lib/search_strategies/failed_transactions_correlations/index.ts +++ b/x-pack/plugins/apm/server/lib/search_strategies/failed_transactions_correlations/index.ts @@ -6,7 +6,7 @@ */ export { - failedTransactionsCorrelationsAsyncSearchServiceProvider, - FailedTransactionsCorrelationsAsyncSearchServiceProvider, + failedTransactionsCorrelationsSearchServiceProvider, + FailedTransactionsCorrelationsSearchServiceProvider, FailedTransactionsCorrelationsSearchStrategy, -} from './async_search_service'; +} from './failed_transactions_correlations_search_service'; diff --git a/x-pack/plugins/apm/server/lib/search_strategies/latency_correlations/index.ts b/x-pack/plugins/apm/server/lib/search_strategies/latency_correlations/index.ts index 9d341e82f0422..073bb122896ff 100644 --- a/x-pack/plugins/apm/server/lib/search_strategies/latency_correlations/index.ts +++ b/x-pack/plugins/apm/server/lib/search_strategies/latency_correlations/index.ts @@ -6,7 +6,7 @@ */ export { - latencyCorrelationsAsyncSearchServiceProvider, - LatencyCorrelationsAsyncSearchServiceProvider, + latencyCorrelationsSearchServiceProvider, + LatencyCorrelationsSearchServiceProvider, LatencyCorrelationsSearchStrategy, -} from './async_search_service'; +} from './latency_correlations_search_service'; diff --git a/x-pack/plugins/apm/server/lib/search_strategies/latency_correlations/async_search_service.ts b/x-pack/plugins/apm/server/lib/search_strategies/latency_correlations/latency_correlations_search_service.ts similarity index 93% rename from x-pack/plugins/apm/server/lib/search_strategies/latency_correlations/async_search_service.ts rename to x-pack/plugins/apm/server/lib/search_strategies/latency_correlations/latency_correlations_search_service.ts index 3e08d2b051a7a..a5f5045642c47 100644 --- a/x-pack/plugins/apm/server/lib/search_strategies/latency_correlations/async_search_service.ts +++ b/x-pack/plugins/apm/server/lib/search_strategies/latency_correlations/latency_correlations_search_service.ts @@ -32,12 +32,12 @@ import { fetchTransactionDurationRanges, } from '../queries'; import { computeExpectationsAndRanges } from '../utils'; -import { asyncSearchServiceLogProvider } from '../async_search_service_log'; -import type { AsyncSearchServiceProvider } from '../search_strategy_provider'; +import { searchServiceLogProvider } from '../search_service_log'; +import type { SearchServiceProvider } from '../search_strategy_provider'; -import { asyncSearchServiceStateProvider } from './async_search_service_state'; +import { latencyCorrelationsSearchServiceStateProvider } from './latency_correlations_search_service_state'; -export type LatencyCorrelationsAsyncSearchServiceProvider = AsyncSearchServiceProvider< +export type LatencyCorrelationsSearchServiceProvider = SearchServiceProvider< LatencyCorrelationsParams, LatencyCorrelationsRawResponse >; @@ -47,15 +47,15 @@ export type LatencyCorrelationsSearchStrategy = ISearchStrategy< IKibanaSearchResponse >; -export const latencyCorrelationsAsyncSearchServiceProvider: LatencyCorrelationsAsyncSearchServiceProvider = ( +export const latencyCorrelationsSearchServiceProvider: LatencyCorrelationsSearchServiceProvider = ( esClient: ElasticsearchClient, getApmIndices: () => Promise, searchServiceParams: LatencyCorrelationsParams, includeFrozen: boolean ) => { - const { addLogMessage, getLogMessages } = asyncSearchServiceLogProvider(); + const { addLogMessage, getLogMessages } = searchServiceLogProvider(); - const state = asyncSearchServiceStateProvider(); + const state = latencyCorrelationsSearchServiceStateProvider(); async function fetchCorrelations() { let params: diff --git a/x-pack/plugins/apm/server/lib/search_strategies/latency_correlations/async_search_service_state.test.ts b/x-pack/plugins/apm/server/lib/search_strategies/latency_correlations/latency_correlations_search_service_state.test.ts similarity index 86% rename from x-pack/plugins/apm/server/lib/search_strategies/latency_correlations/async_search_service_state.test.ts rename to x-pack/plugins/apm/server/lib/search_strategies/latency_correlations/latency_correlations_search_service_state.test.ts index cfa1bf2a5ad71..fa95378086c94 100644 --- a/x-pack/plugins/apm/server/lib/search_strategies/latency_correlations/async_search_service_state.test.ts +++ b/x-pack/plugins/apm/server/lib/search_strategies/latency_correlations/latency_correlations_search_service_state.test.ts @@ -5,12 +5,12 @@ * 2.0. */ -import { asyncSearchServiceStateProvider } from './async_search_service_state'; +import { latencyCorrelationsSearchServiceStateProvider } from './latency_correlations_search_service_state'; -describe('async search service', () => { - describe('asyncSearchServiceStateProvider', () => { +describe('search service', () => { + describe('latencyCorrelationsSearchServiceStateProvider', () => { it('initializes with default state', () => { - const state = asyncSearchServiceStateProvider(); + const state = latencyCorrelationsSearchServiceStateProvider(); const defaultState = state.getState(); const defaultProgress = state.getOverallProgress(); @@ -30,7 +30,7 @@ describe('async search service', () => { }); it('returns updated state', () => { - const state = asyncSearchServiceStateProvider(); + const state = latencyCorrelationsSearchServiceStateProvider(); state.setCcsWarning(true); state.setError(new Error('the-error-message')); diff --git a/x-pack/plugins/apm/server/lib/search_strategies/latency_correlations/async_search_service_state.ts b/x-pack/plugins/apm/server/lib/search_strategies/latency_correlations/latency_correlations_search_service_state.ts similarity index 87% rename from x-pack/plugins/apm/server/lib/search_strategies/latency_correlations/async_search_service_state.ts rename to x-pack/plugins/apm/server/lib/search_strategies/latency_correlations/latency_correlations_search_service_state.ts index 3cdd03869710a..0b92ca3ef8636 100644 --- a/x-pack/plugins/apm/server/lib/search_strategies/latency_correlations/async_search_service_state.ts +++ b/x-pack/plugins/apm/server/lib/search_strategies/latency_correlations/latency_correlations_search_service_state.ts @@ -7,11 +7,11 @@ import type { HistogramItem } from '../../../../common/search_strategies/types'; import type { - AsyncSearchProviderProgress, + LatencyCorrelationSearchServiceProgress, LatencyCorrelation, } from '../../../../common/search_strategies/latency_correlations/types'; -export const asyncSearchServiceStateProvider = () => { +export const latencyCorrelationsSearchServiceStateProvider = () => { let ccsWarning = false; function setCcsWarning(d: boolean) { ccsWarning = d; @@ -45,7 +45,7 @@ export const asyncSearchServiceStateProvider = () => { percentileThresholdValue = d; } - let progress: AsyncSearchProviderProgress = { + let progress: LatencyCorrelationSearchServiceProgress = { started: Date.now(), loadedHistogramStepsize: 0, loadedOverallHistogram: 0, @@ -63,7 +63,7 @@ export const asyncSearchServiceStateProvider = () => { ); } function setProgress( - d: Partial> + d: Partial> ) { progress = { ...progress, @@ -109,6 +109,6 @@ export const asyncSearchServiceStateProvider = () => { }; }; -export type AsyncSearchServiceState = ReturnType< - typeof asyncSearchServiceStateProvider +export type LatencyCorrelationsSearchServiceState = ReturnType< + typeof latencyCorrelationsSearchServiceStateProvider >; diff --git a/x-pack/plugins/apm/server/lib/search_strategies/queries/query_field_value_pairs.test.ts b/x-pack/plugins/apm/server/lib/search_strategies/queries/query_field_value_pairs.test.ts index 17988b334e680..1fff8cde5bbb3 100644 --- a/x-pack/plugins/apm/server/lib/search_strategies/queries/query_field_value_pairs.test.ts +++ b/x-pack/plugins/apm/server/lib/search_strategies/queries/query_field_value_pairs.test.ts @@ -10,8 +10,8 @@ import type { estypes } from '@elastic/elasticsearch'; import type { ElasticsearchClient } from 'src/core/server'; import { ENVIRONMENT_ALL } from '../../../../common/environment_filter_values'; -import { asyncSearchServiceLogProvider } from '../async_search_service_log'; -import { asyncSearchServiceStateProvider } from '../latency_correlations/async_search_service_state'; +import { searchServiceLogProvider } from '../search_service_log'; +import { latencyCorrelationsSearchServiceStateProvider } from '../latency_correlations/latency_correlations_search_service_state'; import { fetchTransactionDurationFieldValuePairs, @@ -62,8 +62,8 @@ describe('query_field_value_pairs', () => { search: esClientSearchMock, } as unknown) as ElasticsearchClient; - const { addLogMessage, getLogMessages } = asyncSearchServiceLogProvider(); - const state = asyncSearchServiceStateProvider(); + const { addLogMessage, getLogMessages } = searchServiceLogProvider(); + const state = latencyCorrelationsSearchServiceStateProvider(); const resp = await fetchTransactionDurationFieldValuePairs( esClientMock, diff --git a/x-pack/plugins/apm/server/lib/search_strategies/queries/query_field_value_pairs.ts b/x-pack/plugins/apm/server/lib/search_strategies/queries/query_field_value_pairs.ts index 3df7b1f46c567..aa7d9f341a345 100644 --- a/x-pack/plugins/apm/server/lib/search_strategies/queries/query_field_value_pairs.ts +++ b/x-pack/plugins/apm/server/lib/search_strategies/queries/query_field_value_pairs.ts @@ -14,8 +14,8 @@ import type { SearchStrategyParams, } from '../../../../common/search_strategies/types'; -import type { AsyncSearchServiceLog } from '../async_search_service_log'; -import type { AsyncSearchServiceState } from '../latency_correlations/async_search_service_state'; +import type { SearchServiceLog } from '../search_service_log'; +import type { LatencyCorrelationsSearchServiceState } from '../latency_correlations/latency_correlations_search_service_state'; import { TERMS_SIZE } from '../constants'; import { getQueryWithParams } from './get_query_with_params'; @@ -44,7 +44,7 @@ const fetchTransactionDurationFieldTerms = async ( esClient: ElasticsearchClient, params: SearchStrategyParams, fieldName: string, - addLogMessage: AsyncSearchServiceLog['addLogMessage'] + addLogMessage: SearchServiceLog['addLogMessage'] ): Promise => { try { const resp = await esClient.search(getTermsAggRequest(params, fieldName)); @@ -93,8 +93,8 @@ export const fetchTransactionDurationFieldValuePairs = async ( esClient: ElasticsearchClient, params: SearchStrategyParams, fieldCandidates: string[], - state: AsyncSearchServiceState, - addLogMessage: AsyncSearchServiceLog['addLogMessage'] + state: LatencyCorrelationsSearchServiceState, + addLogMessage: SearchServiceLog['addLogMessage'] ): Promise => { let fieldValuePairsProgress = 1; diff --git a/x-pack/plugins/apm/server/lib/search_strategies/queries/query_histograms_generator.test.ts b/x-pack/plugins/apm/server/lib/search_strategies/queries/query_histograms_generator.test.ts index 4144dc17d043a..c80b2533d7e32 100644 --- a/x-pack/plugins/apm/server/lib/search_strategies/queries/query_histograms_generator.test.ts +++ b/x-pack/plugins/apm/server/lib/search_strategies/queries/query_histograms_generator.test.ts @@ -10,8 +10,8 @@ import type { estypes } from '@elastic/elasticsearch'; import type { ElasticsearchClient } from 'src/core/server'; import { ENVIRONMENT_ALL } from '../../../../common/environment_filter_values'; -import { asyncSearchServiceLogProvider } from '../async_search_service_log'; -import { asyncSearchServiceStateProvider } from '../latency_correlations/async_search_service_state'; +import { searchServiceLogProvider } from '../search_service_log'; +import { latencyCorrelationsSearchServiceStateProvider } from '../latency_correlations/latency_correlations_search_service_state'; import { fetchTransactionDurationHistograms } from './query_histograms_generator'; @@ -50,8 +50,8 @@ describe('query_histograms_generator', () => { search: esClientSearchMock, } as unknown) as ElasticsearchClient; - const state = asyncSearchServiceStateProvider(); - const { addLogMessage, getLogMessages } = asyncSearchServiceLogProvider(); + const state = latencyCorrelationsSearchServiceStateProvider(); + const { addLogMessage, getLogMessages } = searchServiceLogProvider(); let loadedHistograms = 0; const items = []; @@ -104,8 +104,8 @@ describe('query_histograms_generator', () => { search: esClientSearchMock, } as unknown) as ElasticsearchClient; - const state = asyncSearchServiceStateProvider(); - const { addLogMessage, getLogMessages } = asyncSearchServiceLogProvider(); + const state = latencyCorrelationsSearchServiceStateProvider(); + const { addLogMessage, getLogMessages } = searchServiceLogProvider(); let loadedHistograms = 0; const items = []; diff --git a/x-pack/plugins/apm/server/lib/search_strategies/queries/query_histograms_generator.ts b/x-pack/plugins/apm/server/lib/search_strategies/queries/query_histograms_generator.ts index 4dc59083186f2..a07abd356db6d 100644 --- a/x-pack/plugins/apm/server/lib/search_strategies/queries/query_histograms_generator.ts +++ b/x-pack/plugins/apm/server/lib/search_strategies/queries/query_histograms_generator.ts @@ -14,8 +14,8 @@ import type { SearchStrategyParams, } from '../../../../common/search_strategies/types'; -import type { AsyncSearchServiceLog } from '../async_search_service_log'; -import type { AsyncSearchServiceState } from '../latency_correlations/async_search_service_state'; +import type { SearchServiceLog } from '../search_service_log'; +import type { LatencyCorrelationsSearchServiceState } from '../latency_correlations/latency_correlations_search_service_state'; import { CORRELATION_THRESHOLD, KS_TEST_THRESHOLD } from '../constants'; import { getPrioritizedFieldValuePairs } from './get_prioritized_field_value_pairs'; @@ -24,9 +24,9 @@ import { fetchTransactionDurationRanges } from './query_ranges'; export async function* fetchTransactionDurationHistograms( esClient: ElasticsearchClient, - addLogMessage: AsyncSearchServiceLog['addLogMessage'], + addLogMessage: SearchServiceLog['addLogMessage'], params: SearchStrategyParams, - state: AsyncSearchServiceState, + state: LatencyCorrelationsSearchServiceState, expectations: number[], ranges: estypes.AggregationsAggregationRange[], fractions: number[], diff --git a/x-pack/plugins/apm/server/lib/search_strategies/register_search_strategies.ts b/x-pack/plugins/apm/server/lib/search_strategies/register_search_strategies.ts index 33b764be2c625..713c5e390ca8b 100644 --- a/x-pack/plugins/apm/server/lib/search_strategies/register_search_strategies.ts +++ b/x-pack/plugins/apm/server/lib/search_strategies/register_search_strategies.ts @@ -11,8 +11,8 @@ import { APM_SEARCH_STRATEGIES } from '../../../common/search_strategies/constan import type { ApmIndicesConfig } from '../settings/apm_indices/get_apm_indices'; -import { failedTransactionsCorrelationsAsyncSearchServiceProvider } from './failed_transactions_correlations'; -import { latencyCorrelationsAsyncSearchServiceProvider } from './latency_correlations'; +import { failedTransactionsCorrelationsSearchServiceProvider } from './failed_transactions_correlations'; +import { latencyCorrelationsSearchServiceProvider } from './latency_correlations'; import { searchStrategyProvider } from './search_strategy_provider'; export const registerSearchStrategies = ( @@ -23,7 +23,7 @@ export const registerSearchStrategies = ( registerSearchStrategy( APM_SEARCH_STRATEGIES.APM_LATENCY_CORRELATIONS, searchStrategyProvider( - latencyCorrelationsAsyncSearchServiceProvider, + latencyCorrelationsSearchServiceProvider, getApmIndices, includeFrozen ) @@ -32,7 +32,7 @@ export const registerSearchStrategies = ( registerSearchStrategy( APM_SEARCH_STRATEGIES.APM_FAILED_TRANSACTIONS_CORRELATIONS, searchStrategyProvider( - failedTransactionsCorrelationsAsyncSearchServiceProvider, + failedTransactionsCorrelationsSearchServiceProvider, getApmIndices, includeFrozen ) diff --git a/x-pack/plugins/apm/server/lib/search_strategies/async_search_service_log.test.ts b/x-pack/plugins/apm/server/lib/search_strategies/search_service_log.test.ts similarity index 84% rename from x-pack/plugins/apm/server/lib/search_strategies/async_search_service_log.test.ts rename to x-pack/plugins/apm/server/lib/search_strategies/search_service_log.test.ts index bfc28bc37ea78..c21b31bb4462a 100644 --- a/x-pack/plugins/apm/server/lib/search_strategies/async_search_service_log.test.ts +++ b/x-pack/plugins/apm/server/lib/search_strategies/search_service_log.test.ts @@ -6,11 +6,11 @@ */ import { - asyncSearchServiceLogProvider, + searchServiceLogProvider, currentTimeAsString, -} from './async_search_service_log'; +} from './search_service_log'; -describe('async search service', () => { +describe('search service', () => { describe('currentTimeAsString', () => { it('returns the current time as a string', () => { const mockDate = new Date(1392202800000); @@ -25,9 +25,9 @@ describe('async search service', () => { }); }); - describe('asyncSearchServiceLogProvider', () => { + describe('searchServiceLogProvider', () => { it('adds and retrieves messages from the log', async () => { - const { addLogMessage, getLogMessages } = asyncSearchServiceLogProvider(); + const { addLogMessage, getLogMessages } = searchServiceLogProvider(); const mockDate = new Date(1392202800000); // @ts-ignore ignore the mockImplementation callback error diff --git a/x-pack/plugins/apm/server/lib/search_strategies/async_search_service_log.ts b/x-pack/plugins/apm/server/lib/search_strategies/search_service_log.ts similarity index 84% rename from x-pack/plugins/apm/server/lib/search_strategies/async_search_service_log.ts rename to x-pack/plugins/apm/server/lib/search_strategies/search_service_log.ts index 058a902026c48..73a59021b01ed 100644 --- a/x-pack/plugins/apm/server/lib/search_strategies/async_search_service_log.ts +++ b/x-pack/plugins/apm/server/lib/search_strategies/search_service_log.ts @@ -13,7 +13,7 @@ interface LogMessage { export const currentTimeAsString = () => new Date().toISOString(); -export const asyncSearchServiceLogProvider = () => { +export const searchServiceLogProvider = () => { const log: LogMessage[] = []; function addLogMessage(message: string, error?: string) { @@ -31,6 +31,4 @@ export const asyncSearchServiceLogProvider = () => { return { addLogMessage, getLogMessages }; }; -export type AsyncSearchServiceLog = ReturnType< - typeof asyncSearchServiceLogProvider ->; +export type SearchServiceLog = ReturnType; diff --git a/x-pack/plugins/apm/server/lib/search_strategies/search_strategy_provider.test.ts b/x-pack/plugins/apm/server/lib/search_strategies/search_strategy_provider.test.ts index 2bbca7abd7c3a..b45b95666326f 100644 --- a/x-pack/plugins/apm/server/lib/search_strategies/search_strategy_provider.test.ts +++ b/x-pack/plugins/apm/server/lib/search_strategies/search_strategy_provider.test.ts @@ -16,7 +16,7 @@ import type { LatencyCorrelationsParams } from '../../../common/search_strategie import type { ApmIndicesConfig } from '../settings/apm_indices/get_apm_indices'; -import { latencyCorrelationsAsyncSearchServiceProvider } from './latency_correlations'; +import { latencyCorrelationsSearchServiceProvider } from './latency_correlations'; import { searchStrategyProvider } from './search_strategy_provider'; // helper to trigger promises in the async search service @@ -109,7 +109,7 @@ describe('APM Correlations search strategy', () => { describe('strategy interface', () => { it('returns a custom search strategy with a `search` and `cancel` function', async () => { const searchStrategy = await searchStrategyProvider( - latencyCorrelationsAsyncSearchServiceProvider, + latencyCorrelationsSearchServiceProvider, getApmIndicesMock, false ); @@ -153,7 +153,7 @@ describe('APM Correlations search strategy', () => { describe('when no params are provided', () => { it('throws an error', async () => { const searchStrategy = await searchStrategyProvider( - latencyCorrelationsAsyncSearchServiceProvider, + latencyCorrelationsSearchServiceProvider, mockGetApmIndicesMock, false ); @@ -169,7 +169,7 @@ describe('APM Correlations search strategy', () => { describe('when no ID is provided', () => { it('performs a client search with params', async () => { const searchStrategy = await searchStrategyProvider( - latencyCorrelationsAsyncSearchServiceProvider, + latencyCorrelationsSearchServiceProvider, mockGetApmIndicesMock, false ); @@ -217,7 +217,7 @@ describe('APM Correlations search strategy', () => { describe('when an ID with params is provided', () => { it('retrieves the current request', async () => { const searchStrategy = await searchStrategyProvider( - latencyCorrelationsAsyncSearchServiceProvider, + latencyCorrelationsSearchServiceProvider, mockGetApmIndicesMock, false ); @@ -244,7 +244,7 @@ describe('APM Correlations search strategy', () => { .mockReset() .mockRejectedValueOnce(new Error('client error')); const searchStrategy = await searchStrategyProvider( - latencyCorrelationsAsyncSearchServiceProvider, + latencyCorrelationsSearchServiceProvider, mockGetApmIndicesMock, false ); @@ -263,7 +263,7 @@ describe('APM Correlations search strategy', () => { it('triggers the subscription only once', async () => { expect.assertions(2); const searchStrategy = await searchStrategyProvider( - latencyCorrelationsAsyncSearchServiceProvider, + latencyCorrelationsSearchServiceProvider, mockGetApmIndicesMock, false ); @@ -281,7 +281,7 @@ describe('APM Correlations search strategy', () => { describe('response', () => { it('sends an updated response on consecutive search calls', async () => { const searchStrategy = await searchStrategyProvider( - latencyCorrelationsAsyncSearchServiceProvider, + latencyCorrelationsSearchServiceProvider, mockGetApmIndicesMock, false ); diff --git a/x-pack/plugins/apm/server/lib/search_strategies/search_strategy_provider.ts b/x-pack/plugins/apm/server/lib/search_strategies/search_strategy_provider.ts index dfe936b60bec0..c0376852b2505 100644 --- a/x-pack/plugins/apm/server/lib/search_strategies/search_strategy_provider.ts +++ b/x-pack/plugins/apm/server/lib/search_strategies/search_strategy_provider.ts @@ -21,15 +21,15 @@ import type { RawResponseBase } from '../../../common/search_strategies/types'; import type { ApmIndicesConfig } from '../settings/apm_indices/get_apm_indices'; import type { - LatencyCorrelationsAsyncSearchServiceProvider, + LatencyCorrelationsSearchServiceProvider, LatencyCorrelationsSearchStrategy, } from './latency_correlations'; import type { - FailedTransactionsCorrelationsAsyncSearchServiceProvider, + FailedTransactionsCorrelationsSearchServiceProvider, FailedTransactionsCorrelationsSearchStrategy, } from './failed_transactions_correlations'; -interface AsyncSearchServiceState { +interface SearchServiceState { cancel: () => void; error: Error; meta: { @@ -41,11 +41,11 @@ interface AsyncSearchServiceState { rawResponse: TRawResponse; } -type GetAsyncSearchServiceState< +type GetSearchServiceState< TRawResponse extends RawResponseBase -> = () => AsyncSearchServiceState; +> = () => SearchServiceState; -export type AsyncSearchServiceProvider< +export type SearchServiceProvider< TSearchStrategyClientParams extends SearchStrategyClientParams, TRawResponse extends RawResponseBase > = ( @@ -53,18 +53,18 @@ export type AsyncSearchServiceProvider< getApmIndices: () => Promise, searchServiceParams: TSearchStrategyClientParams, includeFrozen: boolean -) => GetAsyncSearchServiceState; +) => GetSearchServiceState; // Failed Transactions Correlations function overload export function searchStrategyProvider( - asyncSearchServiceProvider: FailedTransactionsCorrelationsAsyncSearchServiceProvider, + searchServiceProvider: FailedTransactionsCorrelationsSearchServiceProvider, getApmIndices: () => Promise, includeFrozen: boolean ): FailedTransactionsCorrelationsSearchStrategy; // Latency Correlations function overload export function searchStrategyProvider( - asyncSearchServiceProvider: LatencyCorrelationsAsyncSearchServiceProvider, + searchServiceProvider: LatencyCorrelationsSearchServiceProvider, getApmIndices: () => Promise, includeFrozen: boolean ): LatencyCorrelationsSearchStrategy; @@ -73,7 +73,7 @@ export function searchStrategyProvider< TSearchStrategyClientParams extends SearchStrategyClientParams, TRawResponse extends RawResponseBase >( - asyncSearchServiceProvider: AsyncSearchServiceProvider< + searchServiceProvider: SearchServiceProvider< TSearchStrategyClientParams, TRawResponse >, @@ -83,9 +83,9 @@ export function searchStrategyProvider< IKibanaSearchRequest, IKibanaSearchResponse > { - const asyncSearchServiceMap = new Map< + const searchServiceMap = new Map< string, - GetAsyncSearchServiceState + GetSearchServiceState >(); return { @@ -94,27 +94,25 @@ export function searchStrategyProvider< throw new Error('Invalid request parameters.'); } - // The function to fetch the current state of the async search service. + // The function to fetch the current state of the search service. // This will be either an existing service for a follow up fetch or a new one for new requests. - let getAsyncSearchServiceState: GetAsyncSearchServiceState; + let getSearchServiceState: GetSearchServiceState; - // If the request includes an ID, we require that the async search service already exists + // If the request includes an ID, we require that the search service already exists // otherwise we throw an error. The client should never poll a service that's been cancelled or finished. - // This also avoids instantiating async search services when the service gets called with random IDs. + // This also avoids instantiating search services when the service gets called with random IDs. if (typeof request.id === 'string') { - const existingGetAsyncSearchServiceState = asyncSearchServiceMap.get( - request.id - ); + const existingGetSearchServiceState = searchServiceMap.get(request.id); - if (typeof existingGetAsyncSearchServiceState === 'undefined') { + if (typeof existingGetSearchServiceState === 'undefined') { throw new Error( - `AsyncSearchService with ID '${request.id}' does not exist.` + `SearchService with ID '${request.id}' does not exist.` ); } - getAsyncSearchServiceState = existingGetAsyncSearchServiceState; + getSearchServiceState = existingGetSearchServiceState; } else { - getAsyncSearchServiceState = asyncSearchServiceProvider( + getSearchServiceState = searchServiceProvider( deps.esClient.asCurrentUser, getApmIndices, request.params as TSearchStrategyClientParams, @@ -125,15 +123,15 @@ export function searchStrategyProvider< // Reuse the request's id or create a new one. const id = request.id ?? uuid(); - const { error, meta, rawResponse } = getAsyncSearchServiceState(); + const { error, meta, rawResponse } = getSearchServiceState(); if (error instanceof Error) { - asyncSearchServiceMap.delete(id); + searchServiceMap.delete(id); throw error; } else if (meta.isRunning) { - asyncSearchServiceMap.set(id, getAsyncSearchServiceState); + searchServiceMap.set(id, getSearchServiceState); } else { - asyncSearchServiceMap.delete(id); + searchServiceMap.delete(id); } return of({ @@ -143,10 +141,10 @@ export function searchStrategyProvider< }); }, cancel: async (id, options, deps) => { - const getAsyncSearchServiceState = asyncSearchServiceMap.get(id); - if (getAsyncSearchServiceState !== undefined) { - getAsyncSearchServiceState().cancel(); - asyncSearchServiceMap.delete(id); + const getSearchServiceState = searchServiceMap.get(id); + if (getSearchServiceState !== undefined) { + getSearchServiceState().cancel(); + searchServiceMap.delete(id); } }, };