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

merge from develop & refact config reader #410

Merged
merged 30 commits into from
Mar 15, 2020
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
Show all changes
30 commits
Select commit Hold shift + click to select a range
ae9c7d4
grpc client and server trace function
flixgithub Feb 7, 2020
0b60bb8
go fmt
flixgithub Feb 8, 2020
a4986f5
go fmt
flixgithub Feb 8, 2020
fd77a7a
split package
flixgithub Feb 10, 2020
50b57f9
Merge branch 'develop' into feature/grpctracing
zouyx Mar 9, 2020
e31ac1d
Add: go report card
AlexStocks Mar 10, 2020
f85d07b
mod grpc tracing
zouyx Mar 11, 2020
d99e9b3
user can add attachment
pantianying Mar 12, 2020
068f7ba
Merge pull request #398 from pantianying/user_add_attachment
pantianying Mar 12, 2020
3606bc1
mod grpc tracing
zouyx Mar 12, 2020
5f2981f
mod grpc tracing
zouyx Mar 12, 2020
59c11c0
mod grpc tracing
zouyx Mar 12, 2020
7db3a2a
mod grpc tracing
zouyx Mar 12, 2020
be26d41
merge import package
zouyx Mar 13, 2020
12699c5
Merge pull request #397 from zouyx/feature/grpctracing
fangyincheng Mar 13, 2020
3030327
update hessian2 version
AlexStocks Mar 14, 2020
6df03bf
Mod: delete a judgment condition
fangyincheng Mar 14, 2020
9279a28
Mod: improve code
fangyincheng Mar 14, 2020
f01d60d
Merge pull request #406 from fangyincheng/develop
AlexStocks Mar 14, 2020
2d8a5cc
Merge remote-tracking branch 'apache/develop' into feature/rest
fangyincheng Mar 14, 2020
9a4db99
fix the problem in before_ut.bat
zouyx Mar 15, 2020
085b915
Merge pull request #409 from zouyx/develop
fangyincheng Mar 15, 2020
69de204
Ref: refact config loader
fangyincheng Mar 15, 2020
b988571
Merge remote-tracking branch 'apache/develop' into feature/rest
fangyincheng Mar 15, 2020
57a2a8f
Mrg: merge upstream
fangyincheng Mar 15, 2020
66d8a1a
Del: delete config/rest
fangyincheng Mar 15, 2020
4c50edc
Fix: resolve travis
fangyincheng Mar 15, 2020
1e9392a
Imp: improve config reader
fangyincheng Mar 15, 2020
17c29b5
Fix: fix nil point
fangyincheng Mar 15, 2020
d7cc3af
Fix: reviews
fangyincheng Mar 15, 2020
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
2 changes: 2 additions & 0 deletions README.md
Original file line number Diff line number Diff line change
Expand Up @@ -3,6 +3,8 @@
[![Build Status](https://travis-ci.org/apache/dubbo-go.svg?branch=master)](https://travis-ci.org/apache/dubbo-go)
[![codecov](https://codecov.io/gh/apache/dubbo-go/branch/master/graph/badge.svg)](https://codecov.io/gh/apache/dubbo-go)
[![go.dev reference](https://img.shields.io/badge/go.dev-reference-007d9c?logo=go&logoColor=white&style=flat-square)](https://pkg.go.dev/github.com/apache/dubbo-go?tab=doc)
[![Go Report Card](https://goreportcard.com/badge/github.com/apache/dubbo-go)](https://goreportcard.com/report/github.com/apache/dubbo-go)
![license](https://img.shields.io/badge/license-Apache--2.0-green.svg)

---
Apache Dubbo Go Implementation.
Expand Down
2 changes: 2 additions & 0 deletions README_CN.md
Original file line number Diff line number Diff line change
Expand Up @@ -3,6 +3,8 @@
[![Build Status](https://travis-ci.org/apache/dubbo-go.svg?branch=master)](https://travis-ci.org/apache/dubbo-go)
[![codecov](https://codecov.io/gh/apache/dubbo-go/branch/master/graph/badge.svg)](https://codecov.io/gh/apache/dubbo-go)
[![go.dev reference](https://img.shields.io/badge/go.dev-reference-007d9c?logo=go&logoColor=white&style=flat-square)](https://pkg.go.dev/github.com/apache/dubbo-go?tab=doc)
[![Go Report Card](https://goreportcard.com/badge/github.com/apache/dubbo-go)](https://goreportcard.com/report/github.com/apache/dubbo-go)
![license](https://img.shields.io/badge/license-Apache--2.0-green.svg)

---
Apache Dubbo Go 语言实现
Expand Down
6 changes: 3 additions & 3 deletions before_ut.bat
Original file line number Diff line number Diff line change
Expand Up @@ -14,10 +14,10 @@
:: See the License for the specific language governing permissions and
:: limitations under the License.

set zkJarName="zookeeper-3.4.9-fatjar.jar"
set zkJarName=zookeeper-3.4.9-fatjar.jar
set remoteJarUrl="https://github.com/dubbogo/resources/raw/master/zookeeper-4unitest/contrib/fatjar/%zkJarName%"
set zkJarPath="remoting/zookeeper/zookeeper-4unittest/contrib/fatjar"
set zkJar="%zkJarPath%/%zkJarName%"
set zkJarPath=remoting/zookeeper/zookeeper-4unittest/contrib/fatjar
set zkJar=%zkJarPath%/%zkJarName%

if not exist "%zkJar%" (
md %zkJarPath%
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -18,24 +18,33 @@
package extension

import (
"github.com/apache/dubbo-go/config/rest/config_reader"
"github.com/apache/dubbo-go/config/interfaces"
)

var (
restConfigReaders = make(map[string]func() config_reader.RestConfigReader)
configReaders = make(map[string]func() interfaces.ConfigReader)
fangyincheng marked this conversation as resolved.
Show resolved Hide resolved
defaults = make(map[string]string)
)

func SetRestConfigReader(name string, fun func() config_reader.RestConfigReader) {
restConfigReaders[name] = fun
// SetConfigReaders set a creator of config reader.
func SetConfigReaders(name string, v func() interfaces.ConfigReader) {
configReaders[name] = v
}

func GetSingletonRestConfigReader(name string) config_reader.RestConfigReader {
if name == "" {
name = "default"
// GetConfigReaders get a config reader by name.
func GetConfigReaders(name string) interfaces.ConfigReader {
if configReaders[name] == nil {
panic("config reader for " + name + " is not existing, make sure you have imported the package.")
}
if restConfigReaders[name] == nil {
panic("restConfigReaders for " + name + " is not existing, make sure you have import the package.")
}
return restConfigReaders[name]()
return configReaders[name]()
}

// SetDefaultConfitReader set {name} to default config reader for {module}
func SetDefaultConfitReader(module, name string) {
defaults[module] = name
}

// GetDefaultConfitReader
func GetDefaultConfitReader() map[string]string {
return defaults
}
8 changes: 8 additions & 0 deletions common/proxy/proxy.go
Original file line number Diff line number Diff line change
Expand Up @@ -140,6 +140,14 @@ func (p *Proxy) Implement(v common.RPCService) {
inv.SetAttachments(k, value)
}

// add user setAttachment
atm := invCtx.Value("attachment")
if m, ok := atm.(map[string]string); ok {
for k, value := range m {
inv.SetAttachments(k, value)
}
}

result := p.invoke.Invoke(invCtx, inv)

err = result.Error()
Expand Down
6 changes: 3 additions & 3 deletions common/yaml/yaml.go
Original file line number Diff line number Diff line change
Expand Up @@ -41,10 +41,10 @@ func LoadYMLConfig(confProFile string) ([]byte, error) {
}

// unmarshalYMLConfig Load yml config byte from file , then unmarshal to object
func UnmarshalYMLConfig(confProFile string, out interface{}) error {
func UnmarshalYMLConfig(confProFile string, out interface{}) ([]byte, error) {
confFileStream, err := LoadYMLConfig(confProFile)
if err != nil {
return perrors.Errorf("ioutil.ReadFile(file:%s) = error:%v", confProFile, perrors.WithStack(err))
return confFileStream, perrors.Errorf("ioutil.ReadFile(file:%s) = error:%v", confProFile, perrors.WithStack(err))
}
return yaml.Unmarshal(confFileStream, out)
return confFileStream, yaml.Unmarshal(confFileStream, out)
}
9 changes: 6 additions & 3 deletions common/yaml/yaml_test.go
Original file line number Diff line number Diff line change
Expand Up @@ -30,7 +30,8 @@ func TestUnmarshalYMLConfig(t *testing.T) {
conPath, err := filepath.Abs("./testdata/config.yml")
assert.NoError(t, err)
c := &Config{}
assert.NoError(t, UnmarshalYMLConfig(conPath, c))
_, err = UnmarshalYMLConfig(conPath, c)
assert.NoError(t, err)
assert.Equal(t, "strTest", c.StrTest)
assert.Equal(t, 11, c.IntTest)
assert.Equal(t, false, c.BooleanTest)
Expand All @@ -39,8 +40,10 @@ func TestUnmarshalYMLConfig(t *testing.T) {

func TestUnmarshalYMLConfig_Error(t *testing.T) {
c := &Config{}
assert.Error(t, UnmarshalYMLConfig("./testdata/config", c))
assert.Error(t, UnmarshalYMLConfig("", c))
_, err := UnmarshalYMLConfig("./testdata/config", c)
assert.Error(t, err)
_, err = UnmarshalYMLConfig("", c)
assert.Error(t, err)
}

type Config struct {
Expand Down
4 changes: 3 additions & 1 deletion config/base_config.go
Original file line number Diff line number Diff line change
Expand Up @@ -18,6 +18,7 @@
package config

import (
"bytes"
"reflect"
"strconv"
"strings"
Expand Down Expand Up @@ -47,6 +48,8 @@ type BaseConfig struct {
fatherConfig interface{}

MetricConfig *MetricConfig `yaml:"metrics" json:"metrics,omitempty"`

fileStream *bytes.Buffer
}

// startConfigCenter will start the config center.
Expand Down Expand Up @@ -361,5 +364,4 @@ func initializeStruct(t reflect.Type, v reflect.Value) {

}
}

}
32 changes: 26 additions & 6 deletions config/config_loader.go
Original file line number Diff line number Diff line change
Expand Up @@ -19,6 +19,8 @@ package config

import (
"fmt"
"github.com/apache/dubbo-go/common/extension"
perrors "github.com/pkg/errors"
"log"
"os"
"time"
Expand Down Expand Up @@ -90,10 +92,19 @@ func Load() {
if consumerConfig == nil {
logger.Warnf("consumerConfig is nil!")
} else {
// init rest consumer config
if err := ConsumerRestConfigInit(consumerConfig.RestConfigType); err != nil {
log.Printf("[initConsumerRestConfig] %#v", err)
// init other consumer config
conConfigType := consumerConfig.ConfigType
for key, value := range extension.GetDefaultConfitReader() {
if conConfigType == nil {
if v, ok := conConfigType[key]; ok {
value = v
}
}
if err := extension.GetConfigReaders(value).ReadConsumerConfig(consumerConfig.fileStream); err != nil {
logger.Errorf("ReadConsumerConfig error: %#v for %s", perrors.WithStack(err), value)
}
}

metricConfig = consumerConfig.MetricConfig
applicationConfig = consumerConfig.ApplicationConfig

Expand Down Expand Up @@ -154,10 +165,19 @@ func Load() {
if providerConfig == nil {
logger.Warnf("providerConfig is nil!")
} else {
// init rest provider config
if err := ProviderRestConfigInit(providerConfig.RestConfigType); err != nil {
log.Printf("[initProviderRestConfig] %#v", err)
// init other provider config
proConfigType := providerConfig.ConfigType
for key, value := range extension.GetDefaultConfitReader() {
if proConfigType != nil {
if v, ok := proConfigType[key]; ok {
value = v
}
}
if err := extension.GetConfigReaders(value).ReadProviderConfig(providerConfig.fileStream); err != nil {
logger.Errorf("ReadProviderConfig error: %#v for %s", perrors.WithStack(err), value)
}
}

// so, you should know that the consumer's config will be override
metricConfig = providerConfig.MetricConfig
applicationConfig = providerConfig.ApplicationConfig
Expand Down
10 changes: 7 additions & 3 deletions config/consumer_config.go
Original file line number Diff line number Diff line change
Expand Up @@ -18,6 +18,7 @@
package config

import (
"bytes"
"time"
)

Expand Down Expand Up @@ -58,7 +59,7 @@ type ConsumerConfig struct {
ProtocolConf interface{} `yaml:"protocol_conf" json:"protocol_conf,omitempty" property:"protocol_conf"`
FilterConf interface{} `yaml:"filter_conf" json:"filter_conf,omitempty" property:"filter_conf" `
ShutdownConfig *ShutdownConfig `yaml:"shutdown_conf" json:"shutdown_conf,omitempty" property:"shutdown_conf" `
RestConfigType string `default:"default" yaml:"rest_config_type" json:"rest_config_type,omitempty" property:"rest_config_type"`
ConfigType map[string]string `yaml:"config_type" json:"config_type,omitempty" property:"config_type"`
}

// UnmarshalYAML ...
Expand Down Expand Up @@ -89,10 +90,11 @@ func ConsumerInit(confConFile string) error {
return perrors.Errorf("application configure(consumer) file name is nil")
}
consumerConfig = &ConsumerConfig{}
err := yaml.UnmarshalYMLConfig(confConFile, consumerConfig)
fileStream, err := yaml.UnmarshalYMLConfig(confConFile, consumerConfig)
if err != nil {
return perrors.Errorf("unmarshalYmlConfig error %v", perrors.WithStack(err))
}
consumerConfig.fileStream = bytes.NewBuffer(fileStream)
//set method interfaceId & interfaceName
for k, v := range consumerConfig.References {
//set id for reference
Expand All @@ -116,6 +118,7 @@ func ConsumerInit(confConFile string) error {
}
}
logger.Debugf("consumer config{%#v}\n", consumerConfig)

return nil
}

Expand All @@ -139,5 +142,6 @@ func configCenterRefreshConsumer() error {
return perrors.WithMessagef(err, "time.ParseDuration(Connect_Timeout{%#v})", consumerConfig.Connect_Timeout)
}
}
return err

return nil
}
4 changes: 3 additions & 1 deletion config/generic_service.go
Original file line number Diff line number Diff line change
Expand Up @@ -17,9 +17,11 @@

package config

import "context"

// GenericService ...
type GenericService struct {
Invoke func(req []interface{}) (interface{}, error) `dubbo:"$invoke"`
Invoke func(ctx context.Context, req []interface{}) (interface{}, error) `dubbo:"$invoke"`
referenceStr string
}

Expand Down
9 changes: 9 additions & 0 deletions config/interfaces/config_reader.go
Original file line number Diff line number Diff line change
@@ -0,0 +1,9 @@
package interfaces

import "bytes"

// ConfigReader
type ConfigReader interface {
ReadConsumerConfig(reader *bytes.Buffer) error
ReadProviderConfig(reader *bytes.Buffer) error
}
10 changes: 8 additions & 2 deletions config/provider_config.go
Original file line number Diff line number Diff line change
Expand Up @@ -17,6 +17,10 @@

package config

import (
"bytes"
)

import (
"github.com/creasty/defaults"
perrors "github.com/pkg/errors"
Expand Down Expand Up @@ -46,7 +50,7 @@ type ProviderConfig struct {
ProtocolConf interface{} `yaml:"protocol_conf" json:"protocol_conf,omitempty" property:"protocol_conf" `
FilterConf interface{} `yaml:"filter_conf" json:"filter_conf,omitempty" property:"filter_conf" `
ShutdownConfig *ShutdownConfig `yaml:"shutdown_conf" json:"shutdown_conf,omitempty" property:"shutdown_conf" `
RestConfigType string `default:"default" yaml:"rest_config_type" json:"rest_config_type,omitempty" property:"rest_config_type"`
ConfigType map[string]string `yaml:"config_type" json:"config_type,omitempty" property:"config_type"`
}

// UnmarshalYAML ...
Expand Down Expand Up @@ -77,10 +81,12 @@ func ProviderInit(confProFile string) error {
return perrors.Errorf("application configure(provider) file name is nil")
}
providerConfig = &ProviderConfig{}
err := yaml.UnmarshalYMLConfig(confProFile, providerConfig)
fileStream, err := yaml.UnmarshalYMLConfig(confProFile, providerConfig)
if err != nil {
return perrors.Errorf("unmarshalYmlConfig error %v", perrors.WithStack(err))
}

providerConfig.fileStream = bytes.NewBuffer(fileStream)
//set method interfaceId & interfaceName
for k, v := range providerConfig.Services {
//set id for reference
Expand Down
83 changes: 0 additions & 83 deletions config/rest/config_reader/reader_impl/default_config_reader.go

This file was deleted.

Loading