import { Setup } from '../../lib/helpers/setup_request' ; import { getFailedTransactionRate } from '../../lib/transaction_groups/get_failed_transaction_rate' ; import { offsetPreviousPeriodCoordinates } from '../../../common/utils/offset_previous_period_coordinate' ; export async function getFailedTransactionRatePeriods ( { environment , kuery , serviceName , transactionType , transactionName , setup , searchAggregatedTransactions , comparisonStart , comparisonEnd , start , end , } ) { const commonProps = { environment , kuery , serviceName , transactionType , transactionName , setup , searchAggregatedTransactions , } ; const currentPeriodPromise = getFailedTransactionRate ( { ... commonProps , start , end , } ) ; const previousPeriodPromise = comparisonStart && comparisonEnd ? getFailedTransactionRate ( { ... commonProps , start : comparisonStart , end : comparisonEnd , } ) : { timeseries : [ ] , average : null } ; const [ currentPeriod , previousPeriod ] = await Promise . all ( [ currentPeriodPromise , previousPeriodPromise , ] ) ; const currentPeriodTimeseries = currentPeriod . timeseries ; return { currentPeriod , previousPeriod : { ... previousPeriod , timeseries : offsetPreviousPeriodCoordinates ( { currentPeriodTimeseries , previousPeriodTimeseries : previousPeriod . timeseries , } ) , } , } ; }