From 6824718c0a15347395d8e49db23b934b475b142d Mon Sep 17 00:00:00 2001 From: Shahzad Date: Tue, 4 Oct 2022 14:46:53 +0200 Subject: [PATCH] [Synthetics] Increase project API payload limit (#142140) --- src/plugins/bfetch/server/plugin.ts | 8 ++++++-- .../server/routes/monitor_cruds/add_monitor_project.ts | 7 +++++++ x-pack/plugins/synthetics/server/server.ts | 5 +++-- .../plugins/synthetics/server/synthetics_route_wrapper.ts | 1 + 4 files changed, 17 insertions(+), 4 deletions(-) diff --git a/src/plugins/bfetch/server/plugin.ts b/src/plugins/bfetch/server/plugin.ts index 0f51f5da62353..85720480cf9a0 100644 --- a/src/plugins/bfetch/server/plugin.ts +++ b/src/plugins/bfetch/server/plugin.ts @@ -20,6 +20,7 @@ import { } from '@kbn/core/server'; import { schema } from '@kbn/config-schema'; import { map$ } from '@kbn/std'; +import { RouteConfigOptions } from '@kbn/core-http-server'; import { StreamingResponseHandler, BatchRequestData, @@ -54,7 +55,8 @@ export interface BfetchServerSetup { context: RequestHandlerContext ) => StreamingResponseHandler, method?: 'GET' | 'POST' | 'PUT' | 'DELETE', - pluginRouter?: ReturnType + pluginRouter?: ReturnType, + options?: RouteConfigOptions<'get' | 'post' | 'put' | 'delete'> ) => void; } @@ -117,14 +119,16 @@ export class BfetchServerPlugin router: ReturnType; logger: Logger; }): BfetchServerSetup['addStreamingResponseRoute'] => - (path, handler, method = 'POST', pluginRouter) => { + (path, handler, method = 'POST', pluginRouter, options) => { const httpRouter = pluginRouter || router; + const routeDefinition = { path: `/${removeLeadingSlash(path)}`, validate: { body: schema.any(), query: schema.object({ compress: schema.boolean({ defaultValue: false }) }), }, + options, }; const routeHandler: RequestHandler = async ( context: RequestHandlerContext, diff --git a/x-pack/plugins/synthetics/server/routes/monitor_cruds/add_monitor_project.ts b/x-pack/plugins/synthetics/server/routes/monitor_cruds/add_monitor_project.ts index 668d97a0819e3..ea269d87413e7 100644 --- a/x-pack/plugins/synthetics/server/routes/monitor_cruds/add_monitor_project.ts +++ b/x-pack/plugins/synthetics/server/routes/monitor_cruds/add_monitor_project.ts @@ -13,6 +13,8 @@ import { API_URLS } from '../../../common/constants'; import { getAllLocations } from '../../synthetics_service/get_all_locations'; import { ProjectMonitorFormatter } from '../../synthetics_service/project_monitor/project_monitor_formatter'; +const MAX_PAYLOAD_SIZE = 1048576 * 20; // 20MiB + export const addSyntheticsProjectMonitorRoute: SyntheticsStreamingRouteFactory = ( libs: UMServerLibs ) => ({ @@ -25,6 +27,11 @@ export const addSyntheticsProjectMonitorRoute: SyntheticsStreamingRouteFactory = monitors: schema.arrayOf(schema.any()), }), }, + options: { + body: { + maxBytes: MAX_PAYLOAD_SIZE, + }, + }, handler: async ({ request, savedObjectsClient, diff --git a/x-pack/plugins/synthetics/server/server.ts b/x-pack/plugins/synthetics/server/server.ts index 12844c9cb9223..7f667e0fb264d 100644 --- a/x-pack/plugins/synthetics/server/server.ts +++ b/x-pack/plugins/synthetics/server/server.ts @@ -57,7 +57,7 @@ export const initSyntheticsServer = ( }); syntheticsAppStreamingApiRoutes.forEach((route) => { - const { method, streamHandler, path } = syntheticsRouteWrapper( + const { method, streamHandler, path, options } = syntheticsRouteWrapper( createSyntheticsRouteWithAuth(libs, route), server, syntheticsMonitorClient @@ -82,7 +82,8 @@ export const initSyntheticsServer = ( }; }, method, - server.router + server.router, + options ); }); }; diff --git a/x-pack/plugins/synthetics/server/synthetics_route_wrapper.ts b/x-pack/plugins/synthetics/server/synthetics_route_wrapper.ts index 8706735fa9256..fc1376e157607 100644 --- a/x-pack/plugins/synthetics/server/synthetics_route_wrapper.ts +++ b/x-pack/plugins/synthetics/server/synthetics_route_wrapper.ts @@ -19,6 +19,7 @@ export const syntheticsRouteWrapper: SyntheticsRouteWrapper = ( ...uptimeRoute, options: { tags: ['access:uptime-read', ...(uptimeRoute?.writeAccess ? ['access:uptime-write'] : [])], + ...(uptimeRoute.options ?? {}), }, streamHandler: async (context, request, subject) => { const coreContext = await context.core;