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] Using data views service for loading data views #113961

Merged
Show file tree
Hide file tree
Changes from 12 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
2 changes: 0 additions & 2 deletions x-pack/plugins/ml/common/types/kibana.ts
Original file line number Diff line number Diff line change
Expand Up @@ -8,7 +8,6 @@
// custom edits or fixes for default kibana types which are incomplete

import type { SimpleSavedObject } from 'kibana/public';
import type { IndexPatternAttributes } from 'src/plugins/data/common';
import type { FieldFormatsRegistry } from '../../../../../src/plugins/field_formats/common';

export type IndexPatternTitle = string;
Expand All @@ -18,7 +17,6 @@ export interface Route {
k7Breadcrumbs: () => any;
}

export type IndexPatternSavedObject = SimpleSavedObject<IndexPatternAttributes>;
// TODO define saved object type
export type SavedSearchSavedObject = SimpleSavedObject<any>;

Expand Down
1 change: 1 addition & 0 deletions x-pack/plugins/ml/kibana.json
Original file line number Diff line number Diff line change
Expand Up @@ -8,6 +8,7 @@
],
"requiredPlugins": [
"data",
"dataViews",
"cloud",
"features",
"dataVisualizer",
Expand Down
1 change: 1 addition & 0 deletions x-pack/plugins/ml/public/application/app.tsx
Original file line number Diff line number Diff line change
Expand Up @@ -135,6 +135,7 @@ export const renderApp = (
urlGenerators: deps.share.urlGenerators,
maps: deps.maps,
dataVisualizer: deps.dataVisualizer,
dataViews: deps.data.dataViews,
});

appMountParams.onAppLeave((actions) => actions.default());
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -19,12 +19,9 @@ import { i18n } from '@kbn/i18n';

import { CoreSetup } from 'src/core/public';

import {
IndexPattern,
IFieldType,
ES_FIELD_TYPES,
KBN_FIELD_TYPES,
} from '../../../../../../../src/plugins/data/public';
import { ES_FIELD_TYPES, KBN_FIELD_TYPES } from '../../../../../../../src/plugins/data/public';

import type { DataView, DataViewField } from '../../../../../../../src/plugins/data_views/common';

import { DEFAULT_RESULTS_FIELD } from '../../../../common/constants/data_frame_analytics';
import { extractErrorMessage } from '../../../../common/util/errors';
Expand Down Expand Up @@ -72,7 +69,7 @@ export const euiDataGridToolbarSettings = {
showFullScreenSelector: false,
};

export const getFieldsFromKibanaIndexPattern = (indexPattern: IndexPattern): string[] => {
export const getFieldsFromKibanaIndexPattern = (indexPattern: DataView): string[] => {
const allFields = indexPattern.fields.map((f) => f.name);
const indexPatternFields: string[] = allFields.filter((f) => {
if (indexPattern.metaFields.includes(f)) {
Expand All @@ -98,7 +95,7 @@ export const getFieldsFromKibanaIndexPattern = (indexPattern: IndexPattern): str
* @param RuntimeMappings
*/
export function getCombinedRuntimeMappings(
indexPattern: IndexPattern | undefined,
indexPattern: DataView | undefined,
runtimeMappings?: RuntimeMappings
): RuntimeMappings | undefined {
let combinedRuntimeMappings = {};
Expand Down Expand Up @@ -219,7 +216,7 @@ export const getDataGridSchemaFromESFieldType = (
};

export const getDataGridSchemaFromKibanaFieldType = (
field: IFieldType | undefined
field: DataViewField | undefined
): string | undefined => {
// Built-in values are ['boolean', 'currency', 'datetime', 'numeric', 'json']
// To fall back to the default string schema it needs to be undefined.
Expand Down Expand Up @@ -312,7 +309,7 @@ export const getTopClasses = (row: Record<string, any>, mlResultsField: string):
};

export const useRenderCellValue = (
indexPattern: IndexPattern | undefined,
indexPattern: DataView | undefined,
pagination: IndexPagination,
tableItems: DataGridItem[],
resultsField?: string,
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -7,10 +7,10 @@

import { FC } from 'react';
import { SavedSearchSavedObject } from '../../../../common/types/kibana';
import type { IIndexPattern } from '../../../../../../../src/plugins/data/public';
import type { DataView } from '../../../../../../../src/plugins/data_views/public';

declare const DataRecognizer: FC<{
indexPattern: IIndexPattern;
indexPattern: DataView;
savedSearch: SavedSearchSavedObject | null;
results: {
count: number;
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -8,15 +8,15 @@
import React from 'react';
import { shallowWithIntl } from '@kbn/test/jest';
import { FullTimeRangeSelector } from './index';
import { Query } from 'src/plugins/data/public';
import { IndexPattern } from '../../../../../../../src/plugins/data/public';
import type { Query } from 'src/plugins/data/public';
import type { DataView } from '../../../../../../../src/plugins/data_views/public';

// Create a mock for the setFullTimeRange function in the service.
// The mock is hoisted to the top, so need to prefix the mock function
// with 'mock' so it can be used lazily.
const mockSetFullTimeRange = jest.fn((indexPattern: IndexPattern, query: Query) => true);
const mockSetFullTimeRange = jest.fn((indexPattern: DataView, query: Query) => true);
jest.mock('./full_time_range_selector_service', () => ({
setFullTimeRange: (indexPattern: IndexPattern, query: Query) =>
setFullTimeRange: (indexPattern: DataView, query: Query) =>
mockSetFullTimeRange(indexPattern, query),
}));

Expand All @@ -26,7 +26,7 @@ describe('FullTimeRangeSelector', () => {
fields: [],
title: 'test-index-pattern',
timeFieldName: '@timestamp',
} as unknown as IndexPattern;
} as unknown as DataView;

const query: Query = {
language: 'kuery',
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -8,12 +8,13 @@
import React, { FC } from 'react';

import { FormattedMessage } from '@kbn/i18n/react';
import { Query, IndexPattern } from 'src/plugins/data/public';
import type { Query } from 'src/plugins/data/public';
import { EuiButton } from '@elastic/eui';
import type { DataView } from '../../../../../../../src/plugins/data_views/public';
import { setFullTimeRange } from './full_time_range_selector_service';

interface Props {
indexPattern: IndexPattern;
indexPattern: DataView;
query: Query;
disabled: boolean;
callback?: (a: any) => void;
Expand All @@ -23,7 +24,7 @@ interface Props {
// to the time range of data in the index(es) mapped to the supplied Kibana index pattern or query.
export const FullTimeRangeSelector: FC<Props> = ({ indexPattern, query, disabled, callback }) => {
// wrapper around setFullTimeRange to allow for the calling of the optional callBack prop
async function setRange(i: IndexPattern, q: Query) {
async function setRange(i: DataView, q: Query) {
const fullTimeRange = await setFullTimeRange(i, q);
if (typeof callback === 'function') {
callback(fullTimeRange);
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -8,11 +8,11 @@
import moment from 'moment';

import { i18n } from '@kbn/i18n';
import { Query } from 'src/plugins/data/public';
import type { Query } from 'src/plugins/data/public';
import dateMath from '@elastic/datemath';
import { getTimefilter, getToastNotifications } from '../../util/dependency_cache';
import { ml, GetTimeFieldRangeResponse } from '../../services/ml_api_service';
import { IndexPattern } from '../../../../../../../src/plugins/data/public';
import type { DataView } from '../../../../../../../src/plugins/data_views/public';
import { isPopulatedObject } from '../../../../common/util/object_utils';
import { RuntimeMappings } from '../../../../common/types/fields';

Expand All @@ -22,7 +22,7 @@ export interface TimeRange {
}

export async function setFullTimeRange(
indexPattern: IndexPattern,
indexPattern: DataView,
query: Query
): Promise<GetTimeFieldRangeResponse> {
try {
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -24,7 +24,7 @@ import {

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

import { IndexPattern } from '../../../../../../../src/plugins/data/public';
import { DataView } from '../../../../../../../src/plugins/data_views/public';
import { extractErrorMessage } from '../../../../common';
import { isRuntimeMappings } from '../../../../common/util/runtime_field_utils';
import { stringHash } from '../../../../common/util/string_utils';
Expand Down Expand Up @@ -89,7 +89,7 @@ export interface ScatterplotMatrixProps {
legendType?: LegendType;
searchQuery?: ResultsSearchQuery;
runtimeMappings?: RuntimeMappings;
indexPattern?: IndexPattern;
indexPattern?: DataView;
}

export const ScatterplotMatrix: FC<ScatterplotMatrixProps> = ({
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -7,12 +7,12 @@

import { useMemo } from 'react';

import type { IndexPattern } from '../../../../../../../src/plugins/data/public';
import type { DataView } from '../../../../../../../src/plugins/data_views/public';

import { ML__INCREMENTAL_ID } from '../../data_frame_analytics/common/fields';

export const useScatterplotFieldOptions = (
indexPattern?: IndexPattern,
indexPattern?: DataView,
includes?: string[],
excludes?: string[],
resultsField = ''
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -5,10 +5,10 @@
* 2.0.
*/

import { IndexPattern } from '../../../../../../../../src/plugins/data/public';
import type { DataView } from '../../../../../../../../src/plugins/data_views/public';

export const indexPatternMock = {
id: 'the-index-pattern-id',
title: 'the-index-pattern-title',
fields: [],
} as unknown as IndexPattern;
} as unknown as DataView;
Original file line number Diff line number Diff line change
Expand Up @@ -5,7 +5,7 @@
* 2.0.
*/

import { IndexPatternsContract } from '../../../../../../../../src/plugins/data/public';
import type { DataViewsContract } from '../../../../../../../../src/plugins/data_views/public';

export const indexPatternsMock = new (class {
fieldFormats = [];
Expand All @@ -19,4 +19,4 @@ export const indexPatternsMock = new (class {
getIds = jest.fn();
getTitles = jest.fn();
make = jest.fn();
})() as unknown as IndexPatternsContract;
})() as unknown as DataViewsContract;
Original file line number Diff line number Diff line change
Expand Up @@ -6,15 +6,15 @@
*/

import React from 'react';
import { IndexPattern, IndexPatternsContract } from '../../../../../../../src/plugins/data/public';
import { DataView, DataViewsContract } from '../../../../../../../src/plugins/data_views/public';
import { SavedSearchSavedObject } from '../../../../common/types/kibana';
import { MlServicesContext } from '../../app';

export interface MlContextValue {
combinedQuery: any;
currentIndexPattern: IndexPattern; // TODO this should be IndexPattern or null
currentIndexPattern: DataView; // TODO this should be IndexPattern or null
currentSavedSearch: SavedSearchSavedObject | null;
indexPatterns: IndexPatternsContract;
indexPatterns: DataViewsContract;
kibanaConfig: any; // IUiSettingsClient;
kibanaVersion: string;
}
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -9,7 +9,7 @@ import { useEffect, useState } from 'react';

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

import { IndexPattern } from '../../../../../../../src/plugins/data/public';
import type { DataView } from '../../../../../../../src/plugins/data_views/public';

import { extractErrorMessage } from '../../../../common/util/errors';

Expand All @@ -34,7 +34,7 @@ export const useResultsViewConfig = (jobId: string) => {
const mlContext = useMlContext();
const trainedModelsApiService = useTrainedModelsApiService();

const [indexPattern, setIndexPattern] = useState<IndexPattern | undefined>(undefined);
const [indexPattern, setIndexPattern] = useState<DataView | undefined>(undefined);
const [indexPatternErrorMessage, setIndexPatternErrorMessage] = useState<undefined | string>(
undefined
);
Expand Down Expand Up @@ -99,7 +99,7 @@ export const useResultsViewConfig = (jobId: string) => {
? jobConfigUpdate.dest.index[0]
: jobConfigUpdate.dest.index;
const destIndexPatternId = getIndexPatternIdFromName(destIndex) || destIndex;
let indexP: IndexPattern | undefined;
let indexP: DataView | undefined;

try {
indexP = await mlContext.indexPatterns.get(destIndexPatternId);
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -11,7 +11,7 @@ import { estypes } from '@elastic/elasticsearch';
import { EuiDataGridColumn } from '@elastic/eui';
import { CoreSetup } from 'src/core/public';

import { IndexPattern } from '../../../../../../../../../src/plugins/data/public';
import type { DataView } from '../../../../../../../../../src/plugins/data_views/public';
import { isRuntimeMappings } from '../../../../../../common/util/runtime_field_utils';
import { RuntimeMappings } from '../../../../../../common/types/fields';
import { DEFAULT_SAMPLER_SHARD_SIZE } from '../../../../../../common/constants/field_histograms';
Expand Down Expand Up @@ -52,13 +52,14 @@ function getRuntimeFieldColumns(runtimeMappings: RuntimeMappings) {
});
}

function getIndexPatternColumns(indexPattern: IndexPattern, fieldsFilter: string[]) {
function getIndexPatternColumns(indexPattern: DataView, fieldsFilter: string[]) {
const { fields } = newJobCapsServiceAnalytics;

return fields
.filter((field) => fieldsFilter.includes(field.name))
.map((field) => {
const schema =
// @ts-expect-error field is not DataViewField
getDataGridSchemaFromESFieldType(field.type) || getDataGridSchemaFromKibanaFieldType(field);

return {
Expand All @@ -71,7 +72,7 @@ function getIndexPatternColumns(indexPattern: IndexPattern, fieldsFilter: string
}

export const useIndexData = (
indexPattern: IndexPattern,
indexPattern: DataView,
query: Record<string, any> | undefined,
toastNotifications: CoreSetup['notifications']['toasts'],
runtimeMappings?: RuntimeMappings
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -12,7 +12,7 @@ import { FormattedMessage } from '@kbn/i18n/react';

import { EuiDataGridColumn, EuiSpacer, EuiText } from '@elastic/eui';

import { IndexPattern } from '../../../../../../../../../../src/plugins/data/public';
import type { DataView } from '../../../../../../../../../../src/plugins/data_views/public';

import {
isClassificationAnalysis,
Expand Down Expand Up @@ -104,7 +104,7 @@ const getResultsSectionHeaderItems = (
interface ExpandableSectionResultsProps {
colorRange?: ReturnType<typeof useColorRange>;
indexData: UseIndexDataReturnType;
indexPattern?: IndexPattern;
indexPattern?: DataView;
jobConfig?: DataFrameAnalyticsConfig;
needsDestIndexPattern: boolean;
searchQuery: SavedSearchQuery;
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -13,7 +13,7 @@ import { debounce } from 'lodash';
import { fromKueryExpression, luceneStringToDsl, toElasticsearchQuery } from '@kbn/es-query';
import { estypes } from '@elastic/elasticsearch';
import { Dictionary } from '../../../../../../../common/types/common';
import { IIndexPattern } from '../../../../../../../../../../src/plugins/data/common';
import { DataView } from '../../../../../../../../../../src/plugins/data_views/common';
import { Query, QueryStringInput } from '../../../../../../../../../../src/plugins/data/public';

import {
Expand All @@ -29,7 +29,7 @@ interface ErrorMessage {
}

export interface ExplorationQueryBarProps {
indexPattern: IIndexPattern;
indexPattern: DataView;
setSearchQuery: (update: {
queryString: string;
query?: SavedSearchQuery;
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -7,7 +7,7 @@

import React, { FC } from 'react';

import { IndexPattern } from '../../../../../../../../../../src/plugins/data/public';
import type { DataView } from '../../../../../../../../../../src/plugins/data_views/public';

import { getToastNotifications } from '../../../../../util/dependency_cache';
import { useMlKibana } from '../../../../../contexts/kibana';
Expand All @@ -22,7 +22,7 @@ import { ExpandableSectionResults } from '../expandable_section';
import { useExplorationResults } from './use_exploration_results';

interface Props {
indexPattern: IndexPattern;
indexPattern: DataView;
jobConfig: DataFrameAnalyticsConfig;
jobStatus?: DataFrameTaskStateType;
needsDestIndexPattern: boolean;
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -13,7 +13,7 @@ import { CoreSetup } from 'src/core/public';

import { i18n } from '@kbn/i18n';
import { MlApiServices } from '../../../../../services/ml_api_service';
import { IndexPattern } from '../../../../../../../../../../src/plugins/data/public';
import type { DataView } from '../../../../../../../../../../src/plugins/data_views/public';

import { DataLoader } from '../../../../../datavisualizer/index_based/data_loader';

Expand Down Expand Up @@ -41,7 +41,7 @@ import { FeatureImportanceBaseline } from '../../../../../../../common/types/fea
import { useExplorationDataGrid } from './use_exploration_data_grid';

export const useExplorationResults = (
indexPattern: IndexPattern | undefined,
indexPattern: DataView | undefined,
jobConfig: DataFrameAnalyticsConfig | undefined,
searchQuery: SavedSearchQuery,
toastNotifications: CoreSetup['notifications']['toasts'],
Expand Down
Loading