Skip to content

Commit 9ae90b3

Browse files
CLOUDP-97442: update performance advisor with new endpoints -> atlas go client (#252)
1 parent 85d8f82 commit 9ae90b3

File tree

2 files changed

+79
-0
lines changed

2 files changed

+79
-0
lines changed

mongodbatlas/performance_advisor.go

Lines changed: 51 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -25,6 +25,7 @@ const (
2525
performanceAdvisorNamespacesPath = performanceAdvisorPath + "/namespaces"
2626
performanceAdvisorSlowQueryLogsPath = performanceAdvisorPath + "/slowQueryLogs"
2727
performanceAdvisorSuggestedIndexesLogsPath = performanceAdvisorPath + "/suggestedIndexes"
28+
performanceAdvisorManagedSlowMs = "api/atlas/v1.0/groups/%s/managedSlowMs"
2829
)
2930

3031
// PerformanceAdvisorService is an interface of the Performance Advisor
@@ -35,6 +36,8 @@ type PerformanceAdvisorService interface {
3536
GetNamespaces(context.Context, string, string, *NamespaceOptions) (*Namespaces, *Response, error)
3637
GetSlowQueries(context.Context, string, string, *SlowQueryOptions) (*SlowQueries, *Response, error)
3738
GetSuggestedIndexes(context.Context, string, string, *SuggestedIndexOptions) (*SuggestedIndexes, *Response, error)
39+
EnableManagedSlowOperationThreshold(context.Context, string) (*Response, error)
40+
DisableManagedSlowOperationThreshold(context.Context, string) (*Response, error)
3841
}
3942

4043
// PerformanceAdvisorServiceOp handles communication with the Performance Advisor related methods of the MongoDB Atlas API.
@@ -221,3 +224,51 @@ func (s *PerformanceAdvisorServiceOp) GetSuggestedIndexes(ctx context.Context, g
221224

222225
return root, resp, err
223226
}
227+
228+
// EnableManagedSlowOperationThreshold enables the Atlas managed slow operation threshold for your project.
229+
//
230+
// See more: https://docs.atlas.mongodb.com/reference/api/pa-managed-slow-ms-enable/
231+
func (s *PerformanceAdvisorServiceOp) EnableManagedSlowOperationThreshold(ctx context.Context, groupID string) (*Response, error) {
232+
if groupID == "" {
233+
return nil, NewArgError("groupID", "must be set")
234+
}
235+
236+
basePath := fmt.Sprintf(performanceAdvisorManagedSlowMs, groupID)
237+
path := fmt.Sprintf("%s/%s", basePath, "enable")
238+
239+
req, err := s.Client.NewRequest(ctx, http.MethodPost, path, nil)
240+
if err != nil {
241+
return nil, err
242+
}
243+
244+
resp, err := s.Client.Do(ctx, req, nil)
245+
if err != nil {
246+
return resp, err
247+
}
248+
249+
return resp, err
250+
}
251+
252+
// DisableManagedSlowOperationThreshold disables the Atlas managed slow operation threshold for your project.
253+
//
254+
// See more: https://docs.atlas.mongodb.com/reference/api/pa-managed-slow-ms-disable/
255+
func (s *PerformanceAdvisorServiceOp) DisableManagedSlowOperationThreshold(ctx context.Context, groupID string) (*Response, error) {
256+
if groupID == "" {
257+
return nil, NewArgError("groupID", "must be set")
258+
}
259+
260+
basePath := fmt.Sprintf(performanceAdvisorManagedSlowMs, groupID)
261+
path := fmt.Sprintf("%s/%s", basePath, "disable")
262+
263+
req, err := s.Client.NewRequest(ctx, http.MethodDelete, path, nil)
264+
if err != nil {
265+
return nil, err
266+
}
267+
268+
resp, err := s.Client.Do(ctx, req, nil)
269+
if err != nil {
270+
return resp, err
271+
}
272+
273+
return resp, err
274+
}

mongodbatlas/performance_advisor_test.go

Lines changed: 28 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -241,3 +241,31 @@ func TestPerformanceAdvisor_GetSuggestedIndexes(t *testing.T) {
241241
t.Error(diff)
242242
}
243243
}
244+
245+
func TestPerformanceAdvisor_EnableManagedSlowOperationThreshold(t *testing.T) {
246+
client, mux, teardown := setup()
247+
defer teardown()
248+
249+
mux.HandleFunc(fmt.Sprintf("/"+performanceAdvisorManagedSlowMs+"/enable", projectID), func(w http.ResponseWriter, r *http.Request) {
250+
testMethod(t, r, http.MethodPost)
251+
})
252+
253+
_, err := client.PerformanceAdvisor.EnableManagedSlowOperationThreshold(ctx, projectID)
254+
if err != nil {
255+
t.Fatalf("PerformanceAdvisor.EnableManagedSlowOperationThreshold returned error: %v", err)
256+
}
257+
}
258+
259+
func TestPerformanceAdvisor_DisableManagedSlowOperationThreshold(t *testing.T) {
260+
client, mux, teardown := setup()
261+
defer teardown()
262+
263+
mux.HandleFunc(fmt.Sprintf("/"+performanceAdvisorManagedSlowMs+"/disable", projectID), func(w http.ResponseWriter, r *http.Request) {
264+
testMethod(t, r, http.MethodDelete)
265+
})
266+
267+
_, err := client.PerformanceAdvisor.DisableManagedSlowOperationThreshold(ctx, projectID)
268+
if err != nil {
269+
t.Fatalf("PerformanceAdvisor.DisableManagedSlowOperationThreshold returned error: %v", err)
270+
}
271+
}

0 commit comments

Comments
 (0)