-
Notifications
You must be signed in to change notification settings - Fork 8.3k
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
Browse files
Browse the repository at this point in the history
* [ML] Adding datafeed api tests * updating tests * adding more AD tests * adding test include * renaming function Co-authored-by: James Gowdy <jgowdy@elastic.co>
- Loading branch information
1 parent
99f4c8f
commit bbc5744
Showing
7 changed files
with
489 additions
and
10 deletions.
There are no files selected for viewing
174 changes: 174 additions & 0 deletions
174
x-pack/test/api_integration/apis/ml/anomaly_detectors/get_stats_with_spaces.ts
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,174 @@ | ||
/* | ||
* Copyright Elasticsearch B.V. and/or licensed to Elasticsearch B.V. under one | ||
* or more contributor license agreements. Licensed under the Elastic License | ||
* 2.0; you may not use this file except in compliance with the Elastic License | ||
* 2.0. | ||
*/ | ||
|
||
import expect from '@kbn/expect'; | ||
import { FtrProviderContext } from '../../../ftr_provider_context'; | ||
import { USER } from '../../../../functional/services/ml/security_common'; | ||
import { COMMON_REQUEST_HEADERS } from '../../../../functional/services/ml/common_api'; | ||
|
||
export default ({ getService }: FtrProviderContext) => { | ||
const ml = getService('ml'); | ||
const spacesService = getService('spaces'); | ||
const supertest = getService('supertestWithoutAuth'); | ||
|
||
const jobIdSpace1 = 'fq_single_space1'; | ||
const jobIdWildcardSpace1 = 'fq_single_space1*'; | ||
const jobGroupSpace1 = 'space1_group'; | ||
const jobGroupWildcardSpace1 = 'space1_group*'; | ||
const idSpace1 = 'space1'; | ||
const idSpace2 = 'space2'; | ||
|
||
async function getJobStatsById( | ||
jobOrGroup: string | undefined, | ||
expectedStatusCode: number, | ||
space?: string | ||
) { | ||
const { body } = await supertest | ||
.get( | ||
`${space ? `/s/${space}` : ''}/api/ml/anomaly_detectors${ | ||
jobOrGroup ? `/${jobOrGroup}` : '' | ||
}/_stats` | ||
) | ||
.auth( | ||
USER.ML_VIEWER_ALL_SPACES, | ||
ml.securityCommon.getPasswordForUser(USER.ML_VIEWER_ALL_SPACES) | ||
) | ||
.set(COMMON_REQUEST_HEADERS) | ||
.expect(expectedStatusCode); | ||
|
||
return body; | ||
} | ||
|
||
describe('GET anomaly_detectors stats with spaces', () => { | ||
before(async () => { | ||
await spacesService.create({ id: idSpace1, name: 'space_one', disabledFeatures: [] }); | ||
await spacesService.create({ id: idSpace2, name: 'space_two', disabledFeatures: [] }); | ||
|
||
const jobConfig = ml.commonConfig.getADFqSingleMetricJobConfig(jobIdSpace1); | ||
await ml.api.createAnomalyDetectionJob({ ...jobConfig, groups: [jobGroupSpace1] }, idSpace1); | ||
|
||
await ml.testResources.setKibanaTimeZoneToUTC(); | ||
}); | ||
|
||
after(async () => { | ||
await spacesService.delete(idSpace1); | ||
await spacesService.delete(idSpace2); | ||
await ml.api.cleanMlIndices(); | ||
await ml.testResources.cleanMLSavedObjects(); | ||
}); | ||
|
||
it('should fail with non-existing job', async () => { | ||
await getJobStatsById('non-existing-job', 404); | ||
}); | ||
|
||
it('should return empty list with non-existing job wildcard', async () => { | ||
const body = await getJobStatsById('non-existing-job*', 200); | ||
|
||
expect(body.count).to.eql(0, `response count should be 0 (got ${body.count})`); | ||
expect(body.jobs.length).to.eql( | ||
0, | ||
`response job stats list should be empty (got ${JSON.stringify(body.jobs)})` | ||
); | ||
}); | ||
|
||
it('should fail with job from different space', async () => { | ||
await getJobStatsById(jobIdSpace1, 404, idSpace2); | ||
}); | ||
|
||
it('should return all job stats when not specifying id', async () => { | ||
const body = await getJobStatsById(undefined, 200, idSpace1); | ||
|
||
expect(body.count).to.eql(1, `response count should be 1 (got ${body.count})`); | ||
expect(body.jobs.length).to.eql( | ||
1, | ||
`response job stats list should contain correct job (got ${JSON.stringify(body.jobs)})` | ||
); | ||
}); | ||
|
||
it('should return empty list when not specifying id in difference space', async () => { | ||
const body = await getJobStatsById(undefined, 200, idSpace2); | ||
|
||
expect(body.count).to.eql(0, `response count should be 0 (got ${body.count})`); | ||
expect(body.jobs.length).to.eql( | ||
0, | ||
`response job stats list should be empty (got ${JSON.stringify(body.jobs)})` | ||
); | ||
}); | ||
|
||
it('should return job stats with job id from correct space', async () => { | ||
const body = await getJobStatsById(jobIdSpace1, 200, idSpace1); | ||
|
||
expect(body.count).to.eql(1, `response count should be 1 (got ${body.count})`); | ||
expect(body.jobs.length).to.eql( | ||
1, | ||
`response job stats list should contain correct job (got ${JSON.stringify(body.jobs)})` | ||
); | ||
}); | ||
|
||
it('should return job stats with job wildcard from correct space', async () => { | ||
const body = await getJobStatsById(jobIdWildcardSpace1, 200, idSpace1); | ||
|
||
expect(body.count).to.eql(1, `response count should be 1 (got ${body.count})`); | ||
expect(body.jobs.length).to.eql( | ||
1, | ||
`response job stats list should contain correct job (got ${JSON.stringify(body.jobs)})` | ||
); | ||
}); | ||
|
||
it('should return empty list with job wildcard from different space', async () => { | ||
const body = await getJobStatsById(jobIdWildcardSpace1, 200, idSpace2); | ||
|
||
expect(body.count).to.eql(0, `response count should be 0 (got ${body.count})`); | ||
expect(body.jobs.length).to.eql( | ||
0, | ||
`response job stats list should be empty (got ${JSON.stringify(body.jobs)})` | ||
); | ||
}); | ||
|
||
it('should return job stats by group from same space', async () => { | ||
const body = await getJobStatsById(jobGroupSpace1, 200, idSpace1); | ||
|
||
expect(body.count).to.eql(1, `response count should be 1 (got ${body.count})`); | ||
expect(body.jobs.length).to.eql( | ||
1, | ||
`response job stats list should have one element (got ${JSON.stringify(body.jobs)})` | ||
); | ||
expect(body.jobs[0].job_id).to.eql( | ||
jobIdSpace1, | ||
`response job id should be ${jobIdSpace1} (got ${body.jobs[0].job_id})` | ||
); | ||
}); | ||
|
||
it('should return job stats by group wildcard from same space', async () => { | ||
const body = await getJobStatsById(jobGroupWildcardSpace1, 200, idSpace1); | ||
|
||
expect(body.count).to.eql(1, `response count should be 1 (got ${body.count})`); | ||
expect(body.jobs.length).to.eql( | ||
1, | ||
`response job stats list should have one element (got ${JSON.stringify(body.jobs)})` | ||
); | ||
expect(body.jobs[0].job_id).to.eql( | ||
jobIdSpace1, | ||
`response job id should be ${jobIdSpace1} (got ${body.jobs[0].job_id})` | ||
); | ||
}); | ||
|
||
it('should fail with group from different space', async () => { | ||
await getJobStatsById(jobGroupSpace1, 404, idSpace2); | ||
}); | ||
|
||
it('should return empty list with group wildcard from different space', async () => { | ||
const body = await getJobStatsById(jobGroupWildcardSpace1, 200, idSpace2); | ||
|
||
expect(body.count).to.eql(0, `response count should be 0 (got ${body.count})`); | ||
expect(body.jobs.length).to.eql( | ||
0, | ||
`response job stats list should be empty (got ${JSON.stringify(body.jobs)})` | ||
); | ||
}); | ||
}); | ||
}; |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Oops, something went wrong.