Better error msg when version mismatch of internode API (#13845)

Sometimes, we see an error message like "Server expects 'storage' API
version 'v41', instead found 'v41'" shows a more generic error message
with the path of the REST call.
This commit is contained in:
Anis Elleuch 2021-12-06 18:44:48 +01:00 committed by GitHub
parent f286ef8e17
commit 0b6225bcc3
No known key found for this signature in database
GPG Key ID: 4AEE18F83AFDEB23

View File

@ -429,6 +429,18 @@ func extractAPIVersion(r *http.Request) string {
return "unknown" return "unknown"
} }
func generateUnexpectedRPCMsg(rpcPath, subsystem string, expectedVersion, gotVersion string) string {
var reason string
switch {
case expectedVersion != gotVersion:
reason = fmt.Sprintf("Server expects '%s' API version '%s', instead found '%s'", subsystem, expectedVersion, gotVersion)
default:
reason = fmt.Sprintf("Unexpected RPC call at this path '%s'", rpcPath)
}
return fmt.Sprintf("%s - *rolling upgrade is not allowed* - please make sure all servers are running the same MinIO version (%s)", reason, ReleaseTag)
}
func methodNotAllowedHandler(api string) func(w http.ResponseWriter, r *http.Request) { func methodNotAllowedHandler(api string) func(w http.ResponseWriter, r *http.Request) {
return func(w http.ResponseWriter, r *http.Request) { return func(w http.ResponseWriter, r *http.Request) {
if r.Method == http.MethodOptions { if r.Method == http.MethodOptions {
@ -437,21 +449,21 @@ func methodNotAllowedHandler(api string) func(w http.ResponseWriter, r *http.Req
version := extractAPIVersion(r) version := extractAPIVersion(r)
switch { switch {
case strings.HasPrefix(r.URL.Path, peerRESTPrefix): case strings.HasPrefix(r.URL.Path, peerRESTPrefix):
desc := fmt.Sprintf("Server expects 'peer' API version '%s', instead found '%s' - *rolling upgrade is not allowed* - please make sure all servers are running the same MinIO version (%s)", peerRESTVersion, version, ReleaseTag) desc := generateUnexpectedRPCMsg(r.URL.Path, "peer", peerRESTVersion, version)
writeErrorResponseString(r.Context(), w, APIError{ writeErrorResponseString(r.Context(), w, APIError{
Code: "XMinioPeerVersionMismatch", Code: "XMinioPeerVersionMismatch",
Description: desc, Description: desc,
HTTPStatusCode: http.StatusUpgradeRequired, HTTPStatusCode: http.StatusUpgradeRequired,
}, r.URL) }, r.URL)
case strings.HasPrefix(r.URL.Path, storageRESTPrefix): case strings.HasPrefix(r.URL.Path, storageRESTPrefix):
desc := fmt.Sprintf("Server expects 'storage' API version '%s', instead found '%s' - *rolling upgrade is not allowed* - please make sure all servers are running the same MinIO version (%s)", storageRESTVersion, version, ReleaseTag) desc := generateUnexpectedRPCMsg(r.URL.Path, "storage", storageRESTVersion, version)
writeErrorResponseString(r.Context(), w, APIError{ writeErrorResponseString(r.Context(), w, APIError{
Code: "XMinioStorageVersionMismatch", Code: "XMinioStorageVersionMismatch",
Description: desc, Description: desc,
HTTPStatusCode: http.StatusUpgradeRequired, HTTPStatusCode: http.StatusUpgradeRequired,
}, r.URL) }, r.URL)
case strings.HasPrefix(r.URL.Path, lockRESTPrefix): case strings.HasPrefix(r.URL.Path, lockRESTPrefix):
desc := fmt.Sprintf("Server expects 'lock' API version '%s', instead found '%s' - *rolling upgrade is not allowed* - please make sure all servers are running the same MinIO version (%s)", lockRESTVersion, version, ReleaseTag) desc := generateUnexpectedRPCMsg(r.URL.Path, "lock", lockRESTVersion, version)
writeErrorResponseString(r.Context(), w, APIError{ writeErrorResponseString(r.Context(), w, APIError{
Code: "XMinioLockVersionMismatch", Code: "XMinioLockVersionMismatch",
Description: desc, Description: desc,