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 Mar 29, 2024
1 parent 22bdbaf commit bf754f5
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 @@ -26,10 +26,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 @@ -47,3 +48,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")

Check failure on line 53 in server/resource/v1/admin_resource_test.go

View workflow job for this annotation

GitHub Actions / mongo-storage

undefined: fmt

Check failure on line 53 in server/resource/v1/admin_resource_test.go

View workflow job for this annotation

GitHub Actions / etcd-storage

undefined: fmt

Check failure on line 53 in server/resource/v1/admin_resource_test.go

View workflow job for this annotation

GitHub Actions / etcd-with-localstorage

undefined: fmt

Check failure on line 53 in server/resource/v1/admin_resource_test.go

View workflow job for this annotation

GitHub Actions / embedded-etcd-storage

undefined: fmt
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 bf754f5

Please sign in to comment.