Skip to content
Merged
Show file tree
Hide file tree
Changes from 6 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
4 changes: 4 additions & 0 deletions scripts/filter.ts
Original file line number Diff line number Diff line change
Expand Up @@ -41,6 +41,10 @@ function filterOpenapi(openapi: OpenAPIV3_1.Document): OpenAPIV3_1.Document {
"deleteProjectIpAccessList",
"listOrganizationProjects",
"listAlerts",
"listDropIndexes",
"listClusterSuggestedIndexes",
"listSchemaAdvice",
"listSlowQueries",
];

const filteredPaths = {};
Expand Down
48 changes: 48 additions & 0 deletions src/common/atlas/apiClient.ts
Original file line number Diff line number Diff line change
Expand Up @@ -429,6 +429,42 @@ export class ApiClient {
return data;
}

// eslint-disable-next-line @typescript-eslint/explicit-function-return-type
async listDropIndexes(options: FetchOptions<operations["listDropIndexes"]>) {
const { data, error, response } = await this.client.GET(
"/api/atlas/v2/groups/{groupId}/clusters/{clusterName}/performanceAdvisor/dropIndexSuggestions",
options
);
if (error) {
throw ApiClientError.fromError(response, error);
}
return data;
}

// eslint-disable-next-line @typescript-eslint/explicit-function-return-type
async listSchemaAdvice(options: FetchOptions<operations["listSchemaAdvice"]>) {
const { data, error, response } = await this.client.GET(
"/api/atlas/v2/groups/{groupId}/clusters/{clusterName}/performanceAdvisor/schemaAdvice",
options
);
if (error) {
throw ApiClientError.fromError(response, error);
}
return data;
}

// eslint-disable-next-line @typescript-eslint/explicit-function-return-type
async listClusterSuggestedIndexes(options: FetchOptions<operations["listClusterSuggestedIndexes"]>) {
const { data, error, response } = await this.client.GET(
"/api/atlas/v2/groups/{groupId}/clusters/{clusterName}/performanceAdvisor/suggestedIndexes",
options
);
if (error) {
throw ApiClientError.fromError(response, error);
}
return data;
}

// eslint-disable-next-line @typescript-eslint/explicit-function-return-type
async listDatabaseUsers(options: FetchOptions<operations["listDatabaseUsers"]>) {
const { data, error, response } = await this.client.GET(
Expand Down Expand Up @@ -508,6 +544,18 @@ export class ApiClient {
return data;
}

// eslint-disable-next-line @typescript-eslint/explicit-function-return-type
async listSlowQueries(options: FetchOptions<operations["listSlowQueries"]>) {
const { data, error, response } = await this.client.GET(
"/api/atlas/v2/groups/{groupId}/processes/{processId}/performanceAdvisor/slowQueryLogs",
options
);
if (error) {
throw ApiClientError.fromError(response, error);
}
return data;
}

// eslint-disable-next-line @typescript-eslint/explicit-function-return-type
async listOrganizations(options?: FetchOptions<operations["listOrganizations"]>) {
const { data, error, response } = await this.client.GET("/api/atlas/v2/orgs", options);
Expand Down
21 changes: 21 additions & 0 deletions src/common/atlas/cluster.ts
Original file line number Diff line number Diff line change
Expand Up @@ -2,6 +2,7 @@ import type { ClusterDescription20240805, FlexClusterDescription20241113 } from
import type { ApiClient } from "./apiClient.js";
import { LogId } from "../logger.js";

const DEFAULT_PORT = "27017";
export interface Cluster {
name?: string;
instanceType: "FREE" | "DEDICATED" | "FLEX";
Expand Down Expand Up @@ -96,3 +97,23 @@ export async function inspectCluster(apiClient: ApiClient, projectId: string, cl
}
}
}

export async function getProcessIdFromCluster(
apiClient: ApiClient,
projectId: string,
clusterName: string
): Promise<string> {
try {
const cluster = await inspectCluster(apiClient, projectId, clusterName);
if (!cluster.connectionString) {
throw new Error("No connection string available for cluster");
}
const url = new URL(cluster.connectionString);
const processId = `${url.hostname}:${url.port || DEFAULT_PORT}`;
return processId;
} catch (error) {
throw new Error(
`Failed to get processId from cluster: ${error instanceof Error ? error.message : String(error)}`
);
}
}
Loading
Loading