Skip to content

Commit

Permalink
Fix bucket size and remove comparisonStart / comparisonEnd
Browse files Browse the repository at this point in the history
  • Loading branch information
gbamparop committed Mar 17, 2022
1 parent 3a23a50 commit 80f5d27
Show file tree
Hide file tree
Showing 6 changed files with 32 additions and 63 deletions.
Original file line number Diff line number Diff line change
Expand Up @@ -22,7 +22,7 @@ function getExpectedTimesAndComparisons({
const comparisonOptions = getComparisonOptions({ start, end });

const comparisons = comparisonOptions.map(({ value, text }) => {
const { comparisonStart, comparisonEnd, offset } = getTimeRangeComparison({
const { offset } = getTimeRangeComparison({
comparisonEnabled: true,
comparisonType: value,
start,
Expand All @@ -32,8 +32,6 @@ function getExpectedTimesAndComparisons({
return {
value,
text,
comparisonStart,
comparisonEnd,
offset,
};
});
Expand Down Expand Up @@ -81,15 +79,11 @@ describe('Comparison test suite', () => {
{
value: TimeRangeComparisonEnum.DayBefore,
text: 'Day before',
comparisonStart: '2022-01-14T18:00:00.000Z',
comparisonEnd: '2022-01-15T18:30:00.000Z',
offset: '1d',
},
{
value: TimeRangeComparisonEnum.WeekBefore,
text: 'Week before',
comparisonStart: '2022-01-08T18:00:00.000Z',
comparisonEnd: '2022-01-09T18:30:00.000Z',
offset: '1w',
},
]);
Expand All @@ -116,8 +110,6 @@ describe('Comparison test suite', () => {
{
value: TimeRangeComparisonEnum.WeekBefore,
text: 'Week before',
comparisonStart: '2022-01-08T18:00:00.000Z',
comparisonEnd: '2022-01-09T19:00:00.000Z',
offset: '1w',
},
]);
Expand All @@ -144,8 +136,6 @@ describe('Comparison test suite', () => {
{
value: TimeRangeComparisonEnum.WeekBefore,
text: 'Week before',
comparisonStart: '2022-01-08T18:00:00.000Z',
comparisonEnd: '2022-01-15T21:00:00.000Z',
offset: '1w',
},
]);
Expand All @@ -172,8 +162,6 @@ describe('Comparison test suite', () => {
{
value: TimeRangeComparisonEnum.PeriodBefore,
text: '07/01 18:00 - 15/01 18:00',
comparisonStart: '2022-01-07T18:00:00.000Z',
comparisonEnd: '2022-01-15T18:00:00.000Z',
offset: '691200000ms',
},
]);
Expand Down Expand Up @@ -206,8 +194,6 @@ describe('Comparison test suite', () => {
{
value: TimeRangeComparisonEnum.PeriodBefore,
text: '06/01 06:00 - 15/01 00:00',
comparisonStart: '2022-01-06T06:00:00.000Z',
comparisonEnd: '2022-01-15T00:00:00.000Z',
offset: '756000000ms',
},
]);
Expand Down Expand Up @@ -240,15 +226,11 @@ describe('Comparison test suite', () => {
{
value: TimeRangeComparisonEnum.DayBefore,
text: 'Day before',
comparisonStart: '2022-01-13T00:00:00.000Z',
comparisonEnd: '2022-01-13T23:59:59.999Z',
offset: '1d',
},
{
value: TimeRangeComparisonEnum.WeekBefore,
text: 'Week before',
comparisonStart: '2022-01-07T00:00:00.000Z',
comparisonEnd: '2022-01-07T23:59:59.999Z',
offset: '1w',
},
]);
Expand All @@ -275,8 +257,6 @@ describe('Comparison test suite', () => {
{
value: TimeRangeComparisonEnum.WeekBefore,
text: 'Week before',
comparisonStart: '2022-01-02T00:00:00.000Z',
comparisonEnd: '2022-01-08T23:59:59.999Z',
offset: '1w',
},
]);
Expand All @@ -303,15 +283,11 @@ describe('Comparison test suite', () => {
{
value: TimeRangeComparisonEnum.DayBefore,
text: 'Day before',
comparisonStart: '2022-01-12T18:30:15.500Z',
comparisonEnd: '2022-01-13T18:30:15.500Z',
offset: '1d',
},
{
value: TimeRangeComparisonEnum.WeekBefore,
text: 'Week before',
comparisonStart: '2022-01-06T18:30:15.500Z',
comparisonEnd: '2022-01-07T18:30:15.500Z',
offset: '1w',
},
]);
Expand All @@ -338,15 +314,11 @@ describe('Comparison test suite', () => {
{
value: TimeRangeComparisonEnum.DayBefore,
text: 'Day before',
comparisonStart: '2022-01-12T18:00:00.000Z',
comparisonEnd: '2022-01-13T18:30:15.500Z',
offset: '1d',
},
{
value: TimeRangeComparisonEnum.WeekBefore,
text: 'Week before',
comparisonStart: '2022-01-06T18:00:00.000Z',
comparisonEnd: '2022-01-07T18:30:15.500Z',
offset: '1w',
},
]);
Expand All @@ -373,8 +345,6 @@ describe('Comparison test suite', () => {
{
value: TimeRangeComparisonEnum.WeekBefore,
text: 'Week before',
comparisonStart: '2021-12-31T18:30:15.500Z',
comparisonEnd: '2022-01-07T18:30:15.500Z',
offset: '1w',
},
]);
Expand All @@ -401,8 +371,6 @@ describe('Comparison test suite', () => {
{
value: TimeRangeComparisonEnum.WeekBefore,
text: 'Week before',
comparisonStart: '2021-12-31T00:00:00.000Z',
comparisonEnd: '2022-01-07T18:30:15.500Z',
offset: '1w',
},
]);
Expand All @@ -429,8 +397,6 @@ describe('Comparison test suite', () => {
{
value: TimeRangeComparisonEnum.PeriodBefore,
text: '15/11/21 18:30 - 15/12/21 18:30',
comparisonStart: '2021-11-15T18:30:15.500Z',
comparisonEnd: '2021-12-15T18:30:15.500Z',
offset: '2592000000ms',
},
]);
Expand Down Expand Up @@ -463,8 +429,6 @@ describe('Comparison test suite', () => {
{
value: TimeRangeComparisonEnum.PeriodBefore,
text: '14/11/21 05:29 - 15/12/21 00:00',
comparisonStart: '2021-11-14T05:29:44.500Z',
comparisonEnd: '2021-12-15T00:00:00.000Z',
offset: '2658615500ms',
},
]);
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -9,6 +9,7 @@ import moment from 'moment';
import { i18n } from '@kbn/i18n';
import { TimeRangeComparisonEnum } from '../../../../common/runtime_types/comparison_type_rt';
import { getTimeRangeComparison } from './get_time_range_comparison';
import { getOffsetInMs } from '../../../../common/utils/get_offset_in_ms';

const eightDaysInHours = moment.duration(8, 'd').asHours();

Expand Down Expand Up @@ -69,13 +70,22 @@ function getSelectOptions({
};
}
case TimeRangeComparisonEnum.PeriodBefore: {
const { comparisonStart, comparisonEnd } = getTimeRangeComparison({
const { offset } = getTimeRangeComparison({
comparisonType: TimeRangeComparisonEnum.PeriodBefore,
start,
end,
comparisonEnabled: true,
});

const { startWithOffset, endWithOffset } = getOffsetInMs({
start: moment(start).valueOf(),
end: moment(end).valueOf(),
offset,
});

const comparisonStart = moment(startWithOffset).toISOString();
const comparisonEnd = moment(endWithOffset).toISOString();

const dateFormat = getDateFormat({
previousPeriodStart: comparisonStart,
currentPeriodEnd: end,
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -71,8 +71,6 @@ export function getTimeRangeComparison({
}

return {
comparisonStart: startMoment.subtract(diff, 'ms').toISOString(),
comparisonEnd: endMoment.subtract(diff, 'ms').toISOString(),
offset,
};
}
Original file line number Diff line number Diff line change
Expand Up @@ -34,7 +34,17 @@ export async function getErrorDistribution({
end: number;
offset?: string;
}) {
const bucketSize = getBucketSize({ start, end });
const { startWithOffset, endWithOffset } = getOffsetInMs({
start,
end,
offset,
});

const bucketSize = getBucketSize({
start: startWithOffset,
end: endWithOffset,
});

const commonProps = {
environment,
kuery,
Expand All @@ -45,14 +55,8 @@ export async function getErrorDistribution({
};
const currentPeriodPromise = getBuckets({
...commonProps,
start,
end,
});

const { startWithOffset, endWithOffset } = getOffsetInMs({
start,
end,
offset,
start: startWithOffset,
end: endWithOffset,
});

const previousPeriodPromise = offset
Expand Down
11 changes: 7 additions & 4 deletions x-pack/plugins/apm/server/routes/services/get_throughput.ts
Original file line number Diff line number Diff line change
Expand Up @@ -22,6 +22,7 @@ import {
} from '../../lib/helpers/transactions';
import { Setup } from '../../lib/helpers/setup_request';
import { getOffsetInMs } from '../../../common/utils/get_offset_in_ms';
import { getBucketSizeForAggregatedTransactions } from '../../lib/helpers/get_bucket_size_for_aggregated_transactions';

interface Options {
environment: string;
Expand All @@ -33,8 +34,6 @@ interface Options {
transactionName?: string;
start: number;
end: number;
intervalString: string;
bucketSize: number;
offset?: string;
}

Expand All @@ -48,8 +47,6 @@ export async function getThroughput({
transactionName,
start,
end,
intervalString,
bucketSize,
offset,
}: Options) {
const { apmEventClient } = setup;
Expand All @@ -60,6 +57,12 @@ export async function getThroughput({
offset,
});

const { intervalString } = getBucketSizeForAggregatedTransactions({
start: startWithOffset,
end: endWithOffset,
searchAggregatedTransactions,
});

const params = {
apm: {
events: [getProcessorEventForTransactions(searchAggregatedTransactions)],
Expand Down
10 changes: 0 additions & 10 deletions x-pack/plugins/apm/server/routes/services/route.ts
Original file line number Diff line number Diff line change
Expand Up @@ -38,7 +38,6 @@ import {
import { offsetPreviousPeriodCoordinates } from '../../../common/utils/offset_previous_period_coordinate';
import { getServicesDetailedStatistics } from './get_services_detailed_statistics';
import { getServiceDependenciesBreakdown } from './get_service_dependencies_breakdown';
import { getBucketSizeForAggregatedTransactions } from '../../lib/helpers/get_bucket_size_for_aggregated_transactions';
import { getAnomalyTimeseries } from '../../lib/anomaly_detection/get_anomaly_timeseries';
import {
UnknownMLCapabilitiesError,
Expand Down Expand Up @@ -540,13 +539,6 @@ const serviceThroughputRoute = createApmServerRoute({
end,
});

const { bucketSize, intervalString } =
getBucketSizeForAggregatedTransactions({
start,
end,
searchAggregatedTransactions,
});

const commonProps = {
environment,
kuery,
Expand All @@ -555,8 +547,6 @@ const serviceThroughputRoute = createApmServerRoute({
setup,
transactionType,
transactionName,
intervalString,
bucketSize,
};

const [currentPeriod, previousPeriod] = await Promise.all([
Expand Down

0 comments on commit 80f5d27

Please sign in to comment.