Skip to content

Commit

Permalink
adjust api/unit test
Browse files Browse the repository at this point in the history
  • Loading branch information
walterra committed Jul 8, 2021
1 parent ea55c02 commit 5161477
Show file tree
Hide file tree
Showing 2 changed files with 118 additions and 28 deletions.
Original file line number Diff line number Diff line change
Expand Up @@ -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]);
Expand All @@ -24,6 +25,7 @@ describe('aggregation utils', () => {
{ from: 5 },
]);
});

it('returns expectations and ranges with adjusted fractions', async () => {
const { expectations, ranges } = computeExpectationsAndRanges([
1,
Expand All @@ -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,
},
]);
});
});
});
52 changes: 24 additions & 28 deletions x-pack/test/apm_api_integration/tests/correlations/latency_ml.ts
Original file line number Diff line number Diff line change
Expand Up @@ -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<Record<string, any>> {
Expand All @@ -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,
},
};
Expand Down Expand Up @@ -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;
Expand Down Expand Up @@ -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);
Expand All @@ -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);
});
}
);
Expand Down

0 comments on commit 5161477

Please sign in to comment.