[ML] Data Frame Analytics audit messages api test (#125325)

* wip: add beginning of messages api test

* adds dfa audit messages api test

* use retry instead of running job
This commit is contained in:
Melissa Alvarez 2022-02-15 13:17:12 -07:00 committed by GitHub
parent c961b4b1f8
commit eafa4d998d
No known key found for this signature in database
GPG key ID: 4AEE18F83AFDEB23
2 changed files with 36 additions and 1 deletions

View file

@ -16,6 +16,7 @@ import {
} from '../../data_frame_analytics/common';
import { DeepPartial } from '../../../../common/types/common';
import { NewJobCapsResponse } from '../../../../common/types/fields';
import { JobMessage } from '../../../../common/types/audit_message';
import {
DeleteDataFrameAnalyticsWithIndexStatus,
AnalyticsMapReturnType,
@ -161,7 +162,7 @@ export const dataFrameAnalytics = {
});
},
getAnalyticsAuditMessages(analyticsId: string) {
return http<any>({
return http<JobMessage[]>({
path: `${basePath()}/data_frame/analytics/${analyticsId}/messages`,
method: 'GET',
});

View file

@ -16,6 +16,7 @@ export default ({ getService }: FtrProviderContext) => {
const esArchiver = getService('esArchiver');
const supertest = getService('supertestWithoutAuth');
const ml = getService('ml');
const retry = getService('retry');
const jobId = `bm_${Date.now()}`;
@ -273,5 +274,38 @@ export default ({ getService }: FtrProviderContext) => {
expect(body).to.have.keys('elements', 'details', 'error');
});
});
describe('GetDataFrameAnalyticsMessages', () => {
it('should fetch single analytics job messages by id', async () => {
await retry.tryForTime(5000, async () => {
const { body } = await supertest
.get(`/api/ml/data_frame/analytics/${jobId}_1/messages`)
.auth(USER.ML_VIEWER, ml.securityCommon.getPasswordForUser(USER.ML_VIEWER))
.set(COMMON_REQUEST_HEADERS)
.expect(200);
expect(body.length).to.eql(1);
expect(body[0].job_id).to.eql(`${jobId}_1`);
expect(body[0]).to.have.keys(
'job_id',
'message',
'level',
'timestamp',
'node_name',
'job_type'
);
});
});
it('should not allow to retrieve job messages without required permissions', async () => {
const { body } = await supertest
.get(`/api/ml/data_frame/analytics/${jobId}_1/messages`)
.auth(USER.ML_UNAUTHORIZED, ml.securityCommon.getPasswordForUser(USER.ML_UNAUTHORIZED))
.set(COMMON_REQUEST_HEADERS)
.expect(403);
expect(body.error).to.eql('Forbidden');
expect(body.message).to.eql('Forbidden');
});
});
});
};