[ML] Consolidating shared types and util functions (#65247)

* [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>
This commit is contained in:
James Gowdy 2020-05-07 12:23:42 +01:00 committed by GitHub
parent 3604f5d21a
commit 55e4c7f9a7
No known key found for this signature in database
GPG key ID: 4AEE18F83AFDEB23
24 changed files with 57 additions and 40 deletions

View file

@ -9,8 +9,6 @@ import React from 'react';
import { EuiToolTip } from '@elastic/eui'; 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 { getMLJobTypeAriaLabel } from '../../util/field_types_utils';
import { ML_JOB_FIELD_TYPES } from '../../../../common/constants/field_types'; import { ML_JOB_FIELD_TYPES } from '../../../../common/constants/field_types';
import { i18n } from '@kbn/i18n'; import { i18n } from '@kbn/i18n';

View file

@ -14,8 +14,6 @@ import PropTypes from 'prop-types';
import { EuiCallOut } from '@elastic/eui'; 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'; import { MESSAGE_LEVEL } from '../../../../common/constants/message_levels';
function getCallOutAttributes(message, status) { function getCallOutAttributes(message, status) {

View file

@ -30,8 +30,6 @@ import { FormattedMessage } from '@kbn/i18n/react';
import { getDocLinks } from '../../util/dependency_cache'; 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 { VALIDATION_STATUS } from '../../../../common/constants/validation';
import { getMostSevereMessageStatus } from '../../../../common/util/validation_utils'; import { getMostSevereMessageStatus } from '../../../../common/util/validation_utils';

View file

@ -5,6 +5,7 @@
*/ */
import { isEqual } from 'lodash'; import { isEqual } from 'lodash';
// @ts-ignore
import numeral from '@elastic/numeral'; import numeral from '@elastic/numeral';
import { ml } from '../../../../services/ml_api_service'; import { ml } from '../../../../services/ml_api_service';
import { AnalysisResult, InputOverrides } from '../../../../../../common/types/file_datavisualizer'; import { AnalysisResult, InputOverrides } from '../../../../../../common/types/file_datavisualizer';

View file

@ -17,8 +17,6 @@ import d3 from 'd3';
import $ from 'jquery'; import $ from 'jquery';
import moment from 'moment'; 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 { formatHumanReadableDateTime } from '../../util/date_utils';
import { formatValue } from '../../formatters/format_value'; import { formatValue } from '../../formatters/format_value';
import { getSeverityColor, getSeverityWithLow } from '../../../../common/util/anomaly_utils'; import { getSeverityColor, getSeverityWithLow } from '../../../../common/util/anomaly_utils';

View file

@ -17,8 +17,6 @@ import d3 from 'd3';
import $ from 'jquery'; import $ from 'jquery';
import moment from 'moment'; 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 { formatHumanReadableDateTime } from '../../util/date_utils';
import { formatValue } from '../../formatters/format_value'; import { formatValue } from '../../formatters/format_value';
import { import {

View file

@ -14,8 +14,6 @@ import _ from 'lodash';
import d3 from 'd3'; import d3 from 'd3';
import moment from 'moment'; 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 { i18n } from '@kbn/i18n';
import { Subscription } from 'rxjs'; import { Subscription } from 'rxjs';
import { TooltipValue } from '@elastic/charts'; import { TooltipValue } from '@elastic/charts';

View file

@ -15,8 +15,6 @@ import React, { Component } from 'react';
import { EuiButton, EuiToolTip } from '@elastic/eui'; 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 { FORECAST_REQUEST_STATE, JOB_STATE } from '../../../../../common/constants/states';
import { MESSAGE_LEVEL } from '../../../../../common/constants/message_levels'; import { MESSAGE_LEVEL } from '../../../../../common/constants/message_levels';
import { isJobVersionGte } from '../../../../../common/util/job_utils'; import { isJobVersionGte } from '../../../../../common/util/job_utils';

View file

@ -23,8 +23,6 @@ import {
EuiToolTip, EuiToolTip,
} from '@elastic/eui'; } 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 { JOB_STATE } from '../../../../../common/constants/states';
import { FORECAST_DURATION_MAX_DAYS } from './forecasting_modal'; import { FORECAST_DURATION_MAX_DAYS } from './forecasting_modal';
import { ForecastProgress } from './forecast_progress'; import { ForecastProgress } from './forecast_progress';

View file

@ -13,7 +13,6 @@ import {
MlSetupDependencies, MlSetupDependencies,
MlStartDependencies, MlStartDependencies,
} from './plugin'; } from './plugin';
import { getMetricChangeDescription } from './application/formatters/metric_change_description';
export const plugin: PluginInitializer< export const plugin: PluginInitializer<
MlPluginSetup, MlPluginSetup,
@ -22,4 +21,5 @@ export const plugin: PluginInitializer<
MlStartDependencies MlStartDependencies
> = () => new MlPlugin(); > = () => new MlPlugin();
export { MlPluginSetup, MlPluginStart, getMetricChangeDescription }; export { MlPluginSetup, MlPluginStart };
export * from './shared';

View file

@ -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';

View file

@ -7,5 +7,6 @@
import { PluginInitializerContext } from 'kibana/server'; import { PluginInitializerContext } from 'kibana/server';
import { MlServerPlugin } from './plugin'; import { MlServerPlugin } from './plugin';
export { MlPluginSetup, MlPluginStart } from './plugin'; export { MlPluginSetup, MlPluginStart } from './plugin';
export * from './shared';
export const plugin = (ctx: PluginInitializerContext) => new MlServerPlugin(ctx); export const plugin = (ctx: PluginInitializerContext) => new MlServerPlugin(ctx);

View file

@ -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';

View file

@ -4,7 +4,7 @@
* you may not use this file except in compliance with the Elastic License. * 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'; import { MlError } from '../ml/types';
export interface Group { export interface Group {

View file

@ -6,7 +6,7 @@
import { SearchResponse, SearchParams } from 'elasticsearch'; import { SearchResponse, SearchParams } from 'elasticsearch';
import { AnomalyRecordDoc as Anomaly } from '../../../../ml/common/types/anomalies'; import { AnomalyRecordDoc as Anomaly } from '../../../../ml/server';
export { Anomaly }; export { Anomaly };
export type AnomalyResults = SearchResponse<Anomaly>; export type AnomalyResults = SearchResponse<Anomaly>;

View file

@ -14,8 +14,8 @@ export const useRequest = jest.fn(() => ({
})); }));
// just passing through the reimports // just passing through the reimports
export { getErrorMessage } from '../../../ml/common/util/errors';
export { export {
getErrorMessage,
getDataGridSchemaFromKibanaFieldType, getDataGridSchemaFromKibanaFieldType,
getFieldsFromKibanaIndexPattern, getFieldsFromKibanaIndexPattern,
multiColumnSortFactory, multiColumnSortFactory,
@ -27,5 +27,5 @@ export {
SearchResponse7, SearchResponse7,
UseDataGridReturnType, UseDataGridReturnType,
UseIndexDataReturnType, UseIndexDataReturnType,
} from '../../../ml/public/application/components/data_grid'; INDEX_STATUS,
export { INDEX_STATUS } from '../../../ml/public/application/data_frame_analytics/common'; } from '../../../ml/public';

View file

@ -4,7 +4,7 @@
* you may not use this file except in compliance with the Elastic License. * 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; export type AggName = string;

View file

@ -16,9 +16,8 @@ export {
useRequest, useRequest,
} from '../../../../src/plugins/es_ui_shared/public/request/np_ready_request'; } from '../../../../src/plugins/es_ui_shared/public/request/np_ready_request';
export { getErrorMessage } from '../../ml/common/util/errors';
export { export {
getErrorMessage,
getDataGridSchemaFromKibanaFieldType, getDataGridSchemaFromKibanaFieldType,
getFieldsFromKibanaIndexPattern, getFieldsFromKibanaIndexPattern,
multiColumnSortFactory, multiColumnSortFactory,
@ -30,5 +29,5 @@ export {
SearchResponse7, SearchResponse7,
UseDataGridReturnType, UseDataGridReturnType,
UseIndexDataReturnType, UseIndexDataReturnType,
} from '../../ml/public/application/components/data_grid'; INDEX_STATUS,
export { INDEX_STATUS } from '../../ml/public/application/data_frame_analytics/common'; } from '../../ml/public';

View file

@ -9,11 +9,11 @@ import moment from 'moment';
import { AnnotationTooltipFormatter, RectAnnotation } from '@elastic/charts'; import { AnnotationTooltipFormatter, RectAnnotation } from '@elastic/charts';
import { RectAnnotationDatum } from '@elastic/charts/dist/chart_types/xy_chart/utils/specs'; import { RectAnnotationDatum } from '@elastic/charts/dist/chart_types/xy_chart/utils/specs';
import { AnnotationTooltip } from './annotation_tooltip'; import { AnnotationTooltip } from './annotation_tooltip';
import { ANOMALY_SEVERITY } from '../../../../../../plugins/ml/common/constants/anomalies';
import { import {
ANOMALY_SEVERITY,
getSeverityColor, getSeverityColor,
getSeverityType, getSeverityType,
} from '../../../../../../plugins/ml/common/util/anomaly_utils'; } from '../../../../../../plugins/ml/public';
interface Props { interface Props {
anomalies: any; anomalies: any;

View file

@ -20,7 +20,7 @@ import { getMLJobId } from '../../../state/api/ml_anomaly';
import * as labels from './translations'; import * as labels from './translations';
import { useKibana } from '../../../../../../../src/plugins/kibana_react/public'; import { useKibana } from '../../../../../../../src/plugins/kibana_react/public';
import { ManageMLJobComponent } from './manage_ml_job'; 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'; import { useMonitorId } from '../../../hooks';
export const MLIntegrationComponent = () => { export const MLIntegrationComponent = () => {

View file

@ -20,7 +20,7 @@ import {
} from '../../../state/selectors'; } from '../../../state/selectors';
import { UptimeRefreshContext } from '../../../contexts'; import { UptimeRefreshContext } from '../../../contexts';
import { getMLJobId } from '../../../state/api/ml_anomaly'; 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 { MonitorDurationComponent } from './monitor_duration';
import { MonitorIdParam } from '../../../../common/types'; import { MonitorIdParam } from '../../../../common/types';

View file

@ -6,15 +6,17 @@
import { createAction } from 'redux-actions'; import { createAction } from 'redux-actions';
import { createAsyncAction } from './utils'; import { createAsyncAction } from './utils';
import { MlCapabilitiesResponse } from '../../../../../plugins/ml/common/types/capabilities'; import {
import { AnomaliesTableRecord } from '../../../../../plugins/ml/common/types/anomalies'; MlCapabilitiesResponse,
AnomaliesTableRecord,
JobExistResult,
} from '../../../../../plugins/ml/public';
import { import {
CreateMLJobSuccess, CreateMLJobSuccess,
DeleteJobResults, DeleteJobResults,
MonitorIdParam, MonitorIdParam,
HeartbeatIndicesParam, HeartbeatIndicesParam,
} from './types'; } from './types';
import { JobExistResult } from '../../../../../plugins/ml/common/types/data_recognizer';
export const resetMLState = createAction('RESET_ML_STATE'); export const resetMLState = createAction('RESET_ML_STATE');

View file

@ -8,15 +8,17 @@ import moment from 'moment';
import { apiService } from './utils'; import { apiService } from './utils';
import { AnomalyRecords, AnomalyRecordsParams } from '../actions'; import { AnomalyRecords, AnomalyRecordsParams } from '../actions';
import { API_URLS, ML_JOB_ID, ML_MODULE_ID } from '../../../common/constants'; 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 { import {
CreateMLJobSuccess, CreateMLJobSuccess,
DeleteJobResults, DeleteJobResults,
MonitorIdParam, MonitorIdParam,
HeartbeatIndicesParam, HeartbeatIndicesParam,
} from '../actions/types'; } from '../actions/types';
import { DataRecognizerConfigResponse } from '../../../../../plugins/ml/common/types/modules';
import { JobExistResult } from '../../../../../plugins/ml/common/types/data_recognizer';
const getJobPrefix = (monitorId: string) => { const getJobPrefix = (monitorId: string) => {
// ML App doesn't support upper case characters in job name // ML App doesn't support upper case characters in job name

View file

@ -16,9 +16,8 @@ import {
} from '../actions'; } from '../actions';
import { getAsyncInitialState, handleAsyncAction } from './utils'; import { getAsyncInitialState, handleAsyncAction } from './utils';
import { AsyncInitialState } from './types'; 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 { CreateMLJobSuccess, DeleteJobResults } from '../actions/types';
import { JobExistResult } from '../../../../../plugins/ml/common/types/data_recognizer';
export interface MLJobState { export interface MLJobState {
mlJob: AsyncInitialState<JobExistResult>; mlJob: AsyncInitialState<JobExistResult>;