mirror of
https://github.com/elastic/kibana.git
synced 2025-04-24 09:48:58 -04:00
[ML] Sharing datafeed start and stop functions (#144968)
Sharing the functions `forceStartDatafeeds` and `stopDatafeeds` for use by the security solutions plugin.
This commit is contained in:
parent
db3572ab72
commit
f82bb68072
5 changed files with 42 additions and 0 deletions
|
@ -8,4 +8,6 @@
|
|||
export const createJobServiceProviderMock = () =>
|
||||
jest.fn(() => ({
|
||||
jobsSummary: jest.fn(),
|
||||
forceStartDatafeeds: jest.fn(),
|
||||
stopDatafeeds: jest.fn(),
|
||||
}));
|
||||
|
|
|
@ -17,6 +17,8 @@ export interface JobServiceProvider {
|
|||
savedObjectsClient: SavedObjectsClientContract
|
||||
): {
|
||||
jobsSummary: OrigJobServiceProvider['jobsSummary'];
|
||||
forceStartDatafeeds: OrigJobServiceProvider['forceStartDatafeeds'];
|
||||
stopDatafeeds: OrigJobServiceProvider['stopDatafeeds'];
|
||||
};
|
||||
}
|
||||
|
||||
|
@ -33,6 +35,24 @@ export function getJobServiceProvider(getGuards: GetGuards): JobServiceProvider
|
|||
return jobsSummary(...args);
|
||||
});
|
||||
},
|
||||
forceStartDatafeeds: async (...args) => {
|
||||
return await getGuards(request, savedObjectsClient)
|
||||
.isFullLicense()
|
||||
.hasMlCapabilities(['canStartStopDatafeed'])
|
||||
.ok(({ scopedClient, mlClient }) => {
|
||||
const { forceStartDatafeeds } = jobServiceProvider(scopedClient, mlClient);
|
||||
return forceStartDatafeeds(...args);
|
||||
});
|
||||
},
|
||||
stopDatafeeds: async (...args) => {
|
||||
return await getGuards(request, savedObjectsClient)
|
||||
.isFullLicense()
|
||||
.hasMlCapabilities(['canStartStopDatafeed'])
|
||||
.ok(({ scopedClient, mlClient }) => {
|
||||
const { stopDatafeeds } = jobServiceProvider(scopedClient, mlClient);
|
||||
return stopDatafeeds(...args);
|
||||
});
|
||||
},
|
||||
};
|
||||
},
|
||||
};
|
||||
|
|
|
@ -22,6 +22,8 @@ jest.mock('../bulk_create_ml_signals');
|
|||
|
||||
describe('ml_executor', () => {
|
||||
let jobsSummaryMock: jest.Mock;
|
||||
let forceStartDatafeedsMock: jest.Mock;
|
||||
let stopDatafeedsMock: jest.Mock;
|
||||
let mlMock: ReturnType<typeof mlPluginServerMock.createSetupContract>;
|
||||
let alertServices: RuleExecutorServicesMock;
|
||||
let ruleExecutionLogger: ReturnType<typeof ruleExecutionLogMock.forExecutors.create>;
|
||||
|
@ -39,6 +41,8 @@ describe('ml_executor', () => {
|
|||
mlMock = mlPluginServerMock.createSetupContract();
|
||||
mlMock.jobServiceProvider.mockReturnValue({
|
||||
jobsSummary: jobsSummaryMock,
|
||||
forceStartDatafeeds: forceStartDatafeedsMock,
|
||||
stopDatafeeds: stopDatafeedsMock,
|
||||
});
|
||||
alertServices = alertsMock.createRuleExecutorServices();
|
||||
ruleExecutionLogger = ruleExecutionLogMock.forExecutors.create({
|
||||
|
|
|
@ -15,6 +15,8 @@ import {
|
|||
import { mlServicesMock } from '../../lib/machine_learning/mocks';
|
||||
import {
|
||||
getMockMlJobSummaryResponse,
|
||||
getMockMlForceStartDatafeedsResponse,
|
||||
getMockMlStopDatafeedsResponse,
|
||||
getMockListModulesResponse,
|
||||
getMockMlJobDetailsResponse,
|
||||
getMockMlJobStatsResponse,
|
||||
|
@ -273,12 +275,18 @@ describe('Detections Usage and Metrics', () => {
|
|||
it('returns an ml job telemetry object from anomaly detectors provider', async () => {
|
||||
const logger = loggingSystemMock.createLogger();
|
||||
const mockJobSummary = jest.fn().mockResolvedValue(getMockMlJobSummaryResponse());
|
||||
const mockForceStartDatafeeds = jest
|
||||
.fn()
|
||||
.mockResolvedValue(getMockMlForceStartDatafeedsResponse());
|
||||
const mockStopDatafeeds = jest.fn().mockResolvedValue(getMockMlStopDatafeedsResponse());
|
||||
const mockListModules = jest.fn().mockResolvedValue(getMockListModulesResponse());
|
||||
mlClient.modulesProvider.mockReturnValue({
|
||||
listModules: mockListModules,
|
||||
} as unknown as ReturnType<typeof mlClient.modulesProvider>);
|
||||
mlClient.jobServiceProvider.mockReturnValue({
|
||||
jobsSummary: mockJobSummary,
|
||||
forceStartDatafeeds: mockForceStartDatafeeds,
|
||||
stopDatafeeds: mockStopDatafeeds,
|
||||
});
|
||||
const mockJobsResponse = jest.fn().mockResolvedValue(getMockMlJobDetailsResponse());
|
||||
const mockJobStatsResponse = jest.fn().mockResolvedValue(getMockMlJobStatsResponse());
|
||||
|
|
|
@ -163,6 +163,14 @@ export const getMockMlJobSummaryResponse = () => [
|
|||
},
|
||||
];
|
||||
|
||||
export const getMockMlForceStartDatafeedsResponse = () => ({
|
||||
linux_anomalous_network_activity_ecs: { started: true },
|
||||
});
|
||||
|
||||
export const getMockMlStopDatafeedsResponse = () => ({
|
||||
linux_anomalous_network_activity_ecs: { stopped: true },
|
||||
});
|
||||
|
||||
export const getMockMlJobDetailsResponse = () => ({
|
||||
count: 20,
|
||||
jobs: [
|
||||
|
|
Loading…
Add table
Add a link
Reference in a new issue