Skip to content

Commit

Permalink
[ML] Fix api tests
Browse files Browse the repository at this point in the history
  • Loading branch information
qn895 committed Aug 22, 2021
1 parent e683e57 commit 7d52366
Showing 1 changed file with 116 additions and 110 deletions.
226 changes: 116 additions & 110 deletions x-pack/test/apm_api_integration/tests/correlations/failed_transactions.ts
Original file line number Diff line number Diff line change
Expand Up @@ -35,7 +35,7 @@ export default function ApiTest({ getService }: FtrProviderContext) {
};
};

registry.when('on trial license without data', { config: 'trial', archives: [] }, () => {
registry.when('quynh on trial license without data', { config: 'trial', archives: [] }, () => {
it('queries the search strategy and returns results', async () => {
const intialResponse = await supertest
.post(`/internal/bsearch`)
Expand Down Expand Up @@ -124,113 +124,119 @@ export default function ApiTest({ getService }: FtrProviderContext) {
});
});

registry.when('on trial license with data', { config: 'trial', archives: ['8.0.0'] }, () => {
it('queries the search strategy and returns results', async () => {
const intialResponse = await supertest
.post(`/internal/bsearch`)
.set('kbn-xsrf', 'foo')
.send(getRequestBody());

expect(intialResponse.status).to.eql(
200,
`Expected status to be '200', got '${intialResponse.status}'`
);
expect(intialResponse.body).to.eql(
{},
`Expected response body to be an empty object, actual response is in the text attribute. Got: '${JSON.stringify(
intialResponse.body
)}'`
);

const body = parseBfetchResponse(intialResponse)[0];

expect(typeof body.result).to.be('object');
const { result } = body;

expect(typeof result?.id).to.be('string');

// pass on id for follow up queries
const searchStrategyId = result.id;

// follow up request body including search strategy ID
const reqBody = getRequestBody();
reqBody.batch[0].request.id = searchStrategyId;

let followUpResponse: Record<string, any> = {};

// continues querying until the search strategy finishes
await retry.waitForWithTimeout(
'search strategy eventually completes and returns full results',
5000,
async () => {
const response = await supertest
.post(`/internal/bsearch`)
.set('kbn-xsrf', 'foo')
.send(reqBody);

followUpResponse = parseBfetchResponse(response)[0];

return (
followUpResponse?.result?.isRunning === false || followUpResponse?.error !== undefined
);
}
);

expect(followUpResponse?.error).to.eql(
undefined,
`search strategy should not return an error, got: ${JSON.stringify(
followUpResponse?.error
)}`
);

const followUpResult = followUpResponse.result;
expect(followUpResult?.isRunning).to.eql(false, 'search strategy should not be running');
expect(followUpResult?.isPartial).to.eql(
false,
'search strategy result should not be partial'
);
expect(followUpResult?.id).to.eql(
searchStrategyId,
'search strategy id should match original id'
);
expect(followUpResult?.isRestored).to.eql(
true,
'search strategy response should be restored'
);
expect(followUpResult?.loaded).to.eql(100, 'loaded state should be 100');
expect(followUpResult?.total).to.eql(100, 'total state should be 100');

expect(typeof followUpResult?.rawResponse).to.be('object');

const { rawResponse: finalRawResponse } = followUpResult;

expect(typeof finalRawResponse?.took).to.be('number');
expect(finalRawResponse?.percentileThresholdValue).to.be(undefined);
expect(finalRawResponse?.overallHistogram).to.be(undefined);

expect(finalRawResponse?.values.length).to.eql(
43,
`Expected 43 identified correlations, got ${finalRawResponse?.values.length}.`
);

expect(finalRawResponse?.log.map((d: string) => d.split(': ')[1])).to.eql([
'Identified 68 fieldCandidates.',
'Identified correlations for 68 fields out of 68 candidates.',
'Identified 43 significant correlations relating to failed transactions.',
]);

const correlation = finalRawResponse?.values[0];
expect(typeof correlation).to.be('object');
expect(correlation?.key).to.be('HTTP 5xx');
expect(correlation?.doc_count).to.be(31);
expect(correlation?.score).to.be(100.17736139032642);
expect(correlation?.bg_count).to.be(60);
expect(correlation?.fieldName).to.be('transaction.result');
expect(correlation?.fieldValue).to.be('transaction.result');
expect(typeof correlation?.pValue).to.be('number');
expect(typeof correlation?.normalizedScore).to.be('number');
expect(typeof correlation?.failurePercentage).to.be('number');
expect(typeof correlation?.successPercentage).to.be('number');
});
});
registry.when(
'quynh on trial license with data',
{ config: 'trial', archives: ['8.0.0'] },
() => {
it('queries the search strategy and returns results', async () => {
const intialResponse = await supertest
.post(`/internal/bsearch`)
.set('kbn-xsrf', 'foo')
.send(getRequestBody());

expect(intialResponse.status).to.eql(
200,
`Expected status to be '200', got '${intialResponse.status}'`
);
expect(intialResponse.body).to.eql(
{},
`Expected response body to be an empty object, actual response is in the text attribute. Got: '${JSON.stringify(
intialResponse.body
)}'`
);

const body = parseBfetchResponse(intialResponse)[0];

expect(typeof body.result).to.be('object');
const { result } = body;

expect(typeof result?.id).to.be('string');

// pass on id for follow up queries
const searchStrategyId = result.id;

// follow up request body including search strategy ID
const reqBody = getRequestBody();
reqBody.batch[0].request.id = searchStrategyId;

let followUpResponse: Record<string, any> = {};

// continues querying until the search strategy finishes
await retry.waitForWithTimeout(
'search strategy eventually completes and returns full results',
5000,
async () => {
const response = await supertest
.post(`/internal/bsearch`)
.set('kbn-xsrf', 'foo')
.send(reqBody);

followUpResponse = parseBfetchResponse(response)[0];

return (
followUpResponse?.result?.isRunning === false || followUpResponse?.error !== undefined
);
}
);

expect(followUpResponse?.error).to.eql(
undefined,
`search strategy should not return an error, got: ${JSON.stringify(
followUpResponse?.error
)}`
);

const followUpResult = followUpResponse.result;
expect(followUpResult?.isRunning).to.eql(false, 'search strategy should not be running');
expect(followUpResult?.isPartial).to.eql(
false,
'search strategy result should not be partial'
);
expect(followUpResult?.id).to.eql(
searchStrategyId,
'search strategy id should match original id'
);
expect(followUpResult?.isRestored).to.eql(
true,
'search strategy response should be restored'
);
expect(followUpResult?.loaded).to.eql(100, 'loaded state should be 100');
expect(followUpResult?.total).to.eql(100, 'total state should be 100');

expect(typeof followUpResult?.rawResponse).to.be('object');

const { rawResponse: finalRawResponse } = followUpResult;

expect(typeof finalRawResponse?.took).to.be('number');
expect(finalRawResponse?.percentileThresholdValue).to.be(undefined);
expect(finalRawResponse?.overallHistogram).to.be(undefined);

expect(finalRawResponse?.values.length).to.eql(
43,
`Expected 43 identified correlations, got ${finalRawResponse?.values.length}.`
);

expect(finalRawResponse?.log.map((d: string) => d.split(': ')[1])).to.eql([
'Identified 68 fieldCandidates.',
'Identified correlations for 68 fields out of 68 candidates.',
'Identified 43 significant correlations relating to failed transactions.',
]);

const sortedCorrelations = finalRawResponse?.values.sort();
const correlation = sortedCorrelations[0];

expect(typeof correlation).to.be('object');
expect(correlation?.key).to.be('HTTP 5xx');
expect(correlation?.doc_count).to.be(31);
expect(correlation?.score).to.be(100.17736139032642);
expect(correlation?.bg_count).to.be(60);
expect(correlation?.fieldName).to.be('transaction.result');
expect(correlation?.fieldValue).to.be('HTTP 5xx');
expect(typeof correlation?.pValue).to.be('number');
expect(typeof correlation?.normalizedScore).to.be('number');
expect(typeof correlation?.failurePercentage).to.be('number');
expect(typeof correlation?.successPercentage).to.be('number');
});
}
);
}

0 comments on commit 7d52366

Please sign in to comment.