[Mappings Editor] Disable _source field in serverless (#181712)

Closes https://github.com/elastic/kibana/issues/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 <42973632+kibanamachine@users.noreply.github.com>
This commit is contained in:
Elena Stoeva 2024-05-01 21:03:25 +03:00 committed by GitHub
parent e4a381a5ba
commit 8e258282f9
No known key found for this signature in database
GPG key ID: B5690EEEBB952194
19 changed files with 175 additions and 30 deletions

View file

@ -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

View file

@ -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)
/**
@ -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)',

View file

@ -84,6 +84,7 @@ const appDependencies = {
enableIndexStats: true,
editableIndexSettings: 'all',
enableDataStreamsStorageColumn: true,
enableMappingsSourceFieldSection: true,
enableTogglingDataRetention: true,
},
} as any;

View file

@ -62,6 +62,7 @@ export interface AppDependencies {
enableIndexStats: boolean;
editableIndexSettings: 'all' | 'limited';
enableDataStreamsStorageColumn: boolean;
enableMappingsSourceFieldSection: boolean;
enableTogglingDataRetention: boolean;
};
history: ScopedHistory;

View file

@ -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);
});
});
});

View file

@ -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;

View file

@ -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);
@ -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>
);

View file

@ -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();
});
@ -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();
@ -282,6 +291,12 @@ describe('Mappings editor: core', () => {
*/
let defaultMappings: any;
const ctx = {
config: {
enableMappingsSourceFieldSection: true,
},
};
beforeEach(async () => {
defaultMappings = {
dynamic: true,
@ -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();
});

View file

@ -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';
@ -25,7 +27,7 @@ interface Props {
esNodesPlugins: string[];
}
const formSerializer = (formData: GenericObject) => {
const formSerializer = (formData: GenericObject, sourceFieldMode?: string) => {
const {
dynamicMapping: {
enabled: dynamicMappingsEnabled,
@ -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,
@ -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',
@ -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>

View file

@ -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,

View file

@ -30,6 +30,7 @@ export interface MappingsConfiguration {
enabled?: boolean;
includes?: string[];
excludes?: string[];
mode?: string;
};
_meta?: string;
_size?: { enabled: boolean };

View file

@ -44,6 +44,7 @@ export class IndexMgmtUIPlugin
editableIndexSettings: 'all' | 'limited';
enableDataStreamsStorageColumn: boolean;
isIndexManagementUiEnabled: boolean;
enableMappingsSourceFieldSection: boolean;
enableTogglingDataRetention: boolean;
};
@ -59,6 +60,7 @@ export class IndexMgmtUIPlugin
enableIndexStats,
editableIndexSettings,
enableDataStreamsStorageColumn,
enableMappingsSourceFieldSection,
enableTogglingDataRetention,
} = ctx.config.get<ClientConfigType>();
this.config = {
@ -68,6 +70,7 @@ export class IndexMgmtUIPlugin
enableIndexStats: enableIndexStats ?? true,
editableIndexSettings: editableIndexSettings ?? 'all',
enableDataStreamsStorageColumn: enableDataStreamsStorageColumn ?? true,
enableMappingsSourceFieldSection: enableMappingsSourceFieldSection ?? true,
enableTogglingDataRetention: enableTogglingDataRetention ?? true,
};
}

View file

@ -39,5 +39,6 @@ export interface ClientConfigType {
enableIndexStats?: boolean;
editableIndexSettings?: 'all' | 'limited';
enableDataStreamsStorageColumn?: boolean;
enableMappingsSourceFieldSection?: boolean;
enableTogglingDataRetention?: boolean;
}

View file

@ -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
@ -69,6 +74,7 @@ const configLatest: PluginConfigDescriptor<IndexManagementConfig> = {
enableIndexStats: true,
editableIndexSettings: true,
enableDataStreamsStorageColumn: true,
enableMappingsSourceFieldSection: true,
enableTogglingDataRetention: true,
},
schema: schemaLatest,

View file

@ -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,

View file

@ -49,6 +49,7 @@ describe('GET privileges', () => {
isLegacyTemplatesEnabled: true,
isIndexStatsEnabled: true,
isDataStreamsStorageColumnEnabled: true,
enableMappingsSourceFieldSection: true,
enableTogglingDataRetention: true,
},
indexDataEnricher: mockedIndexDataEnricher,
@ -119,6 +120,7 @@ describe('GET privileges', () => {
isLegacyTemplatesEnabled: true,
isIndexStatsEnabled: true,
isDataStreamsStorageColumnEnabled: true,
enableMappingsSourceFieldSection: true,
enableTogglingDataRetention: true,
},
indexDataEnricher: mockedIndexDataEnricher,

View file

@ -49,6 +49,7 @@ describe('GET privileges', () => {
isLegacyTemplatesEnabled: true,
isIndexStatsEnabled: true,
isDataStreamsStorageColumnEnabled: true,
enableMappingsSourceFieldSection: true,
enableTogglingDataRetention: true,
},
indexDataEnricher: mockedIndexDataEnricher,
@ -119,6 +120,7 @@ describe('GET privileges', () => {
isLegacyTemplatesEnabled: true,
isIndexStatsEnabled: true,
isDataStreamsStorageColumnEnabled: true,
enableMappingsSourceFieldSection: true,
enableTogglingDataRetention: true,
},
indexDataEnricher: mockedIndexDataEnricher,

View file

@ -15,6 +15,7 @@ export const routeDependencies: Omit<RouteDependencies, 'router'> = {
isLegacyTemplatesEnabled: true,
isIndexStatsEnabled: true,
isDataStreamsStorageColumnEnabled: true,
enableMappingsSourceFieldSection: true,
enableTogglingDataRetention: true,
},
indexDataEnricher: new IndexDataEnricher(),

View file

@ -26,6 +26,7 @@ export interface RouteDependencies {
isLegacyTemplatesEnabled: boolean;
isIndexStatsEnabled: boolean;
isDataStreamsStorageColumnEnabled: boolean;
enableMappingsSourceFieldSection: boolean;
enableTogglingDataRetention: boolean;
};
indexDataEnricher: IndexDataEnricher;