-
Notifications
You must be signed in to change notification settings - Fork 8.3k
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
[SIEM] ML Rules Details #61182
[SIEM] ML Rules Details #61182
Changes from all commits
a08d48d
6eaa824
ed052ca
d7ce1a2
1345cc9
cce8f5b
785d0d2
5646a74
273e76f
36d63b5
b1dfceb
1418a89
e82a35e
9900f52
111402e
File filter
Filter by extension
Conversations
Jump to
Diff view
Diff view
There are no files selected for viewing
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,57 @@ | ||
/* | ||
* Copyright Elasticsearch B.V. and/or licensed to Elasticsearch B.V. under one | ||
* or more contributor license agreements. Licensed under the Elastic License; | ||
* you may not use this file except in compliance with the Elastic License. | ||
*/ | ||
|
||
import { isJobStarted, isJobLoading, isJobFailed } from './'; | ||
|
||
describe('isJobStarted', () => { | ||
test('returns false if only jobState is enabled', () => { | ||
expect(isJobStarted('started', 'closing')).toBe(false); | ||
}); | ||
|
||
test('returns false if only datafeedState is enabled', () => { | ||
expect(isJobStarted('stopping', 'opened')).toBe(false); | ||
}); | ||
|
||
test('returns true if both enabled states are provided', () => { | ||
expect(isJobStarted('started', 'opened')).toBe(true); | ||
}); | ||
}); | ||
|
||
describe('isJobLoading', () => { | ||
test('returns true if both loading states are not provided', () => { | ||
expect(isJobLoading('started', 'closing')).toBe(true); | ||
}); | ||
|
||
test('returns true if only jobState is loading', () => { | ||
expect(isJobLoading('starting', 'opened')).toBe(true); | ||
}); | ||
|
||
test('returns true if only datafeedState is loading', () => { | ||
expect(isJobLoading('started', 'opening')).toBe(true); | ||
}); | ||
|
||
test('returns false if both disabling states are provided', () => { | ||
expect(isJobLoading('stopping', 'closing')).toBe(true); | ||
}); | ||
}); | ||
|
||
describe('isJobFailed', () => { | ||
test('returns true if only jobState is failure/deleted', () => { | ||
expect(isJobFailed('failed', 'stopping')).toBe(true); | ||
}); | ||
|
||
test('returns true if only dataFeed is failure/deleted', () => { | ||
expect(isJobFailed('started', 'deleted')).toBe(true); | ||
}); | ||
|
||
test('returns true if both enabled states are failure/deleted', () => { | ||
expect(isJobFailed('failed', 'deleted')).toBe(true); | ||
}); | ||
|
||
test('returns false only if both states are not failure/deleted', () => { | ||
expect(isJobFailed('opened', 'stopping')).toBe(false); | ||
}); | ||
}); |
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,22 @@ | ||
/* | ||
* Copyright Elasticsearch B.V. and/or licensed to Elasticsearch B.V. under one | ||
* or more contributor license agreements. Licensed under the Elastic License; | ||
* you may not use this file except in compliance with the Elastic License. | ||
*/ | ||
|
||
// Based on ML Job/Datafeed States from x-pack/legacy/plugins/ml/common/constants/states.js | ||
const enabledStates = ['started', 'opened']; | ||
const loadingStates = ['starting', 'stopping', 'opening', 'closing']; | ||
const failureStates = ['deleted', 'failed']; | ||
|
||
export const isJobStarted = (jobState: string, datafeedState: string): boolean => { | ||
return enabledStates.includes(jobState) && enabledStates.includes(datafeedState); | ||
}; | ||
|
||
export const isJobLoading = (jobState: string, datafeedState: string): boolean => { | ||
return loadingStates.includes(jobState) || loadingStates.includes(datafeedState); | ||
}; | ||
|
||
export const isJobFailed = (jobState: string, datafeedState: string): boolean => { | ||
return failureStates.includes(jobState) || failureStates.includes(datafeedState); | ||
}; |
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,11 @@ | ||
/* | ||
* Copyright Elasticsearch B.V. and/or licensed to Elasticsearch B.V. under one | ||
* or more contributor license agreements. Licensed under the Elastic License; | ||
* you may not use this file except in compliance with the Elastic License. | ||
*/ | ||
|
||
import { useContext } from 'react'; | ||
|
||
import { MlCapabilitiesContext } from '../../ml/permissions/ml_capabilities_provider'; | ||
|
||
export const useMlCapabilities = () => useContext(MlCapabilitiesContext); |
Original file line number | Diff line number | Diff line change |
---|---|---|
|
@@ -5,6 +5,7 @@ | |
*/ | ||
|
||
import { MlError } from '../ml/types'; | ||
import { AuditMessageBase } from '../../../../../../plugins/ml/common/types/audit_message'; | ||
|
||
export interface Group { | ||
id: string; | ||
|
@@ -101,6 +102,7 @@ export interface MlSetupArgs { | |
* Representation of an ML Job as returned from the `ml/jobs/jobs_summary` API | ||
*/ | ||
export interface JobSummary { | ||
auditMessage?: AuditMessageBase; | ||
There was a problem hiding this comment. Choose a reason for hiding this commentThe reason will be displayed to describe this comment to others. Learn more. Nice that we can use the explicit ML types! ++ 🎉 There was a problem hiding this comment. Choose a reason for hiding this commentThe reason will be displayed to describe this comment to others. Learn more. I was a little wary of this one... I'm getting no linter complaints, and that file is just types, so I think we should be fine. |
||
datafeedId: string; | ||
datafeedIndices: string[]; | ||
datafeedState: string; | ||
|
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
Yaaay! Tests for verifying job states -- thanks @rylnd! 🎉🥇