Skip to content

Commit

Permalink
[7.11] [APM] use latency sum instead of avg for impact (#89990) (#90029)
Browse files Browse the repository at this point in the history
Co-authored-by: Kibana Machine <42973632+kibanamachine@users.noreply.github.com>
# Conflicts:
#	x-pack/test/apm_api_integration/tests/service_overview/dependencies/index.ts
  • Loading branch information
dgieselaar authored Feb 2, 2021
1 parent 61f4c54 commit f73540a
Show file tree
Hide file tree
Showing 2 changed files with 111 additions and 20 deletions.
Original file line number Diff line number Diff line change
Expand Up @@ -191,19 +191,26 @@ export async function getServiceDependencies({
});

const latencySums = metricsByResolvedAddress
.map((metrics) => metrics.latency.value)
.map(
(metric) => (metric.latency.value ?? 0) * (metric.throughput.value ?? 0)
)
.filter(isFiniteNumber);

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

return metricsByResolvedAddress.map((metric) => ({
...metric,
impact:
metric.latency.value === null
? 0
: ((metric.latency.value - minLatencySum) /
return metricsByResolvedAddress.map((metric) => {
const impact =
isFiniteNumber(metric.latency.value) &&
isFiniteNumber(metric.throughput.value)
? ((metric.latency.value * metric.throughput.value - minLatencySum) /
(maxLatencySum - minLatencySum)) *
100,
}));
100
: 0;

return {
...metric,
impact,
};
});
}
Original file line number Diff line number Diff line change
Expand Up @@ -6,7 +6,7 @@

import expect from '@kbn/expect';
import url from 'url';
import { sortBy, pick, last } from 'lodash';
import { sortBy, pick, last, omit } from 'lodash';
import { ValuesType } from 'utility-types';
import { Maybe } from '../../../../../../plugins/apm/typings/common';
import { isFiniteNumber } from '../../../../../../plugins/apm/common/utils/is_finite_number';
Expand Down Expand Up @@ -298,7 +298,7 @@ export default function ApiTest({ getService }: FtrProviderContext) {

response = await supertest.get(
url.format({
pathname: `/api/apm/services/opbeans-java/dependencies`,
pathname: `/api/apm/services/opbeans-python/dependencies`,
query: {
start,
end,
Expand All @@ -317,14 +317,41 @@ export default function ApiTest({ getService }: FtrProviderContext) {

it('returns at least one item', () => {
expect(response.body.length).to.be.greaterThan(0);

expectSnapshot(
omit(response.body[0], [
'errorRate.timeseries',
'throughput.timeseries',
'latency.timeseries',
])
).toMatchInline(`
Object {
"errorRate": Object {
"value": 0,
},
"impact": 1.97910470896139,
"latency": Object {
"value": 1043.99015586546,
},
"name": "redis",
"spanSubtype": "redis",
"spanType": "db",
"throughput": Object {
"value": 40.6333333333333,
},
"type": "external",
}
`);
});

it('returns the right names', () => {
const names = response.body.map((item) => item.name);
expectSnapshot(names.sort()).toMatchInline(`
Array [
"opbeans-go",
"elasticsearch",
"opbeans-java",
"postgresql",
"redis",
]
`);
});
Expand All @@ -336,7 +363,7 @@ export default function ApiTest({ getService }: FtrProviderContext) {

expectSnapshot(serviceNames.sort()).toMatchInline(`
Array [
"opbeans-go",
"opbeans-java",
]
`);
});
Expand All @@ -350,32 +377,89 @@ export default function ApiTest({ getService }: FtrProviderContext) {
expectSnapshot(latencyValues).toMatchInline(`
Array [
Object {
"latency": 38506.4285714286,
"name": "opbeans-go",
"latency": 2568.40816326531,
"name": "elasticsearch",
},
Object {
"latency": 25593.875,
"name": "opbeans-java",
},
Object {
"latency": 5908.77272727273,
"latency": 28885.3293963255,
"name": "postgresql",
},
Object {
"latency": 1043.99015586546,
"name": "redis",
},
]
`);
});

it('returns the right throughput values', () => {
const throughputValues = sortBy(
response.body.map((item) => ({ name: item.name, latency: item.throughput.value })),
response.body.map((item) => ({ name: item.name, throughput: item.throughput.value })),
'name'
);

expectSnapshot(throughputValues).toMatchInline(`
Array [
Object {
"latency": 0.466666666666667,
"name": "opbeans-go",
"name": "elasticsearch",
"throughput": 13.0666666666667,
},
Object {
"name": "opbeans-java",
"throughput": 0.533333333333333,
},
Object {
"latency": 3.66666666666667,
"name": "postgresql",
"throughput": 50.8,
},
Object {
"name": "redis",
"throughput": 40.6333333333333,
},
]
`);
});

it('returns the right impact values', () => {
const impactValues = sortBy(
response.body.map((item) => ({
name: item.name,
impact: item.impact,
latency: item.latency.value,
throughput: item.throughput.value,
})),
'name'
);

expectSnapshot(impactValues).toMatchInline(`
Array [
Object {
"impact": 1.36961744704522,
"latency": 2568.40816326531,
"name": "elasticsearch",
"throughput": 13.0666666666667,
},
Object {
"impact": 0,
"latency": 25593.875,
"name": "opbeans-java",
"throughput": 0.533333333333333,
},
Object {
"impact": 100,
"latency": 28885.3293963255,
"name": "postgresql",
"throughput": 50.8,
},
Object {
"impact": 1.97910470896139,
"latency": 1043.99015586546,
"name": "redis",
"throughput": 40.6333333333333,
},
]
`);
Expand Down

0 comments on commit f73540a

Please sign in to comment.