Skip to content

Commit

Permalink
[APM] Prefer span metrics over span events
Browse files Browse the repository at this point in the history
  • Loading branch information
cauemarcondes committed Sep 22, 2022
1 parent f7f8fa6 commit 181dcc1
Show file tree
Hide file tree
Showing 5 changed files with 58 additions and 7 deletions.
Original file line number Diff line number Diff line change
Expand Up @@ -18,6 +18,7 @@ export function getSpanDestinationMetrics(events: ApmFields[]) {
'service.environment',
'service.name',
'span.destination.service.resource',
'span.name',
]);

return metricsets.map((metricset) => {
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -9,6 +9,7 @@ import { i18n } from '@kbn/i18n';
import { keyBy } from 'lodash';
import React from 'react';
import { useApmPluginContext } from '../../../../context/apm_plugin/use_apm_plugin_context';
import { useSearchServiceDestinationMetrics } from '../../../../context/time_range_metadata/use_search_service_destination_metrics';
import { useApmParams } from '../../../../hooks/use_apm_params';
import { useBreakpoints } from '../../../../hooks/use_breakpoints';
import { FETCH_STATUS, useFetcher } from '../../../../hooks/use_fetcher';
Expand Down Expand Up @@ -66,6 +67,9 @@ export function DependencyDetailOperationsList() {
urlComparisonEnabled,
});

const { searchServiceDestinationMetrics } =
useSearchServiceDestinationMetrics({ rangeFrom, rangeTo, kuery });

const primaryStatsFetch = useFetcher(
(callApmApi) => {
return callApmApi('GET /internal/apm/dependencies/operations', {
Expand All @@ -76,11 +80,19 @@ export function DependencyDetailOperationsList() {
end,
environment,
kuery,
searchServiceDestinationMetrics,
},
},
});
},
[dependencyName, start, end, environment, kuery]
[
dependencyName,
start,
end,
environment,
kuery,
searchServiceDestinationMetrics,
]
);

const comparisonStatsFetch = useFetcher(
Expand All @@ -99,11 +111,21 @@ export function DependencyDetailOperationsList() {
offset,
environment,
kuery,
searchServiceDestinationMetrics,
},
},
});
},
[dependencyName, start, end, offset, environment, kuery, comparisonEnabled]
[
dependencyName,
start,
end,
offset,
environment,
kuery,
comparisonEnabled,
searchServiceDestinationMetrics,
]
);

const columns: Array<ITableColumn<OperationStatisticsItem>> = [
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -10,7 +10,6 @@ import {
rangeQuery,
termQuery,
} from '@kbn/observability-plugin/server';
import { ProcessorEvent } from '@kbn/observability-plugin/common';
import {
EVENT_OUTCOME,
SPAN_DESTINATION_SERVICE_RESOURCE,
Expand All @@ -28,6 +27,11 @@ import {
import { getMetricsDateHistogramParams } from '../../lib/helpers/metrics';
import { Setup } from '../../lib/helpers/setup_request';
import { calculateImpactBuilder } from '../traces/calculate_impact_builder';
import {
getDocumentTypeFilterForServiceDestinationStatistics,
getLatencyFieldForServiceDestinationStatistics,
getProcessorEventForServiceDestinationStatistics,
} from '../../lib/helpers/spans/get_is_using_service_destination_metrics';

const MAX_NUM_OPERATIONS = 500;

Expand All @@ -51,6 +55,7 @@ export async function getTopDependencyOperations({
offset,
environment,
kuery,
searchServiceDestinationMetrics,
}: {
setup: Setup;
dependencyName: string;
Expand All @@ -59,6 +64,7 @@ export async function getTopDependencyOperations({
offset?: string;
environment: Environment;
kuery: string;
searchServiceDestinationMetrics: boolean;
}) {
const { apmEventClient } = setup;

Expand All @@ -71,7 +77,9 @@ export async function getTopDependencyOperations({
const aggs = {
duration: {
avg: {
field: SPAN_DURATION,
field: getLatencyFieldForServiceDestinationStatistics(
searchServiceDestinationMetrics
),
},
},
successful: {
Expand All @@ -94,7 +102,11 @@ export async function getTopDependencyOperations({
'get_top_dependency_operations',
{
apm: {
events: [ProcessorEvent.span],
events: [
getProcessorEventForServiceDestinationStatistics(
searchServiceDestinationMetrics
),
],
},
body: {
size: 0,
Expand All @@ -105,6 +117,9 @@ export async function getTopDependencyOperations({
...environmentQuery(environment),
...kqlQuery(kuery),
...termQuery(SPAN_DESTINATION_SERVICE_RESOURCE, dependencyName),
...getDocumentTypeFilterForServiceDestinationStatistics(
searchServiceDestinationMetrics
),
],
},
},
Expand Down
16 changes: 14 additions & 2 deletions x-pack/plugins/apm/server/routes/dependencies/route.ts
Original file line number Diff line number Diff line change
Expand Up @@ -492,7 +492,10 @@ const dependencyOperationsRoute = createApmServerRoute({
environmentRt,
kueryRt,
offsetRt,
t.type({ dependencyName: t.string }),
t.type({
dependencyName: t.string,
searchServiceDestinationMetrics: toBooleanRt,
}),
]),
}),
handler: async (
Expand All @@ -501,7 +504,15 @@ const dependencyOperationsRoute = createApmServerRoute({
const setup = await setupRequest(resources);

const {
query: { dependencyName, start, end, environment, kuery, offset },
query: {
dependencyName,
start,
end,
environment,
kuery,
offset,
searchServiceDestinationMetrics,
},
} = resources.params;

const operations = await getTopDependencyOperations({
Expand All @@ -512,6 +523,7 @@ const dependencyOperationsRoute = createApmServerRoute({
offset,
environment,
kuery,
searchServiceDestinationMetrics,
});

return { operations };
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -52,6 +52,7 @@ export default function ApiTest({ getService }: FtrProviderContext) {
environment,
kuery,
dependencyName,
searchServiceDestinationMetrics: false,
},
},
})
Expand Down

0 comments on commit 181dcc1

Please sign in to comment.