Skip to content

Commit

Permalink
Rename traffic to throughput in code
Browse files Browse the repository at this point in the history
  • Loading branch information
dgieselaar committed Nov 20, 2020
1 parent 7d05875 commit d375dc1
Show file tree
Hide file tree
Showing 9 changed files with 47 additions and 35 deletions.
9 changes: 5 additions & 4 deletions x-pack/plugins/apm/common/utils/formatters/duration.ts
Original file line number Diff line number Diff line change
Expand Up @@ -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;
Expand Down Expand Up @@ -99,7 +100,7 @@ function convertTo({
microseconds: Maybe<number>;
defaultValue?: string;
}): ConvertedDuration {
if (microseconds == null) {
if (!isFiniteNumber(microseconds)) {
return { value: defaultValue, formatted: defaultValue };
}

Expand Down Expand Up @@ -144,7 +145,7 @@ export const getDurationFormatter: TimeFormatterBuilder = memoize(
);

export function asTransactionRate(value: Maybe<number>) {
if (!isNumber(value)) {
if (!isFiniteNumber(value)) {
return NOT_AVAILABLE_LABEL;
}

Expand Down Expand Up @@ -173,7 +174,7 @@ export function asDuration(
value: Maybe<number>,
{ defaultValue = NOT_AVAILABLE_LABEL }: FormatterOptions = {}
) {
if (value == null) {
if (!isFiniteNumber(value)) {
return defaultValue;
}

Expand Down
7 changes: 2 additions & 5 deletions x-pack/plugins/apm/common/utils/formatters/formatters.ts
Original file line number Diff line number Diff line change
Expand Up @@ -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');
Expand All @@ -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;
}

Expand Down
12 changes: 12 additions & 0 deletions x-pack/plugins/apm/common/utils/is_finite_number.ts
Original file line number Diff line number Diff line change
@@ -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<number>): value is number {
return isFinite(value);
}
Original file line number Diff line number Diff line change
Expand Up @@ -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;
Expand Down Expand Up @@ -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 (
<SparkPlotWithValueLabel
color="euiColorVis0"
compact
series={traffic.timeseries ?? undefined}
valueLabel={asTransactionRate(traffic.value)}
series={throughput.timeseries ?? undefined}
valueLabel={asTransactionRate(throughput.value)}
start={new Date(start!).getTime()}
end={new Date(end!).getTime()}
/>
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -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<typeof getTransactionGroupsForPage>['transactionGroups']
Expand Down Expand Up @@ -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);
Expand All @@ -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,
}));
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -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,
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -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,
}),
Expand All @@ -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: {
Expand Down
2 changes: 1 addition & 1 deletion x-pack/plugins/apm/server/routes/services.ts
Original file line number Diff line number Diff line change
Expand Up @@ -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'),
]),
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -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 {
Expand All @@ -106,7 +106,7 @@ export default function ApiTest({ getService }: FtrProviderContext) {
"value": 996636.214285714,
},
"name": "DispatcherServlet#doGet",
"traffic": Object {
"throughput": Object {
"value": 28,
},
}
Expand All @@ -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(
Expand Down

0 comments on commit d375dc1

Please sign in to comment.