-
Notifications
You must be signed in to change notification settings - Fork 126
feat: Atlas get performance advisor integration tests #589
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
Changes from 31 commits
bd69450
f331bac
78f9888
2f023eb
a4cbc8b
2ef0ded
923263e
8272719
5871dc0
ce0466b
f0b24bb
3217e95
016af0e
a2fbe34
4645d07
d6b7db8
9dbdca1
5da6e8d
63a94e1
93d9757
4869b78
53c262b
095256c
9d56da0
400bff1
35b695d
3e73b21
3efe310
3b7112d
f5c1d8d
7b4922f
8352d18
26ccdfc
File filter
Filter by extension
Conversations
Jump to
Diff view
Diff view
There are no files selected for viewing
Original file line number | Diff line number | Diff line change |
---|---|---|
|
@@ -38,14 +38,29 @@ For more information on setting up API keys, visit: https://www.mongodb.com/docs | |
}; | ||
} | ||
|
||
if (statusCode === 402) { | ||
There was a problem hiding this comment. Choose a reason for hiding this commentThe reason will be displayed to describe this comment to others. Learn more. Are we getting 402 when a customer tries to access PA on a free/shared tier cluster? There was a problem hiding this comment. Choose a reason for hiding this commentThe reason will be displayed to describe this comment to others. Learn more. No, we're getting a 402 for the integration tests when they're run with an org that has no payment set up, since an M10 is created for the new integration test. PA on a free/shared tier cluster will be a 200. There was a problem hiding this comment. Choose a reason for hiding this commentThe reason will be displayed to describe this comment to others. Learn more. So are users likely to ever get the 402 response? There was a problem hiding this comment. Choose a reason for hiding this commentThe reason will be displayed to describe this comment to others. Learn more. I think one thing to add here is probably elicitation is needed for all these tools since they can add cost to the user, here's some context bcbf889 There was a problem hiding this comment. Choose a reason for hiding this commentThe reason will be displayed to describe this comment to others. Learn more. users are not likely to get the 402 response. This is purely for the integration tests. |
||
return { | ||
content: [ | ||
{ | ||
type: "text", | ||
text: `Received a Payment Required API Error: ${error.message} | ||
|
||
Payment setup is required to perform this action in MongoDB Atlas. | ||
Please ensure that your payment method for your organization has been set up and is active. | ||
For more information on setting up payment, visit: https://www.mongodb.com/docs/atlas/billing/`, | ||
}, | ||
], | ||
}; | ||
} | ||
|
||
if (statusCode === 403) { | ||
return { | ||
content: [ | ||
{ | ||
type: "text", | ||
text: `Received a Forbidden API Error: ${error.message} | ||
|
||
You don't have sufficient permissions to perform this action in MongoDB Atlas | ||
You don't have sufficient permissions to perform this action in MongoDB Atlas. | ||
Please ensure your API key has the necessary roles assigned. | ||
For more information on Atlas API access roles, visit: https://www.mongodb.com/docs/atlas/api/service-accounts-overview/`, | ||
}, | ||
|
Original file line number | Diff line number | Diff line change |
---|---|---|
|
@@ -8,6 +8,7 @@ import { | |
getDropIndexSuggestions, | ||
getSchemaAdvice, | ||
getSlowQueries, | ||
DEFAULT_SLOW_QUERY_LOGS_LIMIT, | ||
} from "../../../common/atlas/performanceAdvisorUtils.js"; | ||
import { AtlasArgs } from "../../args.js"; | ||
|
||
|
@@ -20,8 +21,7 @@ const PerformanceAdvisorOperationType = z.enum([ | |
|
||
export class GetPerformanceAdvisorTool extends AtlasToolBase { | ||
public name = "atlas-get-performance-advisor"; | ||
protected description = | ||
"Get MongoDB Atlas performance advisor recommendations, which includes the operations: suggested indexes, drop index suggestions, slow query logs, and schema suggestions"; | ||
protected description = `Get MongoDB Atlas performance advisor recommendations, which includes the operations: suggested indexes, drop index suggestions, schema suggestions, and a sample of the most recent (max ${DEFAULT_SLOW_QUERY_LOGS_LIMIT}) slow query logs`; | ||
public operationType: OperationType = "read"; | ||
protected argsShape = { | ||
projectId: AtlasArgs.projectId().describe("Atlas project ID to get performance advisor recommendations"), | ||
|
@@ -31,8 +31,11 @@ export class GetPerformanceAdvisorTool extends AtlasToolBase { | |
.default(PerformanceAdvisorOperationType.options) | ||
.describe("Operations to get performance advisor recommendations"), | ||
since: z | ||
.date() | ||
.describe("Date to get slow query logs since. Only relevant for the slowQueryLogs operation.") | ||
.string() | ||
.datetime() | ||
.describe( | ||
"Date to get slow query logs since. Must be a string in ISO 8601 format. Only relevant for the slowQueryLogs operation." | ||
) | ||
.optional(), | ||
namespaces: z | ||
.array(z.string()) | ||
|
@@ -57,26 +60,39 @@ export class GetPerformanceAdvisorTool extends AtlasToolBase { | |
? getDropIndexSuggestions(this.session.apiClient, projectId, clusterName) | ||
: Promise.resolve(undefined), | ||
operations.includes("slowQueryLogs") | ||
? getSlowQueries(this.session.apiClient, projectId, clusterName, since, namespaces) | ||
? getSlowQueries( | ||
this.session.apiClient, | ||
projectId, | ||
clusterName, | ||
since ? new Date(since) : undefined, | ||
namespaces | ||
) | ||
: Promise.resolve(undefined), | ||
operations.includes("schemaSuggestions") | ||
? getSchemaAdvice(this.session.apiClient, projectId, clusterName) | ||
: Promise.resolve(undefined), | ||
]); | ||
|
||
const hasSuggestedIndexes = suggestedIndexesResult && suggestedIndexesResult?.suggestedIndexes?.length > 0; | ||
const hasDropIndexSuggestions = | ||
dropIndexSuggestionsResult && | ||
dropIndexSuggestionsResult?.hiddenIndexes?.length > 0 && | ||
dropIndexSuggestionsResult?.redundantIndexes?.length > 0 && | ||
dropIndexSuggestionsResult?.unusedIndexes?.length > 0; | ||
const hasSlowQueryLogs = slowQueryLogsResult && slowQueryLogsResult?.slowQueryLogs?.length > 0; | ||
const hasSchemaSuggestions = | ||
schemaSuggestionsResult && schemaSuggestionsResult?.recommendations?.length > 0; | ||
|
||
// Inserts the performance advisor data with the relevant section header if it exists | ||
const performanceAdvisorData = [ | ||
suggestedIndexesResult && suggestedIndexesResult?.suggestedIndexes?.length > 0 | ||
? `## Suggested Indexes\n${JSON.stringify(suggestedIndexesResult.suggestedIndexes)}` | ||
: "No suggested indexes found.", | ||
dropIndexSuggestionsResult | ||
? `## Drop Index Suggestions\n${JSON.stringify(dropIndexSuggestionsResult)}` | ||
: "No drop index suggestions found.", | ||
slowQueryLogsResult && slowQueryLogsResult?.slowQueryLogs?.length > 0 | ||
? `## Slow Query Logs\n${JSON.stringify(slowQueryLogsResult.slowQueryLogs)}` | ||
: "No slow query logs found.", | ||
schemaSuggestionsResult && schemaSuggestionsResult?.recommendations?.length > 0 | ||
? `## Schema Suggestions\n${JSON.stringify(schemaSuggestionsResult.recommendations)}` | ||
: "No schema suggestions found.", | ||
`## Suggested Indexes\n${ | ||
hasSuggestedIndexes | ||
? `Note: The "Weight" field is measured in bytes, and represents the estimated number of bytes saved in disk reads per executed read query that would be saved by implementing an index suggestion. Please convert this to MB or GB for easier readability.\n${JSON.stringify(suggestedIndexesResult.suggestedIndexes)}` | ||
|
||
: "No suggested indexes found." | ||
}`, | ||
`## Drop Index Suggestions\n${hasDropIndexSuggestions ? JSON.stringify(dropIndexSuggestionsResult) : "No drop index suggestions found."}`, | ||
`## Slow Query Logs\n${hasSlowQueryLogs ? JSON.stringify(slowQueryLogsResult.slowQueryLogs) : "No slow query logs found."}`, | ||
`## Schema Suggestions\n${hasSchemaSuggestions ? JSON.stringify(schemaSuggestionsResult.recommendations) : "No schema suggestions found."}`, | ||
]; | ||
|
||
if (performanceAdvisorData.length === 0) { | ||
|
Uh oh!
There was an error while loading. Please reload this page.