You are viewing a plain text version of this content. The canonical link for it is here.
Posted to commits@servicecomb.apache.org by li...@apache.org on 2018/08/29 13:55:51 UTC
[incubator-servicecomb-service-center] branch master updated:
SCB-797 More information in dump API (#434)
This is an automated email from the ASF dual-hosted git repository.
littlecui pushed a commit to branch master
in repository https://gitbox.apache.org/repos/asf/incubator-servicecomb-service-center.git
The following commit(s) were added to refs/heads/master by this push:
new 3de5d25 SCB-797 More information in dump API (#434)
3de5d25 is described below
commit 3de5d25f55a9df17b6509dbcd66a8e4c409f9fc8
Author: little-cui <su...@qq.com>
AuthorDate: Wed Aug 29 21:55:47 2018 +0800
SCB-797 More information in dump API (#434)
---
etc/conf/app.conf | 9 ++++-----
server/admin/model/dump.go | 2 +-
server/admin/service.go | 10 +++++++++-
server/core/config.go | 29 +++++++++++++++++++++++++++++
server/core/core.go | 36 ++----------------------------------
server/core/microservice.go | 3 ++-
server/core/microservice_test.go | 6 +++---
server/core/proto/services.go | 10 +++++-----
server/core/swagger/v4.yaml | 8 +++++++-
version/version.go | 40 +++++++++++++++++++++++++++++++---------
10 files changed, 93 insertions(+), 60 deletions(-)
diff --git a/etc/conf/app.conf b/etc/conf/app.conf
index 16fe484..f48935a 100644
--- a/etc/conf/app.conf
+++ b/etc/conf/app.conf
@@ -36,8 +36,10 @@ read_header_timeout = 60s
read_timeout = 60s
idle_timeout = 60s
write_timeout = 60s
-max_header_bytes = 32768 # 32K
-max_body_bytes = 2097152 # 2M
+# 32K
+max_header_bytes = 32768
+# 2M
+max_body_bytes = 2097152
enable_pprof = 0
@@ -65,9 +67,6 @@ manager_cluster = "127.0.0.1:2379"
# default 30s if value less then 0
auto_sync_interval = 30s
-# bootstrap time out of registry
-connect_timeout = 10s
-
# request registry time out
registry_timeout = 30s
diff --git a/server/admin/model/dump.go b/server/admin/model/dump.go
index 8c9ea87..3354d7c 100644
--- a/server/admin/model/dump.go
+++ b/server/admin/model/dump.go
@@ -183,7 +183,7 @@ type DumpRequest struct {
type DumpResponse struct {
Response *pb.Response `json:"response,omitempty"`
Info *version.VersionSet `json:"info,omitempty"`
- Config *pb.ServerConfig `json:"config,omitempty"`
+ Config map[string]string `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 82322ef..91689b2 100644
--- a/server/admin/service.go
+++ b/server/admin/service.go
@@ -25,6 +25,7 @@ import (
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"
+ "github.com/astaxie/beego"
"golang.org/x/net/context"
"os"
"strings"
@@ -32,6 +33,7 @@ import (
var (
AdminServiceAPI = &AdminService{}
+ configs map[string]string
environments = make(map[string]string)
)
@@ -40,6 +42,12 @@ func init() {
arr := strings.Split(kv, "=")
environments[arr[0]] = arr[1]
}
+ configs, _ = beego.AppConfig.GetSection("default")
+ if section, err := beego.AppConfig.GetSection(beego.BConfig.RunMode); err == nil {
+ for k, v := range section {
+ configs[k] = v
+ }
+ }
}
type AdminService struct {
@@ -61,7 +69,7 @@ func (service *AdminService) Dump(ctx context.Context, in *model.DumpRequest) (*
return &model.DumpResponse{
Response: pb.CreateResponse(pb.Response_SUCCESS, "Admin dump successfully"),
Info: version.Ver(),
- Config: &core.ServerInfo.Config,
+ Config: configs,
Environments: environments,
Cache: &cache,
}, nil
diff --git a/server/core/config.go b/server/core/config.go
index 1715117..33876e7 100644
--- a/server/core/config.go
+++ b/server/core/config.go
@@ -17,8 +17,13 @@
package core
import (
+ "github.com/apache/incubator-servicecomb-service-center/pkg/log"
+ "github.com/apache/incubator-servicecomb-service-center/pkg/plugin"
pb "github.com/apache/incubator-servicecomb-service-center/server/core/proto"
+ "github.com/apache/incubator-servicecomb-service-center/version"
"github.com/astaxie/beego"
+ "os"
+ "runtime"
)
const (
@@ -28,7 +33,15 @@ const (
var ServerInfo = new(pb.ServerInformation)
func Configure() {
+ setCPUs()
+
*ServerInfo = newInfo()
+
+ plugin.SetPluginDir(ServerInfo.Config.PluginsDir)
+
+ initLogger()
+
+ version.Ver().Log()
}
func newInfo() pb.ServerInformation {
@@ -80,3 +93,19 @@ func newInfo() pb.ServerInformation {
},
}
}
+
+func setCPUs() {
+ cores := runtime.NumCPU()
+ runtime.GOMAXPROCS(cores)
+ log.Infof("service center is running simultaneously with %d CPU cores", cores)
+}
+
+func initLogger() {
+ log.SetGlobal(log.Config{
+ LoggerLevel: ServerInfo.Config.LogLevel,
+ LoggerFile: os.ExpandEnv(ServerInfo.Config.LogFilePath),
+ LogFormatText: ServerInfo.Config.LogFormat == "text",
+ LogRotateSize: int(ServerInfo.Config.LogRotateSize),
+ LogBackupCount: int(ServerInfo.Config.LogBackupCount),
+ })
+}
diff --git a/server/core/core.go b/server/core/core.go
index 1b6bf98..a2aee9a 100644
--- a/server/core/core.go
+++ b/server/core/core.go
@@ -19,14 +19,11 @@ package core
import (
"flag"
- "fmt"
"github.com/apache/incubator-servicecomb-service-center/pkg/grace"
"github.com/apache/incubator-servicecomb-service-center/pkg/log"
- "github.com/apache/incubator-servicecomb-service-center/pkg/plugin"
"github.com/apache/incubator-servicecomb-service-center/version"
"os"
"os/signal"
- "runtime"
"syscall"
"time"
)
@@ -34,14 +31,9 @@ import (
func Initialize() {
initCommandLine()
+ // initialize configuration
Configure()
- plugin.SetPluginDir(ServerInfo.Config.PluginsDir)
-
- initLogger()
-
- printVersion()
-
go handleSignals()
grace.Init()
@@ -54,35 +46,11 @@ func initCommandLine() {
flag.CommandLine.Parse(os.Args[1:])
if printVer {
- fmt.Printf("ServiceCenter version: %s\n", version.Ver().Version)
- fmt.Printf("Build tag: %s\n", version.Ver().BuildTag)
- fmt.Printf("Go version: %s\n", runtime.Version())
- fmt.Printf("Go OS/Arch: %s/%s\n", runtime.GOOS, runtime.GOARCH)
+ version.Ver().Print()
os.Exit(0)
}
}
-func printVersion() {
- log.Infof("service center version: %s", version.Ver().Version)
- log.Infof("Build tag: %s", version.Ver().BuildTag)
- log.Infof("Go version: %s", runtime.Version())
- log.Infof("Go OS/Arch: %s/%s", runtime.GOOS, runtime.GOARCH)
-
- cores := runtime.NumCPU()
- runtime.GOMAXPROCS(cores)
- log.Infof("service center is running simultaneously with %d CPU cores", cores)
-}
-
-func initLogger() {
- log.SetGlobal(log.Config{
- LoggerLevel: ServerInfo.Config.LogLevel,
- LoggerFile: os.ExpandEnv(ServerInfo.Config.LogFilePath),
- LogFormatText: ServerInfo.Config.LogFormat == "text",
- LogRotateSize: int(ServerInfo.Config.LogRotateSize),
- LogBackupCount: int(ServerInfo.Config.LogBackupCount),
- })
-}
-
func handleSignals() {
defer log.Sync()
diff --git a/server/core/microservice.go b/server/core/microservice.go
index 5e4484c..47adf68 100644
--- a/server/core/microservice.go
+++ b/server/core/microservice.go
@@ -20,6 +20,7 @@ import (
"github.com/apache/incubator-servicecomb-service-center/pkg/util"
pb "github.com/apache/incubator-servicecomb-service-center/server/core/proto"
"github.com/apache/incubator-servicecomb-service-center/version"
+ "github.com/astaxie/beego"
"golang.org/x/net/context"
"os"
"strings"
@@ -68,7 +69,7 @@ func prepareSelfRegistration() {
pb.PROP_ALLOW_CROSS_APP: "true",
},
}
- if version.Ver().RunMode == "dev" {
+ if beego.BConfig.RunMode == "dev" {
Service.Environment = pb.ENV_DEV
}
diff --git a/server/core/microservice_test.go b/server/core/microservice_test.go
index d642d64..0ffb801 100644
--- a/server/core/microservice_test.go
+++ b/server/core/microservice_test.go
@@ -17,20 +17,20 @@ package core
import (
"github.com/apache/incubator-servicecomb-service-center/server/core/proto"
- "github.com/apache/incubator-servicecomb-service-center/version"
+ "github.com/astaxie/beego"
"golang.org/x/net/context"
"os"
"testing"
)
func TestPrepareSelfRegistration(t *testing.T) {
- version.Ver().RunMode = "dev"
+ beego.BConfig.RunMode = "dev"
prepareSelfRegistration()
if Service == nil || Service.Environment != "development" {
t.Fatalf("TestPrepareSelfRegistration faild, %v", Service)
}
- version.Ver().RunMode = "prod"
+ beego.BConfig.RunMode = "prod"
prepareSelfRegistration()
if Service == nil || Service.AppId != "default" || Service.ServiceName != "SERVICECENTER" ||
Service.Environment != "production" || Service.Properties["allowCrossApp"] != "true" {
diff --git a/server/core/proto/services.go b/server/core/proto/services.go
index 60a3e44..7fd0d38 100644
--- a/server/core/proto/services.go
+++ b/server/core/proto/services.go
@@ -96,16 +96,16 @@ type ServerConfig struct {
SslVerifyPeer bool `json:"sslVerifyPeer,string"`
SslCiphers string `json:"sslCiphers"`
- AutoSyncInterval string `json:"autoSyncInterval"`
- CompactIndexDelta int64 `json:"compactIndexDelta"`
- CompactInterval string `json:"compactInterval"`
+ AutoSyncInterval string `json:"-"`
+ CompactIndexDelta int64 `json:"-"`
+ CompactInterval string `json:"-"`
EnablePProf bool `json:"-"`
EnableCache bool `json:"-"`
LoggerName string `json:"-"`
- LogRotateSize int64 `json:"logRotateSize"`
- LogBackupCount int64 `json:"logBackupCount"`
+ LogRotateSize int64 `json:"-"`
+ LogBackupCount int64 `json:"-"`
LogFilePath string `json:"-"`
LogLevel string `json:"-"`
LogFormat string `json:"-"`
diff --git a/server/core/swagger/v4.yaml b/server/core/swagger/v4.yaml
index aec7d91..c7ea633 100644
--- a/server/core/swagger/v4.yaml
+++ b/server/core/swagger/v4.yaml
@@ -1660,6 +1660,12 @@ definitions:
type: string
buildTag:
type: string
+ goVersion:
+ type: string
+ os:
+ type: string
+ arch:
+ type: string
Properties:
type: object
description: 扩展属性
@@ -2393,7 +2399,7 @@ definitions:
info:
$ref: '#/definitions/Version'
config:
- $ref: '#/definitions/Config'
+ $ref: '#/definitions/Properties'
environments:
$ref: '#/definitions/Properties'
cache:
diff --git a/version/version.go b/version/version.go
index 500363f..3afc8a3 100644
--- a/version/version.go
+++ b/version/version.go
@@ -16,7 +16,11 @@
*/
package version
-import "github.com/astaxie/beego"
+import (
+ "fmt"
+ "github.com/apache/incubator-servicecomb-service-center/pkg/log"
+ "runtime"
+)
var (
// no need to modify
@@ -28,19 +32,37 @@ var (
)
type VersionSet struct {
- Version string `json:"version"`
- BuildTag string `json:"buildTag"`
- RunMode string `json:"runMode"`
+ Version string `json:"version"`
+ BuildTag string `json:"buildTag"`
+ GoVersion string `json:"goVersion"`
+ OS string `json:"os"`
+ Arch string `json:"arch"`
+}
+
+func (vs *VersionSet) Print() {
+ fmt.Printf("ServiceCenter version: %s\n", versionSet.Version)
+ fmt.Printf("Build tag: %s\n", versionSet.BuildTag)
+ fmt.Printf("Go version: %s\n", versionSet.GoVersion)
+ fmt.Printf("OS/Arch: %s/%s\n", versionSet.OS, versionSet.Arch)
+}
+
+func (vs *VersionSet) Log() {
+ log.Infof("service center version: %s", versionSet.Version)
+ log.Infof("Build tag: %s", versionSet.BuildTag)
+ log.Infof("Go version: %s", versionSet.GoVersion)
+ log.Infof("OS/Arch: %s/%s", versionSet.OS, versionSet.Arch)
}
-var version VersionSet
+var versionSet VersionSet
func init() {
- version.Version = VERSION
- version.BuildTag = BUILD_TAG
- version.RunMode = beego.AppConfig.DefaultString("runmode", "prod")
+ versionSet.Version = VERSION
+ versionSet.BuildTag = BUILD_TAG
+ versionSet.GoVersion = runtime.Version()
+ versionSet.OS = runtime.GOOS
+ versionSet.Arch = runtime.GOARCH
}
func Ver() *VersionSet {
- return &version
+ return &versionSet
}