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

[Index Management] Disable certain actions for serverless #161528

Merged
3 changes: 3 additions & 0 deletions config/serverless.yml
Original file line number Diff line number Diff line change
Expand Up @@ -36,6 +36,9 @@ xpack.remote_clusters.enabled: false
xpack.snapshot_restore.enabled: false
xpack.license_management.enabled: false

# Disable index management actions from the UI
xpack.index_management.enableIndexActions: false

# Keep deeplinks visible so that they are shown in the sidenav
dev_tools.deeplinks.navLinkStatus: visible
management.deeplinks.navLinkStatus: visible
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -232,6 +232,7 @@ export default function ({ getService }: PluginFunctionalProviderContext) {
'xpack.graph.savePolicy (alternatives)',
'xpack.ilm.ui.enabled (boolean)',
'xpack.index_management.ui.enabled (boolean)',
'xpack.index_management.enableIndexActions (boolean)',
'xpack.infra.sources.default.fields.message (array)',
/**
* xpack.infra.logs is conditional and will resolve to an object of properties
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -225,7 +225,9 @@ describe('<IndexManagementHome />', () => {
]);
httpRequestsMockHelpers.setReloadIndicesResponse({ indexNames: [indexNameA, indexNameB] });

testBed = await setup(httpSetup);
testBed = await setup(httpSetup, {
enableIndexActions: true,
});
const { component, find } = testBed;

component.update();
Expand Down Expand Up @@ -268,7 +270,9 @@ describe('<IndexManagementHome />', () => {
});

test('should be able to open a closed index', async () => {
testBed = await setup(httpSetup);
testBed = await setup(httpSetup, {
enableIndexActions: true,
});
const { component, find, actions } = testBed;

component.update();
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -144,7 +144,7 @@ const getActionMenuButtons = (rendered) => {
describe('index table', () => {
const { httpSetup, httpRequestsMockHelpers } = initHttpRequests();

beforeEach(() => {
const setupMockComponent = (dependenciesOverride) => {
// Mock initialization of services
const services = {
extensionsService: new ExtensionsService(),
Expand All @@ -168,19 +168,25 @@ describe('index table', () => {
},
plugins: {},
url: urlServiceMock,
enableIndexActions: true,
};

component = (
<Provider store={store}>
<MemoryRouter initialEntries={[`${BASE_PATH}indices`]}>
<AppContextProvider value={appDependencies}>
<AppContextProvider value={{ ...appDependencies, ...dependenciesOverride }}>
<AppWithoutRouter />
</AppContextProvider>
</MemoryRouter>
</Provider>
);

store.dispatch(loadIndicesSuccess({ indices }));
};

beforeEach(() => {
// Mock initialization of services
setupMockComponent();

httpRequestsMockHelpers.setLoadIndicesResponse(indices);
httpRequestsMockHelpers.setReloadIndicesResponse(indices);
Expand Down Expand Up @@ -506,4 +512,25 @@ describe('index table', () => {
rendered.update();
testEditor(rendered, 'editIndexMenuButton');
});

describe('Common index actions', () => {
beforeEach(() => {
// Mock initialization of services
setupMockComponent({ enableIndexActions: false });
});

test('Common index actions should be hidden when feature is turned off', async () => {
const rendered = mountWithIntl(component);
await runAllPromises();
rendered.update();

expect(findTestSubject(rendered, 'showStatsIndexMenuButton').length).toBe(0);
expect(findTestSubject(rendered, 'closeIndexMenuButton').length).toBe(0);
expect(findTestSubject(rendered, 'forcemergeIndexMenuButton').length).toBe(0);
expect(findTestSubject(rendered, 'refreshIndexMenuButton').length).toBe(0);
expect(findTestSubject(rendered, 'clearCacheIndexMenuButton').length).toBe(0);
expect(findTestSubject(rendered, 'flushIndexMenuButton').length).toBe(0);
expect(findTestSubject(rendered, 'unfreezeIndexMenuButton').length).toBe(0);
});
});
});
Original file line number Diff line number Diff line change
Expand Up @@ -25,7 +25,7 @@ import type { SettingsStart } from '@kbn/core-ui-settings-browser';
import { ExtensionsService } from '../services';
import { UiMetricService, NotificationService, HttpService } from './services';

const AppContext = createContext<AppDependencies | undefined>(undefined);
export const AppContext = createContext<AppDependencies | undefined>(undefined);

export interface AppDependencies {
core: {
Expand All @@ -52,6 +52,7 @@ export interface AppDependencies {
docLinks: DocLinksStart;
kibanaVersion: SemVer;
theme$: Observable<CoreTheme>;
enableIndexActions: boolean;
}

export const AppContextProvider = ({
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -52,7 +52,8 @@ export async function mountManagementSection(
params: ManagementAppMountParams,
extensionsService: ExtensionsService,
isFleetEnabled: boolean,
kibanaVersion: SemVer
kibanaVersion: SemVer,
enableIndexActions: boolean
) {
const { element, setBreadcrumbs, history, theme$ } = params;
const [core, startDependencies] = await coreSetup.getStartServices();
Expand Down Expand Up @@ -94,6 +95,7 @@ export async function mountManagementSection(
uiMetricService,
extensionsService,
},
enableIndexActions,
history,
setBreadcrumbs,
uiSettings,
Expand Down
sabarasaba marked this conversation as resolved.
Show resolved Hide resolved
Original file line number Diff line number Diff line change
Expand Up @@ -25,9 +25,11 @@ import {

import { flattenPanelTree } from '../../../../lib/flatten_panel_tree';
import { INDEX_OPEN } from '../../../../../../common/constants';
import { AppContextConsumer } from '../../../../app_context';
import { AppContextConsumer, AppContext } from '../../../../app_context';

export class IndexActionsContextMenu extends Component {
static contextType = AppContext;

constructor(props) {
super(props);

Expand All @@ -47,6 +49,8 @@ export class IndexActionsContextMenu extends Component {
this.setState({ isActionConfirmed });
};
panels({ services: { extensionsService }, core: { getUrlForApp } }) {
const { enableIndexActions } = this.context;

const {
closeIndices,
openIndices,
Expand Down Expand Up @@ -94,7 +98,7 @@ export class IndexActionsContextMenu extends Component {
this.closePopoverAndExecute(showMapping);
},
});
if (allOpen) {
if (allOpen && enableIndexActions) {
items.push({
'data-test-subj': 'showStatsIndexMenuButton',
name: i18n.translate('xpack.idxMgmt.indexActionsMenu.showIndexStatsLabel', {
Expand All @@ -118,7 +122,7 @@ export class IndexActionsContextMenu extends Component {
},
});
}
if (allOpen) {
if (allOpen && enableIndexActions) {
items.push({
'data-test-subj': 'closeIndexMenuButton',
name: i18n.translate('xpack.idxMgmt.indexActionsMenu.closeIndexLabel', {
Expand Down Expand Up @@ -187,7 +191,7 @@ export class IndexActionsContextMenu extends Component {
},
});
}
} else {
} else if (!allOpen && enableIndexActions) {
items.push({
'data-test-subj': 'openIndexMenuButton',
name: i18n.translate('xpack.idxMgmt.indexActionsMenu.openIndexLabel', {
Expand Down
4 changes: 3 additions & 1 deletion x-pack/plugins/index_management/public/plugin.ts
Original file line number Diff line number Diff line change
Expand Up @@ -38,6 +38,7 @@ export class IndexMgmtUIPlugin {
): IndexManagementPluginSetup {
const {
ui: { enabled: isIndexManagementUiEnabled },
enableIndexActions,
} = this.ctx.config.get<ClientConfigType>();

if (isIndexManagementUiEnabled) {
Expand All @@ -55,7 +56,8 @@ export class IndexMgmtUIPlugin {
params,
this.extensionsService,
Boolean(fleet),
kibanaVersion
kibanaVersion,
enableIndexActions
);
},
});
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 @@ -28,4 +28,5 @@ export interface ClientConfigType {
ui: {
enabled: boolean;
};
enableIndexActions: boolean;
}
2 changes: 2 additions & 0 deletions x-pack/plugins/index_management/server/config.ts
Original file line number Diff line number Diff line change
Expand Up @@ -22,13 +22,15 @@ const schemaLatest = schema.object(
ui: schema.object({
enabled: schema.boolean({ defaultValue: true }),
}),
enableIndexActions: schema.boolean({ defaultValue: true }),
},
{ defaultValue: undefined }
);

const configLatest: PluginConfigDescriptor<IndexManagementConfig> = {
exposeToBrowser: {
ui: true,
enableIndexActions: true,
},
schema: schemaLatest,
deprecations: () => [],
Expand Down
Loading