Skip to content

Commit

Permalink
[ML] Adding type for job summary state (#131643)
Browse files Browse the repository at this point in the history
* [ML] Adding type for job summary state

* renaming type

* translations

* fixing jobState types in security

* fixing snapshots

* fixing test
  • Loading branch information
jgowdyelastic committed May 11, 2022
1 parent c21c8f7 commit 1dc6216
Show file tree
Hide file tree
Showing 12 changed files with 19 additions and 29 deletions.
20 changes: 6 additions & 14 deletions x-pack/plugins/ml/common/constants/job_actions.ts
Original file line number Diff line number Diff line change
Expand Up @@ -5,8 +5,6 @@
* 2.0.
*/

import { i18n } from '@kbn/i18n';

export const JOB_ACTION = {
DELETE: 'delete',
RESET: 'reset',
Expand All @@ -15,22 +13,16 @@ export const JOB_ACTION = {

export type JobAction = typeof JOB_ACTION[keyof typeof JOB_ACTION];

export function getJobActionString(action: JobAction) {
export type JobActionState = 'deleting' | 'resetting' | 'reverting';

export function getJobActionString(action: JobAction): JobActionState {
switch (action) {
case JOB_ACTION.DELETE:
return i18n.translate('xpack.ml.models.jobService.deletingJob', {
defaultMessage: 'deleting',
});
return 'deleting';
case JOB_ACTION.RESET:
return i18n.translate('xpack.ml.models.jobService.resettingJob', {
defaultMessage: 'resetting',
});
return 'resetting';
case JOB_ACTION.REVERT:
return i18n.translate('xpack.ml.models.jobService.revertingJob', {
defaultMessage: 'reverting',
});
default:
return '';
return 'reverting';
}
}

Expand Down
1 change: 1 addition & 0 deletions x-pack/plugins/ml/common/index.ts
Original file line number Diff line number Diff line change
Expand Up @@ -21,3 +21,4 @@ export { extractErrorMessage } from './util/errors';
export type { RuntimeMappings } from './types/fields';
export { getDefaultCapabilities as getDefaultMlCapabilities } from './types/capabilities';
export { DATAFEED_STATE, JOB_STATE } from './constants/states';
export type { MlSummaryJob, SummaryJobState } from './types/anomaly_detection_jobs';
Original file line number Diff line number Diff line change
Expand Up @@ -5,15 +5,19 @@
* 2.0.
*/

import * as estypes from '@elastic/elasticsearch/lib/api/typesWithBodyKey';
import { Moment } from 'moment';

import { MlCustomSettings } from '@elastic/elasticsearch/lib/api/typesWithBodyKey';
import type { CombinedJob, CombinedJobWithStats } from './combined_job';
import type { MlAnomalyDetectionAlertRule } from '../alerts';
import type { MlJobBlocked } from './job';
import type { JobActionState } from '../../constants/job_actions';
export type { Datafeed } from './datafeed';
export type { DatafeedStats } from './datafeed_stats';

export type SummaryJobState = estypes.MlJobState | JobActionState;

/**
* A summary of an anomaly detection job.
*/
Expand Down Expand Up @@ -47,7 +51,7 @@ export interface MlSummaryJob {
/**
* The status of the job.
*/
jobState: string;
jobState: SummaryJobState;

/**
* An array of index names used by the datafeed. Wildcards are supported.
Expand Down
2 changes: 2 additions & 0 deletions x-pack/plugins/ml/server/index.ts
Original file line number Diff line number Diff line change
Expand Up @@ -14,6 +14,8 @@ export type {
AnomalyResultType as MlAnomalyResultType,
DatafeedStats as MlDatafeedStats,
Job as MlJob,
MlSummaryJob,
SummaryJobState as MlSummaryJobState,
} from './shared';
export {
UnknownMLCapabilitiesError,
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -548,7 +548,7 @@ export const mockSecurityJobs: SecurityJob[] = [
datafeedState: '',
hasDatafeed: false,
isSingleMetricViewerJob: false,
jobState: '',
jobState: 'closed',
memory_status: '',
processed_record_count: 0,
id: 'rare_process_by_host_windows_ecs',
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -44,7 +44,7 @@ describe('useSecurityJobsHelpers', () => {
isElasticJob: true,
isInstalled: false,
isSingleMetricViewerJob: false,
jobState: '',
jobState: 'closed',
jobTags: {},
memory_status: '',
moduleId: 'siem_auditbeat',
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -32,7 +32,7 @@ export const moduleToSecurityJob = (
datafeedState: '',
hasDatafeed: false,
isSingleMetricViewerJob: false,
jobState: '',
jobState: 'closed',
memory_status: '',
processed_record_count: 0,
id: moduleJob.id,
Expand Down

Some generated files are not rendered by default. Learn more about how customized files appear on GitHub.

Some generated files are not rendered by default. Learn more about how customized files appear on GitHub.

3 changes: 0 additions & 3 deletions x-pack/plugins/translations/translations/fr-FR.json
Original file line number Diff line number Diff line change
Expand Up @@ -18799,11 +18799,8 @@
"xpack.ml.models.jobService.categorization.messages.validTokenLength": "Plus de {tokenCount} tokens par exemple ont été trouvés dans plus de {percentage} % des exemples chargés.",
"xpack.ml.models.jobService.categorization.messages.validTooManyTokens": "Moins de 10 000 tokens ont été trouvés en tout dans les exemples chargés.",
"xpack.ml.models.jobService.categorization.messages.validUserPrivileges": "L'utilisateur dispose de privilèges suffisants pour effectuer les vérifications.",
"xpack.ml.models.jobService.deletingJob": "suppression",
"xpack.ml.models.jobService.jobHasNoDatafeedErrorMessage": "La tâche ne comporte aucun flux de données",
"xpack.ml.models.jobService.requestToActionTimedOutErrorMessage": "La requête pour {action} \"{id}\" a expiré.{extra}",
"xpack.ml.models.jobService.resettingJob": "réinitialisation",
"xpack.ml.models.jobService.revertingJob": "restauration",
"xpack.ml.models.jobService.revertModelSnapshot.autoCreatedCalendar.description": "Créé automatiquement",
"xpack.ml.models.jobValidation.messages.bucketSpanEmptyMessage": "Le champ d’étendue du compartiment doit être spécifié.",
"xpack.ml.models.jobValidation.messages.bucketSpanEstimationMismatchHeading": "Étendue du compartiment",
Expand Down
3 changes: 0 additions & 3 deletions x-pack/plugins/translations/translations/ja-JP.json
Original file line number Diff line number Diff line change
Expand Up @@ -18946,11 +18946,8 @@
"xpack.ml.models.jobService.categorization.messages.validTokenLength": "読み込んだサンプルの {percentage}% 以上でサンプルあたり {tokenCount} 個を超えるトークンが見つかりました。",
"xpack.ml.models.jobService.categorization.messages.validTooManyTokens": "読み込んだサンプル内に合計で 10000 個未満のトークンがありました。",
"xpack.ml.models.jobService.categorization.messages.validUserPrivileges": "ユーザーには、確認を実行する十分な権限があります。",
"xpack.ml.models.jobService.deletingJob": "削除中",
"xpack.ml.models.jobService.jobHasNoDatafeedErrorMessage": "ジョブにデータフィードがありません",
"xpack.ml.models.jobService.requestToActionTimedOutErrorMessage": "「{id}」を{action}するリクエストがタイムアウトしました。{extra}",
"xpack.ml.models.jobService.resettingJob": "セットしています",
"xpack.ml.models.jobService.revertingJob": "元に戻しています",
"xpack.ml.models.jobService.revertModelSnapshot.autoCreatedCalendar.description": "自動作成されました",
"xpack.ml.models.jobValidation.messages.bucketSpanEmptyMessage": "バケットスパンフィールドを指定する必要があります。",
"xpack.ml.models.jobValidation.messages.bucketSpanEstimationMismatchHeading": "バケットスパン",
Expand Down
3 changes: 0 additions & 3 deletions x-pack/plugins/translations/translations/zh-CN.json
Original file line number Diff line number Diff line change
Expand Up @@ -18975,11 +18975,8 @@
"xpack.ml.models.jobService.categorization.messages.validTokenLength": "在 {percentage}% 以上的已加载示例中为每个示例找到 {tokenCount} 个以上分词。",
"xpack.ml.models.jobService.categorization.messages.validTooManyTokens": "在已加载示例中总共找到的分词不超过 10000 个。",
"xpack.ml.models.jobService.categorization.messages.validUserPrivileges": "用户有足够的权限执行检查。",
"xpack.ml.models.jobService.deletingJob": "正在删除",
"xpack.ml.models.jobService.jobHasNoDatafeedErrorMessage": "作业没有数据馈送",
"xpack.ml.models.jobService.requestToActionTimedOutErrorMessage": "对 {action} “{id}” 的请求超时。{extra}",
"xpack.ml.models.jobService.resettingJob": "正在重置",
"xpack.ml.models.jobService.revertingJob": "正在恢复",
"xpack.ml.models.jobService.revertModelSnapshot.autoCreatedCalendar.description": "自动创建",
"xpack.ml.models.jobValidation.messages.bucketSpanEmptyMessage": "必须指定存储桶跨度字段。",
"xpack.ml.models.jobValidation.messages.bucketSpanEstimationMismatchHeading": "存储桶跨度",
Expand Down

0 comments on commit 1dc6216

Please sign in to comment.