Skip to content

Commit a5e4cfc

Browse files
committed
Use kibana advanced config for limiting the number of services
1 parent 301a429 commit a5e4cfc

File tree

4 files changed

+34
-12
lines changed

4 files changed

+34
-12
lines changed

x-pack/plugins/apm/server/routes/service_map/get_service_map.ts

Lines changed: 15 additions & 6 deletions
Original file line numberDiff line numberDiff line change
@@ -90,10 +90,17 @@ async function getConnectionData({
9090
});
9191
}
9292

93-
async function getServicesData(options: IEnvOptions) {
94-
const { environment, setup, searchAggregatedTransactions, start, end } =
95-
options;
96-
93+
async function getServicesData(
94+
options: IEnvOptions & { maxNumberOfServices: number }
95+
) {
96+
const {
97+
environment,
98+
setup,
99+
searchAggregatedTransactions,
100+
start,
101+
end,
102+
maxNumberOfServices,
103+
} = options;
97104
const params = {
98105
apm: {
99106
events: [
@@ -117,7 +124,7 @@ async function getServicesData(options: IEnvOptions) {
117124
services: {
118125
terms: {
119126
field: SERVICE_NAME,
120-
size: 500,
127+
size: maxNumberOfServices,
121128
},
122129
aggs: {
123130
agent_name: {
@@ -156,7 +163,9 @@ async function getServicesData(options: IEnvOptions) {
156163
export type ConnectionsResponse = Awaited<ReturnType<typeof getConnectionData>>;
157164
export type ServicesResponse = Awaited<ReturnType<typeof getServicesData>>;
158165

159-
export function getServiceMap(options: IEnvOptions) {
166+
export function getServiceMap(
167+
options: IEnvOptions & { maxNumberOfServices: number }
168+
) {
160169
return withApmSpan('get_service_map', async () => {
161170
const { logger } = options;
162171
const anomaliesPromise = getServiceAnomalies(

x-pack/plugins/apm/server/routes/service_map/route.ts

Lines changed: 8 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -7,6 +7,7 @@
77

88
import Boom from '@hapi/boom';
99
import * as t from 'io-ts';
10+
import { apmServiceGroupMaxNumberOfServices } from '@kbn/observability-plugin/common';
1011
import { isActivePlatinumLicense } from '../../../common/license_check';
1112
import { invalidLicenseMessage } from '../../../common/service_map';
1213
import { notifyFeatureUsage } from '../../feature';
@@ -109,15 +110,19 @@ const serviceMapRoute = createApmServerRoute({
109110
},
110111
} = params;
111112

112-
const savedObjectsClient = (await context.core).savedObjects.client;
113-
const [setup, serviceGroup] = await Promise.all([
113+
const {
114+
savedObjects: { client: savedObjectsClient },
115+
uiSettings: { client: uiSettingsClient },
116+
} = await context.core;
117+
const [setup, serviceGroup, maxNumberOfServices] = await Promise.all([
114118
setupRequest(resources),
115119
serviceGroupId
116120
? getServiceGroup({
117121
savedObjectsClient,
118122
serviceGroupId,
119123
})
120124
: Promise.resolve(null),
125+
uiSettingsClient.get<number>(apmServiceGroupMaxNumberOfServices),
121126
]);
122127

123128
const serviceNames = [
@@ -140,6 +145,7 @@ const serviceMapRoute = createApmServerRoute({
140145
logger,
141146
start,
142147
end,
148+
maxNumberOfServices,
143149
});
144150
},
145151
});

x-pack/plugins/apm/server/routes/services/get_services/get_sorted_and_filtered_services.ts

Lines changed: 3 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -22,13 +22,15 @@ export async function getSortedAndFilteredServices({
2222
environment,
2323
logger,
2424
serviceGroup,
25+
maxNumberOfServices,
2526
}: {
2627
setup: Setup;
2728
start: number;
2829
end: number;
2930
environment: Environment;
3031
logger: Logger;
3132
serviceGroup: ServiceGroup | null;
33+
maxNumberOfServices: number;
3234
}) {
3335
const { apmEventClient } = setup;
3436

@@ -48,7 +50,7 @@ export async function getSortedAndFilteredServices({
4850
],
4951
},
5052
body: {
51-
size: 500,
53+
size: maxNumberOfServices,
5254
field: SERVICE_NAME,
5355
},
5456
}

x-pack/plugins/apm/server/routes/services/route.ts

Lines changed: 8 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -16,6 +16,7 @@ import {
1616
} from '@kbn/ml-plugin/server';
1717
import { ScopedAnnotationsClient } from '@kbn/observability-plugin/server';
1818
import { Annotation } from '@kbn/observability-plugin/common/annotations';
19+
import { apmServiceGroupMaxNumberOfServices } from '@kbn/observability-plugin/common';
1920
import { latencyAggregationTypeRt } from '../../../common/latency_aggregation_types';
2021
import { ProfilingValueType } from '../../../common/profiling';
2122
import { getSearchAggregatedTransactions } from '../../lib/helpers/transactions';
@@ -1246,14 +1247,17 @@ const sortedAndFilteredServicesRoute = createApmServerRoute({
12461247
};
12471248
}
12481249

1249-
const savedObjectsClient = (await resources.context.core).savedObjects
1250-
.client;
1250+
const {
1251+
savedObjects: { client: savedObjectsClient },
1252+
uiSettings: { client: uiSettingsClient },
1253+
} = await resources.context.core;
12511254

1252-
const [setup, serviceGroup] = await Promise.all([
1255+
const [setup, serviceGroup, maxNumberOfServices] = await Promise.all([
12531256
setupRequest(resources),
12541257
serviceGroupId
12551258
? getServiceGroup({ savedObjectsClient, serviceGroupId })
12561259
: Promise.resolve(null),
1260+
uiSettingsClient.get<number>(apmServiceGroupMaxNumberOfServices),
12571261
]);
12581262
return {
12591263
services: await getSortedAndFilteredServices({
@@ -1263,6 +1267,7 @@ const sortedAndFilteredServicesRoute = createApmServerRoute({
12631267
environment,
12641268
logger: resources.logger,
12651269
serviceGroup,
1270+
maxNumberOfServices,
12661271
}),
12671272
};
12681273
},

0 commit comments

Comments
 (0)