This is an automated email from the ASF dual-hosted git repository.

littlecui pushed a commit to branch master
in repository https://gitbox.apache.org/repos/asf/servicecomb-kie.git


The following commit(s) were added to refs/heads/master by this push:
     new fcacc0d  [fix] cancel the depency between healthcheck and etcd (#319)
fcacc0d is described below

commit fcacc0dabea387ed319d677bc26b056781a4a942
Author: tornado-ssy <[email protected]>
AuthorDate: Thu Feb 22 19:49:33 2024 +0800

    [fix] cancel the depency between healthcheck and etcd (#319)
    
    Co-authored-by: songshiyuan 00649746 <[email protected]>
---
 pkg/common/common.go                      |  1 +
 server/resource/v1/admin_resource.go      | 10 ++++++++--
 server/resource/v1/admin_resource_test.go | 18 ++++++++++++++++--
 3 files changed, 25 insertions(+), 4 deletions(-)

diff --git a/pkg/common/common.go b/pkg/common/common.go
index 9e452f3..7eb1d3d 100644
--- a/pkg/common/common.go
+++ b/pkg/common/common.go
@@ -40,6 +40,7 @@ const (
        QueryParamURLPath      = "urlPath"
        QueryParamUserAgent    = "userAgent"
        QueryParamOverride     = "override"
+       QueryParamMode         = "mode"
 )
 
 // http headers
diff --git a/server/resource/v1/admin_resource.go 
b/server/resource/v1/admin_resource.go
index 4d79eb1..d63b0a4 100644
--- a/server/resource/v1/admin_resource.go
+++ b/server/resource/v1/admin_resource.go
@@ -22,13 +22,15 @@ import (
        "strconv"
        "time"
 
-       "github.com/apache/servicecomb-kie/pkg/model"
-       "github.com/apache/servicecomb-kie/server/datasource"
        goRestful "github.com/emicklei/go-restful"
        "github.com/go-chassis/cari/config"
        "github.com/go-chassis/go-chassis/v2/pkg/runtime"
        "github.com/go-chassis/go-chassis/v2/server/restful"
        "github.com/go-chassis/openlog"
+
+       "github.com/apache/servicecomb-kie/pkg/common"
+       "github.com/apache/servicecomb-kie/pkg/model"
+       "github.com/apache/servicecomb-kie/server/datasource"
 )
 
 type AdminResource struct {
@@ -57,6 +59,10 @@ func (r *AdminResource) URLPatterns() []restful.Route {
 
 // HealthCheck provider version info and time info
 func (r *AdminResource) HealthCheck(context *restful.Context) {
+       healthCheckMode := context.ReadQueryParameter(common.QueryParamMode)
+       if healthCheckMode == "liveness" {
+               return
+       }
        domain := ReadDomain(context.Ctx)
        resp := &model.DocHealthCheck{}
        latest, err := 
datasource.GetBroker().GetRevisionDao().GetRevision(context.Ctx, domain)
diff --git a/server/resource/v1/admin_resource_test.go 
b/server/resource/v1/admin_resource_test.go
index 2ed6c2f..d528030 100644
--- a/server/resource/v1/admin_resource_test.go
+++ b/server/resource/v1/admin_resource_test.go
@@ -27,10 +27,11 @@ import (
 
        _ "github.com/apache/servicecomb-kie/test"
 
-       "github.com/apache/servicecomb-kie/pkg/model"
-       v1 "github.com/apache/servicecomb-kie/server/resource/v1"
        "github.com/go-chassis/go-chassis/v2/server/restful/restfultest"
        "github.com/stretchr/testify/assert"
+
+       "github.com/apache/servicecomb-kie/pkg/model"
+       v1 "github.com/apache/servicecomb-kie/server/resource/v1"
 )
 
 func Test_HeathCheck(t *testing.T) {
@@ -48,3 +49,16 @@ func Test_HeathCheck(t *testing.T) {
        assert.NoError(t, err)
        assert.NotEmpty(t, data)
 }
+
+func Test_HeakthCheckLiveMode(t *testing.T) {
+       path := fmt.Sprintf("/v1/health?mode=liveness")
+       r, _ := http.NewRequest("GET", path, nil)
+
+       revision := &v1.AdminResource{}
+       c, err := restfultest.New(revision, nil)
+       assert.NoError(t, err)
+       resp := httptest.NewRecorder()
+       c.ServeHTTP(resp, r)
+       respcode := resp.Code
+       assert.NotEmpty(t, respcode)
+}

Reply via email to