From d375dc1ef853491d4c7ed722568d7765751a438b Mon Sep 17 00:00:00 2001 From: Dario Gieselaar Date: Fri, 20 Nov 2020 09:20:11 +0100 Subject: [PATCH] Rename traffic to throughput in code --- .../plugins/apm/common/utils/formatters/duration.ts | 9 +++++---- .../apm/common/utils/formatters/formatters.ts | 7 ++----- x-pack/plugins/apm/common/utils/is_finite_number.ts | 12 ++++++++++++ .../service_overview_transactions_table/index.tsx | 12 ++++++------ .../get_transaction_groups_for_page.ts | 13 +++++++++---- .../get_service_transaction_groups/index.ts | 11 ++++------- .../merge_transaction_group_data.ts | 10 +++++----- x-pack/plugins/apm/server/routes/services.ts | 2 +- .../tests/service_overview/transaction_groups.ts | 6 +++--- 9 files changed, 47 insertions(+), 35 deletions(-) create mode 100644 x-pack/plugins/apm/common/utils/is_finite_number.ts diff --git a/x-pack/plugins/apm/common/utils/formatters/duration.ts b/x-pack/plugins/apm/common/utils/formatters/duration.ts index 53a4cc98efcaf..8e563399a0f1f 100644 --- a/x-pack/plugins/apm/common/utils/formatters/duration.ts +++ b/x-pack/plugins/apm/common/utils/formatters/duration.ts @@ -6,11 +6,12 @@ import { i18n } from '@kbn/i18n'; import moment from 'moment'; -import { memoize, isNumber } from 'lodash'; +import { memoize } from 'lodash'; import { NOT_AVAILABLE_LABEL } from '../../../common/i18n'; import { asDecimal, asDecimalOrInteger, asInteger } from './formatters'; import { TimeUnit } from './datetime'; import { Maybe } from '../../../typings/common'; +import { isFiniteNumber } from '../is_finite_number'; interface FormatterOptions { defaultValue?: string; @@ -99,7 +100,7 @@ function convertTo({ microseconds: Maybe; defaultValue?: string; }): ConvertedDuration { - if (microseconds == null) { + if (!isFiniteNumber(microseconds)) { return { value: defaultValue, formatted: defaultValue }; } @@ -144,7 +145,7 @@ export const getDurationFormatter: TimeFormatterBuilder = memoize( ); export function asTransactionRate(value: Maybe) { - if (!isNumber(value)) { + if (!isFiniteNumber(value)) { return NOT_AVAILABLE_LABEL; } @@ -173,7 +174,7 @@ export function asDuration( value: Maybe, { defaultValue = NOT_AVAILABLE_LABEL }: FormatterOptions = {} ) { - if (value == null) { + if (!isFiniteNumber(value)) { return defaultValue; } diff --git a/x-pack/plugins/apm/common/utils/formatters/formatters.ts b/x-pack/plugins/apm/common/utils/formatters/formatters.ts index e73ea4f58fba0..2314e915e3161 100644 --- a/x-pack/plugins/apm/common/utils/formatters/formatters.ts +++ b/x-pack/plugins/apm/common/utils/formatters/formatters.ts @@ -7,6 +7,7 @@ import numeral from '@elastic/numeral'; import { i18n } from '@kbn/i18n'; import { Maybe } from '../../../typings/common'; import { NOT_AVAILABLE_LABEL } from '../../i18n'; +import { isFiniteNumber } from '../is_finite_number'; export function asDecimal(value: number) { return numeral(value).format('0,0.0'); @@ -31,11 +32,7 @@ export function asPercent( denominator: number | undefined, fallbackResult = NOT_AVAILABLE_LABEL ) { - if ( - !denominator || - typeof numerator !== 'number' || - Number.isNaN(numerator) - ) { + if (!denominator || !isFiniteNumber(numerator)) { return fallbackResult; } diff --git a/x-pack/plugins/apm/common/utils/is_finite_number.ts b/x-pack/plugins/apm/common/utils/is_finite_number.ts new file mode 100644 index 0000000000000..47c4f5fdbd0ee --- /dev/null +++ b/x-pack/plugins/apm/common/utils/is_finite_number.ts @@ -0,0 +1,12 @@ +/* + * Copyright Elasticsearch B.V. and/or licensed to Elasticsearch B.V. under one + * or more contributor license agreements. Licensed under the Elastic License; + * you may not use this file except in compliance with the Elastic License. + */ +import { isFinite } from 'lodash'; +import { Maybe } from '../../typings/common'; + +// _.isNumber() returns true for NaN, _.isFinite() does not refine +export function isFiniteNumber(value: Maybe): value is number { + return isFinite(value); +} diff --git a/x-pack/plugins/apm/public/components/app/service_overview/service_overview_transactions_table/index.tsx b/x-pack/plugins/apm/public/components/app/service_overview/service_overview_transactions_table/index.tsx index 42e0449475f53..203b7b9097df5 100644 --- a/x-pack/plugins/apm/public/components/app/service_overview/service_overview_transactions_table/index.tsx +++ b/x-pack/plugins/apm/public/components/app/service_overview/service_overview_transactions_table/index.tsx @@ -45,7 +45,7 @@ interface Props { serviceName: string; } -type SortField = 'latency' | 'traffic' | 'errorRate' | 'impact'; +type SortField = 'latency' | 'throughput' | 'errorRate' | 'impact'; type SortDirection = 'asc' | 'desc'; const PAGE_SIZE = 5; @@ -193,21 +193,21 @@ export function ServiceOverviewTransactionsTable(props: Props) { }, }, { - field: 'traffic', + field: 'throughput', name: i18n.translate( - 'xpack.apm.serviceOverview.transactionsTableColumnTraffic', + 'xpack.apm.serviceOverview.transactionsTableColumnTroughput', { defaultMessage: 'Traffic', } ), width: px(unit * 10), - render: (_, { traffic }) => { + render: (_, { throughput }) => { return ( diff --git a/x-pack/plugins/apm/server/lib/services/get_service_transaction_groups/get_transaction_groups_for_page.ts b/x-pack/plugins/apm/server/lib/services/get_service_transaction_groups/get_transaction_groups_for_page.ts index c8ec6dc326585..5d3d7014ba8f8 100644 --- a/x-pack/plugins/apm/server/lib/services/get_service_transaction_groups/get_transaction_groups_for_page.ts +++ b/x-pack/plugins/apm/server/lib/services/get_service_transaction_groups/get_transaction_groups_for_page.ts @@ -19,7 +19,12 @@ import { getTransactionDurationFieldForAggregatedTransactions, } from '../../helpers/aggregated_transactions'; import { APMEventClient } from '../../helpers/create_es_client/create_apm_event_client'; -import { ServiceOverviewTransactionGroupSortField } from '.'; + +export type ServiceOverviewTransactionGroupSortField = + | 'latency' + | 'throughput' + | 'errorRate' + | 'impact'; export type TransactionGroupWithoutTimeseriesData = ValuesType< PromiseReturnType['transactionGroups'] @@ -124,13 +129,13 @@ export async function getTransactionGroupsForPage({ return { name: bucket.key as string, latency: bucket.avg_latency.value, - traffic: bucket.transaction_count.value, + throughput: bucket.transaction_count.value, errorRate, }; }) ?? []; const totalDurationValues = transactionGroups.map( - (group) => (group.latency ?? 0) * group.traffic + (group) => (group.latency ?? 0) * group.throughput ); const minTotalDuration = Math.min(...totalDurationValues); @@ -139,7 +144,7 @@ export async function getTransactionGroupsForPage({ const transactionGroupsWithImpact = transactionGroups.map((group) => ({ ...group, impact: - (((group.latency ?? 0) * group.traffic - minTotalDuration) / + (((group.latency ?? 0) * group.throughput - minTotalDuration) / (maxTotalDuration - minTotalDuration)) * 100, })); diff --git a/x-pack/plugins/apm/server/lib/services/get_service_transaction_groups/index.ts b/x-pack/plugins/apm/server/lib/services/get_service_transaction_groups/index.ts index e9dad22519b3c..88fd189712e07 100644 --- a/x-pack/plugins/apm/server/lib/services/get_service_transaction_groups/index.ts +++ b/x-pack/plugins/apm/server/lib/services/get_service_transaction_groups/index.ts @@ -6,15 +6,12 @@ import { Setup, SetupTimeRange } from '../../helpers/setup_request'; import { getTimeseriesDataForTransactionGroups } from './get_timeseries_data_for_transaction_groups'; -import { getTransactionGroupsForPage } from './get_transaction_groups_for_page'; +import { + getTransactionGroupsForPage, + ServiceOverviewTransactionGroupSortField, +} from './get_transaction_groups_for_page'; import { mergeTransactionGroupData } from './merge_transaction_group_data'; -export type ServiceOverviewTransactionGroupSortField = - | 'latency' - | 'traffic' - | 'errorRate' - | 'impact'; - export async function getServiceTransactionGroups({ serviceName, setup, diff --git a/x-pack/plugins/apm/server/lib/services/get_service_transaction_groups/merge_transaction_group_data.ts b/x-pack/plugins/apm/server/lib/services/get_service_transaction_groups/merge_transaction_group_data.ts index 6ceb52b93d212..f9266baddaf27 100644 --- a/x-pack/plugins/apm/server/lib/services/get_service_transaction_groups/merge_transaction_group_data.ts +++ b/x-pack/plugins/apm/server/lib/services/get_service_transaction_groups/merge_transaction_group_data.ts @@ -56,9 +56,9 @@ export function mergeTransactionGroupData({ y: point.avg_latency.value, }), }, - traffic: { - ...prev.traffic, - timeseries: prev.traffic.timeseries.concat({ + throughput: { + ...prev.throughput, + timeseries: prev.throughput.timeseries.concat({ x: point.key, y: point.transaction_count.value / deltaAsMinutes, }), @@ -83,8 +83,8 @@ export function mergeTransactionGroupData({ value: transactionGroup.latency, timeseries: [] as Array<{ x: number; y: number | null }>, }, - traffic: { - value: transactionGroup.traffic, + throughput: { + value: transactionGroup.throughput, timeseries: [] as Array<{ x: number; y: number }>, }, errorRate: { diff --git a/x-pack/plugins/apm/server/routes/services.ts b/x-pack/plugins/apm/server/routes/services.ts index b8d474d6cca18..7723f66e0575f 100644 --- a/x-pack/plugins/apm/server/routes/services.ts +++ b/x-pack/plugins/apm/server/routes/services.ts @@ -254,7 +254,7 @@ export const serviceTransactionGroupsRoute = createRoute({ sortDirection: t.union([t.literal('asc'), t.literal('desc')]), sortField: t.union([ t.literal('latency'), - t.literal('traffic'), + t.literal('throughput'), t.literal('errorRate'), t.literal('impact'), ]), diff --git a/x-pack/test/apm_api_integration/basic/tests/service_overview/transaction_groups.ts b/x-pack/test/apm_api_integration/basic/tests/service_overview/transaction_groups.ts index a80bdd7502ef6..f9ae8cc9a1976 100644 --- a/x-pack/test/apm_api_integration/basic/tests/service_overview/transaction_groups.ts +++ b/x-pack/test/apm_api_integration/basic/tests/service_overview/transaction_groups.ts @@ -95,7 +95,7 @@ export default function ApiTest({ getService }: FtrProviderContext) { const firstItem = response.body.transactionGroups[0]; expectSnapshot( - pick(firstItem, 'name', 'latency.value', 'traffic.value', 'errorRate.value', 'impact') + pick(firstItem, 'name', 'latency.value', 'throughput.value', 'errorRate.value', 'impact') ).toMatchInline(` Object { "errorRate": Object { @@ -106,7 +106,7 @@ export default function ApiTest({ getService }: FtrProviderContext) { "value": 996636.214285714, }, "name": "DispatcherServlet#doGet", - "traffic": Object { + "throughput": Object { "value": 28, }, } @@ -117,7 +117,7 @@ export default function ApiTest({ getService }: FtrProviderContext) { ).toMatchInline(`15`); expectSnapshot( - firstItem.traffic.timeseries.filter(({ y }: any) => y > 0).length + firstItem.throughput.timeseries.filter(({ y }: any) => y > 0).length ).toMatchInline(`15`); expectSnapshot(