Skip to content

Commit

Permalink
addressing pr comments
Browse files Browse the repository at this point in the history
  • Loading branch information
cauemarcondes committed Dec 9, 2020
1 parent f12bf04 commit 85efe71
Show file tree
Hide file tree
Showing 2 changed files with 20 additions and 16 deletions.
Original file line number Diff line number Diff line change
Expand Up @@ -12,29 +12,35 @@ import { anomalySeriesFetcher } from './fetcher';
import { getMlBucketSize } from './get_ml_bucket_size';
import { anomalySeriesTransform } from './transform';
import { getMLJobIds } from '../../service_map/get_service_anomalies';
import { getLatencyTimeseries } from '../get_latency_charts';
import { PromiseReturnType } from '../../../../../observability/typings/common';

export async function getAnomalySeries({
serviceName,
transactionType,
transactionName,
timeSeriesDates,
latencyTimeseries,
setup,
logger,
}: {
serviceName: string;
transactionType: string | undefined;
transactionName: string | undefined;
timeSeriesDates: number[];
latencyTimeseries: PromiseReturnType<
typeof getLatencyTimeseries
>['latencyTimeseries'];
setup: Setup & SetupTimeRange;
logger: Logger;
}) {
// don't fetch anomalies for transaction details page
if (transactionName) {
return;
}
const timeseriesDates = latencyTimeseries?.avg?.map(({ x }) => x);

// don't fetch anomalies without a type
if (!transactionType) {
/*
* don't fetch:
* - anomalies for transaction details page
* - anomalies without a type
* - timeseries is empty
*/
if (transactionName || !transactionType || !timeseriesDates?.length) {
return;
}

Expand Down Expand Up @@ -94,7 +100,7 @@ export async function getAnomalySeries({
esResponse,
mlBucketSize,
bucketSize,
timeSeriesDates,
timeseriesDates,
jobId
);
}
Expand Down
12 changes: 5 additions & 7 deletions x-pack/plugins/apm/server/routes/transactions.ts
Original file line number Diff line number Diff line change
Expand Up @@ -154,13 +154,11 @@ export const transactionLatencyChatsRoute = createRoute({
overallAvgDuration,
} = await getLatencyTimeseries(options);

const anomalyTimeseries = latencyTimeseries
? await getAnomalySeries({
...options,
logger,
timeSeriesDates: latencyTimeseries.avg.map(({ x }) => x),
})
: null;
const anomalyTimeseries = await getAnomalySeries({
...options,
logger,
latencyTimeseries,
});

return { latencyTimeseries, overallAvgDuration, anomalyTimeseries };
},
Expand Down

0 comments on commit 85efe71

Please sign in to comment.