Skip to content

Commit

Permalink
[ML] API test for ml_node_count (#187484)
Browse files Browse the repository at this point in the history
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.
  • Loading branch information
jgowdyelastic authored Jul 4, 2024
1 parent 3dfcb85 commit ea0bbf7
Show file tree
Hide file tree
Showing 3 changed files with 46 additions and 1 deletion.
2 changes: 1 addition & 1 deletion x-pack/plugins/ml/server/routes/system.ts
Original file line number Diff line number Diff line change
Expand Up @@ -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(
Expand Down
1 change: 1 addition & 0 deletions x-pack/test/api_integration/apis/ml/system/index.ts
Original file line number Diff line number Diff line change
Expand Up @@ -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'));
});
}
44 changes: 44 additions & 0 deletions x-pack/test/api_integration/apis/ml/system/node_count.ts
Original file line number Diff line number Diff line change
@@ -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);
});
});
});
};

0 comments on commit ea0bbf7

Please sign in to comment.