diff --git a/x-pack/plugins/ml/public/application/services/ml_api_service/data_frame_analytics.ts b/x-pack/plugins/ml/public/application/services/ml_api_service/data_frame_analytics.ts index 8aba633970a7..42a18d80f958 100644 --- a/x-pack/plugins/ml/public/application/services/ml_api_service/data_frame_analytics.ts +++ b/x-pack/plugins/ml/public/application/services/ml_api_service/data_frame_analytics.ts @@ -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({ + return http({ path: `${basePath()}/data_frame/analytics/${analyticsId}/messages`, method: 'GET', }); diff --git a/x-pack/test/api_integration/apis/ml/data_frame_analytics/get.ts b/x-pack/test/api_integration/apis/ml/data_frame_analytics/get.ts index f8c7009e39db..69f40e46bc7e 100644 --- a/x-pack/test/api_integration/apis/ml/data_frame_analytics/get.ts +++ b/x-pack/test/api_integration/apis/ml/data_frame_analytics/get.ts @@ -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'); + }); + }); }); };