Skip to content

Commit

Permalink
ftr: triple tracing (#1596)
Browse files Browse the repository at this point in the history
* ftr: triple tracing

* fix: if-else to switch
  • Loading branch information
LaurenceLiZhixin committed Nov 19, 2021
1 parent cc201e9 commit 5c115cb
Show file tree
Hide file tree
Showing 12 changed files with 164 additions and 10 deletions.
2 changes: 2 additions & 0 deletions common/constant/key.go
Original file line number Diff line number Diff line change
Expand Up @@ -207,6 +207,7 @@ const (
ShutdownConfigPrefix = "dubbo.shutdown"
MetadataReportPrefix = "dubbo.metadata-report"
RouterConfigPrefix = "dubbo.router"
TracingConfigPrefix = "dubbo.tracing"
LoggerConfigPrefix = "dubbo.logger"
)

Expand Down Expand Up @@ -258,6 +259,7 @@ const (

const (
TracingRemoteSpanCtx = DubboCtxKey("tracing.remote.span.ctx")
TracingConfigKey = "config.tracing"
)

// Use for router module
Expand Down
4 changes: 4 additions & 0 deletions config/config_loader.go
Original file line number Diff line number Diff line change
Expand Up @@ -166,6 +166,10 @@ func GetMetricConfig() *MetricConfig {
return rootConfig.Metric
}

func GetTracingConfig(tracingKey string) *TracingConfig {
return rootConfig.Tracing[tracingKey]
}

func GetMetadataReportConfg() *MetadataReportConfig {
return rootConfig.MetadataReport
}
Expand Down
8 changes: 8 additions & 0 deletions config/consumer_config.go
Original file line number Diff line number Diff line change
Expand Up @@ -47,6 +47,7 @@ type ConsumerConfig struct {
Check bool `yaml:"check" json:"check,omitempty" property:"check"`

References map[string]*ReferenceConfig `yaml:"references" json:"references,omitempty" property:"references"`
TracingKey string `yaml:"tracing-key" json:"tracing-key" property:"tracing-key"`

FilterConf interface{} `yaml:"filter-conf" json:"filter-conf,omitempty" property:"filter-conf"`
MaxWaitTimeForServiceDiscovery string `default:"3s" yaml:"max-wait-time-for-service-discovery" json:"max-wait-time-for-service-discovery,omitempty" property:"max-wait-time-for-service-discovery"`
Expand All @@ -67,6 +68,12 @@ func (cc *ConsumerConfig) Init(rc *RootConfig) error {
if len(cc.RegistryIDs) <= 0 {
cc.RegistryIDs = rc.getRegistryIds()
}
if cc.TracingKey == "" && len(rc.Tracing) > 0 {
for k, _ := range rc.Tracing {
cc.TracingKey = k
break
}
}
for _, reference := range cc.References {
if err := reference.Init(rc); err != nil {
return err
Expand All @@ -78,6 +85,7 @@ func (cc *ConsumerConfig) Init(rc *RootConfig) error {
if err := verify(cc); err != nil {
return err
}

cc.rootConfig = rc
return nil
}
Expand Down
8 changes: 8 additions & 0 deletions config/provider_config.go
Original file line number Diff line number Diff line change
Expand Up @@ -37,6 +37,8 @@ type ProviderConfig struct {
Register bool `yaml:"register" json:"register" property:"register"`
// RegistryIDs is registry ids list
RegistryIDs []string `yaml:"registry-ids" json:"registry-ids" property:"registry-ids"`
// TracingKey is tracing ids list
TracingKey string `yaml:"tracing-key" json:"tracing-key" property:"tracing-key"`
// Services services
Services map[string]*ServiceConfig `yaml:"services" json:"services,omitempty" property:"services"`

Expand Down Expand Up @@ -67,6 +69,12 @@ func (c *ProviderConfig) Init(rc *RootConfig) error {
if len(c.RegistryIDs) <= 0 {
c.RegistryIDs = rc.getRegistryIds()
}
if c.TracingKey == "" && len(rc.Tracing) > 0 {
for k, _ := range rc.Tracing {
c.TracingKey = k
break
}
}
for _, service := range c.Services {
if err := service.Init(rc); err != nil {
return err
Expand Down
5 changes: 5 additions & 0 deletions config/reference_config.go
Original file line number Diff line number Diff line change
Expand Up @@ -67,6 +67,7 @@ type ReferenceConfig struct {
Sticky bool `yaml:"sticky" json:"sticky,omitempty" property:"sticky"`
RequestTimeout string `yaml:"timeout" json:"timeout,omitempty" property:"timeout"`
ForceTag bool `yaml:"force.tag" json:"force.tag,omitempty" property:"force.tag"`
TracingKey string `yaml:"tracing-key" json:"tracing-key,omitempty" propertiy:"tracing-key"`

rootConfig *RootConfig
metaDataType string
Expand Down Expand Up @@ -97,6 +98,9 @@ func (rc *ReferenceConfig) Init(root *RootConfig) error {
if len(rc.RegistryIDs) <= 0 {
rc.RegistryIDs = root.Consumer.RegistryIDs
}
if rc.TracingKey == "" {
rc.TracingKey = root.Consumer.TracingKey
}
if rc.Check == nil {
rc.Check = &root.Consumer.Check
}
Expand Down Expand Up @@ -244,6 +248,7 @@ func (rc *ReferenceConfig) getURLMap() url.Values {
urlMap.Set(constant.RegistryRoleKey, strconv.Itoa(common.CONSUMER))
urlMap.Set(constant.ProvidedBy, rc.ProvidedBy)
urlMap.Set(constant.SerializationKey, rc.Serialization)
urlMap.Set(constant.TracingConfigKey, rc.TracingKey)

urlMap.Set(constant.ReleaseKey, "dubbo-golang-"+constant.Version)
urlMap.Set(constant.SideKey, (common.RoleType(common.CONSUMER)).Role())
Expand Down
8 changes: 8 additions & 0 deletions config/root_config.go
Original file line number Diff line number Diff line change
Expand Up @@ -66,6 +66,8 @@ type RootConfig struct {

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

Tracing map[string]*TracingConfig `yaml:"tracing" json:"tracing,omitempty" property:"tracing"`

// Logger log
Logger *LoggerConfig `yaml:"logger" json:"logger,omitempty" property:"logger"`

Expand Down Expand Up @@ -181,6 +183,11 @@ func (rc *RootConfig) Init() error {
if err := rc.Metric.Init(); err != nil {
return err
}
for _, t := range rc.Tracing {
if err := t.Init(); err != nil {
return err
}
}
if err := initRouterConfig(rc); err != nil {
return err
}
Expand Down Expand Up @@ -214,6 +221,7 @@ func newEmptyRootConfig() *RootConfig {
Application: NewApplicationConfigBuilder().Build(),
Registries: make(map[string]*RegistryConfig),
Protocols: make(map[string]*ProtocolConfig),
Tracing: make(map[string]*TracingConfig),
Provider: NewProviderConfigBuilder().Build(),
Consumer: NewConsumerConfigBuilder().Build(),
Metric: NewMetricConfigBuilder().Build(),
Expand Down
5 changes: 5 additions & 0 deletions config/service_config.go
Original file line number Diff line number Diff line change
Expand Up @@ -75,6 +75,7 @@ type ServiceConfig struct {
ParamSign string `yaml:"param.sign" json:"param.sign,omitempty" property:"param.sign"`
Tag string `yaml:"tag" json:"tag,omitempty" property:"tag"`
GrpcMaxMessageSize int `default:"4" yaml:"max_message_size" json:"max_message_size,omitempty"`
TracingKey string `yaml:"tracing-key" json:"tracing-key,omitempty" propertiy:"tracing-key"`

RCProtocolsMap map[string]*ProtocolConfig
RCRegistriesMap map[string]*RegistryConfig
Expand Down Expand Up @@ -120,6 +121,9 @@ func (svc *ServiceConfig) Init(rc *RootConfig) error {
svc.ProtocolIDs = append(svc.ProtocolIDs, k)
}
}
if svc.TracingKey == "" {
svc.TracingKey = rc.Provider.TracingKey
}
svc.export = true
return verify(svc)
}
Expand Down Expand Up @@ -377,6 +381,7 @@ func (svc *ServiceConfig) getUrlMap() url.Values {
urlMap.Set(constant.TPSLimitRateKey, svc.TpsLimitRate)
urlMap.Set(constant.TPSLimiterKey, svc.TpsLimiter)
urlMap.Set(constant.TPSRejectedExecutionHandlerKey, svc.TpsLimitRejectedHandler)
urlMap.Set(constant.TracingConfigKey, svc.TracingKey)

// execute limit filter
urlMap.Set(constant.ExecuteLimitKey, svc.ExecuteLimit)
Expand Down
46 changes: 46 additions & 0 deletions config/tracing_config.go
Original file line number Diff line number Diff line change
@@ -0,0 +1,46 @@
/*
* Licensed to the Apache Software Foundation (ASF) under one or more
* contributor license agreements. See the NOTICE file distributed with
* this work for additional information regarding copyright ownership.
* The ASF licenses this file to You under the Apache License, Version 2.0
* (the "License"); you may not use this file except in compliance with
* the License. You may obtain a copy of the License at
*
* http://www.apache.org/licenses/LICENSE-2.0
*
* Unless required by applicable law or agreed to in writing, software
* distributed under the License is distributed on an "AS IS" BASIS,
* WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
* See the License for the specific language governing permissions and
* limitations under the License.
*/

package config

import (
"github.com/creasty/defaults"
)

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

// TracingConfig is the configuration of the tracing.
type TracingConfig struct {
Name string `default:"jaeger" yaml:"name" json:"name,omitempty" property:"name"` // jaeger or zipkin(todo)
ServiceName string `yaml:"serviceName" json:"serviceName,omitempty" property:"serviceName"`
Address string `yaml:"address" json:"address,omitempty" property:"address"`
UseAgent bool `default:"false" yaml:"use-agent" json:"use-agent,omitempty" property:"use-agent"`
}

// Prefix dubbo.router
func (TracingConfig) Prefix() string {
return constant.TracingConfigPrefix
}

func (c *TracingConfig) Init() error {
if err := defaults.Set(c); err != nil {
return err
}
return verify(c)
}
4 changes: 2 additions & 2 deletions go.mod
Original file line number Diff line number Diff line change
Expand Up @@ -13,8 +13,8 @@ require (
github.com/creasty/defaults v1.5.2
github.com/dubbogo/go-zookeeper v1.0.3
github.com/dubbogo/gost v1.11.20-0.20211116110728-26777ca61b4a
github.com/dubbogo/grpc-go v1.42.5-triple
github.com/dubbogo/triple v1.1.3
github.com/dubbogo/grpc-go v1.42.6-triple
github.com/dubbogo/triple v1.1.5
github.com/emicklei/go-restful/v3 v3.7.1
github.com/fsnotify/fsnotify v1.5.1
github.com/ghodss/yaml v1.0.0
Expand Down
Loading

0 comments on commit 5c115cb

Please sign in to comment.