From 5161477a1bd201dda403d1c22db84521a9cb95e4 Mon Sep 17 00:00:00 2001 From: Walter Rafelsberger Date: Thu, 8 Jul 2021 14:17:53 +0200 Subject: [PATCH] adjust api/unit test --- .../utils/aggregation_utils.test.ts | 94 +++++++++++++++++++ .../tests/correlations/latency_ml.ts | 52 +++++----- 2 files changed, 118 insertions(+), 28 deletions(-) diff --git a/x-pack/plugins/apm/server/lib/search_strategies/correlations/utils/aggregation_utils.test.ts b/x-pack/plugins/apm/server/lib/search_strategies/correlations/utils/aggregation_utils.test.ts index 63de0a59d489..4313ad58ecbc 100644 --- a/x-pack/plugins/apm/server/lib/search_strategies/correlations/utils/aggregation_utils.test.ts +++ b/x-pack/plugins/apm/server/lib/search_strategies/correlations/utils/aggregation_utils.test.ts @@ -14,6 +14,7 @@ describe('aggregation utils', () => { expect(expectations).toEqual([0, 0.5, 1]); expect(ranges).toEqual([{ to: 0 }, { from: 0, to: 1 }, { from: 1 }]); }); + it('returns expectations and ranges based on given percentiles #2', async () => { const { expectations, ranges } = computeExpectationsAndRanges([1, 3, 5]); expect(expectations).toEqual([1, 2, 4, 5]); @@ -24,6 +25,7 @@ describe('aggregation utils', () => { { from: 5 }, ]); }); + it('returns expectations and ranges with adjusted fractions', async () => { const { expectations, ranges } = computeExpectationsAndRanges([ 1, @@ -45,5 +47,97 @@ describe('aggregation utils', () => { { from: 5 }, ]); }); + + // TODO identify these results derived from the array of percentiles are usable with the ES correlation aggregation + it('returns expectation and ranges adjusted when percentiles have equal values', async () => { + const { expectations, ranges } = computeExpectationsAndRanges([ + 5000, + 5000, + 3090428, + 3090428, + 3090428, + 3618812, + 3618812, + 3618812, + 3618812, + 3696636, + 3696636, + 3696636, + 3696636, + 3696636, + 3696636, + ]); + expect(expectations).toEqual([ + 5000, + 1856256.7999999998, + 3392361.714285714, + 3665506.4, + 3696636, + ]); + expect(ranges).toEqual([ + { + to: 5000, + }, + { + from: 5000, + to: 5000, + }, + { + from: 5000, + to: 3090428, + }, + { + from: 3090428, + to: 3090428, + }, + { + from: 3090428, + to: 3090428, + }, + { + from: 3090428, + to: 3618812, + }, + { + from: 3618812, + to: 3618812, + }, + { + from: 3618812, + to: 3618812, + }, + { + from: 3618812, + to: 3618812, + }, + { + from: 3618812, + to: 3696636, + }, + { + from: 3696636, + to: 3696636, + }, + { + from: 3696636, + to: 3696636, + }, + { + from: 3696636, + to: 3696636, + }, + { + from: 3696636, + to: 3696636, + }, + { + from: 3696636, + to: 3696636, + }, + { + from: 3696636, + }, + ]); + }); }); }); diff --git a/x-pack/test/apm_api_integration/tests/correlations/latency_ml.ts b/x-pack/test/apm_api_integration/tests/correlations/latency_ml.ts index 6cb7578ec585..c85dc84b78cc 100644 --- a/x-pack/test/apm_api_integration/tests/correlations/latency_ml.ts +++ b/x-pack/test/apm_api_integration/tests/correlations/latency_ml.ts @@ -10,7 +10,6 @@ import request from 'superagent'; import { FtrProviderContext } from '../../common/ftr_provider_context'; import { registry } from '../../common/registry'; -import { SearchServiceValue } from '../../../../plugins/apm/common/search_strategies/correlations/types'; import { PartialSearchRequest } from '../../../../plugins/apm/server/lib/search_strategies/correlations/search_strategy'; function parseBfetchResponse(resp: request.Response): Array> { @@ -28,11 +27,9 @@ export default function ApiTest({ getService }: FtrProviderContext) { const partialSearchRequest: PartialSearchRequest = { params: { index: 'apm-*', - serviceName: 'opbeans-node', - start: '2020-07-05T22:00:00.000Z', - end: '2021-07-06T13:21:46.005Z', environment: 'ENVIRONMENT_ALL', - transactionType: 'request', + start: '2020', + end: '2021', percentileThreshold: 95, }, }; @@ -174,7 +171,10 @@ export default function ApiTest({ getService }: FtrProviderContext) { expect(result?.total).to.be(100); expect(result?.isRunning).to.be(true); expect(result?.isPartial).to.be(true); - expect(result?.isRestored).to.be(false); + expect(result?.isRestored).to.eql( + false, + `Expected response result to be not restored. Got: '${result?.isRestored}'` + ); expect(typeof result?.rawResponse).to.be('object'); const { rawResponse } = result; @@ -205,9 +205,22 @@ export default function ApiTest({ getService }: FtrProviderContext) { } ); + expect(followUpResponse?.error).to.eql( + undefined, + `Finished search strategy should not return an error, got: ${JSON.stringify( + followUpResponse?.error + )}` + ); + const followUpResult = followUpResponse.result; - expect(followUpResult?.isRunning).to.be(false); - expect(followUpResult?.isPartial).to.be(false); + expect(followUpResult?.isRunning).to.eql( + false, + `Expected finished result not to be running. Got: ${followUpResult?.isRunning}` + ); + expect(followUpResult?.isPartial).to.eql( + false, + `Expected finished result not to be partial. Got: ${followUpResult?.isPartial}` + ); expect(followUpResult?.id).to.be(searchStrategyId); expect(followUpResult?.isRestored).to.be(true); expect(followUpResult?.loaded).to.be(100); @@ -218,28 +231,11 @@ export default function ApiTest({ getService }: FtrProviderContext) { const { rawResponse: finalRawResponse } = followUpResult; expect(typeof finalRawResponse?.took).to.be('number'); - expect(finalRawResponse?.percentileThresholdValue).to.be(1507326); + expect(finalRawResponse?.percentileThresholdValue).to.be(1855487.875); expect(finalRawResponse?.overallHistogram.length).to.be(101); - expect(finalRawResponse?.values.length).to.be(2); - const eventOutcome = (finalRawResponse?.values as SearchServiceValue[]).find( - (d) => d.field === 'event.outcome' - ); - expect(typeof eventOutcome).to.be('object'); - expect(eventOutcome?.field).to.be('event.outcome'); - expect(eventOutcome?.value).to.be('unknown'); - expect(eventOutcome?.correlation).to.be(0.8314152072578924); - expect(eventOutcome?.ksTest).to.be(0.012732005168249932); - expect(eventOutcome?.histogram.length).to.be(101); - - const transactionResult = (finalRawResponse?.values as SearchServiceValue[]).find( - (d) => d.field === 'transaction.result' - ); - expect(transactionResult?.field).to.be('transaction.result'); - expect(transactionResult?.value).to.be('success'); - expect(transactionResult?.correlation).to.be(0.8314152072578924); - expect(transactionResult?.ksTest).to.be(0.012732005168249932); - expect(transactionResult?.histogram.length).to.be(101); + // TODO Identify a dataset that returns significant results + expect(finalRawResponse?.values.length).to.be(0); }); } );