[Maps] Abort ES-search when tile request is cancelled (#92069)
This commit is contained in:
parent
a102fa9a70
commit
33010bebf9
|
@ -28,6 +28,10 @@ import { flattenHit } from './util';
|
||||||
import { ESBounds, tileToESBbox } from '../../common/geo_tile_utils';
|
import { ESBounds, tileToESBbox } from '../../common/geo_tile_utils';
|
||||||
import { getCentroidFeatures } from '../../common/get_centroid_features';
|
import { getCentroidFeatures } from '../../common/get_centroid_features';
|
||||||
|
|
||||||
|
function isAbortError(error: Error) {
|
||||||
|
return error.message === 'Request aborted' || error.message === 'Aborted';
|
||||||
|
}
|
||||||
|
|
||||||
export async function getGridTile({
|
export async function getGridTile({
|
||||||
logger,
|
logger,
|
||||||
context,
|
context,
|
||||||
|
@ -40,6 +44,7 @@ export async function getGridTile({
|
||||||
requestType = RENDER_AS.POINT,
|
requestType = RENDER_AS.POINT,
|
||||||
geoFieldType = ES_GEO_FIELD_TYPE.GEO_POINT,
|
geoFieldType = ES_GEO_FIELD_TYPE.GEO_POINT,
|
||||||
searchSessionId,
|
searchSessionId,
|
||||||
|
abortSignal,
|
||||||
}: {
|
}: {
|
||||||
x: number;
|
x: number;
|
||||||
y: number;
|
y: number;
|
||||||
|
@ -52,6 +57,7 @@ export async function getGridTile({
|
||||||
requestType: RENDER_AS;
|
requestType: RENDER_AS;
|
||||||
geoFieldType: ES_GEO_FIELD_TYPE;
|
geoFieldType: ES_GEO_FIELD_TYPE;
|
||||||
searchSessionId?: string;
|
searchSessionId?: string;
|
||||||
|
abortSignal: AbortSignal;
|
||||||
}): Promise<Buffer | null> {
|
}): Promise<Buffer | null> {
|
||||||
try {
|
try {
|
||||||
const tileBounds: ESBounds = tileToESBbox(x, y, z);
|
const tileBounds: ESBounds = tileToESBbox(x, y, z);
|
||||||
|
@ -72,6 +78,7 @@ export async function getGridTile({
|
||||||
},
|
},
|
||||||
{
|
{
|
||||||
sessionId: searchSessionId,
|
sessionId: searchSessionId,
|
||||||
|
abortSignal,
|
||||||
}
|
}
|
||||||
)
|
)
|
||||||
.toPromise();
|
.toPromise();
|
||||||
|
@ -83,7 +90,9 @@ export async function getGridTile({
|
||||||
|
|
||||||
return createMvtTile(featureCollection, z, x, y);
|
return createMvtTile(featureCollection, z, x, y);
|
||||||
} catch (e) {
|
} catch (e) {
|
||||||
|
if (!isAbortError(e)) {
|
||||||
logger.warn(`Cannot generate grid-tile for ${z}/${x}/${y}: ${e.message}`);
|
logger.warn(`Cannot generate grid-tile for ${z}/${x}/${y}: ${e.message}`);
|
||||||
|
}
|
||||||
return null;
|
return null;
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
@ -99,6 +108,7 @@ export async function getTile({
|
||||||
requestBody = {},
|
requestBody = {},
|
||||||
geoFieldType,
|
geoFieldType,
|
||||||
searchSessionId,
|
searchSessionId,
|
||||||
|
abortSignal,
|
||||||
}: {
|
}: {
|
||||||
x: number;
|
x: number;
|
||||||
y: number;
|
y: number;
|
||||||
|
@ -110,6 +120,7 @@ export async function getTile({
|
||||||
requestBody: any;
|
requestBody: any;
|
||||||
geoFieldType: ES_GEO_FIELD_TYPE;
|
geoFieldType: ES_GEO_FIELD_TYPE;
|
||||||
searchSessionId?: string;
|
searchSessionId?: string;
|
||||||
|
abortSignal: AbortSignal;
|
||||||
}): Promise<Buffer | null> {
|
}): Promise<Buffer | null> {
|
||||||
let features: Feature[];
|
let features: Feature[];
|
||||||
try {
|
try {
|
||||||
|
@ -119,6 +130,7 @@ export async function getTile({
|
||||||
|
|
||||||
const searchOptions = {
|
const searchOptions = {
|
||||||
sessionId: searchSessionId,
|
sessionId: searchSessionId,
|
||||||
|
abortSignal,
|
||||||
};
|
};
|
||||||
|
|
||||||
const countResponse = await context
|
const countResponse = await context
|
||||||
|
@ -214,7 +226,9 @@ export async function getTile({
|
||||||
|
|
||||||
return createMvtTile(featureCollection, z, x, y);
|
return createMvtTile(featureCollection, z, x, y);
|
||||||
} catch (e) {
|
} catch (e) {
|
||||||
|
if (!isAbortError(e)) {
|
||||||
logger.warn(`Cannot generate tile for ${z}/${x}/${y}: ${e.message}`);
|
logger.warn(`Cannot generate tile for ${z}/${x}/${y}: ${e.message}`);
|
||||||
|
}
|
||||||
return null;
|
return null;
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
|
@ -10,6 +10,8 @@ import { schema } from '@kbn/config-schema';
|
||||||
import { KibanaRequest, KibanaResponseFactory, Logger } from 'src/core/server';
|
import { KibanaRequest, KibanaResponseFactory, Logger } from 'src/core/server';
|
||||||
import { IRouter } from 'src/core/server';
|
import { IRouter } from 'src/core/server';
|
||||||
import type { DataRequestHandlerContext } from 'src/plugins/data/server';
|
import type { DataRequestHandlerContext } from 'src/plugins/data/server';
|
||||||
|
// @ts-ignore not typed
|
||||||
|
import { AbortController } from 'abortcontroller-polyfill/dist/cjs-ponyfill';
|
||||||
import {
|
import {
|
||||||
MVT_GETTILE_API_PATH,
|
MVT_GETTILE_API_PATH,
|
||||||
API_ROOT_PATH,
|
API_ROOT_PATH,
|
||||||
|
@ -50,6 +52,12 @@ export function initMVTRoutes({
|
||||||
response: KibanaResponseFactory
|
response: KibanaResponseFactory
|
||||||
) => {
|
) => {
|
||||||
const { query } = request;
|
const { query } = request;
|
||||||
|
|
||||||
|
const abortController = new AbortController();
|
||||||
|
request.events.aborted$.subscribe(() => {
|
||||||
|
abortController.abort();
|
||||||
|
});
|
||||||
|
|
||||||
const requestBodyDSL = rison.decode(query.requestBody as string);
|
const requestBodyDSL = rison.decode(query.requestBody as string);
|
||||||
|
|
||||||
const tile = await getTile({
|
const tile = await getTile({
|
||||||
|
@ -63,6 +71,7 @@ export function initMVTRoutes({
|
||||||
requestBody: requestBodyDSL as any,
|
requestBody: requestBodyDSL as any,
|
||||||
geoFieldType: query.geoFieldType as ES_GEO_FIELD_TYPE,
|
geoFieldType: query.geoFieldType as ES_GEO_FIELD_TYPE,
|
||||||
searchSessionId: query.searchSessionId,
|
searchSessionId: query.searchSessionId,
|
||||||
|
abortSignal: abortController.signal,
|
||||||
});
|
});
|
||||||
|
|
||||||
return sendResponse(response, tile);
|
return sendResponse(response, tile);
|
||||||
|
@ -92,6 +101,11 @@ export function initMVTRoutes({
|
||||||
response: KibanaResponseFactory
|
response: KibanaResponseFactory
|
||||||
) => {
|
) => {
|
||||||
const { query } = request;
|
const { query } = request;
|
||||||
|
const abortController = new AbortController();
|
||||||
|
request.events.aborted$.subscribe(() => {
|
||||||
|
abortController.abort();
|
||||||
|
});
|
||||||
|
|
||||||
const requestBodyDSL = rison.decode(query.requestBody as string);
|
const requestBodyDSL = rison.decode(query.requestBody as string);
|
||||||
|
|
||||||
const tile = await getGridTile({
|
const tile = await getGridTile({
|
||||||
|
@ -106,6 +120,7 @@ export function initMVTRoutes({
|
||||||
requestType: query.requestType as RENDER_AS,
|
requestType: query.requestType as RENDER_AS,
|
||||||
geoFieldType: query.geoFieldType as ES_GEO_FIELD_TYPE,
|
geoFieldType: query.geoFieldType as ES_GEO_FIELD_TYPE,
|
||||||
searchSessionId: query.searchSessionId,
|
searchSessionId: query.searchSessionId,
|
||||||
|
abortSignal: abortController.signal,
|
||||||
});
|
});
|
||||||
|
|
||||||
return sendResponse(response, tile);
|
return sendResponse(response, tile);
|
||||||
|
|
Loading…
Reference in a new issue