[Synthetics] Increase project API payload limit (#142140) (#142597)

(cherry picked from commit 6824718c0a)

Co-authored-by: Shahzad <shahzad.muhammad@elastic.co>
This commit is contained in:
Kibana Machine 2022-10-04 07:51:11 -06:00 committed by GitHub
parent 95e32aaab5
commit e55eebd128
No known key found for this signature in database
GPG key ID: 4AEE18F83AFDEB23
4 changed files with 17 additions and 4 deletions

View file

@ -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<Payload, Response>,
method?: 'GET' | 'POST' | 'PUT' | 'DELETE',
pluginRouter?: ReturnType<CoreSetup['http']['createRouter']>
pluginRouter?: ReturnType<CoreSetup['http']['createRouter']>,
options?: RouteConfigOptions<'get' | 'post' | 'put' | 'delete'>
) => void;
}
@ -117,14 +119,16 @@ export class BfetchServerPlugin
router: ReturnType<CoreSetup['http']['createRouter']>;
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<unknown, Query> = async (
context: RequestHandlerContext,

View file

@ -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,

View file

@ -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
);
});
};

View file

@ -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;