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

[Mappings Editor] Disable _source field in serverless #181712

Merged
Show file tree
Hide file tree
Changes from all 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: 2 additions & 0 deletions config/serverless.yml
Original file line number Diff line number Diff line change
Expand Up @@ -48,6 +48,8 @@ xpack.index_management.enableIndexStats: false
xpack.index_management.editableIndexSettings: limited
# Disable Storage size column in the Data streams table from Index Management UI
xpack.index_management.enableDataStreamsStorageColumn: false
# Disable _source field in the Mappings editor's advanced options form from Index Management UI
xpack.index_management.enableMappingsSourceFieldSection: false
# Disable toggle for enabling data retention in DSL form from Index Management UI
xpack.index_management.enableTogglingDataRetention: false

Expand Down
11 changes: 6 additions & 5 deletions test/plugin_functional/test_suites/core_plugins/rendering.ts
Original file line number Diff line number Diff line change
Expand Up @@ -271,11 +271,6 @@ export default function ({ getService }: PluginFunctionalProviderContext) {
'xpack.graph.savePolicy (alternatives)',
'xpack.ilm.ui.enabled (boolean)',
'xpack.index_management.ui.enabled (boolean)',
'xpack.index_management.enableIndexActions (any)',
'xpack.index_management.enableLegacyTemplates (any)',
'xpack.index_management.enableIndexStats (any)',
'xpack.index_management.editableIndexSettings (any)',
'xpack.index_management.enableDataStreamsStorageColumn (any)',
'xpack.infra.sources.default.fields.message (array)',
'xpack.index_management.enableTogglingDataRetention (any)', // It's a boolean (any because schema.conditional)
/**
Expand All @@ -292,6 +287,12 @@ export default function ({ getService }: PluginFunctionalProviderContext) {
'xpack.infra.featureFlags.alertsAndRulesDropdownEnabled (any)',
'xpack.infra.featureFlags.profilingEnabled (boolean)',

'xpack.index_management.enableIndexActions (any)',
'xpack.index_management.enableLegacyTemplates (any)',
'xpack.index_management.enableIndexStats (any)',
'xpack.index_management.editableIndexSettings (any)',
'xpack.index_management.enableDataStreamsStorageColumn (any)',
'xpack.index_management.enableMappingsSourceFieldSection (any)',
'xpack.license_management.ui.enabled (boolean)',
'xpack.maps.preserveDrawingBuffer (boolean)',
'xpack.maps.showMapsInspectorAdapter (boolean)',
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -84,6 +84,7 @@ const appDependencies = {
enableIndexStats: true,
editableIndexSettings: 'all',
enableDataStreamsStorageColumn: true,
enableMappingsSourceFieldSection: true,
enableTogglingDataRetention: true,
},
} as any;
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -62,6 +62,7 @@ export interface AppDependencies {
enableIndexStats: boolean;
editableIndexSettings: 'all' | 'limited';
enableDataStreamsStorageColumn: boolean;
enableMappingsSourceFieldSection: boolean;
enableTogglingDataRetention: boolean;
};
history: ScopedHistory;
Expand Down
Original file line number Diff line number Diff line change
@@ -0,0 +1,83 @@
/*
* 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 { AppDependencies } from '../../../..';
import { registerTestBed, TestBed } from '@kbn/test-jest-helpers';
import { ConfigurationForm } from '../../components/configuration_form';
import { WithAppDependencies } from './helpers/setup_environment';
import { TestSubjects } from './helpers/mappings_editor.helpers';
import { act } from 'react-dom/test-utils';

const setup = (props: any = { onUpdate() {} }, appDependencies?: any) => {
const setupTestBed = registerTestBed<TestSubjects>(
WithAppDependencies(ConfigurationForm, appDependencies),
{
memoryRouter: {
wrapComponent: false,
},
defaultProps: props,
}
);

const testBed = setupTestBed();

return testBed;
};

describe('Mappings editor: configuration form', () => {
let testBed: TestBed<TestSubjects>;

it('renders the form', async () => {
const ctx = {
config: {
enableMappingsSourceFieldSection: true,
},
} as unknown as AppDependencies;

await act(async () => {
testBed = setup({ esNodesPlugins: [] }, ctx);
});
testBed.component.update();
const { exists } = testBed;

expect(exists('advancedConfiguration')).toBe(true);
});

describe('_source field', () => {
it('renders the _source field when it is enabled', async () => {
const ctx = {
config: {
enableMappingsSourceFieldSection: true,
},
} as unknown as AppDependencies;

await act(async () => {
testBed = setup({ esNodesPlugins: [] }, ctx);
});
testBed.component.update();
const { exists } = testBed;

expect(exists('sourceField')).toBe(true);
});

it("doesn't render the _source field when it is disabled", async () => {
const ctx = {
config: {
enableMappingsSourceFieldSection: false,
},
} as unknown as AppDependencies;

await act(async () => {
testBed = setup({ esNodesPlugins: [] }, ctx);
});
testBed.component.update();
const { exists } = testBed;

expect(exists('sourceField')).toBe(false);
});
});
});
Original file line number Diff line number Diff line change
Expand Up @@ -376,13 +376,19 @@ const createActions = (testBed: TestBed<TestSubjects>) => {
};
};

export const setup = (props: any = { onUpdate() {} }): MappingsEditorTestBed => {
const setupTestBed = registerTestBed<TestSubjects>(WithAppDependencies(MappingsEditor), {
memoryRouter: {
wrapComponent: false,
},
defaultProps: props,
});
export const setup = (
props: any = { onUpdate() {} },
appDependencies?: any
): MappingsEditorTestBed => {
const setupTestBed = registerTestBed<TestSubjects>(
WithAppDependencies(MappingsEditor, appDependencies),
{
memoryRouter: {
wrapComponent: false,
},
defaultProps: props,
}
);

const testBed = setupTestBed() as MappingsEditorTestBed;

Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -13,6 +13,7 @@ import { docLinksServiceMock, uiSettingsServiceMock } from '@kbn/core/public/moc
import { MAJOR_VERSION } from '../../../../../../../common';
import { MappingsEditorProvider } from '../../../mappings_editor_context';
import { createKibanaReactContext } from '../../../shared_imports';
import { AppContextProvider } from '../../../../../app_context';
import { Props as MappingsEditorProps } from '../../../mappings_editor';

export const kibanaVersion = new SemVer(MAJOR_VERSION);
Expand Down Expand Up @@ -83,14 +84,16 @@ const defaultProps: MappingsEditorProps = {
};

export const WithAppDependencies =
(Comp: MemoExoticComponent<ComponentType<MappingsEditorProps>>) =>
(Comp: MemoExoticComponent<ComponentType<MappingsEditorProps>>, appDependencies?: any) =>
(props: Partial<MappingsEditorProps>) =>
(
<KibanaReactContextProvider>
<MappingsEditorProvider>
<GlobalFlyoutProvider>
<Comp {...defaultProps} {...props} />
</GlobalFlyoutProvider>
</MappingsEditorProvider>
<AppContextProvider value={appDependencies}>
<MappingsEditorProvider>
<GlobalFlyoutProvider>
<Comp {...defaultProps} {...props} />
</GlobalFlyoutProvider>
</MappingsEditorProvider>
</AppContextProvider>
</KibanaReactContextProvider>
);
Original file line number Diff line number Diff line change
Expand Up @@ -133,9 +133,15 @@ describe('Mappings editor: core', () => {
dynamic_templates: [{ before: 'foo' }],
};

const ctx = {
config: {
enableMappingsSourceFieldSection: true,
},
};

beforeEach(async () => {
await act(async () => {
testBed = setup({ value: defaultMappings, onChange: onChangeHandler });
testBed = setup({ value: defaultMappings, onChange: onChangeHandler }, ctx);
});
testBed.component.update();
});
Expand Down Expand Up @@ -248,10 +254,13 @@ describe('Mappings editor: core', () => {

test('should keep default dynamic templates value when switching tabs', async () => {
await act(async () => {
testBed = setup({
value: { ...defaultMappings, dynamic_templates: [] }, // by default, the UI will provide an empty array for dynamic templates
onChange: onChangeHandler,
});
testBed = setup(
{
value: { ...defaultMappings, dynamic_templates: [] }, // by default, the UI will provide an empty array for dynamic templates
onChange: onChangeHandler,
},
ctx
);
});
testBed.component.update();

Expand Down Expand Up @@ -282,6 +291,12 @@ describe('Mappings editor: core', () => {
*/
let defaultMappings: any;

const ctx = {
config: {
enableMappingsSourceFieldSection: true,
},
};

beforeEach(async () => {
defaultMappings = {
dynamic: true,
Expand Down Expand Up @@ -312,7 +327,7 @@ describe('Mappings editor: core', () => {
};

await act(async () => {
testBed = setup({ value: defaultMappings, onChange: onChangeHandler });
testBed = setup({ value: defaultMappings, onChange: onChangeHandler }, ctx);
});
testBed.component.update();
});
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -5,9 +5,11 @@
* 2.0.
*/

import React, { useEffect, useRef } from 'react';
import React, { useEffect, useRef, useCallback } from 'react';
import { EuiSpacer } from '@elastic/eui';

import { FormData } from '@kbn/es-ui-shared-plugin/static/forms/hook_form_lib';
import { useAppContext } from '../../../../app_context';
import { useForm, Form } from '../../shared_imports';
import { GenericObject, MappingsConfiguration } from '../../types';
import { MapperSizePluginId } from '../../constants';
Expand All @@ -25,7 +27,7 @@ interface Props {
esNodesPlugins: string[];
}

const formSerializer = (formData: GenericObject) => {
const formSerializer = (formData: GenericObject, sourceFieldMode?: string) => {
const {
dynamicMapping: {
enabled: dynamicMappingsEnabled,
Expand All @@ -49,7 +51,7 @@ const formSerializer = (formData: GenericObject) => {
numeric_detection,
date_detection,
dynamic_date_formats,
_source: sourceField,
_source: sourceFieldMode ? { mode: sourceFieldMode } : sourceField,
_meta: metaField,
_routing,
_size,
Expand Down Expand Up @@ -97,11 +99,20 @@ const formDeserializer = (formData: GenericObject) => {
};

export const ConfigurationForm = React.memo(({ value, esNodesPlugins }: Props) => {
const {
config: { enableMappingsSourceFieldSection },
} = useAppContext();

const isMounted = useRef(false);

const serializerCallback = useCallback(
(formData: FormData) => formSerializer(formData, value?._source?.mode),
[value?._source?.mode]
);

const { form } = useForm({
schema: configurationFormSchema,
serializer: formSerializer,
serializer: serializerCallback,
deserializer: formDeserializer,
defaultValue: value,
id: 'configurationForm',
Expand Down Expand Up @@ -159,8 +170,11 @@ export const ConfigurationForm = React.memo(({ value, esNodesPlugins }: Props) =
<EuiSpacer size="xl" />
<MetaFieldSection />
<EuiSpacer size="xl" />
<SourceFieldSection />
<EuiSpacer size="xl" />
{enableMappingsSourceFieldSection && !value?._source?.mode && (
<>
<SourceFieldSection /> <EuiSpacer size="xl" />
</>
)}
<RoutingSection />
{isMapperSizeSectionVisible && <MapperSizePluginSection />}
</Form>
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -223,6 +223,7 @@ export const mappingsConfigurationSchema = t.exact(
enabled: t.boolean,
includes: t.array(t.string),
excludes: t.array(t.string),
mode: t.union([t.literal('disabled'), t.literal('stored'), t.literal('synthetic')]),
})
),
_meta: t.UnknownRecord,
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -30,6 +30,7 @@ export interface MappingsConfiguration {
enabled?: boolean;
includes?: string[];
excludes?: string[];
mode?: string;
};
_meta?: string;
_size?: { enabled: boolean };
Expand Down
3 changes: 3 additions & 0 deletions x-pack/plugins/index_management/public/plugin.ts
Original file line number Diff line number Diff line change
Expand Up @@ -44,6 +44,7 @@ export class IndexMgmtUIPlugin
editableIndexSettings: 'all' | 'limited';
enableDataStreamsStorageColumn: boolean;
isIndexManagementUiEnabled: boolean;
enableMappingsSourceFieldSection: boolean;
enableTogglingDataRetention: boolean;
};

Expand All @@ -59,6 +60,7 @@ export class IndexMgmtUIPlugin
enableIndexStats,
editableIndexSettings,
enableDataStreamsStorageColumn,
enableMappingsSourceFieldSection,
enableTogglingDataRetention,
} = ctx.config.get<ClientConfigType>();
this.config = {
Expand All @@ -68,6 +70,7 @@ export class IndexMgmtUIPlugin
enableIndexStats: enableIndexStats ?? true,
editableIndexSettings: editableIndexSettings ?? 'all',
enableDataStreamsStorageColumn: enableDataStreamsStorageColumn ?? true,
enableMappingsSourceFieldSection: enableMappingsSourceFieldSection ?? true,
enableTogglingDataRetention: enableTogglingDataRetention ?? true,
};
}
Expand Down
1 change: 1 addition & 0 deletions x-pack/plugins/index_management/public/types.ts
Original file line number Diff line number Diff line change
Expand Up @@ -39,5 +39,6 @@ export interface ClientConfigType {
enableIndexStats?: boolean;
editableIndexSettings?: 'all' | 'limited';
enableDataStreamsStorageColumn?: boolean;
enableMappingsSourceFieldSection?: boolean;
enableTogglingDataRetention?: boolean;
}
6 changes: 6 additions & 0 deletions x-pack/plugins/index_management/server/config.ts
Original file line number Diff line number Diff line change
Expand Up @@ -52,6 +52,11 @@ const schemaLatest = schema.object(
// We take this approach in order to have a central place (serverless.yml) for serverless config across Kibana
serverless: schema.boolean({ defaultValue: true }),
}),
enableMappingsSourceFieldSection: offeringBasedSchema({
// The _source field in the Mappings editor's advanced options form is disabled in serverless; refer to the serverless.yml file as the source of truth
// We take this approach in order to have a central place (serverless.yml) for serverless config across Kibana
serverless: schema.boolean({ defaultValue: true }),
}),
enableTogglingDataRetention: offeringBasedSchema({
// The toggle for enabling data retention for DSL in data streams UI is disabled in serverless; refer to the serverless.yml file as the source of truth
// We take this approach in order to have a central place (serverless.yml) for serverless config across Kibana
Expand All @@ -69,6 +74,7 @@ const configLatest: PluginConfigDescriptor<IndexManagementConfig> = {
enableIndexStats: true,
editableIndexSettings: true,
enableDataStreamsStorageColumn: true,
enableMappingsSourceFieldSection: true,
enableTogglingDataRetention: true,
},
schema: schemaLatest,
Expand Down
1 change: 1 addition & 0 deletions x-pack/plugins/index_management/server/plugin.ts
Original file line number Diff line number Diff line change
Expand Up @@ -57,6 +57,7 @@ export class IndexMgmtServerPlugin implements Plugin<IndexManagementPluginSetup,
isLegacyTemplatesEnabled: this.config.enableLegacyTemplates,
isIndexStatsEnabled: this.config.enableIndexStats,
isDataStreamsStorageColumnEnabled: this.config.enableDataStreamsStorageColumn,
enableMappingsSourceFieldSection: this.config.enableMappingsSourceFieldSection,
enableTogglingDataRetention: this.config.enableTogglingDataRetention,
},
indexDataEnricher: this.indexDataEnricher,
Expand Down
Loading