Skip to content

Commit

Permalink
[ML] Adding shared services to ml setup contract (#59730)
Browse files Browse the repository at this point in the history
* [ML] Adding shared services to ml setup contract

* adding data recognizer

* typescripting js client

* adding results service

* code clean up

* adding generic ml index search

* making cloud optional
  • Loading branch information
jgowdyelastic authored Mar 12, 2020
1 parent ed68ede commit d5c0928
Show file tree
Hide file tree
Showing 70 changed files with 511 additions and 173 deletions.
32 changes: 32 additions & 0 deletions x-pack/legacy/plugins/ml/common/types/ml_server_info.ts
Original file line number Diff line number Diff line change
@@ -0,0 +1,32 @@
/*
* 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 { CategorizationAnalyzer } from './categories';

export interface MlServerDefaults {
anomaly_detectors: {
categorization_examples_limit?: number;
model_memory_limit?: string;
model_snapshot_retention_days?: number;
categorization_analyzer?: CategorizationAnalyzer;
};
datafeeds: { scroll_size?: number };
}

export interface MlServerLimits {
max_model_memory_limit?: string;
}

export interface MlInfoResponse {
defaults: MlServerDefaults;
limits: MlServerLimits;
native_code: {
build_hash: string;
version: string;
};
upgrade_mode: boolean;
cloudId?: string;
}
2 changes: 1 addition & 1 deletion x-pack/legacy/plugins/ml/common/types/modules.ts
Original file line number Diff line number Diff line change
Expand Up @@ -3,7 +3,7 @@
* or more contributor license agreements. Licensed under the Elastic License;
* you may not use this file except in compliance with the Elastic License.
*/
import { SavedObjectAttributes } from 'src/core/public';
import { SavedObjectAttributes } from 'kibana/public';
import { Datafeed, Job } from '../types/anomaly_detection_jobs';

export interface ModuleJob {
Expand Down
2 changes: 1 addition & 1 deletion x-pack/legacy/plugins/ml/index.ts
Original file line number Diff line number Diff line change
Expand Up @@ -10,7 +10,7 @@ import { Server } from 'src/legacy/server/kbn_server';
import { DEFAULT_APP_CATEGORIES } from '../../../../src/core/utils';
// @ts-ignore: could not find declaration file for module
import { mirrorPluginStatus } from '../../server/lib/mirror_plugin_status';
// @ts-ignore: could not find declaration file for module
// @ts-ignore: importing JSON file
import mappings from './mappings';

export const ml = (kibana: any) => {
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -8,7 +8,7 @@ import { useReducer } from 'react';

import { i18n } from '@kbn/i18n';

import { SimpleSavedObject } from 'src/core/public';
import { SimpleSavedObject } from 'kibana/public';
import { ml } from '../../../../../services/ml_api_service';
import { useMlContext } from '../../../../../contexts/ml';

Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -5,7 +5,7 @@
*/

import React, { FC, Fragment } from 'react';
import { IUiSettingsClient } from 'src/core/public';
import { IUiSettingsClient } from 'kibana/public';

import { useTimefilter } from '../../contexts/kibana';
import { NavigationMenu } from '../../components/navigation_menu';
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -4,7 +4,7 @@
* you may not use this file except in compliance with the Elastic License.
*/

import { IUiSettingsClient } from 'src/core/public';
import { IUiSettingsClient } from 'kibana/public';
import { esQuery, Query, esKuery } from '../../../../../../../../../src/plugins/data/public';
import { IIndexPattern } from '../../../../../../../../../src/plugins/data/common/index_patterns';
import { SEARCH_QUERY_LANGUAGE } from '../../../../../common/constants/search';
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -5,7 +5,7 @@
*/

import { i18n } from '@kbn/i18n';
import { ChromeBreadcrumb } from '../../../../../../../src/core/public';
import { ChromeBreadcrumb } from 'kibana/public';

export const ML_BREADCRUMB: ChromeBreadcrumb = Object.freeze({
text: i18n.translate('xpack.ml.machineLearningBreadcrumbLabel', {
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -8,7 +8,7 @@ import React, { FC } from 'react';
import { HashRouter, Route, RouteProps } from 'react-router-dom';
import { Location } from 'history';

import { IUiSettingsClient, ChromeStart } from 'src/core/public';
import { IUiSettingsClient, ChromeStart } from 'kibana/public';
import { ChromeBreadcrumb } from 'kibana/public';
import { IndexPatternsContract } from 'src/plugins/data/public';
import { MlContext, MlContextValue } from '../contexts/ml';
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -5,7 +5,7 @@
*/

import { useEffect, useState } from 'react';
import { IUiSettingsClient } from 'src/core/public';
import { IUiSettingsClient } from 'kibana/public';
import {
getIndexPatternById,
getIndexPatternsContract,
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -11,7 +11,11 @@ import { AggFieldNamePair } from '../../../../common/types/fields';
import { Category } from '../../../../common/types/categories';
import { ExistingJobsAndGroups } from '../job_service';
import { PrivilegesResponse } from '../../../../common/types/privileges';
import { MlServerDefaults, MlServerLimits } from '../ml_server_info';
import {
MlInfoResponse,
MlServerDefaults,
MlServerLimits,
} from '../../../../common/types/ml_server_info';
import { ES_AGGREGATION } from '../../../../common/constants/aggregation_types';
import { DataFrameAnalyticsStats } from '../../data_frame_analytics/pages/analytics_management/components/analytics_list/common';
import { JobMessage } from '../../../../common/types/audit_message';
Expand Down Expand Up @@ -69,17 +73,6 @@ export interface BucketSpanEstimatorResponse {
message?: { msg: string } | string;
}

export interface MlInfoResponse {
defaults: MlServerDefaults;
limits: MlServerLimits;
native_code: {
build_hash: string;
version: string;
};
upgrade_mode: boolean;
cloudId?: string;
}

export interface SuccessCardinality {
id: 'success_cardinality';
}
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -5,21 +5,7 @@
*/

import { ml } from './ml_api_service';
import { CategorizationAnalyzer } from '../../../common/types/categories';

export interface MlServerDefaults {
anomaly_detectors: {
categorization_examples_limit?: number;
model_memory_limit?: string;
model_snapshot_retention_days?: number;
categorization_analyzer?: CategorizationAnalyzer;
};
datafeeds: { scroll_size?: number };
}

export interface MlServerLimits {
max_model_memory_limit?: string;
}
import { MlServerDefaults, MlServerLimits } from '../../../common/types/ml_server_info';

export interface CloudInfo {
cloudId: string | null;
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -11,7 +11,7 @@ import {
SavedObjectsClientContract,
ApplicationStart,
HttpStart,
} from 'src/core/public';
} from 'kibana/public';
import { IndexPatternsContract, DataPublicPluginStart } from 'src/plugins/data/public';
import {
DocLinksStart,
Expand Down
2 changes: 1 addition & 1 deletion x-pack/legacy/plugins/ml/public/index.ts
Original file line number Diff line number Diff line change
Expand Up @@ -4,7 +4,7 @@
* you may not use this file except in compliance with the Elastic License.
*/

import { PluginInitializer } from '../../../../../src/core/public';
import { PluginInitializer } from 'kibana/public';
import { MlPlugin, Setup, Start } from './plugin';

export const plugin: PluginInitializer<Setup, Start> = () => new MlPlugin();
Expand Down
2 changes: 1 addition & 1 deletion x-pack/legacy/plugins/ml/public/legacy.ts
Original file line number Diff line number Diff line change
Expand Up @@ -5,7 +5,7 @@
*/

import { npSetup, npStart } from 'ui/new_platform';
import { PluginInitializerContext } from 'src/core/public';
import { PluginInitializerContext } from 'kibana/public';
import { SecurityPluginSetup } from '../../../../plugins/security/public';
import { LicensingPluginSetup } from '../../../../plugins/licensing/public';

Expand Down
2 changes: 1 addition & 1 deletion x-pack/legacy/plugins/ml/public/plugin.ts
Original file line number Diff line number Diff line change
Expand Up @@ -4,7 +4,7 @@
* you may not use this file except in compliance with the Elastic License.
*/

import { Plugin, CoreStart, CoreSetup } from 'src/core/public';
import { Plugin, CoreStart, CoreSetup } from 'kibana/public';
import { MlDependencies } from './application/app';

export class MlPlugin implements Plugin<Setup, Start> {
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -4,14 +4,22 @@
* you may not use this file except in compliance with the Elastic License.
*/

import expect from '@kbn/expect';
import { elasticsearchJsPlugin } from '../elasticsearch_ml';
import { elasticsearchJsPlugin } from './elasticsearch_ml';

interface Endpoint {
fmt: string;
}

interface ClientAction {
urls?: Endpoint[];
url: Endpoint;
}

describe('ML - Endpoints', () => {
// Check all paths in the ML elasticsearchJsPlugin start with a leading forward slash
// so they work if Kibana is run behind a reverse proxy
const PATH_START = '/';
const urls = [];
const PATH_START: string = '/';
const urls: string[] = [];

// Stub objects
const Client = {
Expand All @@ -20,7 +28,7 @@ describe('ML - Endpoints', () => {

const components = {
clientAction: {
factory: function(obj) {
factory(obj: ClientAction) {
// add each endpoint URL to a list
if (obj.urls) {
obj.urls.forEach(url => {
Expand All @@ -45,7 +53,7 @@ describe('ML - Endpoints', () => {
describe('paths', () => {
it(`should start with ${PATH_START}`, () => {
urls.forEach(url => {
expect(url[0]).to.eql(PATH_START);
expect(url[0]).toEqual(PATH_START);
});
});
});
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -4,7 +4,7 @@
* you may not use this file except in compliance with the Elastic License.
*/

export const elasticsearchJsPlugin = (Client, config, components) => {
export const elasticsearchJsPlugin = (Client: any, config: any, components: any) => {
const ca = components.clientAction.factory;

Client.prototype.ml = components.clientAction.namespaceFactory();
Expand Down
2 changes: 1 addition & 1 deletion x-pack/plugins/ml/server/client/error_wrapper.ts
Original file line number Diff line number Diff line change
Expand Up @@ -5,7 +5,7 @@
*/

import { boomify, isBoom } from 'boom';
import { ResponseError, CustomHttpResponseOptions } from 'src/core/server';
import { ResponseError, CustomHttpResponseOptions } from 'kibana/server';

export function wrapError(error: any): CustomHttpResponseOptions<ResponseError> {
const boom = isBoom(error) ? error : boomify(error, { statusCode: error.status });
Expand Down
2 changes: 1 addition & 1 deletion x-pack/plugins/ml/server/client/log.ts
Original file line number Diff line number Diff line change
Expand Up @@ -4,7 +4,7 @@
* you may not use this file except in compliance with the Elastic License.
*/

import { Logger } from '../../../../../src/core/server';
import { Logger } from 'kibana/server';

export interface LogInitialization {
log: Logger;
Expand Down
1 change: 1 addition & 0 deletions x-pack/plugins/ml/server/index.ts
Original file line number Diff line number Diff line change
Expand Up @@ -6,5 +6,6 @@

import { PluginInitializerContext } from 'kibana/server';
import { MlServerPlugin } from './plugin';
export { MlStartContract, MlSetupContract } from './plugin';

export const plugin = (ctx: PluginInitializerContext) => new MlServerPlugin(ctx);
2 changes: 1 addition & 1 deletion x-pack/plugins/ml/server/lib/check_annotations/index.ts
Original file line number Diff line number Diff line change
Expand Up @@ -4,7 +4,7 @@
* you may not use this file except in compliance with the Elastic License.
*/

import { APICaller } from 'src/core/server';
import { APICaller } from 'kibana/server';
import { mlLog } from '../../client/log';

import {
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -16,7 +16,7 @@ import { mlPrivileges } from './privileges';

type ClusterPrivilege = Record<string, boolean>;

interface Response {
export interface MlCapabilities {
capabilities: Privileges;
upgradeInProgress: boolean;
isPlatinumOrTrialLicense: boolean;
Expand All @@ -30,7 +30,7 @@ export function privilegesProvider(
ignoreSpaces: boolean = false
) {
const { isUpgradeInProgress } = upgradeCheckProvider(callAsCurrentUser);
async function getPrivileges(): Promise<Response> {
async function getPrivileges(): Promise<MlCapabilities> {
// get the default privileges, forced to be false.
const privileges = getDefaultPrivileges();

Expand Down
2 changes: 1 addition & 1 deletion x-pack/plugins/ml/server/lib/check_privileges/index.ts
Original file line number Diff line number Diff line change
Expand Up @@ -4,4 +4,4 @@
* you may not use this file except in compliance with the Elastic License.
*/

export { privilegesProvider } from './check_privileges';
export { privilegesProvider, MlCapabilities } from './check_privileges';
2 changes: 1 addition & 1 deletion x-pack/plugins/ml/server/lib/license/ml_server_license.ts
Original file line number Diff line number Diff line change
Expand Up @@ -8,7 +8,7 @@ import {
KibanaResponseFactory,
RequestHandler,
RequestHandlerContext,
} from 'src/core/server';
} from 'kibana/server';

import { MlLicense } from '../../../../../legacy/plugins/ml/common/license';

Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -5,7 +5,7 @@
*/

import { UsageCollectionSetup } from 'src/plugins/usage_collection/server';
import { SavedObjectsServiceStart } from 'src/core/server';
import { SavedObjectsServiceStart } from 'kibana/server';
import {
createMlTelemetry,
ML_TELEMETRY_DOC_ID,
Expand Down
7 changes: 5 additions & 2 deletions x-pack/plugins/ml/server/lib/ml_telemetry/ml_telemetry.ts
Original file line number Diff line number Diff line change
Expand Up @@ -4,7 +4,7 @@
* you may not use this file except in compliance with the Elastic License.
*/

import { SavedObjectAttributes, SavedObjectsClientContract } from 'src/core/server';
import { SavedObjectAttributes, SavedObjectsClientContract } from 'kibana/server';

export interface MlTelemetry extends SavedObjectAttributes {
file_data_visualizer: {
Expand Down Expand Up @@ -40,7 +40,10 @@ export async function incrementFileDataVisualizerIndexCreationCount(
savedObjectsClient: SavedObjectsClientContract
): Promise<void> {
try {
const { attributes } = await savedObjectsClient.get('telemetry', 'telemetry');
const { attributes } = await savedObjectsClient.get<{ enabled: boolean }>(
'telemetry',
'telemetry'
);

if (attributes.enabled === false) {
return;
Expand Down
7 changes: 5 additions & 2 deletions x-pack/plugins/ml/server/lib/spaces_utils.ts
Original file line number Diff line number Diff line change
Expand Up @@ -4,15 +4,18 @@
* you may not use this file except in compliance with the Elastic License.
*/

import { Request } from 'hapi';
import { Legacy } from 'kibana';
import { KibanaRequest } from 'kibana/server';
import { Space, SpacesPluginSetup } from '../../../spaces/server';

export type RequestFacade = KibanaRequest | Legacy.Request;

interface GetActiveSpaceResponse {
valid: boolean;
space?: Space;
}

export function spacesUtilsProvider(spacesPlugin: SpacesPluginSetup, request: Request) {
export function spacesUtilsProvider(spacesPlugin: SpacesPluginSetup, request: RequestFacade) {
async function activeSpace(): Promise<GetActiveSpaceResponse> {
try {
return {
Expand Down
Loading

0 comments on commit d5c0928

Please sign in to comment.