Skip to content

Commit

Permalink
Rebase
Browse files Browse the repository at this point in the history
  • Loading branch information
Anton-Kalpakchiev committed Nov 11, 2024
1 parent 0547aaa commit 30f4b3e
Show file tree
Hide file tree
Showing 2 changed files with 24 additions and 31 deletions.
14 changes: 7 additions & 7 deletions origin/blobserver/server.go
Original file line number Diff line number Diff line change
Expand Up @@ -4,7 +4,7 @@
// you may not use this file except in compliance with the License.
// You may obtain a copy of the License at
//
// http://www.apache.org/licenses/LICENSE-2.0
// http://www.apache.org/licenses/LICENSE-2.0
//
// Unless required by applicable law or agreed to in writing, software
// distributed under the License is distributed on an "AS IS" BASIS,
Expand Down Expand Up @@ -131,7 +131,7 @@ func (s *Server) Handler() http.Handler {

r.Get("/health", handler.Wrap(s.healthCheckHandler))
r.Get("/readiness", handler.Wrap(s.readinessCheckHandler))

r.Get("/blobs/{digest}/locations", handler.Wrap(s.getLocationsHandler))

r.Post("/namespace/{namespace}/blobs/{digest}/uploads", handler.Wrap(s.startClusterUploadHandler))
Expand Down Expand Up @@ -181,12 +181,12 @@ func (s *Server) healthCheckHandler(w http.ResponseWriter, r *http.Request) erro
}

func (s *Server) readinessCheckHandler(w http.ResponseWriter, r *http.Request) error {
isReady, err := s.backends.IsReady()
if isReady {
fmt.Fprintln(w, "OK")
return nil
err := s.backends.CheckReadiness()
if err != nil {
return handler.Errorf("not ready to serve traffic: %s", err).Status(http.StatusServiceUnavailable)
}
return handler.Errorf("not ready to serve traffic: %s", err).Status(http.StatusServiceUnavailable)
fmt.Fprintln(w, "OK")
return nil
}

// statHandler returns blob info if it exists.
Expand Down
41 changes: 17 additions & 24 deletions origin/blobserver/server_test.go
Original file line number Diff line number Diff line change
Expand Up @@ -26,6 +26,7 @@ import (
"github.com/stretchr/testify/require"

"github.com/uber/kraken/core"
"github.com/uber/kraken/lib/backend"
"github.com/uber/kraken/lib/backend/backenderrors"
"github.com/uber/kraken/lib/persistedretry"
"github.com/uber/kraken/lib/persistedretry/writeback"
Expand Down Expand Up @@ -54,31 +55,25 @@ func TestHealth(t *testing.T) {
}

func TestReadiness(t *testing.T) {
const isReadyNamespace = "isReadyNamespace"
const isReadyName = "38a03d499119bc417b8a6a016f2cb4540b9f9cc0c13e4da42a73867120d3e908"
for _, tc := range []struct {
mockStatErr error
expectedRes string
expectedErrMsg string
status int
mockDownloadErr error
expectedErrMsg string
status int
}{
{
mockStatErr: nil,
expectedRes: "OK",
expectedErrMsg: "",
status: http.StatusOK,
mockDownloadErr: nil,
expectedErrMsg: "",
status: http.StatusOK,
},
{
mockStatErr: backenderrors.ErrBlobNotFound,
expectedRes: "OK",
expectedErrMsg: "",
status: http.StatusOK,
mockDownloadErr: backenderrors.ErrBlobNotFound,
expectedErrMsg: "not ready to serve traffic: backend with namespace readiness/blob not ready: blob not found",
status: http.StatusServiceUnavailable,
},
{
mockStatErr: errors.New("stat failed due to backend error"),
expectedRes: "",
expectedErrMsg: "not ready to serve traffic: backend with namespace isReadyNamespace not ready: stat failed due to backend error",
status: http.StatusServiceUnavailable,
mockDownloadErr: errors.New("failed due to backend error"),
expectedErrMsg: "not ready to serve traffic: backend with namespace readiness/blob not ready: failed due to backend error",
status: http.StatusServiceUnavailable,
},
} {
require := require.New(t)
Expand All @@ -88,12 +83,10 @@ func TestReadiness(t *testing.T) {
s := newTestServer(t, master1, hashRingMaxReplica(), cp)
defer s.cleanup()

backendClient := s.backendClient(isReadyNamespace, true)
mockStat := &core.BlobInfo{}
if tc.mockStatErr != nil {
mockStat = nil
}
backendClient.EXPECT().Stat(isReadyNamespace, isReadyName).Return(mockStat, tc.mockStatErr)
backendClient := s.backendClient(backend.ReadinessNamespace, true)

backendClient.EXPECT().Download(backend.ReadinessNamespace, backend.ReadinessName, bytes.NewBuffer([]byte{})).
Return(tc.mockDownloadErr)

resp, err := httputil.Get(
fmt.Sprintf("http://%s/readiness", s.addr))
Expand Down

0 comments on commit 30f4b3e

Please sign in to comment.