mirror of
https://github.com/elastic/kibana.git
synced 2025-04-24 09:48:58 -04:00
Fix maps
plugin async route registration (#181518)
## Summary Async registration is bad, especially when promise rejections are not caught. The PR adapts the routes registration to be synchronous
This commit is contained in:
parent
2bd49f5ae4
commit
923b10baaf
4 changed files with 26 additions and 13 deletions
|
@ -26,11 +26,11 @@ import { getMatchingIndexes } from './get_indexes_matching_pattern';
|
|||
export function initIndexingRoutes({
|
||||
router,
|
||||
logger,
|
||||
dataPlugin,
|
||||
getDataPlugin,
|
||||
}: {
|
||||
router: IRouter<DataRequestHandlerContext>;
|
||||
logger: Logger;
|
||||
dataPlugin: DataPluginStart;
|
||||
getDataPlugin: () => Promise<DataPluginStart>;
|
||||
securityPlugin?: SecurityPluginStart;
|
||||
}) {
|
||||
router.versioned
|
||||
|
@ -58,6 +58,7 @@ export function initIndexingRoutes({
|
|||
async (context, request, response) => {
|
||||
const coreContext = await context.core;
|
||||
const { index, mappings } = request.body;
|
||||
const dataPlugin = await getDataPlugin();
|
||||
const indexPatternsService = await dataPlugin.indexPatterns.dataViewsServiceFactory(
|
||||
coreContext.savedObjects.client,
|
||||
coreContext.elasticsearch.client.asCurrentUser,
|
||||
|
|
|
@ -27,11 +27,11 @@ const CACHE_TIMEOUT_SECONDS = 60 * 60;
|
|||
export function initMVTRoutes({
|
||||
router,
|
||||
logger,
|
||||
core,
|
||||
getCore,
|
||||
}: {
|
||||
router: IRouter<DataRequestHandlerContext>;
|
||||
logger: Logger;
|
||||
core: CoreStart;
|
||||
getCore: () => Promise<CoreStart>;
|
||||
}) {
|
||||
router.versioned
|
||||
.get({
|
||||
|
@ -93,7 +93,7 @@ export function initMVTRoutes({
|
|||
abortController: makeAbortController(request),
|
||||
body: tileRequest.body,
|
||||
context,
|
||||
core,
|
||||
core: await getCore(),
|
||||
executionContext: makeExecutionContext({
|
||||
type: 'server',
|
||||
name: APP_ID,
|
||||
|
@ -173,7 +173,7 @@ export function initMVTRoutes({
|
|||
abortController: makeAbortController(request),
|
||||
body: tileRequest.body,
|
||||
context,
|
||||
core,
|
||||
core: await getCore(),
|
||||
executionContext: makeExecutionContext({
|
||||
type: 'server',
|
||||
name: APP_ID,
|
||||
|
|
|
@ -145,7 +145,7 @@ export class MapsPlugin implements Plugin {
|
|||
);
|
||||
}
|
||||
|
||||
setup(core: CoreSetup, plugins: SetupDeps) {
|
||||
setup(core: CoreSetup<StartDeps>, plugins: SetupDeps) {
|
||||
const getFilterMigrations = plugins.data.query.filterManager.getAllMigrations.bind(
|
||||
plugins.data.query.filterManager
|
||||
);
|
||||
|
|
|
@ -8,7 +8,7 @@
|
|||
import { schema } from '@kbn/config-schema';
|
||||
import fs from 'fs';
|
||||
import path from 'path';
|
||||
import { CoreSetup, CoreStart, IRouter, Logger } from '@kbn/core/server';
|
||||
import { CoreSetup, IRouter, Logger } from '@kbn/core/server';
|
||||
import { DataRequestHandlerContext } from '@kbn/data-plugin/server';
|
||||
import { INDEX_SETTINGS_API_PATH, FONTS_API_PATH } from '../common/constants';
|
||||
import { getIndexPatternSettings } from './lib/get_index_pattern_settings';
|
||||
|
@ -16,10 +16,8 @@ import { initMVTRoutes } from './mvt/mvt_routes';
|
|||
import { initIndexingRoutes } from './data_indexing/indexing_routes';
|
||||
import { StartDeps } from './types';
|
||||
|
||||
export async function initRoutes(coreSetup: CoreSetup, logger: Logger): Promise<void> {
|
||||
export function initRoutes(coreSetup: CoreSetup<StartDeps>, logger: Logger) {
|
||||
const router: IRouter<DataRequestHandlerContext> = coreSetup.http.createRouter();
|
||||
const [coreStart, { data: dataPlugin }]: [CoreStart, StartDeps] =
|
||||
(await coreSetup.getStartServices()) as unknown as [CoreStart, StartDeps];
|
||||
|
||||
router.versioned
|
||||
.get({
|
||||
|
@ -109,6 +107,20 @@ export async function initRoutes(coreSetup: CoreSetup, logger: Logger): Promise<
|
|||
}
|
||||
);
|
||||
|
||||
initMVTRoutes({ router, logger, core: coreStart });
|
||||
initIndexingRoutes({ router, logger, dataPlugin });
|
||||
initMVTRoutes({
|
||||
router,
|
||||
logger,
|
||||
getCore: async () => {
|
||||
const [core] = await coreSetup.getStartServices();
|
||||
return core;
|
||||
},
|
||||
});
|
||||
initIndexingRoutes({
|
||||
router,
|
||||
logger,
|
||||
getDataPlugin: async () => {
|
||||
const [, { data }] = await coreSetup.getStartServices();
|
||||
return data;
|
||||
},
|
||||
});
|
||||
}
|
||||
|
|
Loading…
Add table
Add a link
Reference in a new issue