Skip to content

Commit

Permalink
[fix] cancel the depency between healthcheck and etcd (apache#319)
Browse files Browse the repository at this point in the history
Co-authored-by: songshiyuan 00649746 <[email protected]>
(cherry picked from commit fcacc0d)
  • Loading branch information
tornado-ssy authored and songshiyuan 00649746 committed Apr 1, 2024
1 parent 4d5b39f commit d1c3f5c
Show file tree
Hide file tree
Showing 3 changed files with 25 additions and 4 deletions.
1 change: 1 addition & 0 deletions pkg/common/common.go
Original file line number Diff line number Diff line change
Expand Up @@ -40,6 +40,7 @@ const (
QueryParamURLPath = "urlPath"
QueryParamUserAgent = "userAgent"
QueryParamOverride = "override"
QueryParamMode = "mode"
)

// http headers
Expand Down
10 changes: 8 additions & 2 deletions server/resource/v1/admin_resource.go
Original file line number Diff line number Diff line change
Expand Up @@ -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 {
Expand Down Expand Up @@ -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)
Expand Down
18 changes: 16 additions & 2 deletions server/resource/v1/admin_resource_test.go
Original file line number Diff line number Diff line change
Expand Up @@ -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) {
Expand All @@ -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)
}

0 comments on commit d1c3f5c

Please sign in to comment.