Skip to content

Commit 173c587

Browse files
authored
feat: Adds the atlas-list-performance-advisor base tool (#528)
1 parent c10955a commit 173c587

File tree

8 files changed

+819
-0
lines changed

8 files changed

+819
-0
lines changed

scripts/filter.ts

Lines changed: 4 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -41,6 +41,10 @@ function filterOpenapi(openapi: OpenAPIV3_1.Document): OpenAPIV3_1.Document {
4141
"deleteProjectIpAccessList",
4242
"listOrganizationProjects",
4343
"listAlerts",
44+
"listDropIndexes",
45+
"listClusterSuggestedIndexes",
46+
"listSchemaAdvice",
47+
"listSlowQueries",
4448
];
4549

4650
const filteredPaths = {};

src/common/atlas/apiClient.ts

Lines changed: 48 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -429,6 +429,42 @@ export class ApiClient {
429429
return data;
430430
}
431431

432+
// eslint-disable-next-line @typescript-eslint/explicit-function-return-type
433+
async listDropIndexes(options: FetchOptions<operations["listDropIndexes"]>) {
434+
const { data, error, response } = await this.client.GET(
435+
"/api/atlas/v2/groups/{groupId}/clusters/{clusterName}/performanceAdvisor/dropIndexSuggestions",
436+
options
437+
);
438+
if (error) {
439+
throw ApiClientError.fromError(response, error);
440+
}
441+
return data;
442+
}
443+
444+
// eslint-disable-next-line @typescript-eslint/explicit-function-return-type
445+
async listSchemaAdvice(options: FetchOptions<operations["listSchemaAdvice"]>) {
446+
const { data, error, response } = await this.client.GET(
447+
"/api/atlas/v2/groups/{groupId}/clusters/{clusterName}/performanceAdvisor/schemaAdvice",
448+
options
449+
);
450+
if (error) {
451+
throw ApiClientError.fromError(response, error);
452+
}
453+
return data;
454+
}
455+
456+
// eslint-disable-next-line @typescript-eslint/explicit-function-return-type
457+
async listClusterSuggestedIndexes(options: FetchOptions<operations["listClusterSuggestedIndexes"]>) {
458+
const { data, error, response } = await this.client.GET(
459+
"/api/atlas/v2/groups/{groupId}/clusters/{clusterName}/performanceAdvisor/suggestedIndexes",
460+
options
461+
);
462+
if (error) {
463+
throw ApiClientError.fromError(response, error);
464+
}
465+
return data;
466+
}
467+
432468
// eslint-disable-next-line @typescript-eslint/explicit-function-return-type
433469
async listDatabaseUsers(options: FetchOptions<operations["listDatabaseUsers"]>) {
434470
const { data, error, response } = await this.client.GET(
@@ -508,6 +544,18 @@ export class ApiClient {
508544
return data;
509545
}
510546

547+
// eslint-disable-next-line @typescript-eslint/explicit-function-return-type
548+
async listSlowQueries(options: FetchOptions<operations["listSlowQueries"]>) {
549+
const { data, error, response } = await this.client.GET(
550+
"/api/atlas/v2/groups/{groupId}/processes/{processId}/performanceAdvisor/slowQueryLogs",
551+
options
552+
);
553+
if (error) {
554+
throw ApiClientError.fromError(response, error);
555+
}
556+
return data;
557+
}
558+
511559
// eslint-disable-next-line @typescript-eslint/explicit-function-return-type
512560
async listOrganizations(options?: FetchOptions<operations["listOrganizations"]>) {
513561
const { data, error, response } = await this.client.GET("/api/atlas/v2/orgs", options);

src/common/atlas/cluster.ts

Lines changed: 20 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -2,6 +2,7 @@ import type { ClusterDescription20240805, FlexClusterDescription20241113 } from
22
import type { ApiClient } from "./apiClient.js";
33
import { LogId } from "../logger.js";
44

5+
const DEFAULT_PORT = "27017";
56
export interface Cluster {
67
name?: string;
78
instanceType: "FREE" | "DEDICATED" | "FLEX";
@@ -96,3 +97,22 @@ export async function inspectCluster(apiClient: ApiClient, projectId: string, cl
9697
}
9798
}
9899
}
100+
101+
export async function getProcessIdFromCluster(
102+
apiClient: ApiClient,
103+
projectId: string,
104+
clusterName: string
105+
): Promise<string> {
106+
try {
107+
const cluster = await inspectCluster(apiClient, projectId, clusterName);
108+
if (!cluster.connectionString) {
109+
throw new Error("No connection string available for cluster");
110+
}
111+
const url = new URL(cluster.connectionString);
112+
return `${url.hostname}:${url.port || DEFAULT_PORT}`;
113+
} catch (error) {
114+
throw new Error(
115+
`Failed to get processId from cluster: ${error instanceof Error ? error.message : String(error)}`
116+
);
117+
}
118+
}

0 commit comments

Comments
 (0)