Skip to content

Commit

Permalink
[Logs UI][Metrics UI] Replace usage of deprecated IndexPattern types (#…
Browse files Browse the repository at this point in the history
…114448)

* [Logs UI][Metrics UI] Replace usage of deprecated IndexPattern types (#107887)
  • Loading branch information
miltonhultgren authored Oct 12, 2021
1 parent ab5ecc4 commit 8ea719c
Show file tree
Hide file tree
Showing 24 changed files with 69 additions and 75 deletions.
18 changes: 6 additions & 12 deletions x-pack/plugins/infra/common/dependency_mocks/index_patterns.ts
Original file line number Diff line number Diff line change
Expand Up @@ -7,17 +7,11 @@

import { from, of } from 'rxjs';
import { delay } from 'rxjs/operators';
import {
fieldList,
FieldSpec,
IIndexPattern,
IndexPattern,
IndexPatternsContract,
RuntimeField,
} from 'src/plugins/data/common';
import { DataView, DataViewsContract } from '../../../../../src/plugins/data_views/common';
import { fieldList, FieldSpec, RuntimeField } from '../../../../../src/plugins/data/common';

type IndexPatternMock = Pick<
IndexPattern,
DataView,
| 'fields'
| 'getComputedFields'
| 'getFieldByName'
Expand All @@ -27,7 +21,7 @@ type IndexPatternMock = Pick<
| 'title'
| 'type'
>;
type IndexPatternMockSpec = Pick<IIndexPattern, 'id' | 'title' | 'type' | 'timeFieldName'> & {
type IndexPatternMockSpec = Pick<DataView, 'id' | 'title' | 'type' | 'timeFieldName'> & {
fields: FieldSpec[];
};

Expand Down Expand Up @@ -71,8 +65,8 @@ export const createIndexPatternsMock = (
asyncDelay: number,
indexPatterns: IndexPatternMock[]
): {
getIdsWithTitle: IndexPatternsContract['getIdsWithTitle'];
get: (...args: Parameters<IndexPatternsContract['get']>) => Promise<IndexPatternMock>;
getIdsWithTitle: DataViewsContract['getIdsWithTitle'];
get: (...args: Parameters<DataViewsContract['get']>) => Promise<IndexPatternMock>;
} => {
return {
async getIdsWithTitle(_refresh?: boolean) {
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -6,7 +6,7 @@
*/

import { estypes } from '@elastic/elasticsearch';
import { IndexPattern, IndexPatternsContract } from '../../../../../src/plugins/data/common';
import { DataView, DataViewsContract } from '../../../../../src/plugins/data_views/common';
import { ObjectEntries } from '../utility_types';
import { ResolveLogSourceConfigurationError } from './errors';
import {
Expand All @@ -21,14 +21,14 @@ export interface ResolvedLogSourceConfiguration {
timestampField: string;
tiebreakerField: string;
messageField: string[];
fields: IndexPattern['fields'];
fields: DataView['fields'];
runtimeMappings: estypes.MappingRuntimeFields;
columns: LogSourceColumnConfiguration[];
}

export const resolveLogSourceConfiguration = async (
sourceConfiguration: LogSourceConfigurationProperties,
indexPatternsService: IndexPatternsContract
indexPatternsService: DataViewsContract
): Promise<ResolvedLogSourceConfiguration> => {
if (sourceConfiguration.logIndices.type === 'index_name') {
return await resolveLegacyReference(sourceConfiguration, indexPatternsService);
Expand All @@ -39,7 +39,7 @@ export const resolveLogSourceConfiguration = async (

const resolveLegacyReference = async (
sourceConfiguration: LogSourceConfigurationProperties,
indexPatternsService: IndexPatternsContract
indexPatternsService: DataViewsContract
): Promise<ResolvedLogSourceConfiguration> => {
if (sourceConfiguration.logIndices.type !== 'index_name') {
throw new Error('This function can only resolve legacy references');
Expand Down Expand Up @@ -74,7 +74,7 @@ const resolveLegacyReference = async (

const resolveKibanaIndexPatternReference = async (
sourceConfiguration: LogSourceConfigurationProperties,
indexPatternsService: IndexPatternsContract
indexPatternsService: DataViewsContract
): Promise<ResolvedLogSourceConfiguration> => {
if (sourceConfiguration.logIndices.type !== 'index_pattern') {
throw new Error('This function can only resolve Kibana Index Pattern references');
Expand Down Expand Up @@ -103,7 +103,7 @@ const resolveKibanaIndexPatternReference = async (
};

// this might take other sources of runtime fields into account in the future
const resolveRuntimeMappings = (indexPattern: IndexPattern): estypes.MappingRuntimeFields => {
const resolveRuntimeMappings = (indexPattern: DataView): estypes.MappingRuntimeFields => {
const { runtimeFields } = indexPattern.getComputedFields();

const runtimeMappingsFromIndexPattern = (
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -9,7 +9,7 @@ import { mountWithIntl, nextTick } from '@kbn/test/jest';
// We are using this inside a `jest.mock` call. Jest requires dynamic dependencies to be prefixed with `mock`
import { coreMock as mockCoreMock } from 'src/core/public/mocks';
import { MetricExpression } from '../types';
import { IIndexPattern } from 'src/plugins/data/public';
import { DataViewBase } from '@kbn/es-query';
import { MetricsSourceConfiguration } from '../../../../common/metrics_sources';
import React from 'react';
import { ExpressionChart } from './expression_chart';
Expand Down Expand Up @@ -40,7 +40,7 @@ jest.mock('../hooks/use_metrics_explorer_chart_data', () => ({

describe('ExpressionChart', () => {
async function setup(expression: MetricExpression, filterQuery?: string, groupBy?: string) {
const derivedIndexPattern: IIndexPattern = {
const derivedIndexPattern: DataViewBase = {
title: 'metricbeat-*',
fields: [],
};
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -10,7 +10,7 @@ import { Axis, Chart, niceTimeFormatter, Position, Settings } from '@elastic/cha
import { first, last } from 'lodash';
import { EuiText } from '@elastic/eui';
import { FormattedMessage } from '@kbn/i18n/react';
import { IIndexPattern } from 'src/plugins/data/public';
import { DataViewBase } from '@kbn/es-query';
import { MetricsSourceConfiguration } from '../../../../common/metrics_sources';
import { Color } from '../../../../common/color_palette';
import { MetricsExplorerRow, MetricsExplorerAggregation } from '../../../../common/http_api';
Expand All @@ -34,7 +34,7 @@ import { ThresholdAnnotations } from '../../common/criterion_preview_chart/thres

interface Props {
expression: MetricExpression;
derivedIndexPattern: IIndexPattern;
derivedIndexPattern: DataViewBase;
source: MetricsSourceConfiguration | null;
filterQuery?: string;
groupBy?: string | string[];
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -5,7 +5,7 @@
* 2.0.
*/

import { IIndexPattern } from 'src/plugins/data/public';
import { DataViewBase } from '@kbn/es-query';
import { useMemo } from 'react';
import { MetricsSourceConfiguration } from '../../../../common/metrics_sources';
import { MetricExpression } from '../types';
Expand All @@ -14,7 +14,7 @@ import { useMetricsExplorerData } from '../../../pages/metrics/metrics_explorer/

export const useMetricsExplorerChartData = (
expression: MetricExpression,
derivedIndexPattern: IIndexPattern,
derivedIndexPattern: DataViewBase,
source: MetricsSourceConfiguration | null,
filterQuery?: string,
groupBy?: string | string[]
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -8,7 +8,8 @@
import createContainer from 'constate';
import { useCallback, useState } from 'react';
import useDebounce from 'react-use/lib/useDebounce';
import { esQuery, IIndexPattern, Query } from '../../../../../../../src/plugins/data/public';
import { DataViewBase } from '@kbn/es-query';
import { esQuery, Query } from '../../../../../../../src/plugins/data/public';

type ParsedQuery = ReturnType<typeof esQuery.buildEsQuery>;

Expand All @@ -33,7 +34,7 @@ const initialLogFilterState: ILogFilterState = {

const validationDebounceTimeout = 1000; // milliseconds

export const useLogFilterState = ({ indexPattern }: { indexPattern: IIndexPattern }) => {
export const useLogFilterState = ({ indexPattern }: { indexPattern: DataViewBase }) => {
const [logFilterState, setLogFilterState] = useState<ILogFilterState>(initialLogFilterState);

const parseQuery = useCallback(
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -8,7 +8,7 @@
import createContainer from 'constate';
import { useCallback, useMemo, useState } from 'react';
import type { HttpHandler } from 'src/core/public';
import { IndexPatternsContract } from '../../../../../../../src/plugins/data/common';
import { DataViewsContract } from '../../../../../../../src/plugins/data_views/public';
import {
LogIndexField,
LogSourceConfigurationPropertiesPatch,
Expand Down Expand Up @@ -42,7 +42,7 @@ export const useLogSource = ({
}: {
sourceId: string;
fetch: HttpHandler;
indexPatternsService: IndexPatternsContract;
indexPatternsService: DataViewsContract;
}) => {
const [sourceConfiguration, setSourceConfiguration] = useState<
LogSourceConfiguration | undefined
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -6,7 +6,8 @@
*/

import React from 'react';
import { QuerySuggestion, IIndexPattern, DataPublicPluginStart } from 'src/plugins/data/public';
import { DataViewBase } from '@kbn/es-query';
import { QuerySuggestion, DataPublicPluginStart } from 'src/plugins/data/public';
import {
withKibana,
KibanaReactContextValue,
Expand All @@ -21,7 +22,7 @@ interface WithKueryAutocompletionLifecycleProps {
loadSuggestions: (expression: string, cursorPosition: number, maxSuggestions?: number) => void;
suggestions: QuerySuggestion[];
}>;
indexPattern: IIndexPattern;
indexPattern: DataViewBase;
}

interface WithKueryAutocompletionLifecycleState {
Expand Down Expand Up @@ -82,6 +83,7 @@ class WithKueryAutocompletionComponent extends React.Component<
query: expression,
selectionStart: cursorPosition,
selectionEnd: cursorPosition,
// @ts-expect-error (until data service updates to new types)
indexPatterns: [indexPattern],
boolFilter: [],
})) || [];
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -7,7 +7,7 @@

import React, { useContext } from 'react';

import { IIndexPattern } from 'src/plugins/data/public';
import { DataViewBase } from '@kbn/es-query';
import {
MetricsSourceConfigurationProperties,
PartialMetricsSourceConfigurationProperties,
Expand All @@ -21,7 +21,7 @@ interface WithSourceProps {
create: (
sourceProperties: PartialMetricsSourceConfigurationProperties
) => Promise<any> | undefined;
createDerivedIndexPattern: (type: 'metrics') => IIndexPattern;
createDerivedIndexPattern: (type: 'metrics') => DataViewBase;
exists?: boolean;
hasFailed: boolean;
isLoading: boolean;
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -10,23 +10,16 @@ import { from, of } from 'rxjs';
import { delay } from 'rxjs/operators';
import { CoreStart } from '../../../../../src/core/public';
import { FieldSpec } from '../../../../../src/plugins/data/common';
import {
IIndexPattern,
IndexPattern,
IndexPatternField,
IndexPatternsContract,
} from '../../../../../src/plugins/data/public';
import { DataView, DataViewsContract } from '../../../../../src/plugins/data_views/public';
import { DataViewField } from '../../../../../src/plugins/data_views/common';
import { KibanaContextProvider } from '../../../../../src/plugins/kibana_react/public';
import { Pick2 } from '../../common/utility_types';

type MockIndexPattern = Pick<
IndexPattern,
DataView,
'id' | 'title' | 'type' | 'getTimeField' | 'isTimeBased' | 'getFieldByName' | 'getComputedFields'
>;
export type MockIndexPatternSpec = Pick<
IIndexPattern,
'id' | 'title' | 'type' | 'timeFieldName'
> & {
export type MockIndexPatternSpec = Pick<DataView, 'id' | 'title' | 'type' | 'timeFieldName'> & {
fields: FieldSpec[];
};

Expand Down Expand Up @@ -59,8 +52,8 @@ export const createIndexPatternsMock = (
asyncDelay: number,
indexPatterns: MockIndexPattern[]
): {
getIdsWithTitle: IndexPatternsContract['getIdsWithTitle'];
get: (...args: Parameters<IndexPatternsContract['get']>) => Promise<MockIndexPattern>;
getIdsWithTitle: DataViewsContract['getIdsWithTitle'];
get: (...args: Parameters<DataViewsContract['get']>) => Promise<MockIndexPattern>;
} => {
return {
async getIdsWithTitle(_refresh?: boolean) {
Expand All @@ -85,7 +78,7 @@ export const createIndexPatternMock = ({
fields,
timeFieldName,
}: MockIndexPatternSpec): MockIndexPattern => {
const indexPatternFields = fields.map((fieldSpec) => new IndexPatternField(fieldSpec));
const indexPatternFields = fields.map((fieldSpec) => new DataViewField(fieldSpec));

return {
id,
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -131,6 +131,7 @@ const defaultArgs: IndicesConfigurationPanelStoryArgs = {
id: 'INDEX_PATTERN_A',
title: 'pattern-a-*',
timeFieldName: '@timestamp',
type: undefined,
fields: [
{
name: '@timestamp',
Expand All @@ -149,6 +150,8 @@ const defaultArgs: IndicesConfigurationPanelStoryArgs = {
{
id: 'INDEX_PATTERN_B',
title: 'pattern-b-*',
timeFieldName: '@timestamp',
type: undefined,
fields: [],
},
],
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -5,7 +5,8 @@
* 2.0.
*/

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

export interface GenericValidationError {
type: 'generic';
Expand Down Expand Up @@ -67,17 +68,15 @@ export const validateStringNotEmpty = (fieldName: string, value: string): FormVa
export const validateColumnListNotEmpty = (columns: unknown[]): FormValidationError[] =>
columns.length <= 0 ? [{ type: 'empty_column_list' }] : [];

export const validateIndexPattern = (indexPattern: IndexPattern): FormValidationError[] => {
export const validateIndexPattern = (indexPattern: DataView): FormValidationError[] => {
return [
...validateIndexPatternIsTimeBased(indexPattern),
...validateIndexPatternHasStringMessageField(indexPattern),
...validateIndexPatternIsntRollup(indexPattern),
];
};

export const validateIndexPatternIsTimeBased = (
indexPattern: IndexPattern
): FormValidationError[] =>
export const validateIndexPatternIsTimeBased = (indexPattern: DataView): FormValidationError[] =>
indexPattern.isTimeBased()
? []
: [
Expand All @@ -88,7 +87,7 @@ export const validateIndexPatternIsTimeBased = (
];

export const validateIndexPatternHasStringMessageField = (
indexPattern: IndexPattern
indexPattern: DataView
): FormValidationError[] => {
const messageField = indexPattern.getFieldByName('message');

Expand All @@ -111,7 +110,7 @@ export const validateIndexPatternHasStringMessageField = (
}
};

export const validateIndexPatternIsntRollup = (indexPattern: IndexPattern): FormValidationError[] =>
export const validateIndexPatternIsntRollup = (indexPattern: DataView): FormValidationError[] =>
indexPattern.type != null
? [
{
Expand Down
4 changes: 2 additions & 2 deletions x-pack/plugins/infra/public/pages/metrics/index.tsx
Original file line number Diff line number Diff line change
Expand Up @@ -11,7 +11,7 @@ import React, { useContext } from 'react';
import { Route, RouteComponentProps, Switch } from 'react-router-dom';

import { EuiErrorBoundary, EuiHeaderLinks, EuiHeaderLink } from '@elastic/eui';
import { IIndexPattern } from 'src/plugins/data/common';
import { DataViewBase } from '@kbn/es-query';
import { MetricsSourceConfigurationProperties } from '../../../common/metrics_sources';
import { DocumentTitle } from '../../components/document_title';
import { HelpCenterContent } from '../../components/help_center_content';
Expand Down Expand Up @@ -141,7 +141,7 @@ export const InfrastructurePage = ({ match }: RouteComponentProps) => {

const PageContent = (props: {
configuration: MetricsSourceConfigurationProperties;
createDerivedIndexPattern: (type: 'metrics') => IIndexPattern;
createDerivedIndexPattern: (type: 'metrics') => DataViewBase;
}) => {
const { createDerivedIndexPattern, configuration } = props;
const { options } = useContext(MetricsExplorerOptionsContainer.Context);
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -7,6 +7,7 @@

import React, { FunctionComponent } from 'react';
import { EuiFlexItem } from '@elastic/eui';
import { DataViewBase } from '@kbn/es-query';
import { useSourceContext } from '../../../../../containers/metrics_source';
import {
SnapshotMetricInput,
Expand All @@ -18,13 +19,12 @@ import { findToolbar } from '../../../../../../common/inventory_models/toolbars'
import { ToolbarWrapper } from './toolbar_wrapper';

import { InfraGroupByOptions } from '../../../../../lib/lib';
import { IIndexPattern } from '../../../../../../../../../src/plugins/data/public';
import { InventoryItemType } from '../../../../../../common/inventory_models/types';
import { WaffleOptionsState, WaffleSortOption } from '../../hooks/use_waffle_options';
import { useInventoryMeta } from '../../hooks/use_inventory_meta';

export interface ToolbarProps extends Omit<WaffleOptionsState, 'boundsOverride' | 'autoBounds'> {
createDerivedIndexPattern: (type: 'metrics') => IIndexPattern;
createDerivedIndexPattern: (type: 'metrics') => DataViewBase;
changeMetric: (payload: SnapshotMetricInput) => void;
changeGroupBy: (payload: SnapshotGroupBy) => void;
changeCustomOptions: (payload: InfraGroupByOptions[]) => void;
Expand Down
Loading

0 comments on commit 8ea719c

Please sign in to comment.