1
1
import { LogId } from "../logger.js" ;
2
- import { ApiClient } from "./apiClient.js" ;
2
+ import type { ApiClient } from "./apiClient.js" ;
3
3
import { getProcessIdFromCluster } from "./cluster.js" ;
4
4
5
5
export enum PerformanceAdvisorOperation {
@@ -105,17 +105,14 @@ export async function getSuggestedIndexes(
105
105
} ,
106
106
} ,
107
107
} ) ;
108
- if ( ! response ?. suggestedIndexes ?. length ) {
109
- throw new Error ( "No suggested indexes found." ) ;
110
- }
111
- return { suggestedIndexes : response . suggestedIndexes } ;
108
+ return { suggestedIndexes : response ?. content ?. suggestedIndexes ?? [ ] } ;
112
109
} catch ( err ) {
113
110
apiClient . logger . debug ( {
114
111
id : LogId . atlasPaSuggestedIndexesFailure ,
115
112
context : "performanceAdvisorUtils" ,
116
113
message : `Failed to list suggested indexes: ${ err instanceof Error ? err . message : String ( err ) } ` ,
117
114
} ) ;
118
- throw new Error ( `Failed to list suggested indexes. ` ) ;
115
+ throw new Error ( `Failed to list suggested indexes: ${ err instanceof Error ? err . message : String ( err ) } ` ) ;
119
116
}
120
117
}
121
118
@@ -137,25 +134,18 @@ export async function getDropIndexSuggestions(
137
134
} ,
138
135
} ,
139
136
} ) ;
140
- if (
141
- ! response ?. hiddenIndexes ?. length &&
142
- ! response ?. redundantIndexes ?. length &&
143
- ! response ?. unusedIndexes ?. length
144
- ) {
145
- throw new Error ( "No drop index suggestions found." ) ;
146
- }
147
137
return {
148
- hiddenIndexes : response ?. hiddenIndexes ?? [ ] ,
149
- redundantIndexes : response ?. redundantIndexes ?? [ ] ,
150
- unusedIndexes : response ?. unusedIndexes ?? [ ] ,
138
+ hiddenIndexes : response ?. content ?. hiddenIndexes ?? [ ] ,
139
+ redundantIndexes : response ?. content ?. redundantIndexes ?? [ ] ,
140
+ unusedIndexes : response ?. content ?. unusedIndexes ?? [ ] ,
151
141
} ;
152
142
} catch ( err ) {
153
143
apiClient . logger . debug ( {
154
144
id : LogId . atlasPaDropIndexSuggestionsFailure ,
155
145
context : "performanceAdvisorUtils" ,
156
146
message : `Failed to list drop index suggestions: ${ err instanceof Error ? err . message : String ( err ) } ` ,
157
147
} ) ;
158
- throw new Error ( `Failed to list drop index suggestions. ` ) ;
148
+ throw new Error ( `Failed to list drop index suggestions: ${ err instanceof Error ? err . message : String ( err ) } ` ) ;
159
149
}
160
150
}
161
151
@@ -173,17 +163,14 @@ export async function getSchemaAdvice(
173
163
} ,
174
164
} ,
175
165
} ) ;
176
- if ( ! response ?. recommendations ?. length ) {
177
- throw new Error ( "No schema advice found." ) ;
178
- }
179
- return { recommendations : response . recommendations } ;
166
+ return { recommendations : response ?. content ?. recommendations ?? [ ] } ;
180
167
} catch ( err ) {
181
168
apiClient . logger . debug ( {
182
169
id : LogId . atlasPaSchemaAdviceFailure ,
183
170
context : "performanceAdvisorUtils" ,
184
171
message : `Failed to list schema advice: ${ err instanceof Error ? err . message : String ( err ) } ` ,
185
172
} ) ;
186
- throw new Error ( `Failed to list schema advice. ` ) ;
173
+ throw new Error ( `Failed to list schema advice: ${ err instanceof Error ? err . message : String ( err ) } ` ) ;
187
174
}
188
175
}
189
176
@@ -213,16 +200,13 @@ export async function getSlowQueries(
213
200
} ,
214
201
} ) ;
215
202
216
- if ( ! response ?. slowQueries ?. length ) {
217
- throw new Error ( "No slow query logs found." ) ;
218
- }
219
- return { slowQueryLogs : response . slowQueries } ;
203
+ return { slowQueryLogs : response ?. content ?. slowQueries ?? [ ] } ;
220
204
} catch ( err ) {
221
205
apiClient . logger . debug ( {
222
206
id : LogId . atlasPaSlowQueryLogsFailure ,
223
207
context : "performanceAdvisorUtils" ,
224
208
message : `Failed to list slow query logs: ${ err instanceof Error ? err . message : String ( err ) } ` ,
225
209
} ) ;
226
- throw new Error ( `Failed to list slow query logs. ` ) ;
210
+ throw new Error ( `Failed to list slow query logs: ${ err instanceof Error ? err . message : String ( err ) } ` ) ;
227
211
}
228
212
}
0 commit comments