Skip to content

Commit

Permalink
Changes: Add '-v' flag in command line. (#132)
Browse files Browse the repository at this point in the history
* Code restructure.

* Bug fixes: do not print log when self preservation stopped.

* New features: /version API supports return SC running environment information.

* Optimize log performance.

* Code restructure.

* Optimize log performance.

* Code restructure.

* Optimize heartbeat log print.

* Optimize heartbeat log print.

* Code restructure.

* Optimize heartbeat log print.

* Optimize log print.

* Optimize log print.

* Optimize router and interceptor.

* Add request metrics.

* Add /metrics API.

* Code restructure.

* Code restructure.

* Code restructure.

* Optimize heartbeat log print.

* Optimize heartbeat log print.

* Optimize log print.

* Add request metrics.

* Add /metrics API.

* Optimize versionrule.go

* Optimize versionrule.go

* Bug fixes: 2.0.0 should not match rule [1.0.0, 2.0.0).

* Changes: SC version and build tag.
  • Loading branch information
little-cui committed Oct 21, 2017
1 parent 5d9a590 commit e17d3e0
Show file tree
Hide file tree
Showing 5 changed files with 34 additions and 15 deletions.
1 change: 0 additions & 1 deletion etc/conf/app.conf
Original file line number Diff line number Diff line change
@@ -1,6 +1,5 @@
ComponentName = service_center
version = v3
build_tag = {build_tag}
tenant_mode = dedicated
#run mode could be many options to specify the env like prod,dev
runmode = dev
Expand Down
14 changes: 14 additions & 0 deletions server/core/0_init.go
Original file line number Diff line number Diff line change
Expand Up @@ -2,17 +2,22 @@ package core

import (
"flag"
"fmt"
"github.com/ServiceComb/service-center/pkg/grace"
"github.com/ServiceComb/service-center/pkg/lager"
"github.com/ServiceComb/service-center/pkg/logrotate"
"github.com/ServiceComb/service-center/pkg/tlsutil"
"github.com/ServiceComb/service-center/pkg/util"
"github.com/ServiceComb/service-center/version"
"github.com/astaxie/beego"
"os"
"path/filepath"
"runtime"
"time"
)

var printVersion bool

func init() {
Initialize()
}
Expand All @@ -27,8 +32,17 @@ func Initialize() {
}

func initCommandLine() {
flag.BoolVar(&printVersion, "v", false, "Print the version and exit.")
flag.CommandLine.Init(os.Args[0], flag.ContinueOnError)
flag.CommandLine.Parse(os.Args[1:])

if printVersion {
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)
os.Exit(0)
}
}

func initLogger() {
Expand Down
8 changes: 4 additions & 4 deletions server/core/microservice.go
Original file line number Diff line number Diff line change
Expand Up @@ -34,14 +34,14 @@ const (
REGISTRY_DEFAULT_LEASE_RENEWALINTERVAL int32 = 30
REGISTRY_DEFAULT_LEASE_RETRYTIMES int32 = 3

IS_SC_SELF = "sc_self"
IS_SC_SELF = "sc_self"
)

func init() {
Service = &pb.MicroService{
AppId: registry_app_id,
ServiceName: registry_service_name,
Version: version.Ver().ApiVersion,
Version: version.Ver().Version,
Status: pb.MS_UP,
Level: "BACK",
Schemas: []string{
Expand Down Expand Up @@ -71,7 +71,7 @@ func AddDefaultContextValue(ctx context.Context) context.Context {
return ctx
}

func ISSCSelf(ctx context.Context) bool{
func ISSCSelf(ctx context.Context) bool {
if ctx.Value(IS_SC_SELF) != nil && ctx.Value(IS_SC_SELF).(bool) {
return true
}
Expand All @@ -82,7 +82,7 @@ func GetExistenceRequest() *pb.GetExistenceRequest {
Type: pb.EXISTENCE_MS,
AppId: registry_app_id,
ServiceName: registry_service_name,
Version: version.Ver().ApiVersion,
Version: version.Ver().Version,
}
}

Expand Down
6 changes: 5 additions & 1 deletion server/rest/controller/v3/main_controller.go
Original file line number Diff line number Diff line change
Expand Up @@ -24,11 +24,14 @@ import (
"net/http"
)

const API_VERSION = "3.0.0"

var RunMode string

type Result struct {
version.VersionSet
RunMode string `json:"runMode"`
ApiVersion string `json:"apiVersion"`
RunMode string `json:"runMode"`
}

type MainService struct {
Expand Down Expand Up @@ -62,6 +65,7 @@ func (this *MainService) ClusterHealth(w http.ResponseWriter, r *http.Request) {
func (this *MainService) GetVersion(w http.ResponseWriter, r *http.Request) {
result := Result{
version.Ver(),
API_VERSION,
RunMode,
}
resultJSON, _ := json.Marshal(result)
Expand Down
20 changes: 11 additions & 9 deletions version/version.go
Original file line number Diff line number Diff line change
Expand Up @@ -13,23 +13,25 @@
//limitations under the License.
package version

import "github.com/astaxie/beego"

const VERSION = "0.2.0"
const API_VERSION = "3.0.0"
var (
// no need to modify
// please use:
// go build -ldflags "-X github.com/ServiceComb/service-center/version.VERSION=x.x.x"
// to set these values.
VERSION = "0.0.1"
BUILD_TAG = "Not provided"
)

type VersionSet struct {
Version string `json:"version"`
ApiVersion string `json:"apiVersion"`
BuildTag string `json:"buildTag"`
Version string `json:"version"`
BuildTag string `json:"buildTag"`
}

var version VersionSet

func init() {
version.Version = VERSION
version.ApiVersion = API_VERSION
version.BuildTag = beego.AppConfig.String("build_tag")
version.BuildTag = BUILD_TAG
}

func Ver() VersionSet {
Expand Down

0 comments on commit e17d3e0

Please sign in to comment.