asifdxtreme closed pull request #420: SCB-797 More information in dump API
URL: https://github.com/apache/incubator-servicecomb-service-center/pull/420
 
 
   

This is a PR merged from a forked repository.
As GitHub hides the original diff on merge, it is displayed below for
the sake of provenance:

As this is a foreign pull request (from a fork), the diff is supplied
below (as it won't show otherwise due to GitHub magic):

diff --git a/pkg/chain/callback.go b/pkg/chain/callback.go
index e48e16a3..27e10c70 100644
--- a/pkg/chain/callback.go
+++ b/pkg/chain/callback.go
@@ -47,19 +47,11 @@ type Callback struct {
 func (cb *Callback) Invoke(r Result) {
        if cb.Async {
                pool.Do(func(_ context.Context) {
-                       cb.syncInvoke(r)
+                       cb.Func(r)
                })
                return
        }
-       cb.syncInvoke(r)
-}
-
-func (cb *Callback) syncInvoke(r Result) {
        defer log.Recover()
-       if cb.Func == nil {
-               log.Errorf(nil, "Callback function is nil. result: %s,", r)
-               return
-       }
        cb.Func(r)
 }
 
diff --git a/pkg/chain/chain.go b/pkg/chain/chain.go
index 51441feb..a1ddd305 100644
--- a/pkg/chain/chain.go
+++ b/pkg/chain/chain.go
@@ -16,11 +16,6 @@
  */
 package chain
 
-import (
-       errorsEx 
"github.com/apache/incubator-servicecomb-service-center/pkg/errors"
-       "github.com/apache/incubator-servicecomb-service-center/pkg/log"
-)
-
 type Chain struct {
        name         string
        handlers     []Handler
@@ -38,16 +33,6 @@ func (c *Chain) Name() string {
 }
 
 func (c *Chain) syncNext(i *Invocation) {
-       defer func() {
-               itf := recover()
-               if itf == nil {
-                       return
-               }
-               log.LogPanic(itf)
-
-               i.Fail(errorsEx.RaiseError(itf))
-       }()
-
        if c.currentIndex >= len(c.handlers)-1 {
                i.Success()
                return
diff --git a/pkg/chain/chain_test.go b/pkg/chain/chain_test.go
index d053a815..bb617ed1 100644
--- a/pkg/chain/chain_test.go
+++ b/pkg/chain/chain_test.go
@@ -21,11 +21,12 @@ import (
        "errors"
        "github.com/apache/incubator-servicecomb-service-center/pkg/util"
        "testing"
+       "time"
 )
 
 const (
        times = 1000000
-       count = 100
+       count = 10
 )
 
 func init() {
@@ -73,26 +74,13 @@ func BenchmarkChain(b *testing.B) {
 
        b.N = times
        b.ResetTimer()
-       b.RunParallel(func(pb *testing.PB) {
-               for pb.Next() {
-                       inv := NewInvocation(ctx, NewChain("_bench_chain_", 
Handlers("_bench_handlers_")))
-                       inv.Invoke(f)
-               }
-       })
-       b.ReportAllocs()
-       // 1000000            6607 ns/op              80 B/op          1 
allocs/op
-}
+       for i := 0; i < b.N; i++ {
+               inv := NewInvocation(ctx, NewChain("_bench_chain_", 
Handlers("_bench_handlers_")))
+               inv.Invoke(f)
 
-func BenchmarkSync(b *testing.B) {
-       b.N = times
-       b.ResetTimer()
-       b.RunParallel(func(pb *testing.PB) {
-               for pb.Next() {
-                       syncFunc(0)
-               }
-       })
+       }
        b.ReportAllocs()
-       // 1000000              46.9 ns/op             0 B/op          0 
allocs/op
+       // 1000000             735 ns/op              80 B/op          1 
allocs/op
 }
 
 type mockHandler struct {
@@ -112,7 +100,8 @@ func (h *mockHandler) Handle(i *Invocation) {
        case 4:
                i.Next(WithAsyncFunc(func(r Result) {
                        i.WithContext("x", x*x)
-                       i.Context().Value("ch").(chan struct{}) <- struct{}{}
+                       ch, _ := i.Context().Value("ch").(chan struct{})
+                       ch <- struct{}{}
                }))
        case 5:
                panic(errors.New("error"))
@@ -181,7 +170,7 @@ func TestChain_Next(t *testing.T) {
                t.Fatalf("TestChain_Next")
        }
 
-       x = 4
+       x = 4 // async call back
        ch = NewChain("test", hs)
        i = NewInvocation(context.Background(), ch)
        i.WithContext("x", x)
@@ -216,7 +205,7 @@ func TestChain_Next(t *testing.T) {
                }
        })
 
-       x = 7
+       x = 7 // async call back
        ch = NewChain("test", hs)
        i = NewInvocation(context.Background(), ch)
        i.WithContext("x", x)
@@ -225,4 +214,5 @@ func TestChain_Next(t *testing.T) {
                        t.Fatalf("TestChain_Next")
                }
        })
+       <-time.After(500 * time.Millisecond)
 }
diff --git a/pkg/chain/invocation.go b/pkg/chain/invocation.go
index bb024ca9..457dc36f 100644
--- a/pkg/chain/invocation.go
+++ b/pkg/chain/invocation.go
@@ -17,6 +17,8 @@
 package chain
 
 import (
+       errorsEx 
"github.com/apache/incubator-servicecomb-service-center/pkg/errors"
+       "github.com/apache/incubator-servicecomb-service-center/pkg/log"
        "github.com/apache/incubator-servicecomb-service-center/pkg/util"
        "golang.org/x/net/context"
 )
@@ -94,6 +96,15 @@ func callback(f CallbackFunc, async bool, r Result) {
 }
 
 func (i *Invocation) Invoke(f CallbackFunc) {
+       defer func() {
+               itf := recover()
+               if itf == nil {
+                       return
+               }
+               log.LogPanic(itf)
+
+               i.Fail(errorsEx.RaiseError(itf))
+       }()
        i.Func = f
        i.chain.Next(i)
 }
diff --git a/server/admin/model/dump.go b/server/admin/model/dump.go
index fb91411f..8c9ea878 100644
--- a/server/admin/model/dump.go
+++ b/server/admin/model/dump.go
@@ -18,6 +18,7 @@ package model
 
 import (
        pb 
"github.com/apache/incubator-servicecomb-service-center/server/core/proto"
+       "github.com/apache/incubator-servicecomb-service-center/version"
 )
 
 type Getter interface {
@@ -180,6 +181,9 @@ type DumpRequest struct {
 }
 
 type DumpResponse struct {
-       Response *pb.Response `json:"response,omitempty"`
-       Cache    *Cache       `json:"cache,omitempty"`
+       Response     *pb.Response        `json:"response,omitempty"`
+       Info         *version.VersionSet `json:"info,omitempty"`
+       Config       *pb.ServerConfig    `json:"config,omitempty"`
+       Environments map[string]string   `json:"environments,omitempty"`
+       Cache        *Cache              `json:"cache,omitempty"`
 }
diff --git a/server/admin/service.go b/server/admin/service.go
index 2a6554e0..82322ef9 100644
--- a/server/admin/service.go
+++ b/server/admin/service.go
@@ -24,10 +24,23 @@ import (
        
"github.com/apache/incubator-servicecomb-service-center/server/core/backend"
        pb 
"github.com/apache/incubator-servicecomb-service-center/server/core/proto"
        scerr 
"github.com/apache/incubator-servicecomb-service-center/server/error"
+       "github.com/apache/incubator-servicecomb-service-center/version"
        "golang.org/x/net/context"
+       "os"
+       "strings"
 )
 
-var AdminServiceAPI = &AdminService{}
+var (
+       AdminServiceAPI = &AdminService{}
+       environments    = make(map[string]string)
+)
+
+func init() {
+       for _, kv := range os.Environ() {
+               arr := strings.Split(kv, "=")
+               environments[arr[0]] = arr[1]
+       }
+}
 
 type AdminService struct {
 }
@@ -46,8 +59,11 @@ func (service *AdminService) Dump(ctx context.Context, in 
*model.DumpRequest) (*
        service.dumpAll(ctx, &cache)
 
        return &model.DumpResponse{
-               Response: pb.CreateResponse(pb.Response_SUCCESS, "Admin dump 
successfully"),
-               Cache:    &cache,
+               Response:     pb.CreateResponse(pb.Response_SUCCESS, "Admin 
dump successfully"),
+               Info:         version.Ver(),
+               Config:       &core.ServerInfo.Config,
+               Environments: environments,
+               Cache:        &cache,
        }, nil
 }
 
diff --git a/server/core/swagger/v4.yaml b/server/core/swagger/v4.yaml
index eeccdaf8..aec7d91f 100644
--- a/server/core/swagger/v4.yaml
+++ b/server/core/swagger/v4.yaml
@@ -2348,8 +2348,53 @@ definitions:
         type: array
         items:
           $ref: "#/definitions/MicroServiceInstanceKV"
+  Config:
+    type: object
+    properties:
+      maxHeaderBytes:
+        type: integer
+      maxBodyBytes:
+        type: integer
+      readHeaderTimeout:
+        type: string
+      readTimeout:
+        type: string
+      idleTimeout:
+        type: string
+      writeTimeout:
+        type: string
+      limitTTLUnit:
+        type: string
+      limitConnections:
+        type: integer
+      limitIPLookup:
+        type: string
+      sslEnabled:
+        type: string
+      sslMinVersion:
+        type: string
+      sslVerifyPeer:
+        type: string
+      sslCiphers:
+        type: string
+      autoSyncInterval:
+        type: string
+      compactIndexDelta:
+        type: integer
+      compactInterval:
+        type: string
+      logRotateSize:
+        type: integer
+      logBackupCount:
+        type: integer
   DumpResponse:
     type: object
     properties:
+      info:
+        $ref: '#/definitions/Version'
+      config:
+        $ref: '#/definitions/Config'
+      environments:
+        $ref: '#/definitions/Properties'
       cache:
         $ref: "#/definitions/Cache"
diff --git a/server/rest/controller/v4/main_controller.go 
b/server/rest/controller/v4/main_controller.go
index a58bfc54..0f4beec9 100644
--- a/server/rest/controller/v4/main_controller.go
+++ b/server/rest/controller/v4/main_controller.go
@@ -24,11 +24,13 @@ import (
        
"github.com/apache/incubator-servicecomb-service-center/server/rest/controller"
        "github.com/apache/incubator-servicecomb-service-center/version"
        "net/http"
+       "sync"
 )
 
 var (
        versionJsonCache []byte
        versionResp      *pb.Response
+       parseVersionOnce sync.Once
 )
 
 const API_VERSION = "4.0.0"
@@ -43,16 +45,6 @@ type MainService struct {
        //
 }
 
-func init() {
-       result := Result{
-               version.Ver(),
-               API_VERSION,
-               &core.ServerInfo.Config,
-       }
-       versionJsonCache, _ = json.Marshal(result)
-       versionResp = pb.CreateResponse(pb.Response_SUCCESS, "get version 
successfully")
-}
-
 func (this *MainService) URLPatterns() []rest.Route {
        return []rest.Route{
                {rest.HTTP_METHOD_GET, "/v4/:project/registry/version", 
this.GetVersion},
@@ -68,5 +60,14 @@ func (this *MainService) ClusterHealth(w 
http.ResponseWriter, r *http.Request) {
 }
 
 func (this *MainService) GetVersion(w http.ResponseWriter, r *http.Request) {
+       parseVersionOnce.Do(func() {
+               result := Result{
+                       version.Ver(),
+                       API_VERSION,
+                       &core.ServerInfo.Config,
+               }
+               versionJsonCache, _ = json.Marshal(result)
+               versionResp = pb.CreateResponse(pb.Response_SUCCESS, "get 
version successfully")
+       })
        controller.WriteJsonBytes(w, versionResp, versionJsonCache)
 }


 

----------------------------------------------------------------
This is an automated message from the Apache Git Service.
To respond to the message, please log on GitHub and use the
URL above to go to the specific comment.
 
For queries about this service, please contact Infrastructure at:
us...@infra.apache.org


With regards,
Apache Git Services

Reply via email to