[ML] Adding cloud trial end date to ml info (#144793)

Adds a `isCloudTrial` flag to ML's `/api/ml/info` endpoint.
If `xpack.cloud.trial_end_date` is set in the kibana config and it is
greater than the current time, we can assume that we're currently in a
could trial.
If `xpack.cloud.trial_end_date` is not set, `isCloudTrial` is not added
to the endpoint response. This is the same behaviour as the `cloudId`
property.

Adds a `isCloudTrial()` function to our server info util functions which
can be used in conjunction with our `isCloud()` function.

To test, these cloud settings can be added to the kibana config:
```
xpack.cloud.id: 'cloud_message_test:ZXUtd2VzdC0yLmF3cy5jbG91ZC5lcy5pbyQ4NWQ2NjZmMzM1MGM0NjllOGMzMjQyZDc2YTdmNDU5YyQxNmI1ZDM2ZGE1Mzk0YjlkYjIyZWJlNDk1OWY1OGQzMg=='
xpack.cloud.trial_end_date: '2022-11-20T09:39:52.554Z'
```
This commit is contained in:
James Gowdy 2022-11-09 16:40:23 +00:00 committed by GitHub
parent 7fbf260cc9
commit bfa1a7f20b
No known key found for this signature in database
GPG key ID: 4AEE18F83AFDEB23
6 changed files with 21 additions and 5 deletions

View file

@ -63,9 +63,11 @@ const MLJobsAwaitingNodeWarning: FC<Props> = ({ jobIds }) => {
try {
const resp = await ml.mlInfo();
const cloudId = resp.cloudId ?? null;
const isCloudTrial = resp.isCloudTrial === true;
setCloudInfo({
isCloud: cloudId !== null,
cloudId,
isCloudTrial,
deploymentId: cloudId === null ? null : extractDeploymentId(cloudId),
});
} catch (error) {

View file

@ -17,5 +17,6 @@
"limits": {
"max_model_memory_limit": "128mb"
},
"cloudId": "cloud_message_test:ZXUtd2VzdC0yLmF3cy5jbG91ZC5lcy5pbyQ4NWQ2NjZmMzM1MGM0NjllOGMzMjQyZDc2YTdmNDU5YyQxNmI1ZDM2ZGE1Mzk0YjlkYjIyZWJlNDk1OWY1OGQzMg=="
"cloudId": "cloud_message_test:ZXUtd2VzdC0yLmF3cy5jbG91ZC5lcy5pbyQ4NWQ2NjZmMzM1MGM0NjllOGMzMjQyZDc2YTdmNDU5YyQxNmI1ZDM2ZGE1Mzk0YjlkYjIyZWJlNDk1OWY1OGQzMg==",
"isCloudTrial": true
}

View file

@ -55,6 +55,7 @@ export interface MlInfoResponse {
};
upgrade_mode: boolean;
cloudId?: string;
isCloudTrial?: boolean;
}
export interface BucketSpanEstimatorResponse {

View file

@ -9,6 +9,7 @@ import {
loadMlServerInfo,
getCloudDeploymentId,
isCloud,
isCloudTrial,
getNewJobDefaults,
getNewJobLimits,
extractDeploymentId,
@ -34,8 +35,9 @@ describe('ml_server_info', () => {
});
describe('cloud information', () => {
it('should get could deployment id', () => {
it('should get could deployment id and trial info', () => {
expect(isCloud()).toBe(true);
expect(isCloudTrial()).toBe(true);
expect(getCloudDeploymentId()).toBe('85d666f3350c469e8c3242d76a7f459c');
});
});

View file

@ -11,6 +11,7 @@ import { MlServerDefaults, MlServerLimits } from '../../../common/types/ml_serve
export interface CloudInfo {
cloudId: string | null;
isCloud: boolean;
isCloudTrial: boolean;
deploymentId: string | null;
}
@ -23,6 +24,7 @@ let limits: MlServerLimits = {};
const cloudInfo: CloudInfo = {
cloudId: null,
isCloud: false,
isCloudTrial: false,
deploymentId: null,
};
@ -31,9 +33,11 @@ export async function loadMlServerInfo() {
const resp = await ml.mlInfo();
defaults = resp.defaults;
limits = resp.limits;
cloudInfo.cloudId = resp.cloudId || null;
cloudInfo.cloudId = resp.cloudId ?? null;
cloudInfo.isCloud = resp.cloudId !== undefined;
cloudInfo.isCloudTrial = resp.isCloudTrial === true;
cloudInfo.deploymentId = !resp.cloudId ? null : extractDeploymentId(resp.cloudId);
return { defaults, limits, cloudId: cloudInfo };
} catch (error) {
return { defaults, limits, cloudId: cloudInfo };
@ -56,6 +60,10 @@ export function isCloud(): boolean {
return cloudInfo.isCloud;
}
export function isCloudTrial(): boolean {
return cloudInfo.isCloudTrial;
}
export function getCloudDeploymentId(): string | null {
return cloudInfo.deploymentId;
}

View file

@ -165,9 +165,11 @@ export function systemRoutes(
routeGuard.basicLicenseAPIGuard(async ({ mlClient, response }) => {
try {
const body = await mlClient.info();
const cloudId = cloud && cloud.cloudId;
const cloudId = cloud?.cloudId;
const isCloudTrial = cloud?.trialEndDate && Date.now() < cloud.trialEndDate.getTime();
return response.ok({
body: { ...body, cloudId },
body: { ...body, cloudId, isCloudTrial },
});
} catch (error) {
return response.customError(wrapError(error));