Skip to content

Commit

Permalink
[APM] Add logic to use useSummaryField Prop for get Services endpoint (
Browse files Browse the repository at this point in the history
…elastic#168108)

## Summary

Closes elastic#168031

- This PR includes a long list of files. But mostly they are tests and
places which calls the `getServicesItems` function either directly or
via the endpoint. We have introduced an additional parameter which is
already present in other endpoints, which would make sure if
`transaction.duration.summary` field is present, then use it for
aggregations as its faster. In case of transaction events, it would
fallback to `transaction.duration.histogram`

- To keep the scope simple, API tests are simply setting `true/false`.
Rule of thumb used here is, for function calls in API tests, which are
using transaction events i am passing `useDurationSummary: false` and
which are using metric, passing `useDurationSummary: true`.

---------

Co-authored-by: kibanamachine <[email protected]>
  • Loading branch information
achyutjhunjhunwala and kibanamachine authored Oct 10, 2023
1 parent 5ef9111 commit aa48e31
Show file tree
Hide file tree
Showing 17 changed files with 54 additions and 3 deletions.
Original file line number Diff line number Diff line change
Expand Up @@ -65,6 +65,8 @@ function useServicesMainStatisticsFetcher() {
numBuckets: 20,
});

const shouldUseDurationSummary = !!preferred?.source?.hasDurationSummaryField;

const mainStatisticsFetch = useProgressiveFetcher(
(callApmApi) => {
if (preferred) {
Expand All @@ -76,6 +78,7 @@ function useServicesMainStatisticsFetcher() {
start,
end,
serviceGroup,
useDurationSummary: shouldUseDurationSummary,
documentType: preferred.source.documentType,
rollupInterval: preferred.source.rollupInterval,
},
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -260,6 +260,7 @@ const getApmServicesListRoute = createApmServerRoute({
rollupInterval: RollupInterval.OneMinute,
serviceGroup: null,
mlClient,
useDurationSummary: false,
});

let mappedItems = serviceItems.items.map((item): ApmServicesListItem => {
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -44,6 +44,7 @@ interface AggregationParams {
| ApmDocumentType.TransactionMetric
| ApmDocumentType.TransactionEvent;
rollupInterval: RollupInterval;
useDurationSummary: boolean;
}

export interface ServiceTransactionStatsResponse {
Expand All @@ -70,13 +71,17 @@ export async function getServiceTransactionStats({
randomSampler,
documentType,
rollupInterval,
useDurationSummary,
}: AggregationParams): Promise<ServiceTransactionStatsResponse> {
const outcomes = getOutcomeAggregation(documentType);

const metrics = {
avg_duration: {
avg: {
field: getDurationFieldForTransactions(documentType),
field: getDurationFieldForTransactions(
documentType,
useDurationSummary
),
},
},
...outcomes,
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -41,6 +41,7 @@ export async function getServicesItems({
randomSampler,
documentType,
rollupInterval,
useDurationSummary,
}: {
environment: string;
kuery: string;
Expand All @@ -54,6 +55,7 @@ export async function getServicesItems({
randomSampler: RandomSampler;
documentType: ApmServiceTransactionDocumentType;
rollupInterval: RollupInterval;
useDurationSummary: boolean;
}): Promise<ServicesItemsResponse> {
return withApmSpan('get_services_items', async () => {
const commonParams = {
Expand All @@ -66,6 +68,7 @@ export async function getServicesItems({
randomSampler,
documentType,
rollupInterval,
useDurationSummary,
};

const [
Expand Down
1 change: 1 addition & 0 deletions x-pack/plugins/apm/server/routes/services/queries.test.ts
Original file line number Diff line number Diff line change
Expand Up @@ -71,6 +71,7 @@ describe('services queries', () => {
seed: 0,
},
apmAlertsClient: mockApmAlertsClient,
useDurationSummary: false,
})
);

Expand Down
16 changes: 14 additions & 2 deletions x-pack/plugins/apm/server/routes/services/route.ts
Original file line number Diff line number Diff line change
Expand Up @@ -6,7 +6,12 @@
*/

import Boom from '@hapi/boom';
import { isoToEpochRt, jsonRt, toNumberRt } from '@kbn/io-ts-utils';
import {
isoToEpochRt,
jsonRt,
toBooleanRt,
toNumberRt,
} from '@kbn/io-ts-utils';
import {
InsufficientMLCapabilities,
MLPrivilegesUninitialized,
Expand Down Expand Up @@ -105,7 +110,12 @@ const servicesRoute = createApmServerRoute({
t.partial({ serviceGroup: t.string }),
t.intersection([
probabilityRt,
serviceTransactionDataSourceRt,
t.intersection([
serviceTransactionDataSourceRt,
t.type({
useDurationSummary: toBooleanRt,
}),
]),
environmentRt,
kueryRt,
rangeRt,
Expand All @@ -131,6 +141,7 @@ const servicesRoute = createApmServerRoute({
probability,
documentType,
rollupInterval,
useDurationSummary,
} = params.query;
const savedObjectsClient = (await context.core).savedObjects.client;

Expand Down Expand Up @@ -163,6 +174,7 @@ const servicesRoute = createApmServerRoute({
randomSampler,
documentType,
rollupInterval,
useDurationSummary,
});
},
});
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -71,6 +71,7 @@ export async function fetchServiceInventoryAlertCounts(apmApiClient: ApmApiClien
probability: 1,
documentType: ApmDocumentType.ServiceTransactionMetric,
rollupInterval: RollupInterval.SixtyMinutes,
useDurationSummary: true,
},
},
});
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -51,10 +51,12 @@ export default function ApiTest({ getService }: FtrProviderContext) {
? {
documentType: ApmDocumentType.TransactionMetric,
rollupInterval: RollupInterval.OneMinute,
useDurationSummary: true,
}
: {
documentType: ApmDocumentType.TransactionEvent,
rollupInterval: RollupInterval.None,
useDurationSummary: false,
}),
},
},
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -39,10 +39,12 @@ export default function ApiTest({ getService }: FtrProviderContext) {
? {
documentType: ApmDocumentType.TransactionMetric,
rollupInterval: RollupInterval.OneMinute,
useDurationSummary: true,
}
: {
documentType: ApmDocumentType.TransactionEvent,
rollupInterval: RollupInterval.None,
useDurationSummary: false,
}),
},
},
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -189,6 +189,7 @@ function getApmServices(apmApiClient: ApmApiClient, start: string, end: string)
kuery: '',
documentType: ApmDocumentType.TransactionMetric,
rollupInterval: RollupInterval.OneMinute,
useDurationSummary: true,
},
},
});
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -54,10 +54,12 @@ export default function ApiTest({ getService }: FtrProviderContext) {
? {
documentType: ApmDocumentType.TransactionMetric,
rollupInterval: RollupInterval.OneMinute,
useDurationSummary: true,
}
: {
documentType: ApmDocumentType.TransactionEvent,
rollupInterval: RollupInterval.None,
useDurationSummary: false,
}),
},
},
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -39,10 +39,12 @@ export default function ApiTest({ getService }: FtrProviderContext) {
? {
documentType: ApmDocumentType.TransactionMetric,
rollupInterval: RollupInterval.OneMinute,
useDurationSummary: true,
}
: {
documentType: ApmDocumentType.TransactionEvent,
rollupInterval: RollupInterval.None,
useDurationSummary: false,
}),
},
},
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -36,6 +36,7 @@ export default function ApiTest({ getService }: FtrProviderContext) {
kuery: '',
documentType: ApmDocumentType.TransactionMetric,
rollupInterval: RollupInterval.OneMinute,
useDurationSummary: true,
},
},
}),
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -90,6 +90,7 @@ export default function ApiTest({ getService }: FtrProviderContext) {
probability: 1,
documentType: ApmDocumentType.ServiceTransactionMetric,
rollupInterval: RollupInterval.OneMinute,
useDurationSummary: true,
},
},
});
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -49,6 +49,7 @@ export default function ApiTest({ getService }: FtrProviderContext) {
probability: 1,
documentType: ApmDocumentType.TransactionMetric,
rollupInterval: RollupInterval.OneMinute,
useDurationSummary: true,
},
},
});
Expand Down Expand Up @@ -192,6 +193,7 @@ export default function ApiTest({ getService }: FtrProviderContext) {
probability: 1,
documentType: ApmDocumentType.TransactionMetric,
rollupInterval: RollupInterval.OneMinute,
useDurationSummary: true,
},
},
});
Expand Down Expand Up @@ -227,6 +229,7 @@ export default function ApiTest({ getService }: FtrProviderContext) {
probability: 1,
documentType: ApmDocumentType.TransactionMetric,
rollupInterval: RollupInterval.OneMinute,
useDurationSummary: true,
},
},
});
Expand Down Expand Up @@ -264,6 +267,7 @@ export default function ApiTest({ getService }: FtrProviderContext) {
probability: 1,
documentType: ApmDocumentType.TransactionMetric,
rollupInterval: RollupInterval.OneMinute,
useDurationSummary: true,
},
},
});
Expand Down Expand Up @@ -301,6 +305,7 @@ export default function ApiTest({ getService }: FtrProviderContext) {
probability: 1,
documentType: ApmDocumentType.TransactionMetric,
rollupInterval: RollupInterval.OneMinute,
useDurationSummary: true,
},
},
});
Expand Down Expand Up @@ -328,6 +333,7 @@ export default function ApiTest({ getService }: FtrProviderContext) {
probability: 1,
documentType: ApmDocumentType.ServiceTransactionMetric,
rollupInterval: RollupInterval.OneMinute,
useDurationSummary: true,
},
},
});
Expand Down Expand Up @@ -359,6 +365,7 @@ export default function ApiTest({ getService }: FtrProviderContext) {
probability: 1,
documentType: ApmDocumentType.TransactionMetric,
rollupInterval: RollupInterval.TenMinutes,
useDurationSummary: true,
},
},
});
Expand Down Expand Up @@ -394,6 +401,7 @@ export default function ApiTest({ getService }: FtrProviderContext) {
probability: 1,
documentType: ApmDocumentType.TransactionMetric,
rollupInterval: RollupInterval.OneMinute,
useDurationSummary: true,
},
},
});
Expand Down Expand Up @@ -451,6 +459,7 @@ export default function ApiTest({ getService }: FtrProviderContext) {
probability: 1,
documentType: ApmDocumentType.TransactionMetric,
rollupInterval: RollupInterval.OneMinute,
useDurationSummary: true,
},
},
});
Expand Down Expand Up @@ -487,6 +496,7 @@ export default function ApiTest({ getService }: FtrProviderContext) {
probability: 1,
documentType: ApmDocumentType.TransactionMetric,
rollupInterval: RollupInterval.OneMinute,
useDurationSummary: true,
},
},
});
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -47,10 +47,12 @@ export default function ApiTest({ getService }: FtrProviderContext) {
? {
documentType: ApmDocumentType.TransactionMetric,
rollupInterval: RollupInterval.OneMinute,
useDurationSummary: true,
}
: {
documentType: ApmDocumentType.TransactionEvent,
rollupInterval: RollupInterval.None,
useDurationSummary: false,
}),
},
},
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -50,10 +50,12 @@ export default function ApiTest({ getService }: FtrProviderContext) {
? {
documentType: ApmDocumentType.TransactionMetric,
rollupInterval: RollupInterval.OneMinute,
useDurationSummary: true,
}
: {
documentType: ApmDocumentType.TransactionEvent,
rollupInterval: RollupInterval.None,
useDurationSummary: false,
}),
},
},
Expand Down

0 comments on commit aa48e31

Please sign in to comment.