[ML] Renaming mlSearch to mlAnomalySearch (#67602)
This commit is contained in:
parent
642b6bd36a
commit
321a10d1df
|
@ -23,7 +23,7 @@ export interface MlSystemProvider {
|
|||
): {
|
||||
mlCapabilities(): Promise<MlCapabilitiesResponse>;
|
||||
mlInfo(): Promise<MlInfoResponse>;
|
||||
mlSearch<T>(searchParams: SearchParams): Promise<SearchResponse<T>>;
|
||||
mlAnomalySearch<T>(searchParams: SearchParams): Promise<SearchResponse<T>>;
|
||||
};
|
||||
}
|
||||
|
||||
|
@ -68,7 +68,7 @@ export function getMlSystemProvider(
|
|||
cloudId,
|
||||
};
|
||||
},
|
||||
async mlSearch<T>(searchParams: SearchParams): Promise<SearchResponse<T>> {
|
||||
async mlAnomalySearch<T>(searchParams: SearchParams): Promise<SearchResponse<T>> {
|
||||
isFullLicense();
|
||||
return callAsCurrentUser('search', {
|
||||
...searchParams,
|
||||
|
|
|
@ -27,14 +27,14 @@ export const findMlSignals = async ({
|
|||
from: string;
|
||||
to: string;
|
||||
}) => {
|
||||
const { mlSearch } = ml.mlSystemProvider(callCluster, request);
|
||||
const { mlAnomalySearch } = ml.mlSystemProvider(callCluster, request);
|
||||
const params = {
|
||||
jobIds: [jobId],
|
||||
threshold: anomalyThreshold,
|
||||
earliestMs: dateMath.parse(from)?.valueOf() ?? 0,
|
||||
latestMs: dateMath.parse(to)?.valueOf() ?? 0,
|
||||
};
|
||||
const relevantAnomalies = await getAnomalies(params, mlSearch);
|
||||
const relevantAnomalies = await getAnomalies(params, mlAnomalySearch);
|
||||
|
||||
return relevantAnomalies;
|
||||
};
|
||||
|
|
|
@ -161,7 +161,7 @@ export const signalRulesAlertType = ({
|
|||
ml,
|
||||
callCluster: scopedMlCallCluster,
|
||||
// This is needed to satisfy the ML Services API, but can be empty as it is
|
||||
// currently unused by the mlSearch function.
|
||||
// currently unused by the mlAnomalySearch function.
|
||||
request: ({} as unknown) as KibanaRequest,
|
||||
jobId: machineLearningJobId,
|
||||
anomalyThreshold,
|
||||
|
|
|
@ -173,7 +173,7 @@ describe('mlAuthz', () => {
|
|||
const mockMlCapabilities = jest.fn();
|
||||
mlMock.mlSystemProvider.mockImplementation(() => ({
|
||||
mlInfo: jest.fn(),
|
||||
mlSearch: jest.fn(),
|
||||
mlAnomalySearch: jest.fn(),
|
||||
mlCapabilities: mockMlCapabilities,
|
||||
}));
|
||||
|
||||
|
@ -194,7 +194,7 @@ describe('mlAuthz', () => {
|
|||
const mockMlCapabilities = jest.fn();
|
||||
mlMock.mlSystemProvider.mockImplementation(() => ({
|
||||
mlInfo: jest.fn(),
|
||||
mlSearch: jest.fn(),
|
||||
mlAnomalySearch: jest.fn(),
|
||||
mlCapabilities: mockMlCapabilities,
|
||||
}));
|
||||
|
||||
|
|
|
@ -26,17 +26,17 @@ describe('getAnomalies', () => {
|
|||
};
|
||||
});
|
||||
|
||||
it('calls the provided mlSearch function', () => {
|
||||
const mockMlSearch = jest.fn();
|
||||
getAnomalies(searchParams, mockMlSearch);
|
||||
it('calls the provided mlAnomalySearch function', () => {
|
||||
const mockMlAnomalySearch = jest.fn();
|
||||
getAnomalies(searchParams, mockMlAnomalySearch);
|
||||
|
||||
expect(mockMlSearch).toHaveBeenCalled();
|
||||
expect(mockMlAnomalySearch).toHaveBeenCalled();
|
||||
});
|
||||
|
||||
it('passes anomalyThreshold as part of the query', () => {
|
||||
const mockMlSearch = jest.fn();
|
||||
getAnomalies(searchParams, mockMlSearch);
|
||||
const filters = getFiltersFromMock(mockMlSearch);
|
||||
const mockMlAnomalySearch = jest.fn();
|
||||
getAnomalies(searchParams, mockMlAnomalySearch);
|
||||
const filters = getFiltersFromMock(mockMlAnomalySearch);
|
||||
const criteria = getBoolCriteriaFromFilters(filters);
|
||||
|
||||
expect(criteria).toEqual(
|
||||
|
@ -45,9 +45,9 @@ describe('getAnomalies', () => {
|
|||
});
|
||||
|
||||
it('passes time range as part of the query', () => {
|
||||
const mockMlSearch = jest.fn();
|
||||
getAnomalies(searchParams, mockMlSearch);
|
||||
const filters = getFiltersFromMock(mockMlSearch);
|
||||
const mockMlAnomalySearch = jest.fn();
|
||||
getAnomalies(searchParams, mockMlAnomalySearch);
|
||||
const filters = getFiltersFromMock(mockMlAnomalySearch);
|
||||
const criteria = getBoolCriteriaFromFilters(filters);
|
||||
|
||||
expect(criteria).toEqual(
|
||||
|
@ -66,9 +66,9 @@ describe('getAnomalies', () => {
|
|||
});
|
||||
|
||||
it('passes a single jobId as part of the query', () => {
|
||||
const mockMlSearch = jest.fn();
|
||||
getAnomalies(searchParams, mockMlSearch);
|
||||
const filters = getFiltersFromMock(mockMlSearch);
|
||||
const mockMlAnomalySearch = jest.fn();
|
||||
getAnomalies(searchParams, mockMlAnomalySearch);
|
||||
const filters = getFiltersFromMock(mockMlAnomalySearch);
|
||||
const criteria = getBoolCriteriaFromFilters(filters);
|
||||
|
||||
expect(criteria).toEqual(
|
||||
|
@ -84,10 +84,10 @@ describe('getAnomalies', () => {
|
|||
});
|
||||
|
||||
it('passes multiple jobIds as part of the query', () => {
|
||||
const mockMlSearch = jest.fn();
|
||||
const mockMlAnomalySearch = jest.fn();
|
||||
searchParams.jobIds = ['jobId1', 'jobId2'];
|
||||
getAnomalies(searchParams, mockMlSearch);
|
||||
const filters = getFiltersFromMock(mockMlSearch);
|
||||
getAnomalies(searchParams, mockMlAnomalySearch);
|
||||
const filters = getFiltersFromMock(mockMlAnomalySearch);
|
||||
const criteria = getBoolCriteriaFromFilters(filters);
|
||||
|
||||
expect(criteria).toEqual(
|
||||
|
|
|
@ -10,7 +10,7 @@ import { AnomalyRecordDoc as Anomaly } from '../../../../ml/server';
|
|||
|
||||
export { Anomaly };
|
||||
export type AnomalyResults = SearchResponse<Anomaly>;
|
||||
type MlSearch = <T>(searchParams: SearchParams) => Promise<SearchResponse<T>>;
|
||||
type MlAnomalySearch = <T>(searchParams: SearchParams) => Promise<SearchResponse<T>>;
|
||||
|
||||
export interface AnomaliesSearchParams {
|
||||
jobIds: string[];
|
||||
|
@ -22,11 +22,11 @@ export interface AnomaliesSearchParams {
|
|||
|
||||
export const getAnomalies = async (
|
||||
params: AnomaliesSearchParams,
|
||||
mlSearch: MlSearch
|
||||
mlAnomalySearch: MlAnomalySearch
|
||||
): Promise<AnomalyResults> => {
|
||||
const boolCriteria = buildCriteria(params);
|
||||
|
||||
return mlSearch({
|
||||
return mlAnomalySearch({
|
||||
size: params.maxRecords || 100,
|
||||
body: {
|
||||
query: {
|
||||
|
|
Loading…
Reference in a new issue