Skip to content

Commit

Permalink
[ML] Migrate internal urls to non-hash paths (elastic#76735)
Browse files Browse the repository at this point in the history
Co-authored-by: Elastic Machine <elasticmachine@users.noreply.github.com>
  • Loading branch information
qn895 and elasticmachine committed Sep 17, 2020
1 parent 3d6253f commit 5e08831
Show file tree
Hide file tree
Showing 121 changed files with 2,284 additions and 1,028 deletions.
5 changes: 5 additions & 0 deletions x-pack/plugins/ml/common/constants/app.ts
Original file line number Diff line number Diff line change
Expand Up @@ -4,6 +4,11 @@
* you may not use this file except in compliance with the Elastic License.
*/

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

export const PLUGIN_ID = 'ml';
export const PLUGIN_ICON = 'machineLearningApp';
export const PLUGIN_ICON_SOLUTION = 'logoKibana';
export const ML_APP_NAME = i18n.translate('xpack.ml.navMenu.mlAppNameText', {
defaultMessage: 'Machine Learning',
});
5 changes: 5 additions & 0 deletions x-pack/plugins/ml/common/constants/data_frame_analytics.ts
Original file line number Diff line number Diff line change
Expand Up @@ -4,4 +4,9 @@
* you may not use this file except in compliance with the Elastic License.
*/

export const ANALYSIS_CONFIG_TYPE = {
OUTLIER_DETECTION: 'outlier_detection',
REGRESSION: 'regression',
CLASSIFICATION: 'classification',
} as const;
export const DEFAULT_RESULTS_FIELD = 'ml';
8 changes: 8 additions & 0 deletions x-pack/plugins/ml/common/constants/ml_url_generator.ts
Original file line number Diff line number Diff line change
Expand Up @@ -31,8 +31,16 @@ export const ML_PAGES = {
* Open index data visualizer viewer page
*/
DATA_VISUALIZER_INDEX_VIEWER: 'jobs/new_job/datavisualizer',
ANOMALY_DETECTION_CREATE_JOB: `jobs/new_job`,
ANOMALY_DETECTION_CREATE_JOB_SELECT_TYPE: `jobs/new_job/step/job_type`,
ANOMALY_DETECTION_CREATE_JOB_SELECT_INDEX: `jobs/new_job/step/index_or_search`,
SETTINGS: 'settings',
CALENDARS_MANAGE: 'settings/calendars_list',
CALENDARS_NEW: 'settings/calendars_list/new_calendar',
CALENDARS_EDIT: 'settings/calendars_list/edit_calendar',
FILTER_LISTS_MANAGE: 'settings/filter_lists',
FILTER_LISTS_NEW: 'settings/filter_lists/new_filter_list',
FILTER_LISTS_EDIT: 'settings/filter_lists/edit_filter_list',
ACCESS_DENIED: 'access-denied',
OVERVIEW: 'overview',
} as const;
7 changes: 2 additions & 5 deletions x-pack/plugins/ml/common/types/data_frame_analytics.ts
Original file line number Diff line number Diff line change
Expand Up @@ -6,6 +6,7 @@

import Boom from 'boom';
import { EsErrorBody } from '../util/errors';
import { ANALYSIS_CONFIG_TYPE } from '../constants/data_frame_analytics';

export interface DeleteDataFrameAnalyticsWithIndexStatus {
success: boolean;
Expand Down Expand Up @@ -81,8 +82,4 @@ export interface DataFrameAnalyticsConfig {
allow_lazy_start?: boolean;
}

export enum ANALYSIS_CONFIG_TYPE {
OUTLIER_DETECTION = 'outlier_detection',
REGRESSION = 'regression',
CLASSIFICATION = 'classification',
}
export type DataFrameAnalysisConfigType = typeof ANALYSIS_CONFIG_TYPE[keyof typeof ANALYSIS_CONFIG_TYPE];
82 changes: 52 additions & 30 deletions x-pack/plugins/ml/common/types/ml_url_generator.ts
Original file line number Diff line number Diff line change
Expand Up @@ -5,27 +5,21 @@
*/

import { RefreshInterval, TimeRange } from '../../../../../src/plugins/data/common/query';
import { JobId } from '../../../reporting/common/types';
import { JobId } from './anomaly_detection_jobs/job';
import { ML_PAGES } from '../constants/ml_url_generator';
import { DataFrameAnalysisConfigType } from './data_frame_analytics';

type OptionalPageState = object | undefined;

export type MLPageState<PageType, PageState> = PageState extends OptionalPageState
? { page: PageType; pageState?: PageState }
? { page: PageType; pageState?: PageState; excludeBasePath?: boolean }
: PageState extends object
? { page: PageType; pageState: PageState }
: { page: PageType };

export const ANALYSIS_CONFIG_TYPE = {
OUTLIER_DETECTION: 'outlier_detection',
REGRESSION: 'regression',
CLASSIFICATION: 'classification',
} as const;

type DataFrameAnalyticsType = typeof ANALYSIS_CONFIG_TYPE[keyof typeof ANALYSIS_CONFIG_TYPE];
? { page: PageType; pageState: PageState; excludeBasePath?: boolean }
: { page: PageType; excludeBasePath?: boolean };

export interface MlCommonGlobalState {
time?: TimeRange;
refreshInterval?: RefreshInterval;
}
export interface MlCommonAppState {
[key: string]: any;
Expand All @@ -42,16 +36,28 @@ export interface MlGenericUrlPageState extends MlIndexBasedSearchState {
[key: string]: any;
}

export interface MlGenericUrlState {
page:
| typeof ML_PAGES.DATA_VISUALIZER_INDEX_VIEWER
| typeof ML_PAGES.ANOMALY_DETECTION_CREATE_JOB_SELECT_TYPE;
pageState: MlGenericUrlPageState;
}
export type MlGenericUrlState = MLPageState<
| typeof ML_PAGES.DATA_VISUALIZER_INDEX_VIEWER
| typeof ML_PAGES.ANOMALY_DETECTION_CREATE_JOB
| typeof ML_PAGES.ANOMALY_DETECTION_CREATE_JOB_SELECT_TYPE
| typeof ML_PAGES.ANOMALY_DETECTION_CREATE_JOB_SELECT_INDEX
| typeof ML_PAGES.OVERVIEW
| typeof ML_PAGES.CALENDARS_MANAGE
| typeof ML_PAGES.CALENDARS_NEW
| typeof ML_PAGES.FILTER_LISTS_MANAGE
| typeof ML_PAGES.FILTER_LISTS_NEW
| typeof ML_PAGES.SETTINGS
| typeof ML_PAGES.ACCESS_DENIED
| typeof ML_PAGES.DATA_VISUALIZER
| typeof ML_PAGES.DATA_VISUALIZER_FILE
| typeof ML_PAGES.DATA_VISUALIZER_INDEX_SELECT,
MlGenericUrlPageState | undefined
>;

export interface AnomalyDetectionQueryState {
jobId?: JobId;
groupIds?: string[];
globalState?: MlCommonGlobalState;
}

export type AnomalyDetectionUrlState = MLPageState<
Expand Down Expand Up @@ -86,7 +92,7 @@ export interface ExplorerUrlPageState {
/**
* Job IDs
*/
jobIds: JobId[];
jobIds?: JobId[];
/**
* Optionally set the time range in the time picker.
*/
Expand All @@ -104,6 +110,7 @@ export interface ExplorerUrlPageState {
*/
mlExplorerSwimlane?: ExplorerAppState['mlExplorerSwimlane'];
mlExplorerFilter?: ExplorerAppState['mlExplorerFilter'];
globalState?: MlCommonGlobalState;
}

export type ExplorerUrlState = MLPageState<typeof ML_PAGES.ANOMALY_EXPLORER, ExplorerUrlPageState>;
Expand All @@ -122,6 +129,7 @@ export interface TimeSeriesExplorerAppState {
to?: string;
};
mlTimeSeriesExplorer?: {
forecastId?: string;
detectorIndex?: number;
entities?: Record<string, string>;
};
Expand All @@ -131,10 +139,12 @@ export interface TimeSeriesExplorerAppState {
export interface TimeSeriesExplorerPageState
extends Pick<TimeSeriesExplorerAppState, 'zoom' | 'query'>,
Pick<TimeSeriesExplorerGlobalState, 'refreshInterval'> {
jobIds: JobId[];
jobIds?: JobId[];
timeRange?: TimeRange;
detectorIndex?: number;
entities?: Record<string, string>;
forecastId?: string;
globalState?: MlCommonGlobalState;
}

export type TimeSeriesExplorerUrlState = MLPageState<
Expand All @@ -145,32 +155,43 @@ export type TimeSeriesExplorerUrlState = MLPageState<
export interface DataFrameAnalyticsQueryState {
jobId?: JobId | JobId[];
groupIds?: string[];
globalState?: MlCommonGlobalState;
}

export type DataFrameAnalyticsUrlState = MLPageState<
typeof ML_PAGES.DATA_FRAME_ANALYTICS_JOBS_MANAGE,
DataFrameAnalyticsQueryState | undefined
>;

export interface DataVisualizerUrlState {
page:
| typeof ML_PAGES.DATA_VISUALIZER
| typeof ML_PAGES.DATA_VISUALIZER_FILE
| typeof ML_PAGES.DATA_VISUALIZER_INDEX_SELECT;
}

export interface DataFrameAnalyticsExplorationQueryState {
ml: {
jobId: JobId;
analysisType: DataFrameAnalyticsType;
analysisType: DataFrameAnalysisConfigType;
};
}

export type DataFrameAnalyticsExplorationUrlState = MLPageState<
typeof ML_PAGES.DATA_FRAME_ANALYTICS_EXPLORATION,
{
jobId: JobId;
analysisType: DataFrameAnalyticsType;
analysisType: DataFrameAnalysisConfigType;
globalState?: MlCommonGlobalState;
}
>;

export type CalendarEditUrlState = MLPageState<
typeof ML_PAGES.CALENDARS_EDIT,
{
calendarId: string;
globalState?: MlCommonGlobalState;
}
>;

export type FilterEditUrlState = MLPageState<
typeof ML_PAGES.FILTER_LISTS_EDIT,
{
filterId: string;
globalState?: MlCommonGlobalState;
}
>;

Expand All @@ -183,5 +204,6 @@ export type MlUrlGeneratorState =
| TimeSeriesExplorerUrlState
| DataFrameAnalyticsUrlState
| DataFrameAnalyticsExplorationUrlState
| DataVisualizerUrlState
| CalendarEditUrlState
| FilterEditUrlState
| MlGenericUrlState;
2 changes: 1 addition & 1 deletion x-pack/plugins/ml/common/util/analytics_utils.ts
Original file line number Diff line number Diff line change
Expand Up @@ -9,8 +9,8 @@ import {
ClassificationAnalysis,
OutlierAnalysis,
RegressionAnalysis,
ANALYSIS_CONFIG_TYPE,
} from '../types/data_frame_analytics';
import { ANALYSIS_CONFIG_TYPE } from '../../common/constants/data_frame_analytics';

export const isOutlierAnalysis = (arg: any): arg is OutlierAnalysis => {
const keys = Object.keys(arg);
Expand Down
3 changes: 2 additions & 1 deletion x-pack/plugins/ml/kibana.json
Original file line number Diff line number Diff line change
Expand Up @@ -16,7 +16,8 @@
"embeddable",
"uiActions",
"kibanaLegacy",
"indexPatternManagement"
"indexPatternManagement",
"discover"
],
"optionalPlugins": [
"home",
Expand Down
11 changes: 11 additions & 0 deletions x-pack/plugins/ml/public/application/app.tsx
Original file line number Diff line number Diff line change
Expand Up @@ -20,6 +20,7 @@ import { MlSetupDependencies, MlStartDependencies } from '../plugin';
import { MlRouter } from './routing';
import { mlApiServicesProvider } from './services/ml_api_service';
import { HttpService } from './services/http_service';
import { ML_APP_URL_GENERATOR, ML_PAGES } from '../../common/constants/ml_url_generator';

export type MlDependencies = Omit<MlSetupDependencies, 'share' | 'indexPatternManagement'> &
MlStartDependencies;
Expand Down Expand Up @@ -50,11 +51,21 @@ export interface MlServicesContext {
export type MlGlobalServices = ReturnType<typeof getMlGlobalServices>;

const App: FC<AppProps> = ({ coreStart, deps, appMountParams }) => {
const redirectToMlAccessDeniedPage = async () => {
const accessDeniedPageUrl = await deps.share.urlGenerators
.getUrlGenerator(ML_APP_URL_GENERATOR)
.createUrl({
page: ML_PAGES.ACCESS_DENIED,
});
await coreStart.application.navigateToUrl(accessDeniedPageUrl);
};

const pageDeps = {
history: appMountParams.history,
indexPatterns: deps.data.indexPatterns,
config: coreStart.uiSettings!,
setBreadcrumbs: coreStart.chrome!.setBreadcrumbs,
redirectToMlAccessDeniedPage,
};
const services = {
appName: 'ML',
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -33,10 +33,12 @@ export function checkGetManagementMlJobsResolver() {
});
}

export function checkGetJobsCapabilitiesResolver(): Promise<MlCapabilities> {
export function checkGetJobsCapabilitiesResolver(
redirectToMlAccessDeniedPage: () => Promise<void>
): Promise<MlCapabilities> {
return new Promise((resolve, reject) => {
getCapabilities()
.then(({ capabilities, isPlatinumOrTrialLicense }) => {
.then(async ({ capabilities, isPlatinumOrTrialLicense }) => {
_capabilities = capabilities;
// the minimum privilege for using ML with a platinum or trial license is being able to get the transforms list.
// all other functionality is controlled by the return capabilities object.
Expand All @@ -46,21 +48,23 @@ export function checkGetJobsCapabilitiesResolver(): Promise<MlCapabilities> {
if (_capabilities.canGetJobs || isPlatinumOrTrialLicense === false) {
return resolve(_capabilities);
} else {
window.location.href = '#/access-denied';
await redirectToMlAccessDeniedPage();
return reject();
}
})
.catch((e) => {
window.location.href = '#/access-denied';
.catch(async (e) => {
await redirectToMlAccessDeniedPage();
return reject();
});
});
}

export function checkCreateJobsCapabilitiesResolver(): Promise<MlCapabilities> {
export function checkCreateJobsCapabilitiesResolver(
redirectToJobsManagementPage: () => Promise<void>
): Promise<MlCapabilities> {
return new Promise((resolve, reject) => {
getCapabilities()
.then(({ capabilities, isPlatinumOrTrialLicense }) => {
.then(async ({ capabilities, isPlatinumOrTrialLicense }) => {
_capabilities = capabilities;
// if the license is basic (isPlatinumOrTrialLicense === false) then do not redirect,
// allow the promise to resolve as the separate license check will redirect then user to
Expand All @@ -69,34 +73,36 @@ export function checkCreateJobsCapabilitiesResolver(): Promise<MlCapabilities> {
return resolve(_capabilities);
} else {
// if the user has no permission to create a job,
// redirect them back to the Transforms Management page
window.location.href = '#/jobs';
// redirect them back to the Anomaly Detection Management page
await redirectToJobsManagementPage();
return reject();
}
})
.catch((e) => {
window.location.href = '#/jobs';
.catch(async (e) => {
await redirectToJobsManagementPage();
return reject();
});
});
}

export function checkFindFileStructurePrivilegeResolver(): Promise<MlCapabilities> {
export function checkFindFileStructurePrivilegeResolver(
redirectToMlAccessDeniedPage: () => Promise<void>
): Promise<MlCapabilities> {
return new Promise((resolve, reject) => {
getCapabilities()
.then(({ capabilities }) => {
.then(async ({ capabilities }) => {
_capabilities = capabilities;
// the minimum privilege for using ML with a basic license is being able to use the datavisualizer.
// all other functionality is controlled by the return _capabilities object
if (_capabilities.canFindFileStructure) {
return resolve(_capabilities);
} else {
window.location.href = '#/access-denied';
await redirectToMlAccessDeniedPage();
return reject();
}
})
.catch((e) => {
window.location.href = '#/access-denied';
.catch(async (e) => {
await redirectToMlAccessDeniedPage();
return reject();
});
});
Expand Down
Loading

0 comments on commit 5e08831

Please sign in to comment.