diff --git a/api.handlers.ops.go b/api.handlers.ops.go index e8d4a04..766d5ea 100644 --- a/api.handlers.ops.go +++ b/api.handlers.ops.go @@ -169,9 +169,10 @@ func (api *APIHandler) Maintenance(w http.ResponseWriter, r *http.Request, ps ht case "show": response = map[string]interface{}{ - "message": "service currently unvailable.", - "reason": api.mode.reason, - "since": api.mode.started.Format(time.RFC1123), + "requestid": requestID, + "message": "service currently unvailable.", + "reason": api.mode.reason, + "since": api.mode.started.Format(time.RFC1123), } w.WriteHeader(http.StatusServiceUnavailable) } diff --git a/tests.middlewares_test.go b/tests.middlewares_test.go index 6e6bfb4..b2f74a2 100644 --- a/tests.middlewares_test.go +++ b/tests.middlewares_test.go @@ -1,6 +1,7 @@ package main import ( + "context" "io" "net/http" "net/http/httptest" @@ -122,6 +123,7 @@ func TestMaintenanceModeMiddleware(t *testing.T) { ts := NewMockClocker().Now() api.mode.started = ts api.mode.reason = "ongoing maintenance." + req = req.WithContext(context.WithValue(req.Context(), ContextRequestID, "abc")) wrapped := api.MaintenanceModeMiddleware(handler) wrapped(w, req, nil) // target handler will not be called but the maintenance handler must kick-in. @@ -131,7 +133,7 @@ func TestMaintenanceModeMiddleware(t *testing.T) { defer res.Body.Close() data, err := io.ReadAll(res.Body) require.NoError(t, err) - expected := `{"message":"service currently unvailable.","reason":"ongoing maintenance.", "since":"Sun, 02 Jul 2023 00:00:00 UTC"}` + expected := `{"requestid":"abc","message":"service currently unvailable.","reason":"ongoing maintenance.", "since":"Sun, 02 Jul 2023 00:00:00 UTC"}` assert.JSONEq(t, expected, string(data)) }) }