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 4 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.enableMappingsSourceField: false

# Keep deeplinks visible so that they are shown in the sidenav
dev_tools.deeplinks.navLinkStatus: visible
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -276,6 +276,7 @@ export default function ({ getService }: PluginFunctionalProviderContext) {
'xpack.index_management.enableIndexStats (any)',
'xpack.index_management.editableIndexSettings (any)',
'xpack.index_management.enableDataStreamsStorageColumn (any)',
'xpack.index_management.enableMappingsSourceField (any)',
jeramysoucy marked this conversation as resolved.
Show resolved Hide resolved
Copy link
Contributor

@jeramysoucy jeramysoucy Apr 26, 2024

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Nit: could we just move this down below the comment with the other conditional flags, or comment as 'any' due to offering based schema?

Copy link
Contributor Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Sure, I moved it below the comment as well as the rest of the index management offering-based configs for consistency.

'xpack.infra.sources.default.fields.message (array)',
/**
* Feature flags bellow are conditional based on traditional/serverless offering
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,
enableMappingsSourceField: 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;
enableMappingsSourceField: boolean;
};
history: ScopedHistory;
setBreadcrumbs: (type: IndexManagementBreadcrumb, additionalBreadcrumb?: EuiBreadcrumb) => void;
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: {
enableMappingsSourceField: 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: {
enableMappingsSourceField: 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: {
enableMappingsSourceField: 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: {
enableMappingsSourceField: 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: {
enableMappingsSourceField: 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 @@ -8,6 +8,7 @@
import React, { useEffect, useRef } from 'react';
import { EuiSpacer } from '@elastic/eui';

import { useAppContext } from '../../../../app_context';
import { useForm, Form } from '../../shared_imports';
import { GenericObject, MappingsConfiguration } from '../../types';
import { MapperSizePluginId } from '../../constants';
Expand Down Expand Up @@ -97,6 +98,10 @@ const formDeserializer = (formData: GenericObject) => {
};

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

const isMounted = useRef(false);

const { form } = useForm({
Expand Down Expand Up @@ -159,8 +164,11 @@ export const ConfigurationForm = React.memo(({ value, esNodesPlugins }: Props) =
<EuiSpacer size="xl" />
<MetaFieldSection />
<EuiSpacer size="xl" />
<SourceFieldSection />
<EuiSpacer size="xl" />
{enableMappingsSourceField && (
<>
<SourceFieldSection /> <EuiSpacer size="xl" />
</>
)}
<RoutingSection />
{isMapperSizeSectionVisible && <MapperSizePluginSection />}
</Form>
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;
enableMappingsSourceField: boolean;
};

constructor(ctx: PluginInitializerContext) {
Expand All @@ -58,6 +59,7 @@ export class IndexMgmtUIPlugin
enableIndexStats,
editableIndexSettings,
enableDataStreamsStorageColumn,
enableMappingsSourceField,
} = ctx.config.get<ClientConfigType>();
this.config = {
isIndexManagementUiEnabled,
Expand All @@ -66,6 +68,7 @@ export class IndexMgmtUIPlugin
enableIndexStats: enableIndexStats ?? true,
editableIndexSettings: editableIndexSettings ?? 'all',
enableDataStreamsStorageColumn: enableDataStreamsStorageColumn ?? true,
enableMappingsSourceField: enableMappingsSourceField ?? 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,4 +39,5 @@ export interface ClientConfigType {
enableIndexStats?: boolean;
editableIndexSettings?: 'all' | 'limited';
enableDataStreamsStorageColumn?: boolean;
enableMappingsSourceField?: 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 }),
}),
enableMappingsSourceField: offeringBasedSchema({
Copy link
Contributor Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

I was thinking about renaming the config to enableMappingsSourceFieldConfiguration but this might be too long. I'm open to any suggestions for the name of the config.

Copy link
Contributor

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

What about enableMappingsSourceFieldConfig or enableMappingsSourceFieldSection? A little shorter, but not much 😅 . I'm also OK to leave it how you have it.

Copy link
Contributor Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Thanks for the suggestions! I like enableMappingsSourceFieldSection since the component for the _source field configuration is called SourceFieldSection. Added this change with 813297e.

// 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 }),
}),
},
{ defaultValue: undefined }
);
Expand All @@ -64,6 +69,7 @@ const configLatest: PluginConfigDescriptor<IndexManagementConfig> = {
enableIndexStats: true,
editableIndexSettings: true,
enableDataStreamsStorageColumn: true,
enableMappingsSourceField: true,
},
schema: schemaLatest,
deprecations: ({ unused }) => [unused('dev.enableIndexDetailsPage', { level: 'warning' })],
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,
enableMappingsSourceField: this.config.enableMappingsSourceField,
},
indexDataEnricher: this.indexDataEnricher,
lib: {
Expand Down
1 change: 1 addition & 0 deletions x-pack/plugins/index_management/server/types.ts
Original file line number Diff line number Diff line change
Expand Up @@ -26,6 +26,7 @@ export interface RouteDependencies {
isLegacyTemplatesEnabled: boolean;
isIndexStatsEnabled: boolean;
isDataStreamsStorageColumnEnabled: boolean;
enableMappingsSourceField: boolean;
};
indexDataEnricher: IndexDataEnricher;
lib: {
Expand Down