Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

[ML] Adding type for job summary state #131643

Merged
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
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 @@ -18803,11 +18803,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 @@ -18950,11 +18950,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 @@ -18979,11 +18979,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