From 82f0c9d86a474477c23523cbab05e0d5ad14af38 Mon Sep 17 00:00:00 2001 From: Matt Kime Date: Sat, 5 Aug 2023 23:50:50 -0500 Subject: [PATCH 01/22] scripted fields disabled in serverless --- .../search/search_source/search_source.ts | 1 + .../edit_index_pattern/tabs/tabs.tsx | 4 ++-- .../edit_index_pattern/tabs/utils.ts | 9 +++++++-- .../public/components/utils.ts | 1 + .../common/data_views/data_views.test.ts | 2 ++ .../common/data_views/data_views.ts | 11 +++++++++- src/plugins/data_views/public/index.ts | 6 ++++-- src/plugins/data_views/public/plugin.ts | 11 +++++++++- src/plugins/data_views/public/types.ts | 1 + .../server/data_views_service_factory.ts | 2 ++ src/plugins/data_views/server/index.ts | 20 +++++++++++++++++++ src/plugins/data_views/server/plugin.ts | 10 +++++++++- 12 files changed, 69 insertions(+), 9 deletions(-) diff --git a/src/plugins/data/common/search/search_source/search_source.ts b/src/plugins/data/common/search/search_source/search_source.ts index 0ba2c77c8c016..f6d28480f4f7a 100644 --- a/src/plugins/data/common/search/search_source/search_source.ts +++ b/src/plugins/data/common/search/search_source/search_source.ts @@ -774,6 +774,7 @@ export class SearchSource { return field; } + // todo private flatten() { const { getConfig } = this.dependencies; const searchRequest = this.mergeProps(); diff --git a/src/plugins/data_view_management/public/components/edit_index_pattern/tabs/tabs.tsx b/src/plugins/data_view_management/public/components/edit_index_pattern/tabs/tabs.tsx index 075869ab6fdc2..4d18244d6476c 100644 --- a/src/plugins/data_view_management/public/components/edit_index_pattern/tabs/tabs.tsx +++ b/src/plugins/data_view_management/public/components/edit_index_pattern/tabs/tabs.tsx @@ -569,7 +569,7 @@ export function Tabs({ const euiTabs: EuiTabbedContentTab[] = useMemo( () => - getTabs(indexPattern, fieldFilter, relationships.length).map( + getTabs(indexPattern, fieldFilter, relationships.length, dataViews.scriptedFieldsEnabled).map( (tab: Pick) => { return { ...tab, @@ -577,7 +577,7 @@ export function Tabs({ }; } ), - [fieldFilter, getContent, indexPattern, relationships] + [fieldFilter, getContent, indexPattern, relationships, dataViews.scriptedFieldsEnabled] ); const [selectedTabId, setSelectedTabId] = useState(euiTabs[0].id); diff --git a/src/plugins/data_view_management/public/components/edit_index_pattern/tabs/utils.ts b/src/plugins/data_view_management/public/components/edit_index_pattern/tabs/utils.ts index 00b08037e52fe..eb2acaadb4476 100644 --- a/src/plugins/data_view_management/public/components/edit_index_pattern/tabs/utils.ts +++ b/src/plugins/data_view_management/public/components/edit_index_pattern/tabs/utils.ts @@ -73,7 +73,12 @@ function getTitle(type: string, filteredCount: Dictionary, totalCount: D return title + count; } -export function getTabs(indexPattern: DataView, fieldFilter: string, relationshipCount = 0) { +export function getTabs( + indexPattern: DataView, + fieldFilter: string, + relationshipCount = 0, + scriptedFieldsEnabled: boolean +) { const totalCount = getCounts(indexPattern.fields.getAll(), indexPattern.getSourceFiltering()); const filteredCount = getCounts( indexPattern.fields.getAll(), @@ -89,7 +94,7 @@ export function getTabs(indexPattern: DataView, fieldFilter: string, relationshi 'data-test-subj': 'tab-indexedFields', }); - if (areScriptedFieldsEnabled(indexPattern)) { + if (areScriptedFieldsEnabled(indexPattern) && scriptedFieldsEnabled) { tabs.push({ name: getTitle('scripted', filteredCount, totalCount), id: TAB_SCRIPTED_FIELDS, diff --git a/src/plugins/data_view_management/public/components/utils.ts b/src/plugins/data_view_management/public/components/utils.ts index 5ba434048dc4d..abc89d5844f46 100644 --- a/src/plugins/data_view_management/public/components/utils.ts +++ b/src/plugins/data_view_management/public/components/utils.ts @@ -85,6 +85,7 @@ export const getTags = (indexPattern: DataViewListItem | DataView, isDefault: bo return tags; }; +// todo add to this export const areScriptedFieldsEnabled = (indexPattern: DataViewListItem | DataView) => { return !isRollup(indexPattern.type); }; diff --git a/src/plugins/data_views/common/data_views/data_views.test.ts b/src/plugins/data_views/common/data_views/data_views.test.ts index e6d09710fe016..beb526e02911d 100644 --- a/src/plugins/data_views/common/data_views/data_views.test.ts +++ b/src/plugins/data_views/common/data_views/data_views.test.ts @@ -115,6 +115,7 @@ describe('IndexPatterns', () => { onRedirectNoIndexPattern: () => {}, getCanSave: () => Promise.resolve(true), getCanSaveAdvancedSettings: () => Promise.resolve(true), + scriptedFieldsEnabled: true, }); indexPatternsNoAccess = new DataViewsService({ @@ -127,6 +128,7 @@ describe('IndexPatterns', () => { onRedirectNoIndexPattern: () => {}, getCanSave: () => Promise.resolve(false), getCanSaveAdvancedSettings: () => Promise.resolve(false), + scriptedFieldsEnabled: true, }); }); diff --git a/src/plugins/data_views/common/data_views/data_views.ts b/src/plugins/data_views/common/data_views/data_views.ts index 469fd2a1fa61e..d8e2eb9c47f01 100644 --- a/src/plugins/data_views/common/data_views/data_views.ts +++ b/src/plugins/data_views/common/data_views/data_views.ts @@ -118,6 +118,8 @@ export interface DataViewsServiceDeps { * Determines whether the user can save advancedSettings (used for defaultIndex) */ getCanSaveAdvancedSettings: () => Promise; + + scriptedFieldsEnabled: boolean; } /** @@ -317,6 +319,8 @@ export class DataViewsService { * Can the user save data views? */ public getCanSave: () => Promise; + + public readonly scriptedFieldsEnabled: boolean; /** * DataViewsService constructor * @param deps Service dependencies @@ -331,6 +335,7 @@ export class DataViewsService { onError, getCanSave = () => Promise.resolve(false), getCanSaveAdvancedSettings, + scriptedFieldsEnabled, } = deps; this.apiClient = apiClient; this.config = uiSettings; @@ -342,6 +347,7 @@ export class DataViewsService { this.getCanSaveAdvancedSettings = getCanSaveAdvancedSettings; this.dataViewCache = createDataViewCache(); + this.scriptedFieldsEnabled = scriptedFieldsEnabled; } /** @@ -548,7 +554,10 @@ export class DataViewsService { private refreshFieldsFn = async (indexPattern: DataView) => { const { fields, indices } = await this.getFieldsAndIndicesForDataView(indexPattern); fields.forEach((field) => (field.isMapped = true)); - const scripted = indexPattern.getScriptedFields().map((field) => field.spec); + // todo - uh oh, lifecycle concerns! saving data view reads from whole field list + const scripted = this.scriptedFieldsEnabled + ? indexPattern.getScriptedFields().map((field) => field.spec) + : []; const fieldAttrs = indexPattern.getFieldAttrs(); const fieldsWithSavedAttrs = Object.values( this.fieldArrayToMap([...fields, ...scripted], fieldAttrs) diff --git a/src/plugins/data_views/public/index.ts b/src/plugins/data_views/public/index.ts index 777e386189d62..f690552b5a147 100644 --- a/src/plugins/data_views/public/index.ts +++ b/src/plugins/data_views/public/index.ts @@ -6,6 +6,8 @@ * Side Public License, v 1. */ +import { PluginInitializerContext } from '@kbn/core/public'; + export { ILLEGAL_CHARACTERS_KEY, CONTAINS_SPACES_KEY, @@ -55,8 +57,8 @@ export { UiSettingsPublicToCommon } from './ui_settings_wrapper'; import { DataViewsPublicPlugin } from './plugin'; -export function plugin() { - return new DataViewsPublicPlugin(); +export function plugin(initializerContext: PluginInitializerContext) { + return new DataViewsPublicPlugin(initializerContext); } export type { diff --git a/src/plugins/data_views/public/plugin.ts b/src/plugins/data_views/public/plugin.ts index 119d785139c90..223d5e913f8a5 100644 --- a/src/plugins/data_views/public/plugin.ts +++ b/src/plugins/data_views/public/plugin.ts @@ -6,7 +6,7 @@ * Side Public License, v 1. */ -import { CoreSetup, CoreStart, Plugin } from '@kbn/core/public'; +import { CoreSetup, CoreStart, Plugin, PluginInitializerContext } from '@kbn/core/public'; import { i18n } from '@kbn/i18n'; import { getIndexPatternLoad } from './expressions'; import { @@ -16,6 +16,10 @@ import { DataViewsPublicStartDependencies, } from './types'; +interface ClientConfigType { + scriptedFieldsEnabled?: boolean; +} + import { DataViewsApiClient } from '.'; import { ContentMagementWrapper } from './content_management_wrapper'; @@ -40,6 +44,8 @@ export class DataViewsPublicPlugin { private readonly hasData = new HasData(); + constructor(private readonly initializerContext: PluginInitializerContext) {} + public setup( core: CoreSetup, { expressions, contentManagement }: DataViewsPublicSetupDependencies @@ -74,6 +80,8 @@ export class DataViewsPublicPlugin 10000 ); + const config = this.initializerContext.config.get(); + return new DataViewsServicePublic({ hasData: this.hasData.start(core), uiSettings: new UiSettingsPublicToCommon(uiSettings), @@ -91,6 +99,7 @@ export class DataViewsPublicPlugin getCanSaveAdvancedSettings: () => Promise.resolve(application.capabilities.advancedSettings.save === true), getIndices: (props) => getIndices({ ...props, http: core.http }), + scriptedFieldsEnabled: config.scriptedFieldsEnabled === false ? false : true, // accounting for null value }); } diff --git a/src/plugins/data_views/public/types.ts b/src/plugins/data_views/public/types.ts index c30aebe9243e0..fde0828748f93 100644 --- a/src/plugins/data_views/public/types.ts +++ b/src/plugins/data_views/public/types.ts @@ -120,6 +120,7 @@ export interface DataViewsServicePublic extends DataViewsServicePublicMethods { showAllIndices?: boolean; isRollupIndex: (indexName: string) => boolean; }) => Promise; + scriptedFieldsEnabled: boolean; } export type DataViewsContract = DataViewsServicePublic; diff --git a/src/plugins/data_views/server/data_views_service_factory.ts b/src/plugins/data_views/server/data_views_service_factory.ts index fb5ae2c5afe3a..36173fa8b08c1 100644 --- a/src/plugins/data_views/server/data_views_service_factory.ts +++ b/src/plugins/data_views/server/data_views_service_factory.ts @@ -25,6 +25,7 @@ interface DataViewsServiceFactoryDeps { uiSettings: UiSettingsServiceStart; fieldFormats: FieldFormatsStart; capabilities: CoreStart['capabilities']; + scriptedFieldsEnabled: boolean; } /** @@ -65,5 +66,6 @@ export const dataViewsServiceFactory = (deps: DataViewsServiceFactoryDeps) => : request ? (await capabilities.resolveCapabilities(request)).advancedSettings.save === true : false, + scriptedFieldsEnabled: deps.scriptedFieldsEnabled, }); }; diff --git a/src/plugins/data_views/server/index.ts b/src/plugins/data_views/server/index.ts index 553f1a48d1d6d..21e1c627f4cb4 100644 --- a/src/plugins/data_views/server/index.ts +++ b/src/plugins/data_views/server/index.ts @@ -6,6 +6,8 @@ * Side Public License, v 1. */ +import { schema, TypeOf } from '@kbn/config-schema'; +import type { PluginConfigDescriptor } from '@kbn/core/server'; export { getFieldByName, findIndexPatternById } from './utils'; export type { FieldDescriptor, RollupIndexCapability } from './fetcher'; export { IndexPatternsFetcher, getCapabilitiesForRollupIndices } from './fetcher'; @@ -35,6 +37,24 @@ export type { }; export { DataViewsServerPlugin as Plugin }; +const configSchema = schema.object({ + scriptedFieldsEnabled: schema.conditional( + schema.contextRef('serverless'), + true, + schema.boolean({ defaultValue: false }), + schema.never() + ), +}); + +type ConfigType = TypeOf; + +export const config: PluginConfigDescriptor = { + schema: configSchema, + exposeToBrowser: { + scriptedFieldsEnabled: true, + }, +}; + export { SERVICE_PATH, SERVICE_PATH_LEGACY, diff --git a/src/plugins/data_views/server/plugin.ts b/src/plugins/data_views/server/plugin.ts index fab72338bdb33..b928d99620b58 100644 --- a/src/plugins/data_views/server/plugin.ts +++ b/src/plugins/data_views/server/plugin.ts @@ -23,6 +23,11 @@ import { } from './types'; import { DataViewsStorage } from './content_management'; +// duped, change +interface ClientConfigType { + scriptedFieldsEnabled?: boolean; +} + export class DataViewsServerPlugin implements Plugin< @@ -34,7 +39,7 @@ export class DataViewsServerPlugin { private readonly logger: Logger; - constructor(initializerContext: PluginInitializerContext) { + constructor(private readonly initializerContext: PluginInitializerContext) { this.logger = initializerContext.logger.get('dataView'); } @@ -67,11 +72,14 @@ export class DataViewsServerPlugin { uiSettings, capabilities }: CoreStart, { fieldFormats }: DataViewsServerPluginStartDependencies ) { + const config = this.initializerContext.config.get(); + const serviceFactory = dataViewsServiceFactory({ logger: this.logger.get('indexPatterns'), uiSettings, fieldFormats, capabilities, + scriptedFieldsEnabled: config.scriptedFieldsEnabled === false ? false : true, // accounting for null value }); return { From 5230848467576be6d252165b7cfa01009b857b25 Mon Sep 17 00:00:00 2001 From: Matt Kime Date: Sun, 6 Aug 2023 01:01:50 -0500 Subject: [PATCH 02/22] fix functional test --- test/plugin_functional/test_suites/core_plugins/rendering.ts | 3 ++- 1 file changed, 2 insertions(+), 1 deletion(-) diff --git a/test/plugin_functional/test_suites/core_plugins/rendering.ts b/test/plugin_functional/test_suites/core_plugins/rendering.ts index d150ef4e70612..fe140008a6512 100644 --- a/test/plugin_functional/test_suites/core_plugins/rendering.ts +++ b/test/plugin_functional/test_suites/core_plugins/rendering.ts @@ -23,7 +23,7 @@ declare global { } const EXPOSED_CONFIG_SETTINGS_ERROR = - 'Actual config settings exposed to the browser do not match what is expected; this assertion fails if extra settings are present and/or expected settings are missing'; + 'Actual config settings exposed to the browser do not match list defined in test; this assertion fails if extra settings are present and/or expected settings are missing'; export default function ({ getService }: PluginFunctionalProviderContext) { const appsMenu = getService('appsMenu'); @@ -104,6 +104,7 @@ export default function ({ getService }: PluginFunctionalProviderContext) { 'data.search.sessions.management.refreshTimeout (duration)', 'data.search.sessions.maxUpdateRetries (number)', 'data.search.sessions.notTouchedTimeout (duration)', + 'data_views.scriptedFieldsEnabled (boolean)', 'dev_tools.deeplinks.navLinkStatus (string)', 'enterpriseSearch.canDeployEntSearch (boolean)', 'enterpriseSearch.host (string)', From df98c1b007694ab387f27ee803a0301d23faa3ab Mon Sep 17 00:00:00 2001 From: Matt Kime Date: Sun, 6 Aug 2023 12:30:30 -0500 Subject: [PATCH 03/22] fix functional test --- test/plugin_functional/test_suites/core_plugins/rendering.ts | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/test/plugin_functional/test_suites/core_plugins/rendering.ts b/test/plugin_functional/test_suites/core_plugins/rendering.ts index fe140008a6512..929b673aebf82 100644 --- a/test/plugin_functional/test_suites/core_plugins/rendering.ts +++ b/test/plugin_functional/test_suites/core_plugins/rendering.ts @@ -104,7 +104,7 @@ export default function ({ getService }: PluginFunctionalProviderContext) { 'data.search.sessions.management.refreshTimeout (duration)', 'data.search.sessions.maxUpdateRetries (number)', 'data.search.sessions.notTouchedTimeout (duration)', - 'data_views.scriptedFieldsEnabled (boolean)', + 'data_views.scriptedFieldsEnabled (any)', // It's a boolean (any because schema.conditional) 'dev_tools.deeplinks.navLinkStatus (string)', 'enterpriseSearch.canDeployEntSearch (boolean)', 'enterpriseSearch.host (string)', From 3ade3a74d62758a72ea4b3d3a59398d7406c41e0 Mon Sep 17 00:00:00 2001 From: Matt Kime Date: Wed, 9 Aug 2023 13:32:57 -0500 Subject: [PATCH 04/22] added todo --- src/plugins/data/common/search/search_source/search_source.ts | 1 + 1 file changed, 1 insertion(+) diff --git a/src/plugins/data/common/search/search_source/search_source.ts b/src/plugins/data/common/search/search_source/search_source.ts index f6d28480f4f7a..5028e2c75cb06 100644 --- a/src/plugins/data/common/search/search_source/search_source.ts +++ b/src/plugins/data/common/search/search_source/search_source.ts @@ -797,6 +797,7 @@ export class SearchSource { // set defaults let fieldsFromSource = searchRequest.fieldsFromSource || []; body.fields = body.fields || []; + // maybe this is where the conditional goes body.script_fields = { ...body.script_fields, ...scriptFields, From 631c4af1f981d7467cde413fcfe82dae900ffcd8 Mon Sep 17 00:00:00 2001 From: Matt Kime Date: Sun, 13 Aug 2023 13:18:49 -0500 Subject: [PATCH 05/22] pass scripted fields enabled through service --- .../search/search_source/create_search_source.test.ts | 1 + src/plugins/data/common/search/search_source/mocks.ts | 1 + .../common/search/search_source/search_source.test.ts | 1 + .../data/common/search/search_source/search_source.ts | 1 + .../search/search_source/search_source_service.test.ts | 1 + src/plugins/data/public/plugin.ts | 1 + src/plugins/data/public/search/search_service.test.ts | 1 + src/plugins/data/public/search/search_service.ts | 9 ++++++++- src/plugins/data/server/search/search_service.ts | 1 + .../data_views/public/data_views_service_public.ts | 3 +++ src/plugins/data_views/server/mocks.ts | 1 + src/plugins/data_views/server/plugin.ts | 4 +++- src/plugins/data_views/server/types.ts | 4 ++++ 13 files changed, 27 insertions(+), 2 deletions(-) diff --git a/src/plugins/data/common/search/search_source/create_search_source.test.ts b/src/plugins/data/common/search/search_source/create_search_source.test.ts index 491673dc8ebca..709b065c1ec41 100644 --- a/src/plugins/data/common/search/search_source/create_search_source.test.ts +++ b/src/plugins/data/common/search/search_source/create_search_source.test.ts @@ -23,6 +23,7 @@ describe('createSearchSource', () => { getConfig: jest.fn(), search: jest.fn(), onResponse: (req, res) => res, + scriptedFieldsEnabled: true, }; indexPatternContractMock = { diff --git a/src/plugins/data/common/search/search_source/mocks.ts b/src/plugins/data/common/search/search_source/mocks.ts index a980004bd1ceb..6bcd2a76d9aca 100644 --- a/src/plugins/data/common/search/search_source/mocks.ts +++ b/src/plugins/data/common/search/search_source/mocks.ts @@ -71,4 +71,5 @@ export const createSearchSourceMock = ( ) ), onResponse: jest.fn().mockImplementation((req, res) => res), + scriptedFieldsEnabled: true, }); diff --git a/src/plugins/data/common/search/search_source/search_source.test.ts b/src/plugins/data/common/search/search_source/search_source.test.ts index f4146cc5634de..45319e39060d9 100644 --- a/src/plugins/data/common/search/search_source/search_source.test.ts +++ b/src/plugins/data/common/search/search_source/search_source.test.ts @@ -94,6 +94,7 @@ describe('SearchSource', () => { getConfig: getConfigMock, search: mockSearchMethod, onResponse: jest.fn().mockImplementation((_, res) => res), + scriptedFieldsEnabled: true, }; searchSource = new SearchSource({}, searchSourceDependencies); diff --git a/src/plugins/data/common/search/search_source/search_source.ts b/src/plugins/data/common/search/search_source/search_source.ts index 87fc09b782745..fa0fdd330186a 100644 --- a/src/plugins/data/common/search/search_source/search_source.ts +++ b/src/plugins/data/common/search/search_source/search_source.ts @@ -138,6 +138,7 @@ export const searchSourceRequiredUiSettings = [ export interface SearchSourceDependencies extends FetchHandlers { aggs: AggsStart; search: ISearchGeneric; + scriptedFieldsEnabled: boolean; } interface ExpressionAstOptions { diff --git a/src/plugins/data/common/search/search_source/search_source_service.test.ts b/src/plugins/data/common/search/search_source/search_source_service.test.ts index 70448db335a07..8e03f56fe0421 100644 --- a/src/plugins/data/common/search/search_source/search_source_service.test.ts +++ b/src/plugins/data/common/search/search_source/search_source_service.test.ts @@ -19,6 +19,7 @@ describe('SearchSource service', () => { getConfig: jest.fn(), search: jest.fn(), onResponse: jest.fn(), + scriptedFieldsEnabled: true, }; }); diff --git a/src/plugins/data/public/plugin.ts b/src/plugins/data/public/plugin.ts index 8f4e37afb29b2..a2ed53fde7704 100644 --- a/src/plugins/data/public/plugin.ts +++ b/src/plugins/data/public/plugin.ts @@ -138,6 +138,7 @@ export class DataPublicPlugin fieldFormats, indexPatterns: dataViews, screenshotMode, + scriptedFieldsEnabled: dataViews.scriptedFieldsEnabled, }); setSearchService(search); diff --git a/src/plugins/data/public/search/search_service.test.ts b/src/plugins/data/public/search/search_service.test.ts index a64b90772900a..c94cde6b8f747 100644 --- a/src/plugins/data/public/search/search_service.test.ts +++ b/src/plugins/data/public/search/search_service.test.ts @@ -69,6 +69,7 @@ describe('Search service', () => { fieldFormats: {} as FieldFormatsStart, indexPatterns: {} as DataViewsContract, screenshotMode: screenshotModePluginMock.createStartContract(), + scriptedFieldsEnabled: true, }); }); diff --git a/src/plugins/data/public/search/search_service.ts b/src/plugins/data/public/search/search_service.ts index d9033e0eed5f1..4a16d9487d2ea 100644 --- a/src/plugins/data/public/search/search_service.ts +++ b/src/plugins/data/public/search/search_service.ts @@ -86,6 +86,7 @@ export interface SearchServiceStartDependencies { fieldFormats: FieldFormatsStart; indexPatterns: DataViewsContract; screenshotMode: ScreenshotModePluginStart; + scriptedFieldsEnabled: boolean; } export class SearchService implements Plugin { @@ -216,7 +217,12 @@ export class SearchService implements Plugin { public start( { http, theme, uiSettings, chrome, application }: CoreStart, - { fieldFormats, indexPatterns, screenshotMode }: SearchServiceStartDependencies + { + fieldFormats, + indexPatterns, + screenshotMode, + scriptedFieldsEnabled, + }: SearchServiceStartDependencies ): ISearchStart { const search = ((request, options = {}) => { return this.searchInterceptor.search(request, options); @@ -245,6 +251,7 @@ export class SearchService implements Plugin { } return response; }, + scriptedFieldsEnabled, }; const config = this.initializerContext.config.get(); diff --git a/src/plugins/data/server/search/search_service.ts b/src/plugins/data/server/search/search_service.ts index 0387cb820f165..dd199403c53af 100644 --- a/src/plugins/data/server/search/search_service.ts +++ b/src/plugins/data/server/search/search_service.ts @@ -302,6 +302,7 @@ export class SearchService implements Plugin { getConfig: (key: string): T => uiSettingsCache[key], search: this.asScoped(request).search, onResponse: (req, res) => res, + scriptedFieldsEnabled: true, }; return this.searchSourceService.start(scopedIndexPatterns, searchSourceDependencies); diff --git a/src/plugins/data_views/public/data_views_service_public.ts b/src/plugins/data_views/public/data_views_service_public.ts index 30625b1b59da5..73f4fb6987fa0 100644 --- a/src/plugins/data_views/public/data_views_service_public.ts +++ b/src/plugins/data_views/public/data_views_service_public.ts @@ -29,6 +29,7 @@ export interface DataViewsServicePublicDeps extends DataViewsServiceDeps { showAllIndices?: boolean; isRollupIndex: (indexName: string) => boolean; }) => Promise; + scriptedFieldsEnabled: boolean; } /** @@ -44,6 +45,7 @@ export class DataViewsServicePublic extends DataViewsService { isRollupIndex: (indexName: string) => boolean; }) => Promise; public hasData: HasDataService; + public readonly scriptedFieldsEnabled: boolean; /** * Constructor @@ -55,5 +57,6 @@ export class DataViewsServicePublic extends DataViewsService { this.getCanSaveSync = deps.getCanSaveSync; this.hasData = deps.hasData; this.getIndices = deps.getIndices; + this.scriptedFieldsEnabled = deps.scriptedFieldsEnabled; } } diff --git a/src/plugins/data_views/server/mocks.ts b/src/plugins/data_views/server/mocks.ts index 82595f7dc51a1..1e142d2e1650b 100644 --- a/src/plugins/data_views/server/mocks.ts +++ b/src/plugins/data_views/server/mocks.ts @@ -12,6 +12,7 @@ export function createIndexPatternsStartMock() { const dataViewsServiceFactory = jest.fn().mockResolvedValue({ get: jest.fn() }); return { dataViewsServiceFactory, + getScriptedFieldsEnabled: jest.fn().mockReturnValue(true), }; } diff --git a/src/plugins/data_views/server/plugin.ts b/src/plugins/data_views/server/plugin.ts index c865e7f85563d..6dc98bf0e282d 100644 --- a/src/plugins/data_views/server/plugin.ts +++ b/src/plugins/data_views/server/plugin.ts @@ -81,18 +81,20 @@ export class DataViewsServerPlugin { fieldFormats }: DataViewsServerPluginStartDependencies ) { const config = this.initializerContext.config.get(); + const scriptedFieldsEnabled = config.scriptedFieldsEnabled === false ? false : true; // accounting for null value const serviceFactory = dataViewsServiceFactory({ logger: this.logger.get('indexPatterns'), uiSettings, fieldFormats, capabilities, - scriptedFieldsEnabled: config.scriptedFieldsEnabled === false ? false : true, // accounting for null value + scriptedFieldsEnabled, rollupsEnabled: this.rollupsEnabled, }); return { dataViewsServiceFactory: serviceFactory, + getScriptedFieldsEnabled: () => scriptedFieldsEnabled, }; } diff --git a/src/plugins/data_views/server/types.ts b/src/plugins/data_views/server/types.ts index d595f6e04b275..6bf438dc634bd 100644 --- a/src/plugins/data_views/server/types.ts +++ b/src/plugins/data_views/server/types.ts @@ -48,6 +48,10 @@ export interface DataViewsServerPluginStart { * Returns a DataViews service instance */ dataViewsServiceFactory: ServiceFactory; + /** + * + */ + getScriptedFieldsEnabled: () => boolean; } /** From f04b383353e5defb511140bd7323520f18cc026f Mon Sep 17 00:00:00 2001 From: Matt Kime Date: Sun, 13 Aug 2023 13:40:31 -0500 Subject: [PATCH 06/22] fix tests --- x-pack/plugins/alerting/server/plugin.test.ts | 3 +++ x-pack/plugins/alerting/server/task_runner/task_runner.test.ts | 1 + .../server/task_runner/task_runner_alerts_client.test.ts | 1 + .../alerting/server/task_runner/task_runner_cancel.test.ts | 1 + .../alerting/server/task_runner/task_runner_factory.test.ts | 1 + 5 files changed, 7 insertions(+) diff --git a/x-pack/plugins/alerting/server/plugin.test.ts b/x-pack/plugins/alerting/server/plugin.test.ts index e14ba71c6c1bf..859e69b6da131 100644 --- a/x-pack/plugins/alerting/server/plugin.test.ts +++ b/x-pack/plugins/alerting/server/plugin.test.ts @@ -270,6 +270,7 @@ describe('Alerting Plugin', () => { dataViewsServiceFactory: jest .fn() .mockResolvedValue(dataViewPluginMocks.createStartContract()), + getScriptedFieldsEnabled: jest.fn().mockReturnValue(true), } as DataViewsServerPluginStart, }); @@ -318,6 +319,7 @@ describe('Alerting Plugin', () => { dataViewsServiceFactory: jest .fn() .mockResolvedValue(dataViewPluginMocks.createStartContract()), + getScriptedFieldsEnabled: jest.fn().mockReturnValue(true), } as DataViewsServerPluginStart, }); @@ -377,6 +379,7 @@ describe('Alerting Plugin', () => { dataViewsServiceFactory: jest .fn() .mockResolvedValue(dataViewPluginMocks.createStartContract()), + getScriptedFieldsEnabled: jest.fn().mockReturnValue(true), } as DataViewsServerPluginStart, }); diff --git a/x-pack/plugins/alerting/server/task_runner/task_runner.test.ts b/x-pack/plugins/alerting/server/task_runner/task_runner.test.ts index ceb0c80270881..4e40531a49f2b 100644 --- a/x-pack/plugins/alerting/server/task_runner/task_runner.test.ts +++ b/x-pack/plugins/alerting/server/task_runner/task_runner.test.ts @@ -133,6 +133,7 @@ describe('Task Runner', () => { const inMemoryMetrics = inMemoryMetricsMock.create(); const dataViewsMock = { dataViewsServiceFactory: jest.fn().mockResolvedValue(dataViewPluginMocks.createStartContract()), + getScriptedFieldsEnabled: jest.fn().mockReturnValue(true), } as DataViewsServerPluginStart; const alertsService = alertsServiceMock.create(); const maintenanceWindowClient = maintenanceWindowClientMock.create(); diff --git a/x-pack/plugins/alerting/server/task_runner/task_runner_alerts_client.test.ts b/x-pack/plugins/alerting/server/task_runner/task_runner_alerts_client.test.ts index 73d60259b8610..58f2520ce1f4a 100644 --- a/x-pack/plugins/alerting/server/task_runner/task_runner_alerts_client.test.ts +++ b/x-pack/plugins/alerting/server/task_runner/task_runner_alerts_client.test.ts @@ -129,6 +129,7 @@ describe('Task Runner', () => { const inMemoryMetrics = inMemoryMetricsMock.create(); const dataViewsMock = { dataViewsServiceFactory: jest.fn().mockResolvedValue(dataViewPluginMocks.createStartContract()), + getScriptedFieldsEnabled: jest.fn().mockReturnValue(true), } as DataViewsServerPluginStart; const mockAlertsService = alertsServiceMock.create(); const mockAlertsClient = alertsClientMock.create(); diff --git a/x-pack/plugins/alerting/server/task_runner/task_runner_cancel.test.ts b/x-pack/plugins/alerting/server/task_runner/task_runner_cancel.test.ts index 527a5d58d34d9..870cad51ed4b7 100644 --- a/x-pack/plugins/alerting/server/task_runner/task_runner_cancel.test.ts +++ b/x-pack/plugins/alerting/server/task_runner/task_runner_cancel.test.ts @@ -76,6 +76,7 @@ const alertingEventLogger = alertingEventLoggerMock.create(); const logger: ReturnType = loggingSystemMock.createLogger(); const dataViewsMock = { dataViewsServiceFactory: jest.fn().mockResolvedValue(dataViewPluginMocks.createStartContract()), + getScriptedFieldsEnabled: jest.fn().mockReturnValue(true), } as DataViewsServerPluginStart; const alertsService = alertsServiceMock.create(); diff --git a/x-pack/plugins/alerting/server/task_runner/task_runner_factory.test.ts b/x-pack/plugins/alerting/server/task_runner/task_runner_factory.test.ts index 69480563c355e..3cfa7dde78341 100644 --- a/x-pack/plugins/alerting/server/task_runner/task_runner_factory.test.ts +++ b/x-pack/plugins/alerting/server/task_runner/task_runner_factory.test.ts @@ -45,6 +45,7 @@ const elasticsearchService = elasticsearchServiceMock.createInternalStart(); const dataPlugin = dataPluginMock.createStartContract(); const dataViewsMock = { dataViewsServiceFactory: jest.fn().mockResolvedValue(dataViewPluginMocks.createStartContract()), + getScriptedFieldsEnabled: jest.fn().mockReturnValue(true), } as DataViewsServerPluginStart; const ruleType: UntypedNormalizedRuleType = { id: 'test', From e001c75fd46699a135ac2ddc5c7213f3fa4aecd4 Mon Sep 17 00:00:00 2001 From: Matt Kime Date: Sun, 13 Aug 2023 21:01:07 -0500 Subject: [PATCH 07/22] fix jest test --- .../saved_search/common/service/saved_searches_utils.test.ts | 1 + 1 file changed, 1 insertion(+) diff --git a/src/plugins/saved_search/common/service/saved_searches_utils.test.ts b/src/plugins/saved_search/common/service/saved_searches_utils.test.ts index 8286276bb898e..67f368637d3f5 100644 --- a/src/plugins/saved_search/common/service/saved_searches_utils.test.ts +++ b/src/plugins/saved_search/common/service/saved_searches_utils.test.ts @@ -60,6 +60,7 @@ describe('saved_searches_utils', () => { }, "getConfig": [MockFunction], "onResponse": [MockFunction], + "scriptedFieldsEnabled": true, "search": [MockFunction], }, "fields": Object {}, From f5283cd14d15508dd071c0d7af59df8ed8036d8a Mon Sep 17 00:00:00 2001 From: Matt Kime Date: Sun, 13 Aug 2023 23:47:57 -0500 Subject: [PATCH 08/22] add scripted fields disabled test --- .../test_suites/common/index.ts | 1 + .../test_suites/common/scripted_fields.ts | 45 +++++++++++++++++++ 2 files changed, 46 insertions(+) create mode 100644 x-pack/test_serverless/api_integration/test_suites/common/scripted_fields.ts diff --git a/x-pack/test_serverless/api_integration/test_suites/common/index.ts b/x-pack/test_serverless/api_integration/test_suites/common/index.ts index de30854beccfc..afd5dcfaf1d25 100644 --- a/x-pack/test_serverless/api_integration/test_suites/common/index.ts +++ b/x-pack/test_serverless/api_integration/test_suites/common/index.ts @@ -13,5 +13,6 @@ export default function ({ loadTestFile }: FtrProviderContext) { loadTestFile(require.resolve('./spaces')); loadTestFile(require.resolve('./security_response_headers')); loadTestFile(require.resolve('./rollups')); + loadTestFile(require.resolve('./scripted_fields')); }); } diff --git a/x-pack/test_serverless/api_integration/test_suites/common/scripted_fields.ts b/x-pack/test_serverless/api_integration/test_suites/common/scripted_fields.ts new file mode 100644 index 0000000000000..d6c77c0a27701 --- /dev/null +++ b/x-pack/test_serverless/api_integration/test_suites/common/scripted_fields.ts @@ -0,0 +1,45 @@ +/* + * Copyright Elasticsearch B.V. and/or licensed to Elasticsearch B.V. under one + * or more contributor license agreements. Licensed under the Elastic License + * 2.0; you may not use this file except in compliance with the Elastic License + * 2.0. + */ + +import expect from 'expect'; +import { DATA_VIEW_PATH } from '@kbn/data-views-plugin/server'; +import { FtrProviderContext } from '../../ftr_provider_context'; + +export default function ({ getService }: FtrProviderContext) { + const supertest = getService('supertest'); + const esArchiver = getService('esArchiver'); + + describe('scripted fields disabled', function () { + before(async () => { + await esArchiver.load('test/api_integration/fixtures/es_archiver/index_patterns/basic_index'); + }); + + after(async () => { + await esArchiver.unload( + 'test/api_integration/fixtures/es_archiver/index_patterns/basic_index' + ); + }); + it('scripted fields are ignore when disabled', async () => { + const id = 'abc'; + const response = await supertest.post(DATA_VIEW_PATH).send({ + title: 'basic_index', + id, + fields: { + foo: { + name: 'foo', + type: 'string', + scripted: true, + script: "doc['field_name'].value", + }, + }, + }); + + expect(response.status).toBe(200); + expect(response.body.fields.foo).toBeUndefined(); + }); + }); +} From ee7609e99c56606521b63d0849055536cd4babca Mon Sep 17 00:00:00 2001 From: Matt Kime Date: Mon, 14 Aug 2023 11:11:44 -0500 Subject: [PATCH 09/22] comment cleanup --- .../common/search/search_source/search_source.ts | 13 +++++++------ .../data_views/common/data_views/data_views.ts | 1 - 2 files changed, 7 insertions(+), 7 deletions(-) diff --git a/src/plugins/data/common/search/search_source/search_source.ts b/src/plugins/data/common/search/search_source/search_source.ts index fa0fdd330186a..cf41e29b59248 100644 --- a/src/plugins/data/common/search/search_source/search_source.ts +++ b/src/plugins/data/common/search/search_source/search_source.ts @@ -777,7 +777,6 @@ export class SearchSource { return field; } - // todo private flatten() { const { getConfig } = this.dependencies; const searchRequest = this.mergeProps(); @@ -800,11 +799,13 @@ export class SearchSource { // set defaults let fieldsFromSource = searchRequest.fieldsFromSource || []; body.fields = body.fields || []; - // maybe this is where the conditional goes - body.script_fields = { - ...body.script_fields, - ...scriptFields, - }; + + if (this.dependencies.scriptedFieldsEnabled) { + body.script_fields = { + ...body.script_fields, + ...scriptFields, + }; + } body.stored_fields = storedFields; body.runtime_mappings = runtimeFields || {}; diff --git a/src/plugins/data_views/common/data_views/data_views.ts b/src/plugins/data_views/common/data_views/data_views.ts index 8f97bf1c24a78..4f02a117532c5 100644 --- a/src/plugins/data_views/common/data_views/data_views.ts +++ b/src/plugins/data_views/common/data_views/data_views.ts @@ -597,7 +597,6 @@ export class DataViewsService { private refreshFieldsFn = async (indexPattern: DataView) => { const { fields, indices } = await this.getFieldsAndIndicesForDataView(indexPattern); fields.forEach((field) => (field.isMapped = true)); - // todo - uh oh, lifecycle concerns! saving data view reads from whole field list const scripted = this.scriptedFieldsEnabled ? indexPattern.getScriptedFields().map((field) => field.spec) : []; From 665e16173e31f38f8dedcb6329068f2871139b11 Mon Sep 17 00:00:00 2001 From: Matt Kime Date: Mon, 14 Aug 2023 21:11:27 -0500 Subject: [PATCH 10/22] fix test --- .../common/data_views/data_views.ts | 4 ++- .../test_suites/common/scripted_fields.ts | 29 ++++++++++--------- 2 files changed, 19 insertions(+), 14 deletions(-) diff --git a/src/plugins/data_views/common/data_views/data_views.ts b/src/plugins/data_views/common/data_views/data_views.ts index 4f02a117532c5..7e74a468d3ce8 100644 --- a/src/plugins/data_views/common/data_views/data_views.ts +++ b/src/plugins/data_views/common/data_views/data_views.ts @@ -663,7 +663,9 @@ export class DataViewsService { displayErrors: boolean = true ) => { const fieldsAsArr = Object.values(fields); - const scriptedFields = fieldsAsArr.filter((field) => field.scripted); + const scriptedFields = this.scriptedFieldsEnabled + ? fieldsAsArr.filter((field) => field.scripted) + : []; try { let updatedFieldList: FieldSpec[]; const { fields: newFields, indices } = await this.getFieldsAndIndicesForWildcard(options); diff --git a/x-pack/test_serverless/api_integration/test_suites/common/scripted_fields.ts b/x-pack/test_serverless/api_integration/test_suites/common/scripted_fields.ts index d6c77c0a27701..1376dee19fc31 100644 --- a/x-pack/test_serverless/api_integration/test_suites/common/scripted_fields.ts +++ b/x-pack/test_serverless/api_integration/test_suites/common/scripted_fields.ts @@ -24,22 +24,25 @@ export default function ({ getService }: FtrProviderContext) { ); }); it('scripted fields are ignore when disabled', async () => { - const id = 'abc'; - const response = await supertest.post(DATA_VIEW_PATH).send({ - title: 'basic_index', - id, - fields: { - foo: { - name: 'foo', - type: 'string', - scripted: true, - script: "doc['field_name'].value", + const response = await supertest + .post(DATA_VIEW_PATH) + .set('kbn-xsrf', 'some-xsrf-token') + .send({ + data_view: { + title: 'basic_index', + fields: { + foo: { + name: 'foo', + type: 'string', + scripted: true, + script: "doc['field_name'].value", + }, + }, }, - }, - }); + }); expect(response.status).toBe(200); - expect(response.body.fields.foo).toBeUndefined(); + expect(response.body.data_view.fields.foo).toBeUndefined(); }); }); } From f8f475d4205852a5e3ba3640c9a3bd40c8d30d47 Mon Sep 17 00:00:00 2001 From: Matt Kime Date: Mon, 14 Aug 2023 21:50:06 -0500 Subject: [PATCH 11/22] fix test --- .../api_integration/test_suites/common/scripted_fields.ts | 6 +++--- 1 file changed, 3 insertions(+), 3 deletions(-) diff --git a/x-pack/test_serverless/api_integration/test_suites/common/scripted_fields.ts b/x-pack/test_serverless/api_integration/test_suites/common/scripted_fields.ts index 1376dee19fc31..20194f7eb3e43 100644 --- a/x-pack/test_serverless/api_integration/test_suites/common/scripted_fields.ts +++ b/x-pack/test_serverless/api_integration/test_suites/common/scripted_fields.ts @@ -31,8 +31,8 @@ export default function ({ getService }: FtrProviderContext) { data_view: { title: 'basic_index', fields: { - foo: { - name: 'foo', + foo_scripted: { + name: 'foo_scripted', type: 'string', scripted: true, script: "doc['field_name'].value", @@ -42,7 +42,7 @@ export default function ({ getService }: FtrProviderContext) { }); expect(response.status).toBe(200); - expect(response.body.data_view.fields.foo).toBeUndefined(); + expect(response.body.data_view.fields.foo_scripted).toBeUndefined(); }); }); } From b4d87cd5c7bb6848db6760a2a534035fc98f060d Mon Sep 17 00:00:00 2001 From: Matt Kime Date: Tue, 15 Aug 2023 09:09:30 -0500 Subject: [PATCH 12/22] supply default for scripted_fields --- .../common/search/search_source/search_source.ts | 13 ++++++------- 1 file changed, 6 insertions(+), 7 deletions(-) diff --git a/src/plugins/data/common/search/search_source/search_source.ts b/src/plugins/data/common/search/search_source/search_source.ts index cf41e29b59248..c11289439885b 100644 --- a/src/plugins/data/common/search/search_source/search_source.ts +++ b/src/plugins/data/common/search/search_source/search_source.ts @@ -799,13 +799,12 @@ export class SearchSource { // set defaults let fieldsFromSource = searchRequest.fieldsFromSource || []; body.fields = body.fields || []; - - if (this.dependencies.scriptedFieldsEnabled) { - body.script_fields = { - ...body.script_fields, - ...scriptFields, - }; - } + body.script_fields = this.dependencies.scriptedFieldsEnabled + ? { + ...body.script_fields, + ...scriptFields, + } + : {}; body.stored_fields = storedFields; body.runtime_mappings = runtimeFields || {}; From 173f32bb056c12bf666d487dae0c5318d425a38a Mon Sep 17 00:00:00 2001 From: Matt Kime Date: Tue, 15 Aug 2023 20:55:27 -0500 Subject: [PATCH 13/22] better function names --- .../public/components/edit_index_pattern/tabs/utils.ts | 3 +-- src/plugins/data_view_management/public/components/utils.ts | 5 ----- 2 files changed, 1 insertion(+), 7 deletions(-) diff --git a/src/plugins/data_view_management/public/components/edit_index_pattern/tabs/utils.ts b/src/plugins/data_view_management/public/components/edit_index_pattern/tabs/utils.ts index eb2acaadb4476..6deeaa66ad3af 100644 --- a/src/plugins/data_view_management/public/components/edit_index_pattern/tabs/utils.ts +++ b/src/plugins/data_view_management/public/components/edit_index_pattern/tabs/utils.ts @@ -15,7 +15,6 @@ import { TAB_SOURCE_FILTERS, TAB_RELATIONSHIPS, } from '../constants'; -import { areScriptedFieldsEnabled } from '../../utils'; function filterByName(items: DataViewField[], filter: string) { const lowercaseFilter = (filter || '').toLowerCase(); @@ -94,7 +93,7 @@ export function getTabs( 'data-test-subj': 'tab-indexedFields', }); - if (areScriptedFieldsEnabled(indexPattern) && scriptedFieldsEnabled) { + if (indexPattern.type !== 'rollup' && scriptedFieldsEnabled) { tabs.push({ name: getTitle('scripted', filteredCount, totalCount), id: TAB_SCRIPTED_FIELDS, diff --git a/src/plugins/data_view_management/public/components/utils.ts b/src/plugins/data_view_management/public/components/utils.ts index abc89d5844f46..a5b30fba8f8d5 100644 --- a/src/plugins/data_view_management/public/components/utils.ts +++ b/src/plugins/data_view_management/public/components/utils.ts @@ -85,11 +85,6 @@ export const getTags = (indexPattern: DataViewListItem | DataView, isDefault: bo return tags; }; -// todo add to this -export const areScriptedFieldsEnabled = (indexPattern: DataViewListItem | DataView) => { - return !isRollup(indexPattern.type); -}; - export const getFieldInfo = (indexPattern: DataViewListItem | DataView, field: DataViewField) => { if (!isRollup(indexPattern.type)) { return []; From 94cc6607232858a9404ae14ab93ca729f22199bc Mon Sep 17 00:00:00 2001 From: Matt Kime Date: Wed, 16 Aug 2023 21:29:07 -0500 Subject: [PATCH 14/22] better code reuse, disable path --- .../public/components/edit_index_pattern/tabs/utils.ts | 3 ++- src/plugins/data_view_management/public/components/utils.ts | 2 +- .../public/management_app/mount_management_section.tsx | 6 +++++- 3 files changed, 8 insertions(+), 3 deletions(-) diff --git a/src/plugins/data_view_management/public/components/edit_index_pattern/tabs/utils.ts b/src/plugins/data_view_management/public/components/edit_index_pattern/tabs/utils.ts index 6deeaa66ad3af..1c372e13dbe4b 100644 --- a/src/plugins/data_view_management/public/components/edit_index_pattern/tabs/utils.ts +++ b/src/plugins/data_view_management/public/components/edit_index_pattern/tabs/utils.ts @@ -15,6 +15,7 @@ import { TAB_SOURCE_FILTERS, TAB_RELATIONSHIPS, } from '../constants'; +import { isRollup } from '../../utils'; function filterByName(items: DataViewField[], filter: string) { const lowercaseFilter = (filter || '').toLowerCase(); @@ -93,7 +94,7 @@ export function getTabs( 'data-test-subj': 'tab-indexedFields', }); - if (indexPattern.type !== 'rollup' && scriptedFieldsEnabled) { + if (!isRollup(indexPattern.type) && scriptedFieldsEnabled) { tabs.push({ name: getTitle('scripted', filteredCount, totalCount), id: TAB_SCRIPTED_FIELDS, diff --git a/src/plugins/data_view_management/public/components/utils.ts b/src/plugins/data_view_management/public/components/utils.ts index a5b30fba8f8d5..722ad5059a598 100644 --- a/src/plugins/data_view_management/public/components/utils.ts +++ b/src/plugins/data_view_management/public/components/utils.ts @@ -28,7 +28,7 @@ const rollupIndexPatternListName = i18n.translate( } ); -const isRollup = (indexPatternType: string = '') => { +export const isRollup = (indexPatternType: string = '') => { return indexPatternType === 'rollup'; }; diff --git a/src/plugins/data_view_management/public/management_app/mount_management_section.tsx b/src/plugins/data_view_management/public/management_app/mount_management_section.tsx index d7b21b395fdde..0e3c1758d2992 100644 --- a/src/plugins/data_view_management/public/management_app/mount_management_section.tsx +++ b/src/plugins/data_view_management/public/management_app/mount_management_section.tsx @@ -92,6 +92,10 @@ export async function mountManagementSection( savedObjectsManagement, }; + const editPath = '/dataView/:id/field/:fieldName'; + const createPath = '/dataView/:id/create-field/'; + const createEditPath = dataViews.scriptedFieldsEnabled ? [editPath, createPath] : [editPath]; + ReactDOM.render( @@ -100,7 +104,7 @@ export async function mountManagementSection( - + From 82271f69c4b7ec7bf2d9605bed397772e78d655c Mon Sep 17 00:00:00 2001 From: Matthew Kime Date: Wed, 16 Aug 2023 21:32:38 -0500 Subject: [PATCH 15/22] Update x-pack/test_serverless/api_integration/test_suites/common/scripted_fields.ts Co-authored-by: Julia Rechkunova --- .../api_integration/test_suites/common/scripted_fields.ts | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/x-pack/test_serverless/api_integration/test_suites/common/scripted_fields.ts b/x-pack/test_serverless/api_integration/test_suites/common/scripted_fields.ts index 20194f7eb3e43..f3969e07eea7e 100644 --- a/x-pack/test_serverless/api_integration/test_suites/common/scripted_fields.ts +++ b/x-pack/test_serverless/api_integration/test_suites/common/scripted_fields.ts @@ -23,7 +23,7 @@ export default function ({ getService }: FtrProviderContext) { 'test/api_integration/fixtures/es_archiver/index_patterns/basic_index' ); }); - it('scripted fields are ignore when disabled', async () => { + it('scripted fields are ignored when disabled', async () => { const response = await supertest .post(DATA_VIEW_PATH) .set('kbn-xsrf', 'some-xsrf-token') From 37eff5ea01f55f5863fc75764cc888a78fa0acdb Mon Sep 17 00:00:00 2001 From: Matt Kime Date: Sat, 19 Aug 2023 23:27:38 -0500 Subject: [PATCH 16/22] add functional test for scripted fields tab --- .../components/index_pattern_table/index_pattern_table.tsx | 5 ++++- .../test_serverless/functional/test_suites/common/index.ts | 3 +++ 2 files changed, 7 insertions(+), 1 deletion(-) diff --git a/src/plugins/data_view_management/public/components/index_pattern_table/index_pattern_table.tsx b/src/plugins/data_view_management/public/components/index_pattern_table/index_pattern_table.tsx index f2ab10098e4d6..0d0215e6342d7 100644 --- a/src/plugins/data_view_management/public/components/index_pattern_table/index_pattern_table.tsx +++ b/src/plugins/data_view_management/public/components/index_pattern_table/index_pattern_table.tsx @@ -213,7 +213,10 @@ export const IndexPatternTable = ({ width: '70%', render: (name: string, dataView: IndexPatternTableItem) => (
- + {dataView.getName()} {dataView.name ? ( <> diff --git a/x-pack/test_serverless/functional/test_suites/common/index.ts b/x-pack/test_serverless/functional/test_suites/common/index.ts index 7150589527b04..08e816c9bdfda 100644 --- a/x-pack/test_serverless/functional/test_suites/common/index.ts +++ b/x-pack/test_serverless/functional/test_suites/common/index.ts @@ -17,5 +17,8 @@ export default function ({ loadTestFile }: FtrProviderContext) { // Management loadTestFile(require.resolve('./index_management')); + + // Data View Management + loadTestFile(require.resolve('./data_view_mgmt')); }); } From b0d78f35267b4bff7c334f013658613ac5536d57 Mon Sep 17 00:00:00 2001 From: Matt Kime Date: Sun, 20 Aug 2023 11:42:06 -0500 Subject: [PATCH 17/22] add functional test for scripted fields tab --- .../test_suites/common/data_view_mgmt.ts | 47 +++++++++++++++++++ 1 file changed, 47 insertions(+) create mode 100644 x-pack/test_serverless/functional/test_suites/common/data_view_mgmt.ts diff --git a/x-pack/test_serverless/functional/test_suites/common/data_view_mgmt.ts b/x-pack/test_serverless/functional/test_suites/common/data_view_mgmt.ts new file mode 100644 index 0000000000000..e8ac912f06bed --- /dev/null +++ b/x-pack/test_serverless/functional/test_suites/common/data_view_mgmt.ts @@ -0,0 +1,47 @@ +/* + * Copyright Elasticsearch B.V. and/or licensed to Elasticsearch B.V. under one + * or more contributor license agreements. Licensed under the Elastic License + * 2.0; you may not use this file except in compliance with the Elastic License + * 2.0. + */ + +import expect from 'expect'; +import { DATA_VIEW_PATH } from '@kbn/data-views-plugin/server'; +import { FtrProviderContext } from '../../ftr_provider_context'; + +const archivePath = 'test/api_integration/fixtures/es_archiver/index_patterns/basic_index'; + +export default function ({ getService, getPageObjects }: FtrProviderContext) { + const PageObjects = getPageObjects(['settings', 'common', 'header']); + const esArchiver = getService('esArchiver'); + const supertest = getService('supertest'); + const testSubjects = getService('testSubjects'); + + describe('Data View Management', function () { + before(async () => { + await esArchiver.load(archivePath); + + const response = await supertest + .post(DATA_VIEW_PATH) + .set('kbn-xsrf', 'some-xsrf-token') + .send({ + data_view: { + title: 'basic_index', + }, + override: true, + }); + + expect(response.status).toBe(200); + }); + + after(async () => await esArchiver.unload(archivePath)); + + it('Scripted fields tab is missing', async () => { + await PageObjects.common.navigateToUrl('management'); + await testSubjects.click('app-card-dataViews'); + await testSubjects.click('detail-link-basic_index'); + await testSubjects.exists('tab-indexedFields'); + await testSubjects.missingOrFail('tab-scriptedFields'); + }); + }); +} From 3bfb4f1c39e3f7b6857037e5b959274f4e2e7921 Mon Sep 17 00:00:00 2001 From: Matt Kime Date: Sun, 20 Aug 2023 20:54:09 -0500 Subject: [PATCH 18/22] second attempt at navigating to kibana dat aviews --- .../functional/test_suites/common/data_view_mgmt.ts | 6 ++++-- 1 file changed, 4 insertions(+), 2 deletions(-) diff --git a/x-pack/test_serverless/functional/test_suites/common/data_view_mgmt.ts b/x-pack/test_serverless/functional/test_suites/common/data_view_mgmt.ts index e8ac912f06bed..12d6ba0069d64 100644 --- a/x-pack/test_serverless/functional/test_suites/common/data_view_mgmt.ts +++ b/x-pack/test_serverless/functional/test_suites/common/data_view_mgmt.ts @@ -37,8 +37,10 @@ export default function ({ getService, getPageObjects }: FtrProviderContext) { after(async () => await esArchiver.unload(archivePath)); it('Scripted fields tab is missing', async () => { - await PageObjects.common.navigateToUrl('management'); - await testSubjects.click('app-card-dataViews'); + await PageObjects.common.navigateToUrl('management', 'kibana/dataViews', { + shouldUseHashForSubUrl: true, + }); + // await testSubjects.click('app-card-dataViews'); await testSubjects.click('detail-link-basic_index'); await testSubjects.exists('tab-indexedFields'); await testSubjects.missingOrFail('tab-scriptedFields'); From 003738895bbf00ea73d4645233569d6c04b34cb9 Mon Sep 17 00:00:00 2001 From: Matt Kime Date: Sun, 20 Aug 2023 21:28:36 -0500 Subject: [PATCH 19/22] fix functional test --- .../functional/test_suites/common/data_view_mgmt.ts | 3 +-- 1 file changed, 1 insertion(+), 2 deletions(-) diff --git a/x-pack/test_serverless/functional/test_suites/common/data_view_mgmt.ts b/x-pack/test_serverless/functional/test_suites/common/data_view_mgmt.ts index 12d6ba0069d64..e9af08c301bd6 100644 --- a/x-pack/test_serverless/functional/test_suites/common/data_view_mgmt.ts +++ b/x-pack/test_serverless/functional/test_suites/common/data_view_mgmt.ts @@ -38,9 +38,8 @@ export default function ({ getService, getPageObjects }: FtrProviderContext) { it('Scripted fields tab is missing', async () => { await PageObjects.common.navigateToUrl('management', 'kibana/dataViews', { - shouldUseHashForSubUrl: true, + shouldUseHashForSubUrl: false, }); - // await testSubjects.click('app-card-dataViews'); await testSubjects.click('detail-link-basic_index'); await testSubjects.exists('tab-indexedFields'); await testSubjects.missingOrFail('tab-scriptedFields'); From f3208c0e7062e893e4683fefcadedb9d8cf9b2cc Mon Sep 17 00:00:00 2001 From: Matt Kime Date: Sun, 20 Aug 2023 22:43:31 -0500 Subject: [PATCH 20/22] fix functional test --- .../functional/test_suites/common/data_view_mgmt.ts | 8 +++++++- 1 file changed, 7 insertions(+), 1 deletion(-) diff --git a/x-pack/test_serverless/functional/test_suites/common/data_view_mgmt.ts b/x-pack/test_serverless/functional/test_suites/common/data_view_mgmt.ts index e9af08c301bd6..7e41ed68f8def 100644 --- a/x-pack/test_serverless/functional/test_suites/common/data_view_mgmt.ts +++ b/x-pack/test_serverless/functional/test_suites/common/data_view_mgmt.ts @@ -18,6 +18,8 @@ export default function ({ getService, getPageObjects }: FtrProviderContext) { const testSubjects = getService('testSubjects'); describe('Data View Management', function () { + let dataViewId = ''; + before(async () => { await esArchiver.load(archivePath); @@ -32,9 +34,13 @@ export default function ({ getService, getPageObjects }: FtrProviderContext) { }); expect(response.status).toBe(200); + dataViewId = response.body.data_view.id; }); - after(async () => await esArchiver.unload(archivePath)); + after(async () => { + await esArchiver.unload(archivePath); + await supertest.delete(`${DATA_VIEW_PATH}/${dataViewId}`).set('kbn-xsrf', 'some-xsrf-token'); + }); it('Scripted fields tab is missing', async () => { await PageObjects.common.navigateToUrl('management', 'kibana/dataViews', { From d5ccd0048248964ab0c0ab0e1658552ddc44b48b Mon Sep 17 00:00:00 2001 From: Matt Kime Date: Mon, 21 Aug 2023 08:03:02 -0500 Subject: [PATCH 21/22] simplify type --- src/plugins/data_views/common/types.ts | 4 ++++ src/plugins/data_views/public/plugin.ts | 5 +---- src/plugins/data_views/server/plugin.ts | 6 +----- 3 files changed, 6 insertions(+), 9 deletions(-) diff --git a/src/plugins/data_views/common/types.ts b/src/plugins/data_views/common/types.ts index 97d76941ea40c..9061c4643dce9 100644 --- a/src/plugins/data_views/common/types.ts +++ b/src/plugins/data_views/common/types.ts @@ -525,3 +525,7 @@ export interface HasDataService { hasUserDataView: () => Promise; hasDataView: () => Promise; } + +export interface ClientConfigType { + scriptedFieldsEnabled?: boolean; +} diff --git a/src/plugins/data_views/public/plugin.ts b/src/plugins/data_views/public/plugin.ts index 223d5e913f8a5..98558c803da10 100644 --- a/src/plugins/data_views/public/plugin.ts +++ b/src/plugins/data_views/public/plugin.ts @@ -9,6 +9,7 @@ import { CoreSetup, CoreStart, Plugin, PluginInitializerContext } from '@kbn/core/public'; import { i18n } from '@kbn/i18n'; import { getIndexPatternLoad } from './expressions'; +import type { ClientConfigType } from '../common/types'; import { DataViewsPublicPluginSetup, DataViewsPublicPluginStart, @@ -16,10 +17,6 @@ import { DataViewsPublicStartDependencies, } from './types'; -interface ClientConfigType { - scriptedFieldsEnabled?: boolean; -} - import { DataViewsApiClient } from '.'; import { ContentMagementWrapper } from './content_management_wrapper'; diff --git a/src/plugins/data_views/server/plugin.ts b/src/plugins/data_views/server/plugin.ts index 6dc98bf0e282d..2be269b1a7636 100644 --- a/src/plugins/data_views/server/plugin.ts +++ b/src/plugins/data_views/server/plugin.ts @@ -15,6 +15,7 @@ import { getIndexPatternLoad } from './expressions'; import { registerIndexPatternsUsageCollector } from './register_index_pattern_usage_collection'; import { createScriptedFieldsDeprecationsConfig } from './deprecations'; import { DATA_VIEW_SAVED_OBJECT_TYPE, LATEST_VERSION } from '../common'; +import type { ClientConfigType } from '../common/types'; import { DataViewsServerPluginSetup, DataViewsServerPluginStart, @@ -23,11 +24,6 @@ import { } from './types'; import { DataViewsStorage } from './content_management'; -// duped, change -interface ClientConfigType { - scriptedFieldsEnabled?: boolean; -} - export class DataViewsServerPlugin implements Plugin< From 3480c5247909bc61c54c723cfcacd8e331a178b7 Mon Sep 17 00:00:00 2001 From: Matt Kime Date: Mon, 21 Aug 2023 09:26:39 -0500 Subject: [PATCH 22/22] add unit test --- .../search/search_source/search_source.test.ts | 16 ++++++++++++++++ 1 file changed, 16 insertions(+) diff --git a/src/plugins/data/common/search/search_source/search_source.test.ts b/src/plugins/data/common/search/search_source/search_source.test.ts index 45319e39060d9..eeb4c5a972e3a 100644 --- a/src/plugins/data/common/search/search_source/search_source.test.ts +++ b/src/plugins/data/common/search/search_source/search_source.test.ts @@ -652,6 +652,22 @@ describe('SearchSource', () => { const request = searchSource.getSearchRequestBody(); expect(request.script_fields).toEqual({ hello: {}, world: {} }); }); + + test('ignores scripted fields when scripted fields are disabled', async () => { + searchSource.setField('index', { + ...indexPattern, + getComputedFields: () => ({ + storedFields: [], + scriptFields: { hello: {}, world: {} }, + docvalueFields: [], + }), + } as unknown as DataView); + searchSourceDependencies.scriptedFieldsEnabled = false; + searchSource.setField('fields', ['timestamp', '*']); + + const request = searchSource.getSearchRequestBody(); + expect(request.script_fields).toEqual({}); + }); }); describe('handling for when specific fields are provided', () => {