From d1c3f5c3f4209efad63b8878f120ffb98fb3bfc9 Mon Sep 17 00:00:00 2001 From: tornado-ssy <64736788+tornado-ssy@users.noreply.github.com> Date: Thu, 22 Feb 2024 19:49:33 +0800 Subject: [PATCH] [fix] cancel the depency between healthcheck and etcd (#319) Co-authored-by: songshiyuan 00649746 (cherry picked from commit fcacc0dabea387ed319d677bc26b056781a4a942) --- 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 9e452f34..7eb1d3d7 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 4d79eb10..d63b0a49 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 2ed6c2fa..d5280309 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) +}