Skip to content

Commit

Permalink
[ML] fix i18n
Browse files Browse the repository at this point in the history
  • Loading branch information
darnautov committed Aug 18, 2021
1 parent c263baf commit 124768f
Show file tree
Hide file tree
Showing 2 changed files with 49 additions and 23 deletions.
70 changes: 48 additions & 22 deletions x-pack/plugins/ml/server/lib/alerts/jobs_health_service.ts
Original file line number Diff line number Diff line change
Expand Up @@ -133,8 +133,10 @@ export function jobsHealthServiceProvider(
);

/** Gets values for translation string */
const getJobsAlertingMessageValues = <T extends Array<{ job_id: string }>>(results: T) => {
const jobIds = results.map((v) => v.job_id);
const getJobsAlertingMessageValues = <T extends Array<{ job_id: string } | undefined>>(
results: T
) => {
const jobIds = (results || []).filter(isDefined).map((v) => v.job_id);
return {
count: jobIds.length,
jobsString: jobIds.join(', '),
Expand Down Expand Up @@ -320,6 +322,7 @@ export function jobsHealthServiceProvider(
if (config.datafeed.enabled) {
const response = await this.getNotStartedDatafeeds(jobIds);
if (response && response.length > 0) {
const { count, jobsString } = getJobsAlertingMessageValues(response);
results.push({
name: HEALTH_CHECK_NAMES.datafeed.name,
context: {
Expand All @@ -329,7 +332,7 @@ export function jobsHealthServiceProvider(
{
defaultMessage:
'Datafeed is not started for {count, plural, one {job} other {jobs}} {jobsString}',
values: getJobsAlertingMessageValues(response),
values: { count, jobsString },
}
),
},
Expand All @@ -345,28 +348,49 @@ export function jobsHealthServiceProvider(
'memory_status'
);

const {
count: hardLimitCount,
jobsString: hardLimitJobsString,
} = getJobsAlertingMessageValues(hardLimitJobs);
const {
count: softLimitCount,
jobsString: softLimitJobsString,
} = getJobsAlertingMessageValues(softLimitJobs);

let message = '';

if (hardLimitCount > 0) {
message = i18n.translate('xpack.ml.alertTypes.jobsHealthAlertingRule.mmlMessage', {
defaultMessage: `{count, plural, one {Job} other {Jobs}} {jobsString} reached the hard model memory limit. Assign the job more memory and restore from a snapshot from prior to reaching the hard limit.`,
values: {
count: hardLimitCount,
jobsString: hardLimitJobsString,
},
});
}

if (softLimitCount > 0) {
if (message.length > 0) {
message += '\n';
}
message += i18n.translate(
'xpack.ml.alertTypes.jobsHealthAlertingRule.mmlSoftLimitMessage',
{
defaultMessage:
'{count, plural, one {Job} other {Jobs}} {jobsString} reached the soft model memory limit. Assign the job more memory or edit the datafeed filter to limit scope of analysis.',
values: {
count: softLimitCount,
jobsString: softLimitJobsString,
},
}
);
}

results.push({
name: HEALTH_CHECK_NAMES.mml.name,
context: {
results: response,
message:
hardLimitJobs.length > 0
? i18n.translate(
'xpack.ml.alertTypes.jobsHealthAlertingRule.mmlHardLimitMessage',
{
defaultMessage:
'{count, plural, one {Job} other {Jobs}} {jobsString} reached the hard model memory limit. Assign the job more memory and restore from a snapshot from prior to reaching the hard limit.',
values: getJobsAlertingMessageValues(hardLimitJobs),
}
)
: i18n.translate(
'xpack.ml.alertTypes.jobsHealthAlertingRule.mmlSoftLimitMessage',
{
defaultMessage:
'{count, plural, one {Job} other {Jobs}} {jobsString} reached the soft model memory limit. Assign the job more memory or edit the datafeed filter to limit scope of analysis.',
values: getJobsAlertingMessageValues(softLimitJobs),
}
),
message,
},
});
}
Expand All @@ -379,6 +403,8 @@ export function jobsHealthServiceProvider(
config.delayedData.docsCount
);

const { count, jobsString } = getJobsAlertingMessageValues(response);

if (response.length > 0) {
results.push({
name: HEALTH_CHECK_NAMES.delayedData.name,
Expand All @@ -389,7 +415,7 @@ export function jobsHealthServiceProvider(
{
defaultMessage:
'{count, plural, one {Job} other {Jobs}} {jobsString} {count, plural, one {is} other {are}} suffering from delayed data.',
values: getJobsAlertingMessageValues(response),
values: { count, jobsString },
}
),
},
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -199,7 +199,7 @@ function getRequestItemsProvider(
}

const uiSettingsClient = getUiSettings()?.asScopedToClient(savedObjectsClient);
if (uiSettingsClient === null) {
if (!uiSettingsClient) {
throw getCustomError(
'MLUISettingsClientUninitialized',
`ML's UI settings client has not been initialized`
Expand Down

0 comments on commit 124768f

Please sign in to comment.