diff --git a/package.json b/package.json index e6a51d0c5..e505b4a09 100644 --- a/package.json +++ b/package.json @@ -58,4 +58,4 @@ "engines": { "yarn": "^1.21.1" } -} \ No newline at end of file +} diff --git a/server/models/interfaces.ts b/server/models/interfaces.ts index e1417c6d5..e52a14acf 100644 --- a/server/models/interfaces.ts +++ b/server/models/interfaces.ts @@ -409,6 +409,22 @@ export interface GetSnapshotResponse { snapshots: GetSnapshot[]; } +export interface CatSnapshotsResponse { + snapshots: CatSnapshots[]; +} + +export interface CatSnapshots { + id: string; + status: string; + start_epoch: number; + end_epoch: number; + duration: number; + indices: number; + successful_shards: number; + failed_shards: number; + total_shards: number; +} + export interface CreateSnapshotResponse { snapshot: GetSnapshot; } diff --git a/server/services/SnapshotManagementService.ts b/server/services/SnapshotManagementService.ts index b06581fe4..dbb77ae88 100644 --- a/server/services/SnapshotManagementService.ts +++ b/server/services/SnapshotManagementService.ts @@ -26,6 +26,7 @@ import { AcknowledgedResponse, CreateSnapshotResponse, RestoreSnapshotResponse, + CatSnapshots, } from "../models/interfaces"; import { FailedServerResponse, ServerResponse } from "../models/types"; import { MDSEnabledClientService } from "./MDSEnabledClientService"; @@ -539,12 +540,8 @@ export default class SnapshotManagementService extends MDSEnabledClientService { })) as CatRepository[]; for (let i = 0; i < res.length; i++) { - const getSnapshotRes: GetSnapshotResponse = (await callWithRequest("snapshot.get", { - repository: res[i].id, - snapshot: "_all", - ignore_unavailable: true, - })) as GetSnapshotResponse; - res[i].snapshotCount = getSnapshotRes.snapshots.length; + let catSnapshotResponse = await this._safecatSnapshotForRepo(callWithRequest, res[i].id); + res[i].snapshotCount = catSnapshotResponse?.length; } return response.custom({ @@ -559,6 +556,24 @@ export default class SnapshotManagementService extends MDSEnabledClientService { } }; + private async _safecatSnapshotForRepo( + callWithRequest: (endpoint: string, clientParams: Record, options?: LegacyCallAPIOptions | undefined) => Promise, + repositoryName: string + ): Promise { + try { + const catSnapshotRes: CatSnapshots[] = (await callWithRequest("cat.snapshots", { + format: "json", + repository: repositoryName, + ignore_unavailable: true, + })) as CatSnapshots[]; + + return catSnapshotRes; + } catch (err) { + console.error(`Index Management - SnapshotManagementService - _safeCatSnapshot:`, err); + return undefined; + } + } + deleteRepository = async ( context: RequestHandlerContext, request: OpenSearchDashboardsRequest,