Skip to content

Commit

Permalink
[ML] Consolidating shared types and util functions (elastic#65247) (e…
Browse files Browse the repository at this point in the history
…lastic#65660)

* [ML] Consolidating shared types and util functions

* including formatter

* adding missing includes

* removing unused export

* ignoring numeral type error

Co-authored-by: Elastic Machine <elasticmachine@users.noreply.github.com>

Co-authored-by: Elastic Machine <elasticmachine@users.noreply.github.com>
  • Loading branch information
jgowdyelastic and elasticmachine committed May 7, 2020
1 parent a15ced2 commit ca05440
Show file tree
Hide file tree
Showing 24 changed files with 57 additions and 40 deletions.
Original file line number Diff line number Diff line change
Expand Up @@ -9,8 +9,6 @@ import React from 'react';

import { EuiToolTip } from '@elastic/eui';

// don't use something like plugins/ml/../common
// because it won't work with the jest tests
import { getMLJobTypeAriaLabel } from '../../util/field_types_utils';
import { ML_JOB_FIELD_TYPES } from '../../../../common/constants/field_types';
import { i18n } from '@kbn/i18n';
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -14,8 +14,6 @@ import PropTypes from 'prop-types';

import { EuiCallOut } from '@elastic/eui';

// don't use something like plugins/ml/../common
// because it won't work with the jest tests
import { MESSAGE_LEVEL } from '../../../../common/constants/message_levels';

function getCallOutAttributes(message, status) {
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -30,8 +30,6 @@ import { FormattedMessage } from '@kbn/i18n/react';

import { getDocLinks } from '../../util/dependency_cache';

// don't use something like plugins/ml/../common
// because it won't work with the jest tests
import { VALIDATION_STATUS } from '../../../../common/constants/validation';
import { getMostSevereMessageStatus } from '../../../../common/util/validation_utils';

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

import { isEqual } from 'lodash';
// @ts-ignore
import numeral from '@elastic/numeral';
import { ml } from '../../../../services/ml_api_service';
import { AnalysisResult, InputOverrides } from '../../../../../../common/types/file_datavisualizer';
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -17,8 +17,6 @@ import d3 from 'd3';
import $ from 'jquery';
import moment from 'moment';

// don't use something like plugins/ml/../common
// because it won't work with the jest tests
import { formatHumanReadableDateTime } from '../../util/date_utils';
import { formatValue } from '../../formatters/format_value';
import { getSeverityColor, getSeverityWithLow } from '../../../../common/util/anomaly_utils';
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -17,8 +17,6 @@ import d3 from 'd3';
import $ from 'jquery';
import moment from 'moment';

// don't use something like plugins/ml/../common
// because it won't work with the jest tests
import { formatHumanReadableDateTime } from '../../util/date_utils';
import { formatValue } from '../../formatters/format_value';
import {
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -14,8 +14,6 @@ import _ from 'lodash';
import d3 from 'd3';
import moment from 'moment';

// don't use something like plugins/ml/../common
// because it won't work with the jest tests
import { i18n } from '@kbn/i18n';
import { Subscription } from 'rxjs';
import { TooltipValue } from '@elastic/charts';
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -15,8 +15,6 @@ import React, { Component } from 'react';

import { EuiButton, EuiToolTip } from '@elastic/eui';

// don't use something like plugins/ml/../common
// because it won't work with the jest tests
import { FORECAST_REQUEST_STATE, JOB_STATE } from '../../../../../common/constants/states';
import { MESSAGE_LEVEL } from '../../../../../common/constants/message_levels';
import { isJobVersionGte } from '../../../../../common/util/job_utils';
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -23,8 +23,6 @@ import {
EuiToolTip,
} from '@elastic/eui';

// don't use something like plugins/ml/../common
// because it won't work with the jest tests
import { JOB_STATE } from '../../../../../common/constants/states';
import { FORECAST_DURATION_MAX_DAYS } from './forecasting_modal';
import { ForecastProgress } from './forecast_progress';
Expand Down
4 changes: 2 additions & 2 deletions x-pack/plugins/ml/public/index.ts
Original file line number Diff line number Diff line change
Expand Up @@ -13,7 +13,6 @@ import {
MlSetupDependencies,
MlStartDependencies,
} from './plugin';
import { getMetricChangeDescription } from './application/formatters/metric_change_description';

export const plugin: PluginInitializer<
MlPluginSetup,
Expand All @@ -22,4 +21,5 @@ export const plugin: PluginInitializer<
MlStartDependencies
> = () => new MlPlugin();

export { MlPluginSetup, MlPluginStart, getMetricChangeDescription };
export { MlPluginSetup, MlPluginStart };
export * from './shared';
22 changes: 22 additions & 0 deletions x-pack/plugins/ml/public/shared.ts
Original file line number Diff line number Diff line change
@@ -0,0 +1,22 @@
/*
* 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.
*/

export * from '../common/constants/anomalies';

export * from '../common/types/data_recognizer';
export * from '../common/types/capabilities';
export * from '../common/types/anomalies';
export * from '../common/types/modules';
export * from '../common/types/audit_message';

export * from '../common/util/anomaly_utils';
export * from '../common/util/errors';
export * from '../common/util/validators';

export * from './application/formatters/metric_change_description';

export * from './application/components/data_grid';
export * from './application/data_frame_analytics/common';
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 @@ -7,5 +7,6 @@
import { PluginInitializerContext } from 'kibana/server';
import { MlServerPlugin } from './plugin';
export { MlPluginSetup, MlPluginStart } from './plugin';
export * from './shared';

export const plugin = (ctx: PluginInitializerContext) => new MlServerPlugin(ctx);
7 changes: 7 additions & 0 deletions x-pack/plugins/ml/server/shared.ts
Original file line number Diff line number Diff line change
@@ -0,0 +1,7 @@
/*
* 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.
*/

export * from '../common/types/anomalies';
2 changes: 1 addition & 1 deletion x-pack/plugins/siem/public/components/ml_popover/types.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 { AuditMessageBase } from '../../../../ml/common/types/audit_message';
import { AuditMessageBase } from '../../../../ml/public';
import { MlError } from '../ml/types';

export interface Group {
Expand Down
2 changes: 1 addition & 1 deletion x-pack/plugins/siem/server/lib/machine_learning/index.ts
Original file line number Diff line number Diff line change
Expand Up @@ -6,7 +6,7 @@

import { SearchResponse, SearchParams } from 'elasticsearch';

import { AnomalyRecordDoc as Anomaly } from '../../../../ml/common/types/anomalies';
import { AnomalyRecordDoc as Anomaly } from '../../../../ml/server';

export { Anomaly };
export type AnomalyResults = SearchResponse<Anomaly>;
Expand Down
6 changes: 3 additions & 3 deletions x-pack/plugins/transform/public/__mocks__/shared_imports.ts
Original file line number Diff line number Diff line change
Expand Up @@ -14,8 +14,8 @@ export const useRequest = jest.fn(() => ({
}));

// just passing through the reimports
export { getErrorMessage } from '../../../ml/common/util/errors';
export {
getErrorMessage,
getDataGridSchemaFromKibanaFieldType,
getFieldsFromKibanaIndexPattern,
multiColumnSortFactory,
Expand All @@ -27,5 +27,5 @@ export {
SearchResponse7,
UseDataGridReturnType,
UseIndexDataReturnType,
} from '../../../ml/public/application/components/data_grid';
export { INDEX_STATUS } from '../../../ml/public/application/data_frame_analytics/common';
INDEX_STATUS,
} from '../../../ml/public';
2 changes: 1 addition & 1 deletion x-pack/plugins/transform/public/app/common/aggregations.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 { composeValidators, patternValidator } from '../../../../ml/common/util/validators';
import { composeValidators, patternValidator } from '../../../../ml/public';

export type AggName = string;

Expand Down
7 changes: 3 additions & 4 deletions x-pack/plugins/transform/public/shared_imports.ts
Original file line number Diff line number Diff line change
Expand Up @@ -16,9 +16,8 @@ export {
useRequest,
} from '../../../../src/plugins/es_ui_shared/public/request/np_ready_request';

export { getErrorMessage } from '../../ml/common/util/errors';

export {
getErrorMessage,
getDataGridSchemaFromKibanaFieldType,
getFieldsFromKibanaIndexPattern,
multiColumnSortFactory,
Expand All @@ -30,5 +29,5 @@ export {
SearchResponse7,
UseDataGridReturnType,
UseIndexDataReturnType,
} from '../../ml/public/application/components/data_grid';
export { INDEX_STATUS } from '../../ml/public/application/data_frame_analytics/common';
INDEX_STATUS,
} from '../../ml/public';
Original file line number Diff line number Diff line change
Expand Up @@ -9,11 +9,11 @@ import moment from 'moment';
import { AnnotationTooltipFormatter, RectAnnotation } from '@elastic/charts';
import { RectAnnotationDatum } from '@elastic/charts/dist/chart_types/xy_chart/utils/specs';
import { AnnotationTooltip } from './annotation_tooltip';
import { ANOMALY_SEVERITY } from '../../../../../../plugins/ml/common/constants/anomalies';
import {
ANOMALY_SEVERITY,
getSeverityColor,
getSeverityType,
} from '../../../../../../plugins/ml/common/util/anomaly_utils';
} from '../../../../../../plugins/ml/public';

interface Props {
anomalies: any;
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -20,7 +20,7 @@ import { getMLJobId } from '../../../state/api/ml_anomaly';
import * as labels from './translations';
import { useKibana } from '../../../../../../../src/plugins/kibana_react/public';
import { ManageMLJobComponent } from './manage_ml_job';
import { JobStat } from '../../../../../../plugins/ml/common/types/data_recognizer';
import { JobStat } from '../../../../../../plugins/ml/public';
import { useMonitorId } from '../../../hooks';

export const MLIntegrationComponent = () => {
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -20,7 +20,7 @@ import {
} from '../../../state/selectors';
import { UptimeRefreshContext } from '../../../contexts';
import { getMLJobId } from '../../../state/api/ml_anomaly';
import { JobStat } from '../../../../../ml/common/types/data_recognizer';
import { JobStat } from '../../../../../ml/public';
import { MonitorDurationComponent } from './monitor_duration';
import { MonitorIdParam } from '../../../../common/types';

Expand Down
8 changes: 5 additions & 3 deletions x-pack/plugins/uptime/public/state/actions/ml_anomaly.ts
Original file line number Diff line number Diff line change
Expand Up @@ -6,15 +6,17 @@

import { createAction } from 'redux-actions';
import { createAsyncAction } from './utils';
import { MlCapabilitiesResponse } from '../../../../../plugins/ml/common/types/capabilities';
import { AnomaliesTableRecord } from '../../../../../plugins/ml/common/types/anomalies';
import {
MlCapabilitiesResponse,
AnomaliesTableRecord,
JobExistResult,
} from '../../../../../plugins/ml/public';
import {
CreateMLJobSuccess,
DeleteJobResults,
MonitorIdParam,
HeartbeatIndicesParam,
} from './types';
import { JobExistResult } from '../../../../../plugins/ml/common/types/data_recognizer';

export const resetMLState = createAction('RESET_ML_STATE');

Expand Down
8 changes: 5 additions & 3 deletions x-pack/plugins/uptime/public/state/api/ml_anomaly.ts
Original file line number Diff line number Diff line change
Expand Up @@ -8,15 +8,17 @@ import moment from 'moment';
import { apiService } from './utils';
import { AnomalyRecords, AnomalyRecordsParams } from '../actions';
import { API_URLS, ML_JOB_ID, ML_MODULE_ID } from '../../../common/constants';
import { MlCapabilitiesResponse } from '../../../../../plugins/ml/common/types/capabilities';
import {
MlCapabilitiesResponse,
DataRecognizerConfigResponse,
JobExistResult,
} from '../../../../../plugins/ml/public';
import {
CreateMLJobSuccess,
DeleteJobResults,
MonitorIdParam,
HeartbeatIndicesParam,
} from '../actions/types';
import { DataRecognizerConfigResponse } from '../../../../../plugins/ml/common/types/modules';
import { JobExistResult } from '../../../../../plugins/ml/common/types/data_recognizer';

const getJobPrefix = (monitorId: string) => {
// ML App doesn't support upper case characters in job name
Expand Down
3 changes: 1 addition & 2 deletions x-pack/plugins/uptime/public/state/reducers/ml_anomaly.ts
Original file line number Diff line number Diff line change
Expand Up @@ -16,9 +16,8 @@ import {
} from '../actions';
import { getAsyncInitialState, handleAsyncAction } from './utils';
import { AsyncInitialState } from './types';
import { MlCapabilitiesResponse } from '../../../../../plugins/ml/common/types/capabilities';
import { MlCapabilitiesResponse, JobExistResult } from '../../../../../plugins/ml/public';
import { CreateMLJobSuccess, DeleteJobResults } from '../actions/types';
import { JobExistResult } from '../../../../../plugins/ml/common/types/data_recognizer';

export interface MLJobState {
mlJob: AsyncInitialState<JobExistResult>;
Expand Down

0 comments on commit ca05440

Please sign in to comment.