[ML] API test for ml_node_count (#187484)

We can't be sure of the node count when running tests, so we just make
sure the counts are above expected values.

Also updates the route access tags to be `access:ml:canGetMlInfo` rather
than `access:ml:canGetJobs` and `access:ml:canGetDatafeeds`.
In serverless, AD can be disabled and these tags would be false.
This commit is contained in:
James Gowdy 2024-07-04 09:48:37 +01:00 committed by GitHub
parent 3dfcb859c4
commit ea0bbf76be
No known key found for this signature in database
GPG key ID: B5690EEEBB952194
3 changed files with 46 additions and 1 deletions

View file

@ -147,7 +147,7 @@ export function systemRoutes(
path: `${ML_INTERNAL_BASE_PATH}/ml_node_count`,
access: 'internal',
options: {
tags: ['access:ml:canGetJobs', 'access:ml:canGetDatafeeds'],
tags: ['access:ml:canGetMlInfo'],
},
})
.addVersion(

View file

@ -12,5 +12,6 @@ export default function ({ loadTestFile }: FtrProviderContext) {
loadTestFile(require.resolve('./capabilities'));
loadTestFile(require.resolve('./space_capabilities'));
loadTestFile(require.resolve('./index_exists'));
loadTestFile(require.resolve('./node_count'));
});
}

View file

@ -0,0 +1,44 @@
/*
* 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 { getCommonRequestHeader } from '../../../../functional/services/ml/common_api';
export default ({ getService }: FtrProviderContext) => {
const supertest = getService('supertestWithoutAuth');
const ml = getService('ml');
async function runRequest(user: USER, expectedStatusCode: number) {
const { body, status } = await supertest
.get(`/internal/ml/ml_node_count`)
.auth(user, ml.securityCommon.getPasswordForUser(user))
.set(getCommonRequestHeader('1'));
ml.api.assertResponseStatusCode(expectedStatusCode, status, body);
return body;
}
describe('GET ml/ml_node_count', function () {
describe('get ml node count', () => {
it('should match expected values', async () => {
const resp = await runRequest(USER.ML_POWERUSER, 200);
expect(resp.count).to.be.greaterThan(0, 'count should be greater than 0');
expect(resp.lazyNodeCount).to.be.greaterThan(
-1,
'lazyNodeCount should be greater or equal to 0'
);
});
it('should should fail for a unauthorized user', async () => {
await runRequest(USER.ML_UNAUTHORIZED, 403);
});
});
});
};