From 6c7c6bec91bee8c2ba82595f619f5989900c22a0 Mon Sep 17 00:00:00 2001 From: Anis Elleuch Date: Thu, 27 Sep 2018 18:34:37 +0100 Subject: [PATCH] profiler: Download API returns error when all nodes fail (#6525) When download profiling data API fails to gather profiling data from all nodes for any reason (including profiler not enabled), return 400 http code with the appropriate json message. --- cmd/admin-handlers.go | 10 ++++++++-- cmd/api-errors.go | 6 ++++++ 2 files changed, 14 insertions(+), 2 deletions(-) diff --git a/cmd/admin-handlers.go b/cmd/admin-handlers.go index 81097f1ef..212ef029f 100644 --- a/cmd/admin-handlers.go +++ b/cmd/admin-handlers.go @@ -355,8 +355,7 @@ func (a adminAPIHandlers) DownloadProfilingHandler(w http.ResponseWriter, r *htt return } - // Return 200 OK - w.WriteHeader(http.StatusOK) + profilingDataFound := false // Initialize a zip writer which will provide a zipped content // of profiling data of all nodes @@ -371,6 +370,8 @@ func (a adminAPIHandlers) DownloadProfilingHandler(w http.ResponseWriter, r *htt continue } + profilingDataFound = true + // Send profiling data to zip as file header, err := zip.FileInfoHeader(dummyFileInfo{ name: fmt.Sprintf("profiling-%d", i), @@ -391,6 +392,11 @@ func (a adminAPIHandlers) DownloadProfilingHandler(w http.ResponseWriter, r *htt return } } + + if !profilingDataFound { + writeErrorResponseJSON(w, ErrAdminProfilerNotEnabled, r.URL) + return + } } // extractHealInitParams - Validates params for heal init API. diff --git a/cmd/api-errors.go b/cmd/api-errors.go index d3b10fa3c..532853bc6 100644 --- a/cmd/api-errors.go +++ b/cmd/api-errors.go @@ -291,6 +291,7 @@ const ( ErrInvalidColumnIndex ErrMissingHeaders ErrAdminConfigNotificationTargetsFailed + ErrAdminProfilerNotEnabled ) // error code to APIError structure, these fields carry respective @@ -892,6 +893,11 @@ var errorCodeResponse = map[APIErrorCode]APIError{ Description: "Configuration update failed due an unsuccessful attempt to connect to one or more notification servers", HTTPStatusCode: http.StatusBadRequest, }, + ErrAdminProfilerNotEnabled: { + Code: "XMinioAdminProfilerNotEnabled", + Description: "Unable to perform the requested operation because profiling is not enabled", + HTTPStatusCode: http.StatusBadRequest, + }, ErrAdminCredentialsMismatch: { Code: "XMinioAdminCredentialsMismatch", Description: "Credentials in config mismatch with server environment variables",