Skip to content

Commit

Permalink
addint api tests for latency calc
Browse files Browse the repository at this point in the history
  • Loading branch information
cauemarcondes committed Oct 15, 2021
1 parent ab6526b commit bf852e3
Show file tree
Hide file tree
Showing 2 changed files with 32 additions and 16 deletions.
4 changes: 4 additions & 0 deletions x-pack/test/apm_api_integration/tests/index.ts
Original file line number Diff line number Diff line change
Expand Up @@ -229,6 +229,10 @@ export default function apmApiIntegrationTests(providerContext: FtrProviderConte
loadTestFile(require.resolve('./historical_data/has_data'));
});

describe('latency/service_apis', function () {
loadTestFile(require.resolve('./latency/service_apis'));
});

registry.run(providerContext);
});
}
44 changes: 28 additions & 16 deletions x-pack/test/apm_api_integration/tests/latency/service_apis.ts
Original file line number Diff line number Diff line change
Expand Up @@ -8,10 +8,10 @@ import { service, timerange } from '@elastic/apm-generator';
import expect from '@kbn/expect';
import { meanBy, sumBy } from 'lodash';
import { LatencyAggregationType } from '../../../../plugins/apm/common/latency_aggregation_types';
import { isFiniteNumber } from '../../../../plugins/apm/common/utils/is_finite_number';
import { PromiseReturnType } from '../../../../plugins/observability/typings/common';
import { FtrProviderContext } from '../../common/ftr_provider_context';
import { registry } from '../../common/registry';
import { roundNumber } from '../../utils';

export default function ApiTest({ getService }: FtrProviderContext) {
const apmApiClient = getService('apmApiClient');
Expand Down Expand Up @@ -89,7 +89,9 @@ export default function ApiTest({ getService }: FtrProviderContext) {
const serviceInventoryLatency = serviceInventoryAPIResponse.body.items[0].latency;

const latencyChartApiMean = meanBy(
serviceLantencyAPIResponse.body.currentPeriod.latencyTimeseries,
serviceLantencyAPIResponse.body.currentPeriod.latencyTimeseries.filter(
(item) => isFiniteNumber(item.y) && item.y > 0
),
'y'
);

Expand Down Expand Up @@ -130,21 +132,21 @@ export default function ApiTest({ getService }: FtrProviderContext) {
await traceData.index([
...timerange(start, end)
.interval('1m')
.rate(80)
.rate(GO_PROD_RATE)
.flatMap((timestamp) =>
serviceGoProdInstance
.transaction('GET /api/product/list')
.duration(1000)
.duration(GO_PROD_DURATION)
.timestamp(timestamp)
.serialize()
),
...timerange(start, end)
.interval('1m')
.rate(20)
.rate(GO_DEV_RATE)
.flatMap((timestamp) =>
serviceGoDevInstance
.transaction('GET /api/product/:id')
.duration(500)
.duration(GO_DEV_DURATION)
.timestamp(timestamp)
.serialize()
),
Expand All @@ -161,17 +163,27 @@ export default function ApiTest({ getService }: FtrProviderContext) {
]);
});

it('returns same latency value for Transaction-based and Metric-based data', () => {
console.log('### caue ~ latencyTransactionValues', {
latencyTransactionValues,
latencyMetricValues,
});
it('returns same avg latency value for Transaction-based and Metric-based data', () => {
const expectedLatencyAvgValueMs =
((GO_PROD_RATE * GO_PROD_DURATION + GO_DEV_RATE * GO_DEV_DURATION) /
(GO_PROD_RATE + GO_DEV_RATE)) *
1000;
[
...Object.values(latencyTransactionValues),
...Object.values(latencyMetricValues),
].forEach((value) =>
expect(roundNumber(value)).to.be.equal(roundNumber(GO_PROD_DURATION + GO_DEV_DURATION))
);
latencyTransactionValues.latencyChartApiMean,
latencyTransactionValues.serviceInventoryLatency,
latencyMetricValues.latencyChartApiMean,
latencyMetricValues.serviceInventoryLatency,
].forEach((value) => expect(value).to.be.equal(expectedLatencyAvgValueMs));
});

it('returns same sum latency value for Transaction-based and Metric-based data', () => {
const expectedLatencySumValueMs = (GO_PROD_DURATION + GO_DEV_DURATION) * 1000;
[
latencyTransactionValues.transactionsGroupLatencySum,
latencyTransactionValues.serviceInstancesLatencySum,
latencyMetricValues.transactionsGroupLatencySum,
latencyMetricValues.serviceInstancesLatencySum,
].forEach((value) => expect(value).to.be.equal(expectedLatencySumValueMs));
});
});
});
Expand Down

0 comments on commit bf852e3

Please sign in to comment.