Skip to content

Commit a4cbc8b

Browse files
committed
Clean up getting slow query logs from atlas admin api
1 parent 2f023eb commit a4cbc8b

File tree

2 files changed

+19
-6
lines changed

2 files changed

+19
-6
lines changed

src/common/atlas/performanceAdvisorUtils.ts

Lines changed: 6 additions & 4 deletions
Original file line numberDiff line numberDiff line change
@@ -178,8 +178,9 @@ export async function getSlowQueries(
178178
apiClient: ApiClient,
179179
projectId: string,
180180
clusterName: string,
181-
since: string,
182-
processId?: string
181+
since?: number,
182+
processId?: string,
183+
namespaces?: string[]
183184
): Promise<{ slowQueryLogs: Array<SlowQueryLog> }> {
184185
try {
185186
// If processId is not provided, get it from inspecting the cluster
@@ -195,12 +196,13 @@ export async function getSlowQueries(
195196
processId: actualProcessId,
196197
},
197198
query: {
198-
since: Number(since),
199+
...(since && { since: Number(since) }),
200+
...(namespaces && { namespaces: namespaces }),
199201
},
200202
},
201203
});
202204

203-
return { slowQueryLogs: response?.content?.slowQueries ?? [] };
205+
return { slowQueryLogs: response?.slowQueries ?? [] };
204206
} catch (err) {
205207
apiClient.logger.debug({
206208
id: LogId.atlasPaSlowQueryLogsFailure,

src/tools/atlas/read/listPerformanceAdvisor.ts

Lines changed: 13 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -21,14 +21,18 @@ export class ListPerformanceAdvisorTool extends AtlasToolBase {
2121
operations: z
2222
.array(z.nativeEnum(PerformanceAdvisorOperation))
2323
.describe("Operations to list performance advisor recommendations"),
24-
since: z.string().describe("Date to list performance advisor recommendations since"),
24+
since: z.number().describe("Date to list slow query logs since").optional(),
25+
processId: z.string().describe("Process ID to list slow query logs").optional(),
26+
namespaces: z.array(z.string()).describe("Namespaces to list slow query logs").optional(),
2527
};
2628

2729
protected async execute({
2830
projectId,
2931
clusterName,
3032
operations,
3133
since,
34+
processId,
35+
namespaces,
3236
}: ToolArgs<typeof this.argsShape>): Promise<CallToolResult> {
3337
const data: PerformanceAdvisorData = {
3438
suggestedIndexes: [],
@@ -57,7 +61,14 @@ export class ListPerformanceAdvisorTool extends AtlasToolBase {
5761
}
5862

5963
if (operationsToExecute.includes(PerformanceAdvisorOperation.SLOW_QUERY_LOGS)) {
60-
const { slowQueryLogs } = await getSlowQueries(this.session.apiClient, projectId, clusterName, since);
64+
const { slowQueryLogs } = await getSlowQueries(
65+
this.session.apiClient,
66+
projectId,
67+
clusterName,
68+
since,
69+
processId,
70+
namespaces
71+
);
6172
data.slowQueryLogs = slowQueryLogs;
6273
}
6374

0 commit comments

Comments
 (0)