diff --git a/internal/api/response.go b/internal/api/response.go index 7b517edb..57d4cd3d 100644 --- a/internal/api/response.go +++ b/internal/api/response.go @@ -26,7 +26,6 @@ type StatusResponse struct { StackAlloc uint64 `json:"mem_stack_used"` KeyStoreLatency int64 `json:"keystore_latency,omitempty"` // In microseconds - KeyStoreUnavailable bool `json:"keystore_unavailable,omitempty"` KeyStoreUnreachable bool `json:"keystore_unreachable,omitempty"` } diff --git a/keystore.go b/keystore.go index f48e0bf6..ba3dccdd 100644 --- a/keystore.go +++ b/keystore.go @@ -16,6 +16,7 @@ import ( "github.com/minio/kes-go" "github.com/minio/kes/internal/cache" "github.com/minio/kes/internal/key" + "github.com/minio/kes/kv" ) // A KeyStore stores key-value pairs. It provides durable storage for a @@ -238,7 +239,13 @@ type cacheEntry struct { } // Status returns the current state of the underlying KeyStore. +// +// It immediately returns an error if the backend keystore is not +// reachable and offline caching is enabled. func (c *keyCache) Status(ctx context.Context) (KeyStoreState, error) { + if c.offline.Load() { + return KeyStoreState{}, &kv.Unreachable{Err: errors.New("keystore is offline")} + } return c.store.Status(ctx) } diff --git a/server.go b/server.go index 4dd73382..5b3de36f 100644 --- a/server.go +++ b/server.go @@ -477,27 +477,27 @@ func (s *Server) ready(resp *api.Response, req *api.Request) { } func (s *Server) status(resp *api.Response, req *api.Request) { + info, err := sys.ReadBinaryInfo() + if err != nil { + s.state.Load().Log.ErrorContext(req.Context(), err.Error(), "req", req) + resp.Fail(http.StatusInternalServerError, "failed to read server version") + return + } + var ( - unavailable, unreachable bool - latency time.Duration + latency time.Duration + unreachable = true ) state, err := s.state.Load().Keys.Status(req.Context()) - if err != nil { - unavailable = true - _, unreachable = kv.IsUnreachable(err) - } else { + if err == nil { + unreachable = false latency = state.Latency.Round(time.Millisecond) + if latency == 0 { // Make sure we actually send a latency even if the key store respond time is < 1ms. latency = 1 * time.Millisecond } } - info, err := sys.ReadBinaryInfo() - if err != nil { - s.state.Load().Log.ErrorContext(req.Context(), err.Error(), "req", req) - resp.Fail(http.StatusInternalServerError, "failed to read server version") - return - } var memStats runtime.MemStats runtime.ReadMemStats(&memStats) @@ -513,7 +513,6 @@ func (s *Server) status(resp *api.Response, req *api.Request) { StackAlloc: memStats.StackSys, KeyStoreLatency: latency.Milliseconds(), - KeyStoreUnavailable: unavailable, KeyStoreUnreachable: unreachable, }) }