Skip to content

Commit

Permalink
Merge remote-tracking branch 'origin/rm-rpc' into rm-rpc
Browse files Browse the repository at this point in the history
  • Loading branch information
alchemy-lee committed Aug 2, 2021
2 parents 97f25a9 + e441a84 commit a2f1a2f
Show file tree
Hide file tree
Showing 54 changed files with 716 additions and 207 deletions.
4 changes: 2 additions & 2 deletions .github/workflows/github-actions.yml
Original file line number Diff line number Diff line change
Expand Up @@ -2,7 +2,7 @@ name: CI

on:
push:
branches: [master, develop]
branches: [master, develop, "1.5", "3.0"]
pull_request:
branches: "*"

Expand Down Expand Up @@ -59,7 +59,7 @@ jobs:
# diff -u <(echo -n) <(gofmt -d -s .)
- name: Install go ci lint
run: curl -sSfL https://raw.githubusercontent.com/golangci/golangci-lint/master/install.sh | sh -s -- -b $(go env GOPATH)/bin v1.27.0
run: curl -sSfL https://raw.githubusercontent.com/golangci/golangci-lint/master/install.sh | sh -s -- -b $(go env GOPATH)/bin v1.41.1

- name: Run Linter
run: golangci-lint run --timeout=10m -v
Expand Down
1 change: 1 addition & 0 deletions .gitignore
Original file line number Diff line number Diff line change
Expand Up @@ -5,6 +5,7 @@
*.so
*.dylib
*.jar
*.log

# Test binary, build with `go test -c`
*.test
Expand Down
4 changes: 0 additions & 4 deletions cluster/cluster_impl/failover_cluster_test.go
Original file line number Diff line number Diff line change
Expand Up @@ -40,10 +40,6 @@ import (
"dubbo.apache.org/dubbo-go/v3/protocol/invocation"
)

// ///////////////////////////
// mock invoker
// ///////////////////////////

// nolint
type MockInvoker struct {
url *common.URL
Expand Down
4 changes: 3 additions & 1 deletion cluster/router/v3router/judger/bool_match_judger.go
Original file line number Diff line number Diff line change
Expand Up @@ -17,7 +17,9 @@

package judger

import "dubbo.apache.org/dubbo-go/v3/config"
import (
"dubbo.apache.org/dubbo-go/v3/config"
)

// nolint
type BoolMatchJudger struct {
Expand Down
12 changes: 3 additions & 9 deletions cluster/router/v3router/router_chain_test.go
Original file line number Diff line number Diff line change
Expand Up @@ -23,22 +23,16 @@ import (
)

import (
"github.com/stretchr/testify/assert"
metav1 "k8s.io/apimachinery/pkg/apis/meta/v1"
)

import (
"dubbo.apache.org/dubbo-go/v3/cluster/router/v3router/k8s_api"
"dubbo.apache.org/dubbo-go/v3/config"
"dubbo.apache.org/dubbo-go/v3/config_center"
)

import (
"github.com/stretchr/testify/assert"
)

import (
"dubbo.apache.org/dubbo-go/v3/common"
"dubbo.apache.org/dubbo-go/v3/common/yaml"
"dubbo.apache.org/dubbo-go/v3/config"
"dubbo.apache.org/dubbo-go/v3/config_center"
"dubbo.apache.org/dubbo-go/v3/protocol"
"dubbo.apache.org/dubbo-go/v3/protocol/invocation"
)
Expand Down
1 change: 1 addition & 0 deletions common/constant/key.go
Original file line number Diff line number Diff line change
Expand Up @@ -314,4 +314,5 @@ const (
GenericSerializationDefault = "true"
// disable "protobuf-json" temporarily
//GenericSerializationProtobuf = "protobuf-json"
GenericSerializationGson = "gson"
)
4 changes: 3 additions & 1 deletion common/host_util.go
Original file line number Diff line number Diff line change
Expand Up @@ -17,7 +17,9 @@

package common

import gxnet "github.com/dubbogo/gost/net"
import (
gxnet "github.com/dubbogo/gost/net"
)

var localIp string

Expand Down
36 changes: 36 additions & 0 deletions common/logger/file_log.yml
Original file line number Diff line number Diff line change
@@ -0,0 +1,36 @@
lumberjackConfig:
filename: "logs.log"
maxSize: 1
maxAge: 3
maxBackups: 5
localTime: true
compress: false

zapConfig:
level: "debug"
development: false
disableCaller: false
disableStacktrace: false
sampling:
encoding: "console"

# encoder
encoderConfig:
messageKey: "message"
levelKey: "level"
timeKey: "time"
nameKey: "logger"
callerKey: "caller"
stacktraceKey: "stacktrace"
lineEnding: ""
levelEncoder: "capitalColor"
timeEncoder: "iso8601"
durationEncoder: "seconds"
callerEncoder: "short"
nameEncoder: ""

outputPaths:
- "stderr"
errorOutputPaths:
- "stderr"
initialFields:
58 changes: 50 additions & 8 deletions common/logger/logger.go
Original file line number Diff line number Diff line change
Expand Up @@ -26,6 +26,7 @@ import (

import (
"github.com/apache/dubbo-getty"
"github.com/natefinch/lumberjack"
perrors "github.com/pkg/errors"
"go.uber.org/zap"
"go.uber.org/zap/zapcore"
Expand All @@ -44,6 +45,11 @@ type DubboLogger struct {
dynamicLevel zap.AtomicLevel
}

type Config struct {
LumberjackConfig *lumberjack.Logger `yaml:"lumberjackConfig"`
ZapConfig *zap.Config `yaml:"zapConfig"`
}

// Logger is the interface for Logger types
type Logger interface {
Info(args ...interface{})
Expand Down Expand Up @@ -95,7 +101,7 @@ func InitLog(logConfFile string) error {
return perrors.Errorf("ioutil.ReadFile(file:%s) = error:%v", logConfFile, err)
}

conf := &zap.Config{}
conf := &Config{}
err = yaml.Unmarshal(confFileStream, conf)
if err != nil {
InitLogger(nil)
Expand All @@ -108,9 +114,12 @@ func InitLog(logConfFile string) error {
}

// InitLogger use for init logger by @conf
func InitLogger(conf *zap.Config) {
var zapLoggerConfig zap.Config
if conf == nil {
func InitLogger(conf *Config) {
var (
zapLogger *zap.Logger
config = &Config{}
)
if conf == nil || conf.ZapConfig == nil {
zapLoggerEncoderConfig := zapcore.EncoderConfig{
TimeKey: "time",
LevelKey: "level",
Expand All @@ -123,7 +132,7 @@ func InitLogger(conf *zap.Config) {
EncodeDuration: zapcore.SecondsDurationEncoder,
EncodeCaller: zapcore.ShortCallerEncoder,
}
zapLoggerConfig = zap.Config{
config.ZapConfig = &zap.Config{
Level: zap.NewAtomicLevelAt(zap.DebugLevel),
Development: false,
Encoding: "console",
Expand All @@ -132,10 +141,17 @@ func InitLogger(conf *zap.Config) {
ErrorOutputPaths: []string{"stderr"},
}
} else {
zapLoggerConfig = *conf
config.ZapConfig = conf.ZapConfig
}

if conf == nil || conf.LumberjackConfig == nil {
zapLogger, _ = config.ZapConfig.Build(zap.AddCallerSkip(1))
} else {
config.LumberjackConfig = conf.LumberjackConfig
zapLogger = initZapLoggerWithSyncer(config)
}
zapLogger, _ := zapLoggerConfig.Build(zap.AddCallerSkip(1))
logger = &DubboLogger{Logger: zapLogger.Sugar(), dynamicLevel: zapLoggerConfig.Level}

logger = &DubboLogger{Logger: zapLogger.Sugar(), dynamicLevel: config.ZapConfig.Level}

// set getty log
getty.SetLogger(logger)
Expand Down Expand Up @@ -174,3 +190,29 @@ func (dl *DubboLogger) SetLoggerLevel(level string) {
dl.dynamicLevel.SetLevel(*l)
}
}

// initZapLoggerWithSyncer init zap Logger with syncer
func initZapLoggerWithSyncer(conf *Config) *zap.Logger {
core := zapcore.NewCore(
conf.getEncoder(),
conf.getLogWriter(),
zap.NewAtomicLevelAt(zap.DebugLevel),
)

return zap.New(core, zap.AddCallerSkip(1))
}

// getEncoder get encoder by config, zapcore support json and console encoder
func (c *Config) getEncoder() zapcore.Encoder {
if c.ZapConfig.Encoding == "json" {
return zapcore.NewJSONEncoder(c.ZapConfig.EncoderConfig)
} else if c.ZapConfig.Encoding == "console" {
return zapcore.NewConsoleEncoder(c.ZapConfig.EncoderConfig)
}
return nil
}

// getLogWriter get Lumberjack writer by LumberjackConfig
func (c *Config) getLogWriter() zapcore.WriteSyncer {
return zapcore.AddSync(c.LumberjackConfig)
}
54 changes: 54 additions & 0 deletions common/logger/logger_test.go
Original file line number Diff line number Diff line change
Expand Up @@ -81,3 +81,57 @@ func TestSetLevel(t *testing.T) {
Debug("debug")
Info("info")
}

func TestInitLogWidthFile(t *testing.T) {
var (
err error
path string
)

err = InitLog("")
assert.EqualError(t, err, "log configure file name is nil")

path, err = filepath.Abs("./file_log.xml")
assert.NoError(t, err)
err = InitLog(path)
assert.EqualError(t, err, "log configure file name{"+path+"} suffix must be .yml")

path, err = filepath.Abs("./logger.yml")
assert.NoError(t, err)
err = InitLog(path)
var errMsg string
if runtime.GOOS == "windows" {
errMsg = fmt.Sprintf("open %s: The system cannot find the file specified.", path)
} else {
errMsg = fmt.Sprintf("open %s: no such file or directory", path)
}
assert.EqualError(t, err, fmt.Sprintf("ioutil.ReadFile(file:%s) = error:%s", path, errMsg))

err = InitLog("./file_log.yml")
assert.NoError(t, err)

Debug("debug")
Info("info")
Warn("warn")
Error("error")
Debugf("%s", "debug")
Infof("%s", "info")
Warnf("%s", "warn")
Errorf("%s", "error")
}

func TestSetLevelWidthFile(t *testing.T) {
err := InitLog("./file_log.yml")
assert.NoError(t, err)
Debug("debug")
Info("info")

assert.True(t, SetLoggerLevel("info"))
Debug("debug")
Info("info")

SetLogger(GetLogger().(*DubboLogger).Logger)
assert.False(t, SetLoggerLevel("debug"))
Debug("debug")
Info("info")
}
13 changes: 2 additions & 11 deletions common/url.go
Original file line number Diff line number Diff line change
Expand Up @@ -39,14 +39,9 @@ import (

import (
"dubbo.apache.org/dubbo-go/v3/common/constant"
"dubbo.apache.org/dubbo-go/v3/common/logger"
)

// ///////////////////////////////
// dubbo role type
// ///////////////////////////////

// role constant
// dubbo role type constant
const (
// CONSUMER is consumer role
CONSUMER = iota
Expand Down Expand Up @@ -210,11 +205,7 @@ func WithToken(token string) Option {
if len(token) > 0 {
value := token
if strings.ToLower(token) == "true" || strings.ToLower(token) == "default" {
u, err := uuid.NewV4()
if err != nil {
logger.Errorf("could not generator UUID: %v", err)
return
}
u := uuid.NewV4()
value = u.String()
}
url.SetParam(constant.TOKEN_KEY, value)
Expand Down
4 changes: 3 additions & 1 deletion config/generic_service.go
Original file line number Diff line number Diff line change
Expand Up @@ -17,7 +17,9 @@

package config

import "context"
import (
"context"
)

// GenericService uses for generic invoke for service call
type GenericService struct {
Expand Down
4 changes: 3 additions & 1 deletion config/interfaces/config_reader.go
Original file line number Diff line number Diff line change
Expand Up @@ -17,7 +17,9 @@

package interfaces

import "bytes"
import (
"bytes"
)

// ConfigReader is used to read config from consumer or provider
type ConfigReader interface {
Expand Down
4 changes: 3 additions & 1 deletion config/service_discovery_config.go
Original file line number Diff line number Diff line change
Expand Up @@ -17,7 +17,9 @@

package config

import "dubbo.apache.org/dubbo-go/v3/common/constant"
import (
"dubbo.apache.org/dubbo-go/v3/common/constant"
)

// ServiceDiscoveryConfig will be used to create
type ServiceDiscoveryConfig struct {
Expand Down
7 changes: 5 additions & 2 deletions filter/generic/generalizer/example.pb.go

Some generated files are not rendered by default. Learn more about how customized files appear on GitHub.

4 changes: 3 additions & 1 deletion filter/generic/generalizer/generalizer.go
Original file line number Diff line number Diff line change
Expand Up @@ -17,7 +17,9 @@

package generalizer

import "reflect"
import (
"reflect"
)

type Generalizer interface {

Expand Down
Loading

0 comments on commit a2f1a2f

Please sign in to comment.