Skip to content

Commit

Permalink
fix field value pair error handling
Browse files Browse the repository at this point in the history
  • Loading branch information
walterra committed Nov 8, 2021
1 parent de63d24 commit 22f785c
Show file tree
Hide file tree
Showing 2 changed files with 21 additions and 15 deletions.
Original file line number Diff line number Diff line change
Expand Up @@ -15,6 +15,8 @@ import type {
} from '../../../../common/correlations/types';
import { TERMS_SIZE } from '../../../../common/correlations/constants';

import { splitAllSettledPromises } from '../utils';

import { getQueryWithParams } from './get_query_with_params';
import { getRequestBase } from './get_request_base';

Expand Down Expand Up @@ -73,12 +75,14 @@ export const fetchTransactionDurationFieldValuePairs = async (
esClient: ElasticsearchClient,
params: CorrelationsParams,
fieldCandidates: string[]
): Promise<FieldValuePair[]> => {
const responses = await Promise.all(
fieldCandidates.map((fieldCandidate) =>
fetchTransactionDurationFieldTerms(esClient, params, fieldCandidate)
): Promise<{ fieldValuePairs: FieldValuePair[]; errors: any[] }> => {
const { fulfilled: responses, rejected: errors } = splitAllSettledPromises(
await Promise.allSettled(
fieldCandidates.map((fieldCandidate) =>
fetchTransactionDurationFieldTerms(esClient, params, fieldCandidate)
)
)
);

return responses.flat();
return { fieldValuePairs: responses.flat(), errors };
};
22 changes: 12 additions & 10 deletions x-pack/plugins/apm/server/routes/correlations.ts
Original file line number Diff line number Diff line change
Expand Up @@ -141,16 +141,18 @@ const fieldValuePairsRoute = createApmServerRoute({

const { fieldCandidates, ...params } = resources.params.body;

return withApmSpan('get_correlations_field_value_pairs', async () => ({
fieldValuePairs: await fetchTransactionDurationFieldValuePairs(
esClient,
{
...params,
index: indices.transaction,
},
fieldCandidates
),
}));
return withApmSpan(
'get_correlations_field_value_pairs',
async () =>
await fetchTransactionDurationFieldValuePairs(
esClient,
{
...params,
index: indices.transaction,
},
fieldCandidates
)
);
},
});

Expand Down

0 comments on commit 22f785c

Please sign in to comment.