Skip to content

Commit 0f1f3f1

Browse files
[APM] use latency sum instead of avg for impact (#89990) (#90019)
Co-authored-by: Kibana Machine <42973632+kibanamachine@users.noreply.github.com> Co-authored-by: Kibana Machine <42973632+kibanamachine@users.noreply.github.com>
1 parent 821b850 commit 0f1f3f1

File tree

2 files changed

+111
-20
lines changed
  • x-pack
    • plugins/apm/server/lib/services/get_service_dependencies
    • test/apm_api_integration/tests/service_overview/dependencies

2 files changed

+111
-20
lines changed

x-pack/plugins/apm/server/lib/services/get_service_dependencies/index.ts

Lines changed: 16 additions & 9 deletions
Original file line numberDiff line numberDiff line change
@@ -196,19 +196,26 @@ export async function getServiceDependencies({
196196
});
197197

198198
const latencySums = metricsByResolvedAddress
199-
.map((metrics) => metrics.latency.value)
199+
.map(
200+
(metric) => (metric.latency.value ?? 0) * (metric.throughput.value ?? 0)
201+
)
200202
.filter(isFiniteNumber);
201203

202204
const minLatencySum = Math.min(...latencySums);
203205
const maxLatencySum = Math.max(...latencySums);
204206

205-
return metricsByResolvedAddress.map((metric) => ({
206-
...metric,
207-
impact:
208-
metric.latency.value === null
209-
? 0
210-
: ((metric.latency.value - minLatencySum) /
207+
return metricsByResolvedAddress.map((metric) => {
208+
const impact =
209+
isFiniteNumber(metric.latency.value) &&
210+
isFiniteNumber(metric.throughput.value)
211+
? ((metric.latency.value * metric.throughput.value - minLatencySum) /
211212
(maxLatencySum - minLatencySum)) *
212-
100,
213-
}));
213+
100
214+
: 0;
215+
216+
return {
217+
...metric,
218+
impact,
219+
};
220+
});
214221
}

x-pack/test/apm_api_integration/tests/service_overview/dependencies/index.ts

Lines changed: 95 additions & 11 deletions
Original file line numberDiff line numberDiff line change
@@ -6,7 +6,7 @@
66

77
import expect from '@kbn/expect';
88
import url from 'url';
9-
import { sortBy, pick, last } from 'lodash';
9+
import { sortBy, pick, last, omit } from 'lodash';
1010
import { ValuesType } from 'utility-types';
1111
import { registry } from '../../../common/registry';
1212
import { Maybe } from '../../../../../plugins/apm/typings/common';
@@ -306,7 +306,7 @@ export default function ApiTest({ getService }: FtrProviderContext) {
306306
before(async () => {
307307
response = await supertest.get(
308308
url.format({
309-
pathname: `/api/apm/services/opbeans-java/dependencies`,
309+
pathname: `/api/apm/services/opbeans-python/dependencies`,
310310
query: {
311311
start,
312312
end,
@@ -323,14 +323,41 @@ export default function ApiTest({ getService }: FtrProviderContext) {
323323

324324
it('returns at least one item', () => {
325325
expect(response.body.length).to.be.greaterThan(0);
326+
327+
expectSnapshot(
328+
omit(response.body[0], [
329+
'errorRate.timeseries',
330+
'throughput.timeseries',
331+
'latency.timeseries',
332+
])
333+
).toMatchInline(`
334+
Object {
335+
"errorRate": Object {
336+
"value": 0,
337+
},
338+
"impact": 1.97910470896139,
339+
"latency": Object {
340+
"value": 1043.99015586546,
341+
},
342+
"name": "redis",
343+
"spanSubtype": "redis",
344+
"spanType": "db",
345+
"throughput": Object {
346+
"value": 40.6333333333333,
347+
},
348+
"type": "external",
349+
}
350+
`);
326351
});
327352

328353
it('returns the right names', () => {
329354
const names = response.body.map((item) => item.name);
330355
expectSnapshot(names.sort()).toMatchInline(`
331356
Array [
332-
"opbeans-go",
357+
"elasticsearch",
358+
"opbeans-java",
333359
"postgresql",
360+
"redis",
334361
]
335362
`);
336363
});
@@ -342,7 +369,7 @@ export default function ApiTest({ getService }: FtrProviderContext) {
342369

343370
expectSnapshot(serviceNames.sort()).toMatchInline(`
344371
Array [
345-
"opbeans-go",
372+
"opbeans-java",
346373
]
347374
`);
348375
});
@@ -356,32 +383,89 @@ export default function ApiTest({ getService }: FtrProviderContext) {
356383
expectSnapshot(latencyValues).toMatchInline(`
357384
Array [
358385
Object {
359-
"latency": 38506.4285714286,
360-
"name": "opbeans-go",
386+
"latency": 2568.40816326531,
387+
"name": "elasticsearch",
388+
},
389+
Object {
390+
"latency": 25593.875,
391+
"name": "opbeans-java",
361392
},
362393
Object {
363-
"latency": 5908.77272727273,
394+
"latency": 28885.3293963255,
364395
"name": "postgresql",
365396
},
397+
Object {
398+
"latency": 1043.99015586546,
399+
"name": "redis",
400+
},
366401
]
367402
`);
368403
});
369404

370405
it('returns the right throughput values', () => {
371406
const throughputValues = sortBy(
372-
response.body.map((item) => ({ name: item.name, latency: item.throughput.value })),
407+
response.body.map((item) => ({ name: item.name, throughput: item.throughput.value })),
373408
'name'
374409
);
375410

376411
expectSnapshot(throughputValues).toMatchInline(`
377412
Array [
378413
Object {
379-
"latency": 0.466666666666667,
380-
"name": "opbeans-go",
414+
"name": "elasticsearch",
415+
"throughput": 13.0666666666667,
416+
},
417+
Object {
418+
"name": "opbeans-java",
419+
"throughput": 0.533333333333333,
381420
},
382421
Object {
383-
"latency": 3.66666666666667,
384422
"name": "postgresql",
423+
"throughput": 50.8,
424+
},
425+
Object {
426+
"name": "redis",
427+
"throughput": 40.6333333333333,
428+
},
429+
]
430+
`);
431+
});
432+
433+
it('returns the right impact values', () => {
434+
const impactValues = sortBy(
435+
response.body.map((item) => ({
436+
name: item.name,
437+
impact: item.impact,
438+
latency: item.latency.value,
439+
throughput: item.throughput.value,
440+
})),
441+
'name'
442+
);
443+
444+
expectSnapshot(impactValues).toMatchInline(`
445+
Array [
446+
Object {
447+
"impact": 1.36961744704522,
448+
"latency": 2568.40816326531,
449+
"name": "elasticsearch",
450+
"throughput": 13.0666666666667,
451+
},
452+
Object {
453+
"impact": 0,
454+
"latency": 25593.875,
455+
"name": "opbeans-java",
456+
"throughput": 0.533333333333333,
457+
},
458+
Object {
459+
"impact": 100,
460+
"latency": 28885.3293963255,
461+
"name": "postgresql",
462+
"throughput": 50.8,
463+
},
464+
Object {
465+
"impact": 1.97910470896139,
466+
"latency": 1043.99015586546,
467+
"name": "redis",
468+
"throughput": 40.6333333333333,
385469
},
386470
]
387471
`);

0 commit comments

Comments
 (0)