Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

feat: juno升级到适配最新jupiter版本 #137

Merged
merged 3 commits into from
Aug 27, 2021
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension


Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
55 changes: 7 additions & 48 deletions app/adminengine/engine_admin.go
Original file line number Diff line number Diff line change
Expand Up @@ -16,8 +16,6 @@ package adminengine

import (
"context"
"os"
"path/filepath"
"strconv"
"time"

Expand All @@ -42,11 +40,10 @@ import (
"github.com/douyu/jupiter/pkg/client/etcdv3"
jgrpc "github.com/douyu/jupiter/pkg/client/grpc"
"github.com/douyu/jupiter/pkg/flag"
"github.com/douyu/jupiter/pkg/server/governor"
"github.com/douyu/jupiter/pkg/governor"
"github.com/douyu/jupiter/pkg/server/xecho"
"github.com/douyu/jupiter/pkg/worker/xcron"
"github.com/douyu/jupiter/pkg/xlog"
"go.uber.org/zap"
)

// Admin ...
Expand Down Expand Up @@ -121,31 +118,21 @@ func (eng *Admin) parseFlag() error {

func (eng *Admin) initConfig() (err error) {
cfg.InitCfg()

jupiterConfig := xlog.DefaultConfig()
jupiterConfig.Name = cfg.Cfg.Logger.System.Name
jupiterConfig.Debug = cfg.Cfg.Logger.System.Debug
jupiterConfig.Level = cfg.Cfg.Logger.System.Level
jupiterConfig.Async = cfg.Cfg.Logger.System.Async

jupiterConfig.Dir = LogDir(cfg.Cfg.Logger.System.Dir)
jupiterConfig.Fields = []zap.Field{
xlog.FieldAid(ID()),
xlog.FieldName(Name()),
}
xlog.JupiterLogger = jupiterConfig.Build()
//

bizConfig := xlog.DefaultConfig()
bizConfig.Name = cfg.Cfg.Logger.Biz.Name
bizConfig.Debug = cfg.Cfg.Logger.Biz.Debug
bizConfig.Level = cfg.Cfg.Logger.Biz.Level
bizConfig.Async = cfg.Cfg.Logger.Biz.Async

bizConfig.Dir = LogDir(cfg.Cfg.Logger.Biz.Dir)
bizConfig.Fields = []zap.Field{
xlog.FieldAid(ID()),
xlog.FieldName(Name()),
}
xlog.DefaultLogger = bizConfig.Build()

return
}

Expand Down Expand Up @@ -181,7 +168,7 @@ func (eng *Admin) serveHTTP() (err error) {
serverConfig.Host = eng.hostFlag
}
serverConfig.Port = cfg.Cfg.Server.Http.Port
server := serverConfig.Build()
server := serverConfig.MustBuild()
server.Debug = true

server.Use(middleware.ProxyGatewayMW)
Expand All @@ -205,7 +192,7 @@ func (eng *Admin) serveGovern() (err error) {
config.ConnectTimeout = cfg.Cfg.Register.ConnectTimeout
config.Secure = cfg.Cfg.Register.Secure

client := config.Build()
client := config.MustBuild()

host := cfg.Cfg.Server.Govern.Host
if eng.hostFlag != "" {
Expand Down Expand Up @@ -263,7 +250,7 @@ func (eng *Admin) defers() (err error) {
config.Endpoints = cfg.Cfg.Register.Endpoints
config.ConnectTimeout = cfg.Cfg.Register.ConnectTimeout
config.Secure = cfg.Cfg.Register.Secure
client := config.Build()
client := config.MustBuild()
ctx, cancel := context.WithTimeout(context.Background(), time.Second*2)
defer cancel()
// todo optimize, jupiter will after support metric
Expand Down Expand Up @@ -316,31 +303,3 @@ func (eng *Admin) initUserVisitWorker() (err error) {
cron.Schedule(xcron.Every(time.Hour*12), xcron.FuncJob(user.User.CronCleanUserVisitRecord))
return eng.Schedule(cron)
}

func ID() string {
// 优先基于jupiter框架获取APP_ID
id := pkg.AppID()
if id == "" {
id = os.Getenv("APP_ID")
}
if id == "" {
id = "1234567890"
}
return id
}

func Name() string {
name := pkg.Name()
if name == "" {
name = filepath.Base(os.Args[0])
}
return name
}

func LogDir(cfgLog string) string {
if cfgLog != "" {
return cfgLog
} else {
return pkg.AppLogDir()
}
}
59 changes: 8 additions & 51 deletions app/proxyengine/engine.go
Original file line number Diff line number Diff line change
Expand Up @@ -17,8 +17,6 @@ package proxyengine
import (
"context"
"errors"
"os"
"path/filepath"
"strconv"
"time"

Expand All @@ -31,7 +29,6 @@ import (
"github.com/douyu/jupiter"
"github.com/douyu/jupiter/pkg"
"github.com/douyu/jupiter/pkg/client/etcdv3"
compound_registry "github.com/douyu/jupiter/pkg/registry/compound"
etcdv3_registry "github.com/douyu/jupiter/pkg/registry/etcdv3"
"github.com/douyu/jupiter/pkg/server/xecho"
"github.com/douyu/jupiter/pkg/server/xgrpc"
Expand Down Expand Up @@ -66,31 +63,21 @@ func New() *Proxy {

func (eng *Proxy) initConfig() (err error) {
cfg.InitCfg()

jupiterConfig := xlog.DefaultConfig()
jupiterConfig.Name = cfg.Cfg.Logger.System.Name
jupiterConfig.Debug = cfg.Cfg.Logger.System.Debug
jupiterConfig.Level = cfg.Cfg.Logger.System.Level
jupiterConfig.Async = cfg.Cfg.Logger.System.Async

jupiterConfig.Dir = LogDir(cfg.Cfg.Logger.System.Dir)
jupiterConfig.Fields = []zap.Field{
xlog.FieldAid(ID()),
xlog.FieldName(Name()),
}
xlog.JupiterLogger = jupiterConfig.Build()
//

bizConfig := xlog.DefaultConfig()
bizConfig.Name = cfg.Cfg.Logger.Biz.Name
bizConfig.Debug = cfg.Cfg.Logger.Biz.Debug
bizConfig.Level = cfg.Cfg.Logger.Biz.Level
bizConfig.Async = cfg.Cfg.Logger.Biz.Async

bizConfig.Dir = LogDir(cfg.Cfg.Logger.Biz.Dir)
bizConfig.Fields = []zap.Field{
xlog.FieldAid(ID()),
xlog.FieldName(Name()),
}
xlog.DefaultLogger = bizConfig.Build()

invoker.Init()
return
}
Expand All @@ -108,9 +95,7 @@ func (eng *Proxy) initRegister() (err error) {
config.Password = cfg.Cfg.Register.Password

eng.SetRegistry(
compound_registry.New(
config.Build(),
),
config.MustBuild(),
)
return
}
Expand Down Expand Up @@ -143,7 +128,7 @@ func (eng *Proxy) serveHTTP() (err error) {
serverConfig.Host = cfg.Cfg.ServerProxy.HTTPServer.Host
serverConfig.Port = cfg.Cfg.ServerProxy.HTTPServer.Port

server := serverConfig.Build()
server := serverConfig.MustBuild()
server.Debug = true
server.Validator = &FormValidator{validator: validator.New()}
apiV1(server)
Expand All @@ -160,7 +145,7 @@ func (eng *Proxy) serveGRPC() (err error) {
serverConfig.Host = cfg.Cfg.ServerProxy.GrpcServer.Host
serverConfig.Port = cfg.Cfg.ServerProxy.GrpcServer.Port

server := serverConfig.Build()
server := serverConfig.MustBuild()

pb.RegisterProxyServer(server.Server, new(ProxyGrpc))
err = eng.Serve(server)
Expand All @@ -179,7 +164,7 @@ func (eng *Proxy) serveGovern() (err error) {
config.Password = cfg.Cfg.Register.Password
config.BasicAuth = cfg.Cfg.Register.BasicAuth

client := config.Build()
client := config.MustBuild()

ctx, cancel := context.WithTimeout(context.Background(), time.Second*2)
defer cancel()
Expand Down Expand Up @@ -265,7 +250,7 @@ func (eng *Proxy) defers() (err error) {
config.Endpoints = cfg.Cfg.Register.Endpoints
config.ConnectTimeout = cfg.Cfg.Register.ConnectTimeout
config.Secure = cfg.Cfg.Register.Secure
client := config.Build()
client := config.MustBuild()
ctx, cancel := context.WithTimeout(context.Background(), time.Second*2)
defer cancel()
// todo optimize, jupiter will after support metric
Expand All @@ -279,31 +264,3 @@ func (eng *Proxy) defers() (err error) {
}
return nil
}

func ID() string {
// 优先基于jupiter框架获取APP_ID
id := pkg.AppID()
if id == "" {
id = os.Getenv("APP_ID")
}
if id == "" {
id = "1234567890"
}
return id
}

func Name() string {
name := pkg.Name()
if name == "" {
name = filepath.Base(os.Args[0])
}
return name
}

func LogDir(cfgLog string) string {
if cfgLog != "" {
return cfgLog
} else {
return pkg.AppLogDir()
}
}
2 changes: 1 addition & 1 deletion app/worker/http.go
Original file line number Diff line number Diff line change
Expand Up @@ -8,7 +8,7 @@ import (
)

func (w *Worker) serveHttp() error {
s := xecho.StdConfig("http").Build()
s := xecho.StdConfig("http").MustBuild()

s.Validator = &FormValidator{
validator: validator.New(),
Expand Down
26 changes: 17 additions & 9 deletions go.mod
Original file line number Diff line number Diff line change
Expand Up @@ -5,8 +5,9 @@ go 1.14
require (
github.com/BurntSushi/toml v0.3.1
github.com/alecthomas/template v0.0.0-20190718012654-fb15b899a751
github.com/alibaba/sentinel-golang v0.6.0
github.com/alibaba/sentinel-golang v1.0.2
github.com/aliyun/alibaba-cloud-sdk-go v1.61.18
github.com/apache/dubbo-go v1.4.2 // indirect
github.com/apache/rocketmq-client-go/v2 v2.0.0
github.com/arsmn/fiber-swagger/v2 v2.3.0
github.com/beeker1121/goque v2.1.0+incompatible
Expand All @@ -15,25 +16,27 @@ require (
github.com/cockroachdb/cmux v0.0.0-20170110192607-30d10be49292
github.com/coreos/etcd v3.3.22+incompatible
github.com/denisenkom/go-mssqldb v0.0.0-20200428022330-06a60b6afbbc // indirect
github.com/douyu/jupiter v0.2.9
github.com/douyu/jupiter v0.3.3-0.20210826091832-c7a43d560176
github.com/dustin/go-humanize v1.0.0 // indirect
github.com/go-git/go-git/v5 v5.1.0
github.com/go-gomail/gomail v0.0.0-20160411212932-81ebce5c23df
github.com/go-openapi/spec v0.20.3 // indirect
github.com/go-playground/validator v9.30.0+incompatible
github.com/go-playground/validator/v10 v10.3.0
github.com/go-playground/validator/v10 v10.9.0
github.com/go-resty/resty/v2 v2.2.0
github.com/gofiber/fiber/v2 v2.5.0
github.com/golang/protobuf v1.4.2
github.com/gomodule/redigo v2.0.0+incompatible
github.com/google/go-cmp v0.5.1
github.com/google/go-cmp v0.5.2
github.com/gorilla/sessions v1.2.0
github.com/grpc-ecosystem/go-grpc-prometheus v1.2.0
github.com/hashicorp/consul/api v1.4.0 // indirect
github.com/jhump/protoreflect v1.7.0
github.com/jinzhu/gorm v1.9.12
github.com/jinzhu/now v1.1.1 // indirect
github.com/jmespath/go-jmespath v0.0.0-20180206201540-c2b33e8439af
github.com/jmespath/go-jmespath v0.4.0
github.com/klauspost/compress v1.11.7 // indirect
github.com/kr/pty v1.1.5 // indirect
github.com/labstack/echo-contrib v0.9.0
github.com/labstack/echo/v4 v4.1.16
github.com/labstack/gommon v0.3.0
Expand All @@ -42,6 +45,8 @@ require (
github.com/mailru/easyjson v0.7.7 // indirect
github.com/mattn/go-colorable v0.1.7 // indirect
github.com/mattn/go-sqlite3 v2.0.3+incompatible // indirect
github.com/micro/go-micro/v2 v2.9.1 // indirect
github.com/nacos-group/nacos-sdk-go v1.0.0 // indirect
github.com/onsi/ginkgo v1.12.3
github.com/pkg/errors v0.9.1
github.com/robertkrimen/otto v0.0.0-20191219234010-c382bd3c16ff
Expand All @@ -50,6 +55,7 @@ require (
github.com/smartystreets/assertions v1.0.1 // indirect
github.com/spf13/cast v1.3.1
github.com/spf13/viper v1.6.3
github.com/swaggo/gin-swagger v1.2.0 // indirect
github.com/swaggo/swag v1.7.0
github.com/syndtr/goleveldb v1.0.0
github.com/tidwall/gjson v1.6.5
Expand All @@ -58,24 +64,26 @@ require (
github.com/unknwon/com v1.0.1
github.com/urfave/negroni v1.0.0
github.com/valyala/fasthttp v1.21.0 // indirect
github.com/xdg/scram v0.0.0-20180814205039-7eeb5667e42c // indirect
github.com/xdg/stringprep v0.0.0-20180714160509-73f8eece6fdc // indirect
go.uber.org/zap v1.15.0
golang.org/x/crypto v0.0.0-20201124201722-c8d3bf9c5392
golang.org/x/crypto v0.0.0-20210711020723-a769d52b0f97
golang.org/x/lint v0.0.0-20200302205851-738671d3881b
golang.org/x/net v0.0.0-20210119194325-5f4716e94777
golang.org/x/net v0.0.0-20210226172049-e18ecbb05110
golang.org/x/oauth2 v0.0.0-20190604053449-0f29369cfe45
golang.org/x/sync v0.0.0-20201020160332-67f06af15bc9
golang.org/x/sys v0.0.0-20210218155724-8ebf48af031b // indirect
golang.org/x/time v0.0.0-20200416051211-89c76fbcd5d1 // indirect
golang.org/x/tools v0.1.0 // indirect
golang.org/x/xerrors v0.0.0-20200804184101-5ec99f83aff1
google.golang.org/grpc v1.29.1
gopkg.in/alexcesaro/quotedprintable.v3 v3.0.0-20150716171945-2caba252f4dc // indirect
gopkg.in/fsnotify.v1 v1.4.7
gopkg.in/go-playground/validator.v9 v9.29.1 // indirect
gopkg.in/gomail.v2 v2.0.0-20160411212932-81ebce5c23df // indirect
gopkg.in/mgo.v2 v2.0.0-20190816093944-a6b53ec6cb22
gopkg.in/sourcemap.v1 v1.0.5 // indirect
gopkg.in/yaml.v2 v2.4.0
gopkg.in/yaml.v3 v3.0.0-20200615113413-eeeca48fe776
gopkg.in/yaml.v3 v3.0.0-20210107192922-496545a6307b
k8s.io/api v0.0.0-20190325185214-7544f9db76f6
k8s.io/apimachinery v0.0.0-20190223001710-c182ff3b9841
k8s.io/client-go v8.0.0+incompatible
Expand Down
Loading