From e96aed98fef032200afb97897622079463c11969 Mon Sep 17 00:00:00 2001 From: Walter Rafelsberger Date: Mon, 6 Sep 2021 14:55:02 +0200 Subject: [PATCH] [ML] Improve FieldValuePair type usage. --- .../failed_transactions_correlations.tsx | 4 +++- .../app/correlations/latency_correlations.tsx | 4 +++- .../queries/get_query_with_params.ts | 13 ++++++++----- .../search_strategies/queries/query_correlation.ts | 9 +++++---- .../search_strategies/queries/query_histogram.ts | 9 +++++---- .../search_strategies/queries/query_percentiles.ts | 9 +++++---- .../lib/search_strategies/queries/query_ranges.ts | 9 +++++---- 7 files changed, 34 insertions(+), 23 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 8def817969066..84bcadbca627a 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,6 +36,7 @@ import { FailedTransactionsCorrelation, } from '../../../../common/search_strategies/failed_transactions_correlations/types'; import { APM_SEARCH_STRATEGIES } from '../../../../common/search_strategies/constants'; +import { FieldValuePair } from '../../../../common/search_strategies/types'; import { useApmPluginContext } from '../../../context/apm_plugin/use_apm_plugin_context'; import { FETCH_STATUS } from '../../../hooks/use_fetcher'; @@ -224,7 +225,8 @@ export function FailedTransactionsCorrelations({ 'xpack.apm.correlations.failedTransactions.correlationsTable.fieldValueLabel', { defaultMessage: 'Field value' } ), - render: (fieldValue: string) => String(fieldValue).slice(0, 50), + render: (fieldValue: FieldValuePair['fieldValue']) => + String(fieldValue).slice(0, 50), sortable: true, }, ...percentageColumns, 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 bcdee7a35dbcd..fa463bdc92e24 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 @@ -33,6 +33,7 @@ import { APM_SEARCH_STRATEGIES, DEFAULT_PERCENTILE_THRESHOLD, } from '../../../../common/search_strategies/constants'; +import { FieldValuePair } from '../../../../common/search_strategies/types'; import { isLatencyCorrelations, LatencyCorrelation, @@ -173,7 +174,8 @@ export function LatencyCorrelations({ onFilter }: { onFilter: () => void }) { 'xpack.apm.correlations.latencyCorrelations.correlationsTable.fieldValueLabel', { defaultMessage: 'Field value' } ), - render: (fieldValue: string) => String(fieldValue).slice(0, 50), + render: (fieldValue: FieldValuePair['fieldValue']) => + String(fieldValue).slice(0, 50), sortable: true, }, { diff --git a/x-pack/plugins/apm/server/lib/search_strategies/queries/get_query_with_params.ts b/x-pack/plugins/apm/server/lib/search_strategies/queries/get_query_with_params.ts index 6220e1be098ff..445f432f2d5ad 100644 --- a/x-pack/plugins/apm/server/lib/search_strategies/queries/get_query_with_params.ts +++ b/x-pack/plugins/apm/server/lib/search_strategies/queries/get_query_with_params.ts @@ -10,22 +10,25 @@ import { getOrElse } from 'fp-ts/lib/Either'; import { pipe } from 'fp-ts/lib/pipeable'; import * as t from 'io-ts'; import { failure } from 'io-ts/lib/PathReporter'; -import type { SearchStrategyParams } from '../../../../common/search_strategies/types'; +import type { + FieldValuePair, + SearchStrategyParams, +} from '../../../../common/search_strategies/types'; import { rangeRt } from '../../../routes/default_api_types'; import { getCorrelationsFilters } from '../../correlations/get_filters'; import { Setup, SetupTimeRange } from '../../helpers/setup_request'; export const getTermsQuery = ( - fieldName: string | undefined, - fieldValue: string | undefined + fieldName: FieldValuePair['fieldName'] | undefined, + fieldValue: FieldValuePair['fieldValue'] | undefined ) => { return fieldName && fieldValue ? [{ term: { [fieldName]: fieldValue } }] : []; }; interface QueryParams { params: SearchStrategyParams; - fieldName?: string; - fieldValue?: string; + fieldName?: FieldValuePair['fieldName']; + fieldValue?: FieldValuePair['fieldValue']; } export const getQueryWithParams = ({ params, diff --git a/x-pack/plugins/apm/server/lib/search_strategies/queries/query_correlation.ts b/x-pack/plugins/apm/server/lib/search_strategies/queries/query_correlation.ts index b00023d417ac2..6e2981032d67d 100644 --- a/x-pack/plugins/apm/server/lib/search_strategies/queries/query_correlation.ts +++ b/x-pack/plugins/apm/server/lib/search_strategies/queries/query_correlation.ts @@ -11,6 +11,7 @@ import type { ElasticsearchClient } from 'src/core/server'; import { TRANSACTION_DURATION } from '../../../../common/elasticsearch_fieldnames'; import type { + FieldValuePair, ResponseHit, SearchStrategyParams, } from '../../../../common/search_strategies/types'; @@ -37,8 +38,8 @@ export const getTransactionDurationCorrelationRequest = ( ranges: estypes.AggregationsAggregationRange[], fractions: number[], totalDocCount: number, - fieldName?: string, - fieldValue?: string + fieldName?: FieldValuePair['fieldName'], + fieldValue?: FieldValuePair['fieldValue'] ): estypes.SearchRequest => { const query = getQueryWithParams({ params, fieldName, fieldValue }); @@ -92,8 +93,8 @@ export const fetchTransactionDurationCorrelation = async ( ranges: estypes.AggregationsAggregationRange[], fractions: number[], totalDocCount: number, - fieldName?: string, - fieldValue?: string + fieldName?: FieldValuePair['fieldName'], + fieldValue?: FieldValuePair['fieldValue'] ): Promise<{ ranges: unknown[]; correlation: number | null; diff --git a/x-pack/plugins/apm/server/lib/search_strategies/queries/query_histogram.ts b/x-pack/plugins/apm/server/lib/search_strategies/queries/query_histogram.ts index d9a2d0a6264d3..1dac98d785f3c 100644 --- a/x-pack/plugins/apm/server/lib/search_strategies/queries/query_histogram.ts +++ b/x-pack/plugins/apm/server/lib/search_strategies/queries/query_histogram.ts @@ -11,6 +11,7 @@ import type { ElasticsearchClient } from 'src/core/server'; import { TRANSACTION_DURATION } from '../../../../common/elasticsearch_fieldnames'; import type { + FieldValuePair, HistogramItem, ResponseHit, SearchStrategyParams, @@ -22,8 +23,8 @@ import { getRequestBase } from './get_request_base'; export const getTransactionDurationHistogramRequest = ( params: SearchStrategyParams, interval: number, - fieldName?: string, - fieldValue?: string + fieldName?: FieldValuePair['fieldName'], + fieldValue?: FieldValuePair['fieldValue'] ): estypes.SearchRequest => ({ ...getRequestBase(params), body: { @@ -41,8 +42,8 @@ export const fetchTransactionDurationHistogram = async ( esClient: ElasticsearchClient, params: SearchStrategyParams, interval: number, - fieldName?: string, - fieldValue?: string + fieldName?: FieldValuePair['fieldName'], + fieldValue?: FieldValuePair['fieldValue'] ): Promise => { const resp = await esClient.search( getTransactionDurationHistogramRequest( diff --git a/x-pack/plugins/apm/server/lib/search_strategies/queries/query_percentiles.ts b/x-pack/plugins/apm/server/lib/search_strategies/queries/query_percentiles.ts index a1d0c4c560df4..8d9e2ed88ba37 100644 --- a/x-pack/plugins/apm/server/lib/search_strategies/queries/query_percentiles.ts +++ b/x-pack/plugins/apm/server/lib/search_strategies/queries/query_percentiles.ts @@ -11,6 +11,7 @@ import type { ElasticsearchClient } from 'src/core/server'; import { TRANSACTION_DURATION } from '../../../../common/elasticsearch_fieldnames'; import type { + FieldValuePair, ResponseHit, SearchStrategyParams, } from '../../../../common/search_strategies/types'; @@ -22,8 +23,8 @@ import { SIGNIFICANT_VALUE_DIGITS } from '../constants'; export const getTransactionDurationPercentilesRequest = ( params: SearchStrategyParams, percents?: number[], - fieldName?: string, - fieldValue?: string + fieldName?: FieldValuePair['fieldName'], + fieldValue?: FieldValuePair['fieldValue'] ): estypes.SearchRequest => { const query = getQueryWithParams({ params, fieldName, fieldValue }); @@ -52,8 +53,8 @@ export const fetchTransactionDurationPercentiles = async ( esClient: ElasticsearchClient, params: SearchStrategyParams, percents?: number[], - fieldName?: string, - fieldValue?: string + fieldName?: FieldValuePair['fieldName'], + fieldValue?: FieldValuePair['fieldValue'] ): Promise<{ totalDocs: number; percentiles: Record }> => { const resp = await esClient.search( getTransactionDurationPercentilesRequest( diff --git a/x-pack/plugins/apm/server/lib/search_strategies/queries/query_ranges.ts b/x-pack/plugins/apm/server/lib/search_strategies/queries/query_ranges.ts index 29f25bc277c1c..e15962f2979ba 100644 --- a/x-pack/plugins/apm/server/lib/search_strategies/queries/query_ranges.ts +++ b/x-pack/plugins/apm/server/lib/search_strategies/queries/query_ranges.ts @@ -11,6 +11,7 @@ import type { ElasticsearchClient } from 'src/core/server'; import { TRANSACTION_DURATION } from '../../../../common/elasticsearch_fieldnames'; import type { + FieldValuePair, ResponseHit, SearchStrategyParams, } from '../../../../common/search_strategies/types'; @@ -21,8 +22,8 @@ import { getRequestBase } from './get_request_base'; export const getTransactionDurationRangesRequest = ( params: SearchStrategyParams, rangesSteps: number[], - fieldName?: string, - fieldValue?: string + fieldName?: FieldValuePair['fieldName'], + fieldValue?: FieldValuePair['fieldValue'] ): estypes.SearchRequest => { const query = getQueryWithParams({ params, fieldName, fieldValue }); @@ -59,8 +60,8 @@ export const fetchTransactionDurationRanges = async ( esClient: ElasticsearchClient, params: SearchStrategyParams, rangesSteps: number[], - fieldName?: string, - fieldValue?: string + fieldName?: FieldValuePair['fieldName'], + fieldValue?: FieldValuePair['fieldValue'] ): Promise> => { const resp = await esClient.search( getTransactionDurationRangesRequest(