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

tianxiaoliang 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 6d11d2b  add monitoring middleware (#118)
6d11d2b is described below

commit 6d11d2b5ec5b2702c7faced84ea967cb826a1bf5
Author: Shawn <[email protected]>
AuthorDate: Mon Mar 23 21:33:35 2020 +0800

    add monitoring middleware (#118)
---
 cmd/kieserver/main.go                       |  9 +++++++--
 examples/dev/conf/chassis.yaml              |  2 +-
 go.mod                                      |  2 +-
 go.sum                                      |  7 +++++++
 pkg/common/common.go                        |  5 +++++
 scripts/start.sh                            |  2 +-
 server/handler/track_handler.go             |  2 +-
 server/resource/v1/common.go                |  3 ++-
 server/resource/v1/doc_struct.go            |  2 +-
 server/resource/v1/history_resource_test.go | 15 +++++++++------
 10 files changed, 35 insertions(+), 14 deletions(-)

diff --git a/cmd/kieserver/main.go b/cmd/kieserver/main.go
index 28862b3..a0323f9 100644
--- a/cmd/kieserver/main.go
+++ b/cmd/kieserver/main.go
@@ -21,15 +21,20 @@ import (
        "os"
 
        "github.com/apache/servicecomb-kie/server/config"
-       _ "github.com/apache/servicecomb-kie/server/handler"
        "github.com/apache/servicecomb-kie/server/pubsub"
        v1 "github.com/apache/servicecomb-kie/server/resource/v1"
        "github.com/apache/servicecomb-kie/server/service"
-       _ "github.com/apache/servicecomb-kie/server/service/mongo"
        "github.com/go-chassis/go-chassis"
        "github.com/go-chassis/go-chassis/core/common"
        "github.com/go-mesh/openlogging"
        "github.com/urfave/cli"
+
+       //custom handlers
+       _ "github.com/apache/servicecomb-kie/server/handler"
+       _ "github.com/go-chassis/go-chassis/middleware/monitoring"
+       _ "github.com/go-chassis/go-chassis/middleware/ratelimiter"
+       //storage
+       _ "github.com/apache/servicecomb-kie/server/service/mongo"
 )
 
 const (
diff --git a/examples/dev/conf/chassis.yaml b/examples/dev/conf/chassis.yaml
index d5c8888..da4c6df 100755
--- a/examples/dev/conf/chassis.yaml
+++ b/examples/dev/conf/chassis.yaml
@@ -10,7 +10,7 @@ cse:
   handler:
     chain:
       Provider:
-        default: auth-handler,track-handler,ratelimiter-provider
+        default: ratelimiter-provider,monitoring,auth-handler,track-handler
 # ssl:
 #   Provider.cipherPlugin: default
 #   Provider.verifyPeer: false
diff --git a/go.mod b/go.mod
index 44163c7..5ab7fa6 100644
--- a/go.mod
+++ b/go.mod
@@ -3,7 +3,7 @@ module github.com/apache/servicecomb-kie
 require (
        github.com/emicklei/go-restful v2.12.0+incompatible
        github.com/go-chassis/go-archaius v1.2.1-0.20200309104817-8c3d4e87d33c
-       github.com/go-chassis/go-chassis v1.8.2-0.20200310060113-4b383ba3d3f0
+       github.com/go-chassis/go-chassis v0.0.0-20200322084331-36849ab2cb10
        github.com/go-chassis/paas-lager v1.1.1
        github.com/go-mesh/openlogging v1.0.1
        github.com/hashicorp/mdns v1.0.1 // indirect
diff --git a/go.sum b/go.sum
index cb42577..44b4b38 100644
--- a/go.sum
+++ b/go.sum
@@ -53,8 +53,15 @@ github.com/go-chassis/foundation 
v0.1.1-0.20191113114104-2b05871e9ec4 h1:wx8JXvg
 github.com/go-chassis/foundation v0.1.1-0.20191113114104-2b05871e9ec4/go.mod 
h1:21/ajGtgJlWTCeM0TxGJdRhO8bJkKirWyV8Stlh6g6c=
 github.com/go-chassis/go-archaius v1.2.1-0.20200309104817-8c3d4e87d33c 
h1:pimEM4Oy/Uf4xG4G7TrRUQbIRFAfHiarxDQQS2gmKaM=
 github.com/go-chassis/go-archaius v1.2.1-0.20200309104817-8c3d4e87d33c/go.mod 
h1:gVP52u/jCU0fgUjXdUW1VLp5YLLJ+Yl2zoOPrLM/WOM=
+github.com/go-chassis/go-chassis v0.0.0-20200318142212-4ca7f5fb7745 
h1:BDHDeJBW+0/iC/1otn4XQ7ndfqzeGrFFi6SLSBuhRvs=
+github.com/go-chassis/go-chassis v0.0.0-20200318142212-4ca7f5fb7745/go.mod 
h1:UsROzOZPD9YgTpVUE/jFclVxDwHWESLNdwwbfKQ8aMs=
+github.com/go-chassis/go-chassis v0.0.0-20200320074343-30f669c0c47b 
h1:ZH88vLcGL4bNc+Vbm1g3jrhtTxBSnGvyZCpbbkVa5a0=
+github.com/go-chassis/go-chassis v0.0.0-20200320074343-30f669c0c47b/go.mod 
h1:UsROzOZPD9YgTpVUE/jFclVxDwHWESLNdwwbfKQ8aMs=
+github.com/go-chassis/go-chassis v0.0.0-20200322084331-36849ab2cb10 
h1:l3bUZf0Hjh1+7b2Ed5Fqb/cCOjMGBe8WmPd/ucyoGgQ=
+github.com/go-chassis/go-chassis v0.0.0-20200322084331-36849ab2cb10/go.mod 
h1:UsROzOZPD9YgTpVUE/jFclVxDwHWESLNdwwbfKQ8aMs=
 github.com/go-chassis/go-chassis v1.8.2-0.20200310060113-4b383ba3d3f0 
h1:YD9MtuYIpQb+EKxIzV/swdXUhnV5PtXtSW696JiwW1c=
 github.com/go-chassis/go-chassis v1.8.2-0.20200310060113-4b383ba3d3f0/go.mod 
h1:sFnVxSvprpy6umPFK4uSdfCDdfqdgbp3FdW/CG0VNnE=
+github.com/go-chassis/go-chassis v1.8.2 
h1:lX+XJbIGSkC4c+1h8IcoBQFEX9vaZ0+KNugE24Q/I/Y=
 github.com/go-chassis/go-restful-swagger20 
v1.0.3-0.20200310030431-17d80f34264f 
h1:5QmmNpVcGqIc6tuKNe5EAI4PA8Yn2EL9Oee7YdcJ4PE=
 github.com/go-chassis/go-restful-swagger20 
v1.0.3-0.20200310030431-17d80f34264f/go.mod 
h1:eW62fYuzlNFDvIacB6AV8bhUDCTy4myfTCv0bT9Gbb0=
 github.com/go-chassis/paas-lager v1.1.1 
h1:/6wqawUGjPCpd57A/tzJzgC4MnEhNuigbayQS+2VWPQ=
diff --git a/pkg/common/common.go b/pkg/common/common.go
index 06f1118..82449c3 100644
--- a/pkg/common/common.go
+++ b/pkg/common/common.go
@@ -69,3 +69,8 @@ const (
 
        MaxWait = 5 * time.Minute
 )
+
+// all msg server returns
+const (
+       MsgDBError = "database operation error"
+)
diff --git a/scripts/start.sh b/scripts/start.sh
index 3f230e0..d53451a 100755
--- a/scripts/start.sh
+++ b/scripts/start.sh
@@ -38,7 +38,7 @@ cse:
   handler:
     chain:
       Provider:
-        default: auth-handler,track-handler,ratelimiter-provider
+        default: ratelimiter-provider,monitoring,auth-handler,track-handler
 EOM
 cat <<EOM > ${root_dir}/conf/lager.yaml
 logger_level: ${LOG_LEVEL}
diff --git a/server/handler/track_handler.go b/server/handler/track_handler.go
index 3d6979d..1fc1122 100644
--- a/server/handler/track_handler.go
+++ b/server/handler/track_handler.go
@@ -82,7 +82,7 @@ func (h *TrackHandler) Handle(chain *handler.Chain, inv 
*invocation.Invocation,
                }
                _, err := track.CreateOrUpdate(inv.Ctx, data)
                if err != nil {
-                       openlogging.Warn("record polling detail failed" + 
err.Error())
+                       openlogging.Warn("record polling detail failed:" + 
err.Error())
                        err := cb(ir)
                        if err != nil {
                                return err
diff --git a/server/resource/v1/common.go b/server/resource/v1/common.go
index 3a7a151..d84ea45 100644
--- a/server/resource/v1/common.go
+++ b/server/resource/v1/common.go
@@ -242,7 +242,8 @@ func queryAndResponse(rctx *restful.Context, doc 
*model.KVDoc, offset, limit int
        }
        kv, err := service.KVService.List(rctx.Ctx, doc.Domain, doc.Project, 
opts...)
        if err != nil {
-               WriteErrResponse(rctx, http.StatusInternalServerError, 
err.Error(), common.ContentTypeText)
+               openlogging.Error("common: " + err.Error())
+               WriteErrResponse(rctx, http.StatusInternalServerError, 
common.MsgDBError, common.ContentTypeText)
                return
        }
        rctx.ReadResponseWriter().Header().Set(common.HeaderRevision, 
strconv.FormatInt(rev, 10))
diff --git a/server/resource/v1/doc_struct.go b/server/resource/v1/doc_struct.go
index 4ae6620..92a7df1 100644
--- a/server/resource/v1/doc_struct.go
+++ b/server/resource/v1/doc_struct.go
@@ -170,5 +170,5 @@ type KVBody struct {
 
 //ErrorMsg is open api doc
 type ErrorMsg struct {
-       Msg string `json:"msg"`
+       Msg string `json:"error_msg"`
 }
diff --git a/server/resource/v1/history_resource_test.go 
b/server/resource/v1/history_resource_test.go
index e7f9ed8..82d6d2b 100644
--- a/server/resource/v1/history_resource_test.go
+++ b/server/resource/v1/history_resource_test.go
@@ -20,6 +20,11 @@ import (
        "context"
        "encoding/json"
        "fmt"
+       "io/ioutil"
+       "net/http"
+       "net/http/httptest"
+       "testing"
+
        "github.com/apache/servicecomb-kie/pkg/model"
        handler2 "github.com/apache/servicecomb-kie/server/handler"
        v1 "github.com/apache/servicecomb-kie/server/resource/v1"
@@ -28,10 +33,6 @@ import (
        "github.com/go-chassis/go-chassis/core/handler"
        "github.com/go-chassis/go-chassis/server/restful/restfultest"
        "github.com/stretchr/testify/assert"
-       "io/ioutil"
-       "net/http"
-       "net/http/httptest"
-       "testing"
 
        _ "github.com/apache/servicecomb-kie/server/service/mongo"
 )
@@ -107,7 +108,8 @@ func TestHistoryResource_GetPollingData(t *testing.T) {
        t.Run("get polling data", func(t *testing.T) {
                r, _ := http.NewRequest("GET", 
"/v1/test/kie/track?sessionId=test", nil)
                noopH := &handler2.NoopAuthHandler{}
-               chain, _ := handler.CreateChain(common.Provider, "testchain3", 
noopH.Name())
+               track := handler2.TrackHandler{}
+               chain, _ := handler.CreateChain(common.Provider, "testchain3", 
noopH.Name(), track.Name())
                r.Header.Set("Content-Type", "application/json")
                revision := &v1.HistoryResource{}
                c, err := restfultest.New(revision, chain)
@@ -129,7 +131,8 @@ func Test_HeathCheck(t *testing.T) {
        r, _ := http.NewRequest("GET", path, nil)
        noopH := &handler2.NoopAuthHandler{}
        revision := &v1.HistoryResource{}
-       chain, _ := handler.CreateChain(common.Provider, "", noopH.Name())
+       chain, err := handler.CreateChain(common.Provider, "default", 
noopH.Name())
+       assert.NoError(t, err)
        c, err := restfultest.New(revision, chain)
        assert.NoError(t, err)
        resp := httptest.NewRecorder()

Reply via email to