[Index Management] Disable toggling data retention in serverless (#181556)

This commit is contained in:
Ignacio Rivas 2024-04-29 19:57:25 +02:00 committed by GitHub
parent 89b7a65426
commit 4ffe8c8b26
No known key found for this signature in database
GPG key ID: B5690EEEBB952194
11 changed files with 50 additions and 23 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 toggle for enabling data retention in DSL form from Index Management UI
xpack.index_management.enableTogglingDataRetention: false
# Keep deeplinks visible so that they are shown in the sidenav
dev_tools.deeplinks.navLinkStatus: visible

View file

@ -277,6 +277,7 @@ export default function ({ getService }: PluginFunctionalProviderContext) {
'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)
/**
* Feature flags bellow are conditional based on traditional/serverless offering
* and will all resolve to xpack.infra.featureFlags.* (boolean)

View file

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

View file

@ -21,11 +21,11 @@ import {
} from '@kbn/core/public';
import type { MlPluginStart } from '@kbn/ml-plugin/public';
import type { SharePluginStart } from '@kbn/share-plugin/public';
import { EuiBreadcrumb } from '@elastic/eui';
import type { SettingsStart } from '@kbn/core-ui-settings-browser';
import type { CloudSetup } from '@kbn/cloud-plugin/public';
import type { ConsolePluginStart } from '@kbn/console-plugin/public';
import type { SettingsStart } from '@kbn/core-ui-settings-browser';
import { EuiBreadcrumb } from '@elastic/eui';
import { ExtensionsService } from '../services';
import { HttpService, NotificationService, UiMetricService } from './services';
import { IndexManagementBreadcrumb } from './services/breadcrumbs';
@ -62,6 +62,7 @@ export interface AppDependencies {
enableIndexStats: boolean;
editableIndexSettings: 'all' | 'limited';
enableDataStreamsStorageColumn: boolean;
enableTogglingDataRetention: boolean;
};
history: ScopedHistory;
setBreadcrumbs: (type: IndexManagementBreadcrumb, additionalBreadcrumb?: EuiBreadcrumb) => void;

View file

@ -19,6 +19,7 @@ import {
EuiText,
EuiCallOut,
} from '@elastic/eui';
import { has } from 'lodash';
import { ScopedHistory } from '@kbn/core/public';
import { i18n } from '@kbn/i18n';
import { FormattedMessage } from '@kbn/i18n-react';
@ -193,6 +194,7 @@ export const EditDataRetentionModal: React.FunctionComponent<Props> = ({
const { size, unit } = splitSizeAndUnits(lifecycle?.data_retention as string);
const {
services: { notificationService },
config: { enableTogglingDataRetention },
} = useAppContext();
const { form } = useForm({
@ -218,6 +220,16 @@ export const EditDataRetentionModal: React.FunctionComponent<Props> = ({
return;
}
// When enableTogglingDataRetention is disabled (ie: serverless) we don't mount
// the dataRetentionEnabled field in the UI, which means that the form state for
// this field regardless if it has defaultValue or if its set with form.setValue.
// This seems to be a design decision from the formlib and there doesnt seem to
// be a way around it AFAICT.
// So when that happens we want to make sure that the dataRetention is always enabled.
if (!has(data, 'dataRetentionEnabled')) {
data.dataRetentionEnabled = true;
}
return updateDataRetention(dataStreamName, data).then(({ data: responseData, error }) => {
if (responseData) {
const successMessage = i18n.translate(
@ -273,11 +285,13 @@ export const EditDataRetentionModal: React.FunctionComponent<Props> = ({
</>
)}
<UseField
path="dataRetentionEnabled"
component={ToggleField}
data-test-subj="dataRetentionEnabledField"
/>
{enableTogglingDataRetention && (
<UseField
path="dataRetentionEnabled"
component={ToggleField}
data-test-subj="dataRetentionEnabledField"
/>
)}
<UseField
path="dataRetention"
@ -297,14 +311,19 @@ export const EditDataRetentionModal: React.FunctionComponent<Props> = ({
componentProps={{
fullWidth: false,
euiFieldProps: {
disabled: formData.infiniteRetentionPeriod || !formData.dataRetentionEnabled,
disabled:
formData.infiniteRetentionPeriod ||
(!formData.dataRetentionEnabled && enableTogglingDataRetention),
'data-test-subj': `dataRetentionValue`,
min: 1,
append: (
<UnitField
path="timeUnit"
options={timeUnits}
disabled={formData.infiniteRetentionPeriod || !formData.dataRetentionEnabled}
disabled={
formData.infiniteRetentionPeriod ||
(!formData.dataRetentionEnabled && enableTogglingDataRetention)
}
euiFieldProps={{
'data-test-subj': 'timeUnit',
'aria-label': i18n.translate(
@ -326,7 +345,7 @@ export const EditDataRetentionModal: React.FunctionComponent<Props> = ({
data-test-subj="infiniteRetentionPeriod"
componentProps={{
euiFieldProps: {
disabled: !formData.dataRetentionEnabled,
disabled: !formData.dataRetentionEnabled && enableTogglingDataRetention,
},
}}
/>

View file

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

View file

@ -39,4 +39,5 @@ export interface ClientConfigType {
enableIndexStats?: boolean;
editableIndexSettings?: 'all' | 'limited';
enableDataStreamsStorageColumn?: 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 }),
}),
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
serverless: schema.boolean({ defaultValue: true }),
}),
},
{ defaultValue: undefined }
);
@ -64,6 +69,7 @@ const configLatest: PluginConfigDescriptor<IndexManagementConfig> = {
enableIndexStats: true,
editableIndexSettings: true,
enableDataStreamsStorageColumn: true,
enableTogglingDataRetention: true,
},
schema: schemaLatest,
deprecations: ({ unused }) => [unused('dev.enableIndexDetailsPage', { level: 'warning' })],

View file

@ -57,6 +57,7 @@ export class IndexMgmtServerPlugin implements Plugin<IndexManagementPluginSetup,
isLegacyTemplatesEnabled: this.config.enableLegacyTemplates,
isIndexStatsEnabled: this.config.enableIndexStats,
isDataStreamsStorageColumnEnabled: this.config.enableDataStreamsStorageColumn,
enableTogglingDataRetention: this.config.enableTogglingDataRetention,
},
indexDataEnricher: this.indexDataEnricher,
lib: {

View file

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

View file

@ -19,8 +19,7 @@ export default ({ getPageObjects, getService }: FtrProviderContext) => {
const TEST_DS_NAME = 'test-ds-1';
// FAILING: https://github.com/elastic/kibana/issues/181242
describe.skip('Data Streams', function () {
describe('Data Streams', function () {
// failsOnMKI, see https://github.com/elastic/kibana/issues/181242
this.tags(['failsOnMKI']);
before(async () => {
@ -122,22 +121,14 @@ export default ({ getPageObjects, getService }: FtrProviderContext) => {
expect(await successToast.getVisibleText()).to.contain('Data retention updated');
});
it('allows to disable data retention', async () => {
it('disabling data retention in serverless is not allowed', async () => {
// Open details flyout
await pageObjects.indexManagement.clickDataStreamNameLink(TEST_DS_NAME);
// Open the edit retention dialog
await testSubjects.click('manageDataStreamButton');
await testSubjects.click('editDataRetentionButton');
// Disable infinite retention
await testSubjects.click('dataRetentionEnabledField > input');
// Submit the form
await testSubjects.click('saveButton');
// Expect to see a success toast
const successToast = await toasts.getElementByIndex(1);
expect(await successToast.getVisibleText()).to.contain('Data retention disabled');
expect(await testSubjects.exists('dataRetentionEnabledField')).to.be(false);
});
});
};