Skip to content

Commit

Permalink
[Synthetics] Increase project API payload limit (#142140)
Browse files Browse the repository at this point in the history
  • Loading branch information
shahzad31 authored Oct 4, 2022
1 parent b62c0f9 commit 6824718
Show file tree
Hide file tree
Showing 4 changed files with 17 additions and 4 deletions.
8 changes: 6 additions & 2 deletions src/plugins/bfetch/server/plugin.ts
Original file line number Diff line number Diff line change
Expand Up @@ -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,
Expand Down Expand Up @@ -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;
}

Expand Down Expand Up @@ -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,
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -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
) => ({
Expand All @@ -25,6 +27,11 @@ export const addSyntheticsProjectMonitorRoute: SyntheticsStreamingRouteFactory =
monitors: schema.arrayOf(schema.any()),
}),
},
options: {
body: {
maxBytes: MAX_PAYLOAD_SIZE,
},
},
handler: async ({
request,
savedObjectsClient,
Expand Down
5 changes: 3 additions & 2 deletions x-pack/plugins/synthetics/server/server.ts
Original file line number Diff line number Diff line change
Expand Up @@ -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
Expand All @@ -82,7 +82,8 @@ export const initSyntheticsServer = (
};
},
method,
server.router
server.router,
options
);
});
};
Original file line number Diff line number Diff line change
Expand Up @@ -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;
Expand Down

0 comments on commit 6824718

Please sign in to comment.