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] New Platform server shim: update recognize modules routes to use new platform router #57206

Merged
merged 6 commits into from
Feb 11, 2020
Merged
Show file tree
Hide file tree
Changes from 5 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
5 changes: 4 additions & 1 deletion x-pack/legacy/plugins/ml/common/types/jobs.ts
Original file line number Diff line number Diff line change
Expand Up @@ -20,7 +20,10 @@ export interface MlJob {
};
create_time: number;
custom_settings: object;
data_counts: object;
data_counts: {
earliest_record_timestamp: number;
latest_record_timestamp: number;
};
data_description: {
time_field: string;
time_format: string;
Expand Down
39 changes: 26 additions & 13 deletions x-pack/legacy/plugins/ml/common/types/modules.ts
Original file line number Diff line number Diff line change
Expand Up @@ -11,16 +11,25 @@ export interface ModuleJob {
config: Omit<Job, 'job_id'>;
}

export interface ModuleDataFeed {
id: string;
config: Omit<Datafeed, 'datafeed_id'>;
}

export interface KibanaObjectConfig extends SavedObjectAttributes {
description: string;
title: string;
version: number;
kibanaSavedObjectMeta?: {
searchSourceJSON: string;
};
}

export interface KibanaObject {
id: string;
title: string;
config: KibanaObjectConfig;
exists?: boolean;
}

export interface KibanaObjects {
Expand All @@ -39,14 +48,18 @@ export interface Module {
defaultIndexPattern: string;
query: any;
jobs: ModuleJob[];
datafeeds: Datafeed[];
datafeeds: ModuleDataFeed[];
kibana: KibanaObjects;
}

export interface KibanaObjectResponse {
exists?: boolean;
success?: boolean;
export interface ResultItem {
id: string;
success?: boolean;
}

export interface KibanaObjectResponse extends ResultItem {
exists?: boolean;
error?: any;
}

export interface SetupError {
Expand All @@ -58,27 +71,27 @@ export interface SetupError {
statusCode: number;
}

export interface DatafeedResponse {
id: string;
success: boolean;
export interface DatafeedResponse extends ResultItem {
started: boolean;
error?: SetupError;
}

export interface JobResponse {
id: string;
success: boolean;
export interface JobResponse extends ResultItem {
error?: SetupError;
}

export interface DataRecognizerConfigResponse {
datafeeds: DatafeedResponse[];
jobs: JobResponse[];
kibana: {
search: KibanaObjectResponse;
visualization: KibanaObjectResponse;
dashboard: KibanaObjectResponse;
search: KibanaObjectResponse[];
visualization: KibanaObjectResponse[];
dashboard: KibanaObjectResponse[];
};
}

export type GeneralOverride = any;

export type JobOverride = Partial<Job>;

export type DatafeedOverride = Partial<Datafeed>;
7 changes: 7 additions & 0 deletions x-pack/legacy/plugins/ml/common/util/job_utils.d.ts
Original file line number Diff line number Diff line change
Expand Up @@ -45,3 +45,10 @@ export function mlFunctionToESAggregation(functionName: string): string | null;
export function isModelPlotEnabled(job: Job, detectorIndex: number, entityFields: any[]): boolean;

export function getSafeAggregationName(fieldName: string, index: number): string;

export function getLatestDataOrBucketTimestamp(
latestDataTimestamp: number,
latestBucketTimestamp: number
): number;

export function prefixDatafeedId(datafeedId: string, prefix: string): string;
Original file line number Diff line number Diff line change
Expand Up @@ -15,6 +15,10 @@ export interface Datafeed {
chunking_config?: ChunkingConfig;
frequency?: string;
indices: IndexPatternTitle[];
/**
* The datafeed can contain indexes and indices
*/
indexes?: IndexPatternTitle[];
job_id?: JobId;
query: object;
query_delay?: string;
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -4,11 +4,26 @@
* you may not use this file except in compliance with the Elastic License.
*/

import expect from '@kbn/expect';
import { RequestHandlerContext } from 'kibana/server';
import { Module } from '../../../common/types/modules';
import { DataRecognizer } from '../data_recognizer';

describe('ML - data recognizer', () => {
const dr = new DataRecognizer({});
const dr = new DataRecognizer(({
ml: {
mlClient: {
callAsCurrentUser: jest.fn(),
},
},
core: {
savedObjects: {
client: {
find: jest.fn(),
bulkCreate: jest.fn(),
},
},
},
} as unknown) as RequestHandlerContext);

const moduleIds = [
'apache_ecs',
Expand All @@ -34,20 +49,20 @@ describe('ML - data recognizer', () => {
it('listModules - check all module IDs', async () => {
const modules = await dr.listModules();
const ids = modules.map(m => m.id);
expect(ids.join()).to.equal(moduleIds.join());
expect(ids.join()).toEqual(moduleIds.join());
});

it('getModule - load a single module', async () => {
const module = await dr.getModule(moduleIds[0]);
expect(module.id).to.equal(moduleIds[0]);
expect(module.id).toEqual(moduleIds[0]);
});

describe('jobOverrides', () => {
it('should apply job overrides correctly', () => {
// arrange
const prefix = 'pre-';
const testJobId = 'test-job';
const moduleConfig = {
const moduleConfig = ({
jobs: [
{
id: `${prefix}${testJobId}`,
Expand All @@ -64,7 +79,7 @@ describe('ML - data recognizer', () => {
},
},
],
};
} as unknown) as Module;
const jobOverrides = [
{
analysis_limits: {
Expand All @@ -80,7 +95,7 @@ describe('ML - data recognizer', () => {
// act
dr.applyJobConfigOverrides(moduleConfig, jobOverrides, prefix);
// assert
expect(moduleConfig.jobs).to.eql([
expect(moduleConfig.jobs).toEqual([
{
config: {
analysis_config: {
Expand Down
Loading