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

[Unified observability] Migrate deprecated IndexPattern types #124962

Merged
merged 15 commits into from
Mar 9, 2022
Original file line number Diff line number Diff line change
Expand Up @@ -7,14 +7,14 @@

import React from 'react';
import { fireEvent, screen, waitFor } from '@testing-library/react';
import { mockAppIndexPattern, mockIndexPattern, mockUxSeries, render } from '../rtl_helpers';
import { mockAppDataView, mockDataView, mockUxSeries, render } from '../rtl_helpers';
import { FilterLabel } from './filter_label';
import * as useSeriesHook from '../hooks/use_series_filters';
import { buildFilterLabel } from '../../filter_value_label/filter_value_label';

// FLAKY: https://github.com/elastic/kibana/issues/115324
describe.skip('FilterLabel', function () {
mockAppIndexPattern();
mockAppDataView();

const invertFilter = jest.fn();
jest.spyOn(useSeriesHook, 'useSeriesFilters').mockReturnValue({
Expand All @@ -30,7 +30,7 @@ describe.skip('FilterLabel', function () {
negate={false}
seriesId={0}
removeFilter={jest.fn()}
indexPattern={mockIndexPattern}
dataView={mockDataView}
series={mockUxSeries}
/>
);
Expand All @@ -55,7 +55,7 @@ describe.skip('FilterLabel', function () {
negate={false}
seriesId={0}
removeFilter={removeFilter}
indexPattern={mockIndexPattern}
dataView={mockDataView}
series={mockUxSeries}
/>
);
Expand All @@ -79,7 +79,7 @@ describe.skip('FilterLabel', function () {
negate={false}
seriesId={0}
removeFilter={removeFilter}
indexPattern={mockIndexPattern}
dataView={mockDataView}
series={mockUxSeries}
/>
);
Expand All @@ -106,7 +106,7 @@ describe.skip('FilterLabel', function () {
negate={true}
seriesId={0}
removeFilter={jest.fn()}
indexPattern={mockIndexPattern}
dataView={mockDataView}
series={mockUxSeries}
/>
);
Expand All @@ -126,7 +126,7 @@ describe.skip('FilterLabel', function () {
buildFilterLabel({
field: 'user_agent.name',
label: 'Browser family',
indexPattern: mockIndexPattern,
dataView: mockDataView,
value: 'Firefox',
negate: false,
})
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -6,7 +6,7 @@
*/

import React from 'react';
import { IndexPattern } from '../../../../../../../../src/plugins/data/public';
import type { DataView } from '../../../../../../../../src/plugins/data_views/common';
import { useSeriesFilters } from '../hooks/use_series_filters';
import { FilterValueLabel } from '../../filter_value_label/filter_value_label';
import { SeriesUrl } from '../types';
Expand All @@ -19,7 +19,7 @@ interface Props {
series: SeriesUrl;
negate: boolean;
definitionFilter?: boolean;
indexPattern: IndexPattern;
dataView: DataView;
removeFilter: (field: string, value: string | string[], notVal: boolean) => void;
}

Expand All @@ -30,15 +30,15 @@ export function FilterLabel({
field,
value,
negate,
indexPattern,
dataView,
removeFilter,
definitionFilter,
}: Props) {
const { invertFilter } = useSeriesFilters({ seriesId, series });

return indexPattern ? (
return dataView ? (
<FilterValueLabel
indexPattern={indexPattern}
dataView={dataView}
removeFilter={removeFilter}
invertFilter={(val) => {
if (!definitionFilter) invertFilter(val);
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -6,26 +6,26 @@
*/

import { AppDataType, ReportViewType, SeriesConfig } from '../types';
import { IndexPattern } from '../../../../../../../../src/plugins/data/common';
import type { DataView } from '../../../../../../../../src/plugins/data_views/common';
import { ReportConfigMap } from '../contexts/exploratory_view_config';

interface Props {
reportType: ReportViewType;
indexPattern: IndexPattern;
dataView: DataView;
dataType: AppDataType;
reportConfigMap: ReportConfigMap;
}

export const getDefaultConfigs = ({
reportType,
dataType,
indexPattern,
dataView,
reportConfigMap,
}: Props): SeriesConfig => {
let configResult: SeriesConfig | undefined;

reportConfigMap[dataType]?.some((fn) => {
const config = fn({ indexPattern });
const config = fn({ dataView });
if (config.reportType === reportType) {
configResult = config;
}
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -20,7 +20,7 @@ import {
SYSTEM_MEMORY_USAGE,
} from '../constants/labels';

export function getMetricsKPIConfig({ indexPattern }: ConfigProps): SeriesConfig {
export function getMetricsKPIConfig({ dataView }: ConfigProps): SeriesConfig {
return {
reportType: ReportTypes.KPI,
defaultSeriesType: 'area',
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -6,7 +6,7 @@
*/

import { LayerConfig, LensAttributes } from './lens_attributes';
import { mockAppIndexPattern, mockIndexPattern } from '../rtl_helpers';
import { mockAppDataView, mockDataView } from '../rtl_helpers';
import { getDefaultConfigs } from './default_configs';
import { sampleAttribute } from './test_data/sample_attribute';

Expand All @@ -21,24 +21,24 @@ import { RECORDS_FIELD, REPORT_METRIC_FIELD, PERCENTILE_RANKS, ReportTypes } fro
import { obsvReportConfigMap } from '../obsv_exploratory_view';

describe('Lens Attribute', () => {
mockAppIndexPattern();
mockAppDataView();

const reportViewConfig = getDefaultConfigs({
reportType: 'data-distribution',
dataType: 'ux',
indexPattern: mockIndexPattern,
dataView: mockDataView,
reportConfigMap: obsvReportConfigMap,
});

reportViewConfig.baseFilters?.push(...buildExistsFilter('transaction.type', mockIndexPattern));
reportViewConfig.baseFilters?.push(...buildExistsFilter('transaction.type', mockDataView));

let lnsAttr: LensAttributes;

const layerConfig: LayerConfig = {
seriesConfig: reportViewConfig,
seriesType: 'line',
operationType: 'count',
indexPattern: mockIndexPattern,
indexPattern: mockDataView,
reportDefinitions: {},
time: { from: 'now-15m', to: 'now' },
color: 'green',
Expand All @@ -58,7 +58,7 @@ describe('Lens Attribute', () => {
const seriesConfigKpi = getDefaultConfigs({
reportType: ReportTypes.KPI,
dataType: 'ux',
indexPattern: mockIndexPattern,
dataView: mockDataView,
reportConfigMap: obsvReportConfigMap,
});

Expand All @@ -67,7 +67,7 @@ describe('Lens Attribute', () => {
seriesConfig: seriesConfigKpi,
seriesType: 'line',
operationType: 'count',
indexPattern: mockIndexPattern,
indexPattern: mockDataView,
reportDefinitions: { 'service.name': ['elastic-co'] },
time: { from: 'now-15m', to: 'now' },
color: 'green',
Expand All @@ -83,7 +83,7 @@ describe('Lens Attribute', () => {
const seriesConfigKpi = getDefaultConfigs({
reportType: ReportTypes.KPI,
dataType: 'ux',
indexPattern: mockIndexPattern,
dataView: mockDataView,
reportConfigMap: obsvReportConfigMap,
});

Expand All @@ -95,7 +95,7 @@ describe('Lens Attribute', () => {
from: 'now-1h',
to: 'now',
},
indexPattern: mockIndexPattern,
indexPattern: mockDataView,
name: 'ux-series-1',
breakdown: 'percentile',
reportDefinitions: {},
Expand Down Expand Up @@ -200,7 +200,7 @@ describe('Lens Attribute', () => {
seriesConfig: reportViewConfig,
seriesType: 'line',
operationType: 'count',
indexPattern: mockIndexPattern,
indexPattern: mockDataView,
reportDefinitions: { 'performance.metric': [LCP_FIELD] },
time: { from: 'now-15m', to: 'now' },
color: 'green',
Expand Down Expand Up @@ -493,7 +493,7 @@ describe('Lens Attribute', () => {
seriesConfig: reportViewConfig,
seriesType: 'line',
operationType: 'count',
indexPattern: mockIndexPattern,
indexPattern: mockDataView,
reportDefinitions: { 'performance.metric': [LCP_FIELD] },
breakdown: USER_AGENT_NAME,
time: { from: 'now-15m', to: 'now' },
Expand All @@ -507,7 +507,7 @@ describe('Lens Attribute', () => {
lnsAttr.getBreakdownColumn({
sourceField: USER_AGENT_NAME,
layerId: 'layer0',
indexPattern: mockIndexPattern,
indexPattern: mockDataView,
labels: layerConfig.seriesConfig.labels,
});

Expand Down Expand Up @@ -676,14 +676,14 @@ describe('Lens Attribute', () => {
describe('Layer Filters', function () {
it('should return expected filters', function () {
reportViewConfig.baseFilters?.push(
...buildPhrasesFilter('service.name', ['elastic', 'kibana'], mockIndexPattern)
...buildPhrasesFilter('service.name', ['elastic', 'kibana'], mockDataView)
);

const layerConfig1: LayerConfig = {
seriesConfig: reportViewConfig,
seriesType: 'line',
operationType: 'count',
indexPattern: mockIndexPattern,
indexPattern: mockDataView,
reportDefinitions: { 'performance.metric': [LCP_FIELD] },
time: { from: 'now-15m', to: 'now' },
color: 'green',
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -30,7 +30,7 @@ import {
CardinalityIndexPatternColumn,
} from '../../../../../../lens/public';
import { urlFiltersToKueryString } from '../utils/stringify_kueries';
import { IndexPattern } from '../../../../../../../../src/plugins/data/common';
import type { DataView } from '../../../../../../../../src/plugins/data_views/common';
import {
FILTER_RECORDS,
USE_BREAK_DOWN_COLUMN,
Expand Down Expand Up @@ -91,7 +91,7 @@ export interface LayerConfig {
operationType?: OperationType;
reportDefinitions: URLReportDefinition;
time: { to: string; from: string };
indexPattern: IndexPattern;
indexPattern: DataView; // TODO: Figure out if this can be renamed or if it's a Lens requirement
selectedMetricField: string;
color: string;
name: string;
Expand Down Expand Up @@ -150,7 +150,7 @@ export class LensAttributes {
sourceField: string;
layerId: string;
labels: Record<string, string>;
indexPattern: IndexPattern;
indexPattern: DataView;
}): TermsIndexPatternColumn {
const fieldMeta = indexPattern.getFieldByName(sourceField);

Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -18,7 +18,7 @@ import { SERVICE_NAME } from '../constants/elasticsearch_fieldnames';
import { MOBILE_APP, NUMBER_OF_DEVICES } from '../constants/labels';
import { MobileFields } from './mobile_fields';

export function getMobileDeviceDistributionConfig({ indexPattern }: ConfigProps): SeriesConfig {
export function getMobileDeviceDistributionConfig({ dataView }: ConfigProps): SeriesConfig {
return {
reportType: ReportTypes.DEVICE_DISTRIBUTION,
defaultSeriesType: 'bar',
Expand All @@ -36,8 +36,8 @@ export function getMobileDeviceDistributionConfig({ indexPattern }: ConfigProps)
filterFields: [...Object.keys(MobileFields), LABEL_FIELDS_FILTER],
breakdownFields: Object.keys(MobileFields),
baseFilters: [
...buildPhraseFilter('agent.name', 'iOS/swift', indexPattern),
...buildPhraseFilter('processor.event', 'transaction', indexPattern),
...buildPhraseFilter('agent.name', 'iOS/swift', dataView),
...buildPhraseFilter('processor.event', 'transaction', dataView),
],
labels: {
...FieldLabels,
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -26,7 +26,7 @@ import {
import { CPU_USAGE, SYSTEM_MEMORY_USAGE, MOBILE_APP, RESPONSE_LATENCY } from '../constants/labels';
import { MobileFields } from './mobile_fields';

export function getMobileKPIDistributionConfig({ indexPattern }: ConfigProps): SeriesConfig {
export function getMobileKPIDistributionConfig({ dataView }: ConfigProps): SeriesConfig {
return {
reportType: ReportTypes.DISTRIBUTION,
defaultSeriesType: 'bar',
Expand All @@ -43,7 +43,7 @@ export function getMobileKPIDistributionConfig({ indexPattern }: ConfigProps): S
filterFields: [...Object.keys(MobileFields), LABEL_FIELDS_FILTER],
breakdownFields: Object.keys(MobileFields),
baseFilters: [
...buildPhrasesFilter('agent.name', ['iOS/swift', 'open-telemetry/swift'], indexPattern),
...buildPhrasesFilter('agent.name', ['iOS/swift', 'open-telemetry/swift'], dataView),
],
labels: {
...FieldLabels,
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -32,7 +32,7 @@ import {
} from '../constants/labels';
import { MobileFields } from './mobile_fields';

export function getMobileKPIConfig({ indexPattern }: ConfigProps): SeriesConfig {
export function getMobileKPIConfig({ dataView }: ConfigProps): SeriesConfig {
return {
reportType: ReportTypes.KPI,
defaultSeriesType: 'line',
Expand All @@ -50,7 +50,7 @@ export function getMobileKPIConfig({ indexPattern }: ConfigProps): SeriesConfig
filterFields: [...Object.keys(MobileFields), LABEL_FIELDS_FILTER],
breakdownFields: Object.keys(MobileFields),
baseFilters: [
...buildPhrasesFilter('agent.name', ['iOS/swift', 'open-telemetry/swift'], indexPattern),
...buildPhrasesFilter('agent.name', ['iOS/swift', 'open-telemetry/swift'], dataView),
],
labels: {
...FieldLabels,
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -5,16 +5,16 @@
* 2.0.
*/

import { mockAppIndexPattern, mockIndexPattern } from '../../rtl_helpers';
import { mockAppDataView, mockDataView } from '../../rtl_helpers';
import { LensAttributes } from '../lens_attributes';
import { METRIC_SYSTEM_MEMORY_USAGE, SERVICE_NAME } from '../constants/elasticsearch_fieldnames';
import { obsvReportConfigMap } from '../../obsv_exploratory_view';
import { testMobileKPIAttr } from '../test_data/mobile_test_attribute';
import { getLayerConfigs } from '../../hooks/use_lens_attributes';
import { IndexPatternState } from '../../hooks/use_app_index_pattern';
import { DataViewState } from '../../hooks/use_app_data_view';

describe('Mobile kpi config test', function () {
mockAppIndexPattern();
mockAppDataView();

let lnsAttr: LensAttributes;

Expand All @@ -31,7 +31,7 @@ describe('Mobile kpi config test', function () {
],
'kpi-over-time',
{} as any,
{ mobile: mockIndexPattern } as IndexPatternState,
{ mobile: mockDataView } as DataViewState,
obsvReportConfigMap
);

Expand Down
Loading