mirror of
https://github.com/elastic/kibana.git
synced 2025-04-24 09:48:58 -04:00
[Upgrade Assistant] Make saved objects hidden (#154180)
## Summary Fixes https://github.com/elastic/kibana/issues/154037 This PR updates the saved objects types used in Upgrade Assistant for reindexing operations and ML snapshots. This is needed in preparation for serverless and should not have any affect on the UI. For testing this PR I would suggest using the same steps as in these 2 PRs for [reindexing](https://github.com/elastic/kibana/pull/150878) and [ml snapshots](https://github.com/elastic/kibana/pull/151014). --------- Co-authored-by: kibanamachine <42973632+kibanamachine@users.noreply.github.com>
This commit is contained in:
parent
54757a0db8
commit
1b36fb83c4
9 changed files with 52 additions and 25 deletions
|
@ -29,7 +29,11 @@ import { registerUpgradeAssistantUsageCollector } from './lib/telemetry';
|
|||
import { versionService } from './lib/version';
|
||||
import { createReindexWorker } from './routes/reindex_indices';
|
||||
import { registerRoutes } from './routes/register_routes';
|
||||
import { reindexOperationSavedObjectType, mlSavedObjectType } from './saved_object_types';
|
||||
import {
|
||||
reindexOperationSavedObjectType,
|
||||
mlSavedObjectType,
|
||||
hiddenTypes,
|
||||
} from './saved_object_types';
|
||||
import { handleEsError } from './shared_imports';
|
||||
import { RouteDependencies } from './types';
|
||||
import type { UpgradeAssistantConfig } from './config';
|
||||
|
@ -169,7 +173,7 @@ export class UpgradeAssistantServerPlugin implements Plugin {
|
|||
elasticsearchService: elasticsearch,
|
||||
logger: this.logger,
|
||||
savedObjects: new SavedObjectsClient(
|
||||
this.savedObjectsServiceStart.createInternalRepository()
|
||||
this.savedObjectsServiceStart.createInternalRepository(hiddenTypes)
|
||||
),
|
||||
security: this.securityPluginStart,
|
||||
});
|
||||
|
|
|
@ -13,12 +13,13 @@ import {
|
|||
deprecationsServiceMock,
|
||||
} from '@kbn/core/server/mocks';
|
||||
|
||||
export const savedObjectsClient = savedObjectsClientMock.create();
|
||||
export const routeHandlerContextMock = {
|
||||
core: {
|
||||
elasticsearch: {
|
||||
client: elasticsearchServiceMock.createScopedClusterClient(),
|
||||
},
|
||||
savedObjects: { client: savedObjectsClientMock.create() },
|
||||
savedObjects: { getClient: () => savedObjectsClient },
|
||||
deprecations: { client: deprecationsServiceMock.createClient() },
|
||||
},
|
||||
} as unknown as AwaitedProperties<RequestHandlerContext>;
|
||||
|
|
|
@ -9,7 +9,12 @@ import { kibanaResponseFactory, RequestHandler } from '@kbn/core/server';
|
|||
|
||||
import { errors as esErrors } from '@elastic/elasticsearch';
|
||||
import { handleEsError } from '../shared_imports';
|
||||
import { createMockRouter, MockRouter, routeHandlerContextMock } from './__mocks__/routes.mock';
|
||||
import {
|
||||
createMockRouter,
|
||||
MockRouter,
|
||||
routeHandlerContextMock,
|
||||
savedObjectsClient,
|
||||
} from './__mocks__/routes.mock';
|
||||
import { createRequestMock } from './__mocks__/request.mock';
|
||||
import { registerMlSnapshotRoutes } from './ml_snapshots';
|
||||
|
||||
|
@ -285,7 +290,7 @@ describe('ML snapshots APIs', () => {
|
|||
],
|
||||
});
|
||||
|
||||
(routeHandlerContextMock.core.savedObjects.client.find as jest.Mock).mockResolvedValue({
|
||||
(savedObjectsClient.find as jest.Mock).mockResolvedValue({
|
||||
total: 1,
|
||||
saved_objects: [
|
||||
{
|
||||
|
@ -356,7 +361,7 @@ describe('ML snapshots APIs', () => {
|
|||
],
|
||||
});
|
||||
|
||||
(routeHandlerContextMock.core.savedObjects.client.find as jest.Mock).mockResolvedValue({
|
||||
(savedObjectsClient.find as jest.Mock).mockResolvedValue({
|
||||
total: 1,
|
||||
saved_objects: [
|
||||
{
|
||||
|
@ -421,7 +426,7 @@ describe('ML snapshots APIs', () => {
|
|||
],
|
||||
});
|
||||
|
||||
(routeHandlerContextMock.core.savedObjects.client.find as jest.Mock).mockResolvedValue({
|
||||
(savedObjectsClient.find as jest.Mock).mockResolvedValue({
|
||||
total: 1,
|
||||
saved_objects: [
|
||||
{
|
||||
|
@ -449,7 +454,7 @@ describe('ML snapshots APIs', () => {
|
|||
index_settings: {},
|
||||
});
|
||||
|
||||
(routeHandlerContextMock.core.savedObjects.client.delete as jest.Mock).mockResolvedValue({});
|
||||
(savedObjectsClient.delete as jest.Mock).mockResolvedValue({});
|
||||
|
||||
const resp = await routeDependencies.router.getHandler({
|
||||
method: 'get',
|
||||
|
|
|
@ -155,7 +155,7 @@ export function registerMlSnapshotRoutes({
|
|||
versionCheckHandlerWrapper(async ({ core }, request, response) => {
|
||||
try {
|
||||
const {
|
||||
savedObjects: { client: savedObjectsClient },
|
||||
savedObjects: { getClient },
|
||||
elasticsearch: { client: esClient },
|
||||
} = await core;
|
||||
const { snapshotId, jobId } = request.body;
|
||||
|
@ -173,7 +173,10 @@ export function registerMlSnapshotRoutes({
|
|||
|
||||
// Store snapshot in saved object if upgrade not complete
|
||||
if (body.completed !== true) {
|
||||
await createMlOperation(savedObjectsClient, snapshotInfo);
|
||||
await createMlOperation(
|
||||
getClient({ includedHiddenTypes: [ML_UPGRADE_OP_TYPE] }),
|
||||
snapshotInfo
|
||||
);
|
||||
}
|
||||
|
||||
return response.ok({
|
||||
|
@ -202,9 +205,10 @@ export function registerMlSnapshotRoutes({
|
|||
versionCheckHandlerWrapper(async ({ core }, request, response) => {
|
||||
try {
|
||||
const {
|
||||
savedObjects: { client: savedObjectsClient },
|
||||
savedObjects: { getClient },
|
||||
elasticsearch: { client: esClient },
|
||||
} = await core;
|
||||
const savedObjectsClient = getClient({ includedHiddenTypes: [ML_UPGRADE_OP_TYPE] });
|
||||
const { snapshotId, jobId } = request.params;
|
||||
|
||||
// Verify snapshot exists
|
||||
|
|
|
@ -9,7 +9,7 @@ import { schema } from '@kbn/config-schema';
|
|||
import { errors } from '@elastic/elasticsearch';
|
||||
|
||||
import { API_BASE_PATH } from '../../../common/constants';
|
||||
import { ReindexStatus } from '../../../common/types';
|
||||
import { REINDEX_OP_TYPE, ReindexStatus } from '../../../common/types';
|
||||
import { versionCheckHandlerWrapper } from '../../lib/es_version_precheck';
|
||||
import { ReindexWorker } from '../../lib/reindexing';
|
||||
import { reindexActionsFactory } from '../../lib/reindexing/reindex_actions';
|
||||
|
@ -43,9 +43,12 @@ export function registerBatchReindexIndicesRoutes(
|
|||
elasticsearch: { client: esClient },
|
||||
savedObjects,
|
||||
} = await core;
|
||||
const { client } = savedObjects;
|
||||
const { getClient } = savedObjects;
|
||||
const callAsCurrentUser = esClient.asCurrentUser;
|
||||
const reindexActions = reindexActionsFactory(client, callAsCurrentUser);
|
||||
const reindexActions = reindexActionsFactory(
|
||||
getClient({ includedHiddenTypes: [REINDEX_OP_TYPE] }),
|
||||
callAsCurrentUser
|
||||
);
|
||||
try {
|
||||
const inProgressOps = await reindexActions.findAllByStatus(ReindexStatus.inProgress);
|
||||
const { queue } = sortAndOrderReindexOperations(inProgressOps);
|
||||
|
@ -76,7 +79,7 @@ export function registerBatchReindexIndicesRoutes(
|
|||
},
|
||||
versionCheckHandlerWrapper(async ({ core }, request, response) => {
|
||||
const {
|
||||
savedObjects: { client: savedObjectsClient },
|
||||
savedObjects: { getClient },
|
||||
elasticsearch: { client: esClient },
|
||||
} = await core;
|
||||
const { indexNames } = request.body;
|
||||
|
@ -87,7 +90,7 @@ export function registerBatchReindexIndicesRoutes(
|
|||
for (const indexName of indexNames) {
|
||||
try {
|
||||
const result = await reindexHandler({
|
||||
savedObjects: savedObjectsClient,
|
||||
savedObjects: getClient({ includedHiddenTypes: [REINDEX_OP_TYPE] }),
|
||||
dataClient: esClient,
|
||||
indexName,
|
||||
log,
|
||||
|
|
|
@ -9,7 +9,7 @@ import { schema } from '@kbn/config-schema';
|
|||
import { errors } from '@elastic/elasticsearch';
|
||||
|
||||
import { API_BASE_PATH } from '../../../common/constants';
|
||||
import type { ReindexStatusResponse } from '../../../common/types';
|
||||
import { ReindexStatusResponse, REINDEX_OP_TYPE } from '../../../common/types';
|
||||
import { versionCheckHandlerWrapper } from '../../lib/es_version_precheck';
|
||||
import { reindexServiceFactory, ReindexWorker, generateNewIndexName } from '../../lib/reindexing';
|
||||
import { reindexActionsFactory } from '../../lib/reindexing/reindex_actions';
|
||||
|
@ -42,13 +42,13 @@ export function registerReindexIndicesRoutes(
|
|||
},
|
||||
versionCheckHandlerWrapper(async ({ core }, request, response) => {
|
||||
const {
|
||||
savedObjects: { client: savedObjectsClient },
|
||||
savedObjects: { getClient },
|
||||
elasticsearch: { client: esClient },
|
||||
} = await core;
|
||||
const { indexName } = request.params;
|
||||
try {
|
||||
const result = await reindexHandler({
|
||||
savedObjects: savedObjectsClient,
|
||||
savedObjects: getClient({ includedHiddenTypes: [REINDEX_OP_TYPE] }),
|
||||
dataClient: esClient,
|
||||
indexName,
|
||||
log,
|
||||
|
@ -88,10 +88,13 @@ export function registerReindexIndicesRoutes(
|
|||
savedObjects,
|
||||
elasticsearch: { client: esClient },
|
||||
} = await core;
|
||||
const { client } = savedObjects;
|
||||
const { getClient } = savedObjects;
|
||||
const { indexName } = request.params;
|
||||
const asCurrentUser = esClient.asCurrentUser;
|
||||
const reindexActions = reindexActionsFactory(client, asCurrentUser);
|
||||
const reindexActions = reindexActionsFactory(
|
||||
getClient({ includedHiddenTypes: [REINDEX_OP_TYPE] }),
|
||||
asCurrentUser
|
||||
);
|
||||
const reindexService = reindexServiceFactory(asCurrentUser, reindexActions, log, licensing);
|
||||
|
||||
try {
|
||||
|
@ -143,9 +146,12 @@ export function registerReindexIndicesRoutes(
|
|||
elasticsearch: { client: esClient },
|
||||
} = await core;
|
||||
const { indexName } = request.params;
|
||||
const { client } = savedObjects;
|
||||
const { getClient } = savedObjects;
|
||||
const callAsCurrentUser = esClient.asCurrentUser;
|
||||
const reindexActions = reindexActionsFactory(client, callAsCurrentUser);
|
||||
const reindexActions = reindexActionsFactory(
|
||||
getClient({ includedHiddenTypes: [REINDEX_OP_TYPE] }),
|
||||
callAsCurrentUser
|
||||
);
|
||||
const reindexService = reindexServiceFactory(
|
||||
callAsCurrentUser,
|
||||
reindexActions,
|
||||
|
|
|
@ -5,5 +5,9 @@
|
|||
* 2.0.
|
||||
*/
|
||||
|
||||
import { reindexOperationSavedObjectType } from './reindex_operation_saved_object_type';
|
||||
import { mlSavedObjectType } from './ml_upgrade_operation_saved_object_type';
|
||||
|
||||
export { reindexOperationSavedObjectType } from './reindex_operation_saved_object_type';
|
||||
export { mlSavedObjectType } from './ml_upgrade_operation_saved_object_type';
|
||||
export const hiddenTypes = [reindexOperationSavedObjectType.name, mlSavedObjectType.name];
|
||||
|
|
|
@ -11,7 +11,7 @@ import { ML_UPGRADE_OP_TYPE } from '../../common/types';
|
|||
|
||||
export const mlSavedObjectType: SavedObjectsType = {
|
||||
name: ML_UPGRADE_OP_TYPE,
|
||||
hidden: false,
|
||||
hidden: true,
|
||||
namespaceType: 'agnostic',
|
||||
mappings: {
|
||||
dynamic: false,
|
||||
|
|
|
@ -11,7 +11,7 @@ import { REINDEX_OP_TYPE } from '../../common/types';
|
|||
|
||||
export const reindexOperationSavedObjectType: SavedObjectsType = {
|
||||
name: REINDEX_OP_TYPE,
|
||||
hidden: false,
|
||||
hidden: true,
|
||||
namespaceType: 'agnostic',
|
||||
mappings: {
|
||||
dynamic: false,
|
||||
|
|
Loading…
Add table
Add a link
Reference in a new issue