From 9b0ea892e26481bef3263202cea72e99a4454df2 Mon Sep 17 00:00:00 2001 From: "opensearch-trigger-bot[bot]" <98922864+opensearch-trigger-bot[bot]@users.noreply.github.com> Date: Tue, 4 Jul 2023 09:42:46 +0800 Subject: [PATCH] feat: exclude remote model for admin UI (#225) (#228) Signed-off-by: Lin Wang (cherry picked from commit ba01d34b60735de75ba122e7041bac9a4b7a1380) Co-authored-by: Lin Wang --- public/apis/model.ts | 1 + .../components/monitoring/use_monitoring.ts | 1 + server/routes/model_router.ts | 4 +++- server/services/model_service.ts | 1 + server/services/utils/model.ts | 21 +++++++++++++++---- 5 files changed, 23 insertions(+), 5 deletions(-) diff --git a/public/apis/model.ts b/public/apis/model.ts index daf0689c..040feb25 100644 --- a/public/apis/model.ts +++ b/public/apis/model.ts @@ -30,6 +30,7 @@ export class Model { size: number; states?: MODEL_STATE[]; nameOrId?: string; + exclude?: 'REMOTE_MODEL'; }) { return InnerHttpProvider.getHttp().get(MODEL_API_ENDPOINT, { query, diff --git a/public/components/monitoring/use_monitoring.ts b/public/components/monitoring/use_monitoring.ts index 35031ad5..34907b5e 100644 --- a/public/components/monitoring/use_monitoring.ts +++ b/public/components/monitoring/use_monitoring.ts @@ -47,6 +47,7 @@ const fetchDeployedModels = async (params: Params) => { ? [MODEL_STATE.loadFailed, MODEL_STATE.loaded, MODEL_STATE.partiallyLoaded] : states, sort: [`${params.sort.field}-${params.sort.direction}`], + exclude: 'REMOTE_MODEL', }); const totalPages = Math.ceil(result.total_models / params.pageSize); return { diff --git a/server/routes/model_router.ts b/server/routes/model_router.ts index 822df4c2..94a8512e 100644 --- a/server/routes/model_router.ts +++ b/server/routes/model_router.ts @@ -42,11 +42,12 @@ export const modelRouter = (router: IRouter) => { ), states: schema.maybe(schema.oneOf([schema.arrayOf(modelStateSchema), modelStateSchema])), nameOrId: schema.maybe(schema.string()), + exclude: schema.maybe(schema.literal('REMOTE_MODEL')), }), }, }, async (context, request) => { - const { from, size, sort, states, nameOrId } = request.query; + const { from, size, sort, states, nameOrId, exclude } = request.query; try { const payload = await ModelService.search({ client: context.core.opensearch.client, @@ -55,6 +56,7 @@ export const modelRouter = (router: IRouter) => { sort: typeof sort === 'string' ? [sort] : sort, states: typeof states === 'string' ? [states] : states, nameOrId, + exclude, }); return opensearchDashboardsResponseFactory.ok({ body: payload }); } catch (err) { diff --git a/server/services/model_service.ts b/server/services/model_service.ts index 2b98dfdf..35480209 100644 --- a/server/services/model_service.ts +++ b/server/services/model_service.ts @@ -43,6 +43,7 @@ export class ModelService { sort?: ModelSearchSort[]; states?: MODEL_STATE[]; nameOrId?: string; + exclude?: 'REMOTE_MODEL'; }) { const { body: { hits }, diff --git a/server/services/utils/model.ts b/server/services/utils/model.ts index f7b585c4..e347fd33 100644 --- a/server/services/utils/model.ts +++ b/server/services/utils/model.ts @@ -9,9 +9,11 @@ import { generateTermQuery } from './query'; export const generateModelSearchQuery = ({ states, nameOrId, + exclude, }: { states?: MODEL_STATE[]; nameOrId?: string; + exclude?: 'REMOTE_MODEL'; }) => ({ bool: { must: [ @@ -33,10 +35,21 @@ export const generateModelSearchQuery = ({ ] : []), ], - must_not: { - exists: { - field: 'chunk_number', + must_not: [ + { + exists: { + field: 'chunk_number', + }, }, - }, + ...(exclude === 'REMOTE_MODEL' + ? [ + { + term: { + algorithm: 'REMOTE', + }, + }, + ] + : []), + ], }, });