diff --git a/cdc/api/v1/api.go b/cdc/api/v1/api.go index 1d35d398250..bbca9d5aeae 100644 --- a/cdc/api/v1/api.go +++ b/cdc/api/v1/api.go @@ -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 diff --git a/cdc/api/v1/api_test.go b/cdc/api/v1/api_test.go index cabb5f8832b..e92215e30de 100644 --- a/cdc/api/v1/api_test.go +++ b/cdc/api/v1/api_test.go @@ -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() @@ -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)