Skip to content

Commit

Permalink
[Maps] Propagate http abort requests to Elasticsearch for mvt endpoin…
Browse files Browse the repository at this point in the history
…ts (#119043)
  • Loading branch information
thomasneirynck authored and dmlemeshko committed Nov 29, 2021
1 parent d74fe14 commit 730d5a8
Show file tree
Hide file tree
Showing 3 changed files with 34 additions and 22 deletions.
17 changes: 12 additions & 5 deletions x-pack/plugins/maps/server/mvt/get_grid_tile.ts
Original file line number Diff line number Diff line change
Expand Up @@ -23,6 +23,7 @@ export async function getEsGridTile({
z,
requestBody = {},
requestType = RENDER_AS.POINT,
abortController,
}: {
x: number;
y: number;
Expand All @@ -33,6 +34,7 @@ export async function getEsGridTile({
logger: Logger;
requestBody: any;
requestType: RENDER_AS.GRID | RENDER_AS.POINT;
abortController: AbortController;
}): Promise<Buffer | null> {
try {
const path = `/${encodeURIComponent(index)}/_mvt/${geometryFieldName}/${z}/${x}/${y}`;
Expand All @@ -47,11 +49,16 @@ export async function getEsGridTile({
fields: requestBody.fields,
runtime_mappings: requestBody.runtime_mappings,
};
const tile = await context.core.elasticsearch.client.asCurrentUser.transport.request({
method: 'GET',
path,
body,
});
const tile = await context.core.elasticsearch.client.asCurrentUser.transport.request(
{
method: 'GET',
path,
body,
},
{
signal: abortController.signal,
}
);
return tile.body as unknown as Buffer;
} catch (e) {
if (!isAbortError(e)) {
Expand Down
17 changes: 12 additions & 5 deletions x-pack/plugins/maps/server/mvt/get_tile.ts
Original file line number Diff line number Diff line change
Expand Up @@ -22,6 +22,7 @@ export async function getEsTile({
y,
z,
requestBody = {},
abortController,
}: {
x: number;
y: number;
Expand All @@ -31,6 +32,7 @@ export async function getEsTile({
context: DataRequestHandlerContext;
logger: Logger;
requestBody: any;
abortController: AbortController;
}): Promise<Buffer | null> {
try {
const path = `/${encodeURIComponent(index)}/_mvt/${geometryFieldName}/${z}/${x}/${y}`;
Expand All @@ -45,11 +47,16 @@ export async function getEsTile({
runtime_mappings: requestBody.runtime_mappings,
track_total_hits: requestBody.size + 1,
};
const tile = await context.core.elasticsearch.client.asCurrentUser.transport.request({
method: 'GET',
path,
body,
});
const tile = await context.core.elasticsearch.client.asCurrentUser.transport.request(
{
method: 'GET',
path,
body,
},
{
signal: abortController.signal,
}
);
return tile.body as unknown as Buffer;
} catch (e) {
if (!isAbortError(e)) {
Expand Down
22 changes: 10 additions & 12 deletions x-pack/plugins/maps/server/mvt/mvt_routes.ts
Original file line number Diff line number Diff line change
Expand Up @@ -10,8 +10,6 @@ import { schema } from '@kbn/config-schema';
import { KibanaRequest, KibanaResponseFactory, Logger } from 'src/core/server';
import { IRouter } from 'src/core/server';
import type { DataRequestHandlerContext } from 'src/plugins/data/server';
// @ts-ignore not typed
import { AbortController } from 'abortcontroller-polyfill/dist/cjs-ponyfill';
import {
MVT_GETTILE_API_PATH,
API_ROOT_PATH,
Expand Down Expand Up @@ -54,11 +52,10 @@ export function initMVTRoutes({
) => {
const { query, params } = request;

// todo - replace with direct abortion of raw transport request
// const abortController = new AbortController();
// request.events.aborted$.subscribe(() => {
// abortController.abort();
// });
const abortController = new AbortController();
request.events.aborted$.subscribe(() => {
abortController.abort();
});

const requestBodyDSL = rison.decode(query.requestBody as string);

Expand All @@ -71,6 +68,7 @@ export function initMVTRoutes({
z: parseInt((params as any).z, 10) as number,
index: query.index as string,
requestBody: requestBodyDSL as any,
abortController,
});

return sendResponse(response, tile);
Expand Down Expand Up @@ -102,11 +100,10 @@ export function initMVTRoutes({
) => {
const { query, params } = request;

// todo - replace with direct abortion of raw transport request
// const abortController = new AbortController();
// request.events.aborted$.subscribe(() => {
// abortController.abort();
// });
const abortController = new AbortController();
request.events.aborted$.subscribe(() => {
abortController.abort();
});

const requestBodyDSL = rison.decode(query.requestBody as string);

Expand All @@ -120,6 +117,7 @@ export function initMVTRoutes({
index: query.index as string,
requestBody: requestBodyDSL as any,
requestType: query.requestType as RENDER_AS.POINT | RENDER_AS.GRID,
abortController,
});

return sendResponse(response, tile);
Expand Down

0 comments on commit 730d5a8

Please sign in to comment.