Skip to content

Commit

Permalink
[Mappings Editor] Disable _source field in serverless (#181712)
Browse files Browse the repository at this point in the history
Closes #181555

## Summary

This PR disables the `_source` field in the Mappings editor's advanced
options when in serverless.

**How to test:**
1. Start a serverless project.
2. Go to Index Management and start creating an index template or a
component template.
3. In the Mappings step, go to the "Advanced options" tab.
4. Verify that the `_source` field is not displayed and that creating a
template doesn't add this property to the Es request.
5. Verify that, in stateful Kibana, the `_source` field still exists and
works as expected.

<!--
### Checklist

Delete any items that are not applicable to this PR.

- [ ] Any text added follows [EUI's writing
guidelines](https://elastic.github.io/eui/#/guidelines/writing), uses
sentence case text and includes [i18n
support](https://github.com/elastic/kibana/blob/main/packages/kbn-i18n/README.md)
- [ ]
[Documentation](https://www.elastic.co/guide/en/kibana/master/development-documentation.html)
was added for features that require explanation or tutorials
- [ ] [Unit or functional
tests](https://www.elastic.co/guide/en/kibana/master/development-tests.html)
were updated or added to match the most common scenarios
- [ ] [Flaky Test
Runner](https://ci-stats.kibana.dev/trigger_flaky_test_runner/1) was
used on any tests changed
- [ ] Any UI touched in this PR is usable by keyboard only (learn more
about [keyboard accessibility](https://webaim.org/techniques/keyboard/))
- [ ] Any UI touched in this PR does not create any new axe failures
(run axe in browser:
[FF](https://addons.mozilla.org/en-US/firefox/addon/axe-devtools/),
[Chrome](https://chrome.google.com/webstore/detail/axe-web-accessibility-tes/lhdoppojpmngadmnindnejefpokejbdd?hl=en-US))
- [ ] If a plugin configuration key changed, check if it needs to be
allowlisted in the cloud and added to the [docker
list](https://github.com/elastic/kibana/blob/main/src/dev/build/tasks/os_packages/docker_generator/resources/base/bin/kibana-docker)
- [ ] This renders correctly on smaller devices using a responsive
layout. (You can test this [in your
browser](https://www.browserstack.com/guide/responsive-testing-on-local-server))
- [ ] This was checked for [cross-browser
compatibility](https://www.elastic.co/support/matrix#matrix_browsers)


### Risk Matrix

Delete this section if it is not applicable to this PR.

Before closing this PR, invite QA, stakeholders, and other developers to
identify risks that should be tested prior to the change/feature
release.

When forming the risk matrix, consider some of the following examples
and how they may potentially impact the change:

| Risk | Probability | Severity | Mitigation/Notes |

|---------------------------|-------------|----------|-------------------------|
| Multiple Spaces&mdash;unexpected behavior in non-default Kibana Space.
| Low | High | Integration tests will verify that all features are still
supported in non-default Kibana Space and when user switches between
spaces. |
| Multiple nodes&mdash;Elasticsearch polling might have race conditions
when multiple Kibana nodes are polling for the same tasks. | High | Low
| Tasks are idempotent, so executing them multiple times will not result
in logical error, but will degrade performance. To test for this case we
add plenty of unit tests around this logic and document manual testing
procedure. |
| Code should gracefully handle cases when feature X or plugin Y are
disabled. | Medium | High | Unit tests will verify that any feature flag
or plugin combination still results in our service operational. |
| [See more potential risk
examples](https://github.com/elastic/kibana/blob/main/RISK_MATRIX.mdx) |

### For maintainers

- [ ] This was checked for breaking API changes and was [labeled
appropriately](https://www.elastic.co/guide/en/kibana/master/contributing.html#kibana-release-notes-process)
-->

---------

Co-authored-by: kibanamachine <[email protected]>
  • Loading branch information
ElenaStoeva and kibanamachine authored May 1, 2024
1 parent e4a381a commit 8e25828
Show file tree
Hide file tree
Showing 19 changed files with 175 additions and 30 deletions.
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

0 comments on commit 8e25828

Please sign in to comment.