Skip to content

Commit

Permalink
Merge branch 'main' into upgrade/superagent-supertest
Browse files Browse the repository at this point in the history
  • Loading branch information
kibanamachine authored Aug 14, 2023
2 parents b15ecc8 + 10102cc commit 5d712ea
Show file tree
Hide file tree
Showing 58 changed files with 1,041 additions and 73 deletions.
5 changes: 4 additions & 1 deletion config/serverless.yml
Original file line number Diff line number Diff line change
Expand Up @@ -32,8 +32,11 @@ xpack.remote_clusters.enabled: false
xpack.snapshot_restore.enabled: false
xpack.license_management.enabled: false

# Disable index management actions from the UI
# Management team UI configurations
# Disable index actions from the Index Management UI
xpack.index_management.enableIndexActions: false
# Disable legacy index templates from Index Management UI
xpack.index_management.enableLegacyTemplates: 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 @@ -240,6 +240,7 @@ export default function ({ getService }: PluginFunctionalProviderContext) {
'xpack.ilm.ui.enabled (boolean)',
'xpack.index_management.ui.enabled (boolean)',
'xpack.index_management.enableIndexActions (any)',
'xpack.index_management.enableLegacyTemplates (any)',
'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 @@ -285,6 +285,7 @@ export async function getApmServiceSummary({
}),
apmAlertsClient.search({
size: 100,
// @ts-expect-error types for apm alerts client needs to be reviewed
query: {
bool: {
filter: [
Expand Down
4 changes: 3 additions & 1 deletion x-pack/plugins/index_management/README.md
Original file line number Diff line number Diff line change
Expand Up @@ -53,7 +53,7 @@ POST %25%7B%5B%40metadata%5D%5Bbeat%5D%7D-%25%7B%5B%40metadata%5D%5Bversion%5D%7

### Quick steps for testing

By default, **legacy index templates** are not shown in the UI. Make them appear by creating one in Console:
**Legacy index templates** are only shown in the UI on stateful *and* if a user has existing legacy index templates. You can test this functionality by creating one in Console:

```
PUT _template/template_1
Expand All @@ -62,6 +62,8 @@ PUT _template/template_1
}
```

On serverless, Elasticsearch does not support legacy index templates and therefore this functionality is disabled in Kibana via the config `xpack.index_management.enableLegacyTemplates`. For more details, see [#163518](https://github.com/elastic/kibana/pull/163518).

To test **Cloud-managed templates**:

1. Add `cluster.metadata.managed_index_templates` setting via Dev Tools:
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -56,6 +56,11 @@ const appDependencies = {
executionContext: executionContextServiceMock.createStartContract(),
},
plugins: {},
// Default stateful configuration
config: {
enableLegacyTemplates: true,
enableIndexActions: true,
},
} as any;

export const kibanaVersion = new SemVer(MAJOR_VERSION);
Expand All @@ -82,7 +87,6 @@ export const WithAppDependencies =
(props: any) => {
httpService.setup(httpSetup);
const mergedDependencies = merge({}, appDependencies, overridingDependencies);

return (
<KibanaReactContextProvider>
<AppContextProvider value={mergedDependencies}>
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -225,11 +225,11 @@ describe('<IndexManagementHome />', () => {
]);
httpRequestsMockHelpers.setReloadIndicesResponse({ indexNames: [indexNameA, indexNameB] });

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

const { component, find } = testBed;
component.update();

find('indexTableIndexNameLink').at(0).simulate('click');
Expand Down Expand Up @@ -270,8 +270,8 @@ describe('<IndexManagementHome />', () => {
});

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

Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -168,7 +168,11 @@ describe('index table', () => {
},
plugins: {},
url: urlServiceMock,
enableIndexActions: true,
// Default stateful configuration
config: {
enableLegacyTemplates: true,
enableIndexActions: true,
},
};

component = (
Expand Down Expand Up @@ -515,8 +519,8 @@ describe('index table', () => {

describe('Common index actions', () => {
beforeEach(() => {
// Mock initialization of services
setupMockComponent({ enableIndexActions: false });
// Mock initialization of services; set enableIndexActions=false to verify config behavior
setupMockComponent({ config: { enableIndexActions: false, enableLegacyTemplates: true } });
});

test('Common index actions should be hidden when feature is turned off', async () => {
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -6,3 +6,5 @@
*/

export const API_BASE_PATH = '/api/index_management';

export const INTERNAL_API_BASE_PATH = '/internal/index_management';
2 changes: 1 addition & 1 deletion x-pack/plugins/index_management/common/constants/index.ts
Original file line number Diff line number Diff line change
Expand Up @@ -6,7 +6,7 @@
*/

export { BASE_PATH } from './base_path';
export { API_BASE_PATH } from './api_base_path';
export { API_BASE_PATH, INTERNAL_API_BASE_PATH } from './api_base_path';
export { INVALID_INDEX_PATTERN_CHARS, INVALID_TEMPLATE_NAME_CHARS } from './invalid_characters';
export * from './index_statuses';

Expand Down
2 changes: 1 addition & 1 deletion x-pack/plugins/index_management/common/index.ts
Original file line number Diff line number Diff line change
Expand Up @@ -8,7 +8,7 @@
// TODO: https://github.com/elastic/kibana/issues/110892
/* eslint-disable @kbn/eslint/no_export_all */

export { API_BASE_PATH, BASE_PATH, MAJOR_VERSION } from './constants';
export { API_BASE_PATH, INTERNAL_API_BASE_PATH, BASE_PATH, MAJOR_VERSION } from './constants';

export { getTemplateParameter } from './lib';

Expand Down
16 changes: 16 additions & 0 deletions x-pack/plugins/index_management/common/types/enrich_policies.ts
Original file line number Diff line number Diff line change
@@ -0,0 +1,16 @@
/*
* 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 type { EnrichPolicyType } from '@elastic/elasticsearch/lib/api/types';

export interface SerializedEnrichPolicy {
type: EnrichPolicyType;
name: string;
sourceIndices: string[];
matchField: string;
enrichFields: string[];
}
2 changes: 2 additions & 0 deletions x-pack/plugins/index_management/common/types/index.ts
Original file line number Diff line number Diff line change
Expand Up @@ -16,3 +16,5 @@ export * from './templates';
export type { DataStreamFromEs, Health, DataStream, DataStreamIndex } from './data_streams';

export * from './component_templates';

export * from './enrich_policies';
Original file line number Diff line number Diff line change
Expand Up @@ -44,6 +44,10 @@ export interface AppDependencies {
httpService: HttpService;
notificationService: NotificationService;
};
config: {
enableIndexActions: boolean;
enableLegacyTemplates: boolean;
};
history: ScopedHistory;
setBreadcrumbs: ManagementAppMountParams['setBreadcrumbs'];
uiSettings: IUiSettingsClient;
Expand All @@ -52,7 +56,6 @@ 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 @@ -53,7 +53,8 @@ export async function mountManagementSection(
extensionsService: ExtensionsService,
isFleetEnabled: boolean,
kibanaVersion: SemVer,
enableIndexActions: boolean = true
enableIndexActions: boolean = true,
enableLegacyTemplates: boolean = true
) {
const { element, setBreadcrumbs, history, theme$ } = params;
const [core, startDependencies] = await coreSetup.getStartServices();
Expand Down Expand Up @@ -95,7 +96,10 @@ export async function mountManagementSection(
uiMetricService,
extensionsService,
},
enableIndexActions,
config: {
enableIndexActions,
enableLegacyTemplates,
},
history,
setBreadcrumbs,
uiSettings,
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -49,7 +49,9 @@ export class IndexActionsContextMenu extends Component {
this.setState({ isActionConfirmed });
};
panels({ services: { extensionsService }, core: { getUrlForApp } }) {
const { enableIndexActions } = this.context;
const {
config: { enableIndexActions },
} = this.context;

const {
closeIndices,
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -19,6 +19,7 @@ import { getTemplateDetailsLink } from '../../services/routing';
import { saveTemplate, useLoadIndexTemplate } from '../../services/api';
import { getIsLegacyFromQueryParams } from '../../lib/index_templates';
import { attemptToURIDecode } from '../../../shared_imports';
import { useAppContext } from '../../app_context';

interface MatchParams {
name: string;
Expand All @@ -32,7 +33,11 @@ export const TemplateClone: React.FunctionComponent<RouteComponentProps<MatchPar
history,
}) => {
const decodedTemplateName = attemptToURIDecode(name)!;
const isLegacy = getIsLegacyFromQueryParams(location);
const {
config: { enableLegacyTemplates },
} = useAppContext();
// We don't expect the `legacy` query to be used when legacy templates are disabled, however, we add the `enableLegacyTemplates` check as a safeguard
const isLegacy = enableLegacyTemplates && getIsLegacyFromQueryParams(location);

const [isSaving, setIsSaving] = useState<boolean>(false);
const [saveError, setSaveError] = useState<any>(null);
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -18,12 +18,17 @@ import { TemplateForm } from '../../components';
import { breadcrumbService } from '../../services/breadcrumbs';
import { saveTemplate } from '../../services/api';
import { getTemplateDetailsLink } from '../../services/routing';
import { useAppContext } from '../../app_context';

export const TemplateCreate: React.FunctionComponent<RouteComponentProps> = ({ history }) => {
const [isSaving, setIsSaving] = useState<boolean>(false);
const [saveError, setSaveError] = useState<any>(null);
const {
config: { enableLegacyTemplates },
} = useAppContext();
const search = parse(useLocation().search.substring(1));
const isLegacy = Boolean(search.legacy);
// We don't expect the `legacy` query to be used when legacy templates are disabled, however, we add the `enableLegacyTemplates` check as a safeguard
const isLegacy = enableLegacyTemplates && Boolean(search.legacy);

const onSave = async (template: TemplateDeserialized) => {
const { name } = template;
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -23,6 +23,7 @@ import { useLoadIndexTemplate, updateTemplate } from '../../services/api';
import { getTemplateDetailsLink } from '../../services/routing';
import { TemplateForm } from '../../components';
import { getIsLegacyFromQueryParams } from '../../lib/index_templates';
import { useAppContext } from '../../app_context';

interface MatchParams {
name: string;
Expand All @@ -36,7 +37,12 @@ export const TemplateEdit: React.FunctionComponent<RouteComponentProps<MatchPara
history,
}) => {
const decodedTemplateName = attemptToURIDecode(name)!;
const isLegacy = getIsLegacyFromQueryParams(location);
const {
config: { enableLegacyTemplates },
} = useAppContext();

// We don't expect the `legacy` query to be used when legacy templates are disabled, however, we add the enableLegacyTemplates check as a safeguard
const isLegacy = enableLegacyTemplates && getIsLegacyFromQueryParams(location);

const [isSaving, setIsSaving] = useState<boolean>(false);
const [saveError, setSaveError] = useState<any>(null);
Expand Down
3 changes: 3 additions & 0 deletions x-pack/plugins/index_management/public/mocks.ts
Original file line number Diff line number Diff line change
Expand Up @@ -6,12 +6,15 @@
*/

import { extensionsServiceMock } from './services/extensions_service.mock';
import { publicApiServiceMock } from './services/public_api_service.mock';

export { extensionsServiceMock } from './services/extensions_service.mock';
export { publicApiServiceMock } from './services/public_api_service.mock';

function createIdxManagementSetupMock() {
const mock = {
extensionsService: extensionsServiceMock,
publicApiService: publicApiServiceMock,
};

return mock;
Expand Down
7 changes: 5 additions & 2 deletions x-pack/plugins/index_management/public/plugin.ts
Original file line number Diff line number Diff line change
Expand Up @@ -11,7 +11,7 @@ import SemVer from 'semver/classes/semver';
import { CoreSetup, PluginInitializerContext } from '@kbn/core/public';
import { setExtensionsService } from './application/store/selectors/extension_service';

import { ExtensionsService } from './services';
import { ExtensionsService, PublicApiService } from './services';

import {
IndexManagementPluginSetup,
Expand Down Expand Up @@ -39,6 +39,7 @@ export class IndexMgmtUIPlugin {
const {
ui: { enabled: isIndexManagementUiEnabled },
enableIndexActions,
enableLegacyTemplates,
} = this.ctx.config.get<ClientConfigType>();

if (isIndexManagementUiEnabled) {
Expand All @@ -57,13 +58,15 @@ export class IndexMgmtUIPlugin {
this.extensionsService,
Boolean(fleet),
kibanaVersion,
enableIndexActions
enableIndexActions,
enableLegacyTemplates
);
},
});
}

return {
apiService: new PublicApiService(coreSetup.http),
extensionsService: this.extensionsService.setup(),
};
}
Expand Down
3 changes: 3 additions & 0 deletions x-pack/plugins/index_management/public/services/index.ts
Original file line number Diff line number Diff line change
Expand Up @@ -7,3 +7,6 @@

export type { ExtensionsSetup } from './extensions_service';
export { ExtensionsService } from './extensions_service';

export type { PublicApiServiceSetup } from './public_api_service';
export { PublicApiService } from './public_api_service';
Original file line number Diff line number Diff line change
@@ -0,0 +1,18 @@
/*
* 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 { PublicApiServiceSetup } from './public_api_service';

export type PublicApiServiceSetupMock = jest.Mocked<PublicApiServiceSetup>;

const createServiceMock = (): PublicApiServiceSetupMock => ({
getAllEnrichPolicies: jest.fn(),
});

export const publicApiServiceMock = {
createSetupContract: createServiceMock,
};
Original file line number Diff line number Diff line change
@@ -0,0 +1,40 @@
/*
* 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 { HttpSetup } from '@kbn/core/public';
import { sendRequest, SendRequestResponse } from '../shared_imports';
import { API_BASE_PATH } from '../../common/constants';
import { SerializedEnrichPolicy } from '../../common/types';

export interface PublicApiServiceSetup {
getAllEnrichPolicies(): Promise<SendRequestResponse<SerializedEnrichPolicy[]>>;
}

/**
* Index Management public API service
*/
export class PublicApiService {
private http: HttpSetup;

/**
* constructor
* @param http http dependency
*/
constructor(http: HttpSetup) {
this.http = http;
}

/**
* Gets a list of all the enrich policies
*/
getAllEnrichPolicies() {
return sendRequest(this.http, {
path: `${API_BASE_PATH}/enrich_policies`,
method: 'get',
});
}
}
Loading

0 comments on commit 5d712ea

Please sign in to comment.