Skip to content

Commit

Permalink
forward healthy to owner.
Browse files Browse the repository at this point in the history
  • Loading branch information
3AceShowHand committed Sep 16, 2022
1 parent 6636c3f commit b702481
Show file tree
Hide file tree
Showing 2 changed files with 8 additions and 21 deletions.
12 changes: 4 additions & 8 deletions cdc/api/v1/api.go
Original file line number Diff line number Diff line change
Expand Up @@ -872,17 +872,13 @@ func (h *OpenAPI) ServerStatus(c *gin.Context) {
// @Failure 500 {object} model.HTTPError
// @Router /api/v1/health [get]
func (h *OpenAPI) Health(c *gin.Context) {
ctx := c.Request.Context()

var err error
provider := h.statusProvider()
if provider == nil {
err = cerror.ErrOwnerNotFound.FastGenByArgs()
c.JSON(http.StatusInternalServerError, model.NewHTTPError(err))
if !h.capture.IsOwner() {
middleware.ForwardToOwnerMiddleware(h.capture)(c)
return
}

health, err := provider.IsHealthy(ctx)
ctx := c.Request.Context()
health, err := h.statusProvider().IsHealthy(ctx)
if err != nil {
c.IndentedJSON(http.StatusInternalServerError, model.NewHTTPError(err))
return
Expand Down
17 changes: 4 additions & 13 deletions cdc/api/v1/api_test.go
Original file line number Diff line number Diff line change
Expand Up @@ -896,21 +896,12 @@ func TestHealth(t *testing.T) {
// capture is owner
ctrl := gomock.NewController(t)
cp := mock_capture.NewMockCapture(ctrl)
ownerRouter := newRouter(cp, nil)

cp.EXPECT().IsReady().Return(true).AnyTimes()
cp.EXPECT().StatusProvider().Return(nil).Times(1)

api := testCase{url: "/api/v1/health", method: "GET"}

w := httptest.NewRecorder()
req, _ := http.NewRequestWithContext(context.Background(), api.method, api.url, nil)
ownerRouter.ServeHTTP(w, req)
require.Equal(t, 500, w.Code)

sp := mock_owner.NewMockStatusProvider(ctrl)
ownerRouter = newRouter(cp, sp)
ownerRouter := newRouter(cp, sp)

cp.EXPECT().IsReady().Return(true).AnyTimes()
cp.EXPECT().Info().DoAndReturn(func() (model.CaptureInfo, error) {
return model.CaptureInfo{}, nil
}).AnyTimes()
Expand All @@ -921,8 +912,8 @@ func TestHealth(t *testing.T) {
// IsHealthy returns error.
isHealthError := sp.EXPECT().IsHealthy(gomock.Any()).
Return(false, cerror.ErrOwnerNotFound)
w = httptest.NewRecorder()
req, _ = http.NewRequestWithContext(context.Background(), api.method, api.url, nil)
w := httptest.NewRecorder()
req, _ := http.NewRequestWithContext(context.Background(), api.method, api.url, nil)
ownerRouter.ServeHTTP(w, req)
require.Equal(t, 500, w.Code)

Expand Down

0 comments on commit b702481

Please sign in to comment.