Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Use cat snapshot API to get the number of snapshot for a repository #1242

Merged
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension


Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
2 changes: 1 addition & 1 deletion package.json
Original file line number Diff line number Diff line change
Expand Up @@ -58,4 +58,4 @@
"engines": {
"yarn": "^1.21.1"
}
}
}
16 changes: 16 additions & 0 deletions server/models/interfaces.ts
Original file line number Diff line number Diff line change
Expand Up @@ -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;
}
Expand Down
27 changes: 21 additions & 6 deletions server/services/SnapshotManagementService.ts
Original file line number Diff line number Diff line change
Expand Up @@ -26,6 +26,7 @@ import {
AcknowledgedResponse,
CreateSnapshotResponse,
RestoreSnapshotResponse,
CatSnapshots,
} from "../models/interfaces";
import { FailedServerResponse, ServerResponse } from "../models/types";
import { MDSEnabledClientService } from "./MDSEnabledClientService";
Expand Down Expand Up @@ -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({
Expand All @@ -559,6 +556,24 @@ export default class SnapshotManagementService extends MDSEnabledClientService {
}
};

private async _safecatSnapshotForRepo(
RamakrishnaChilaka marked this conversation as resolved.
Show resolved Hide resolved
callWithRequest: (endpoint: string, clientParams: Record<string, any>, options?: LegacyCallAPIOptions | undefined) => Promise<unknown>,
repositoryName: string
): Promise<CatSnapshots[] | undefined> {
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,
Expand Down
Loading