This is an automated email from the ASF dual-hosted git repository. liujun pushed a commit to branch feature-triple in repository https://gitbox.apache.org/repos/asf/dubbo-go.git
The following commit(s) were added to refs/heads/feature-triple by this push: new 689115eeb Update metrics and tracing configs (#2463) 689115eeb is described below commit 689115eeb36606b9e470f33d5544e0e305b0fcdb Author: Ken Liu <ken.lj...@gmail.com> AuthorDate: Tue Oct 31 14:00:42 2023 +0800 Update metrics and tracing configs (#2463) --- client/options.go | 6 -- compat.go | 39 ++++++----- config/tracing_config.go | 1 + dubbo.go | 4 -- global/metric_config.go | 16 +++-- global/otel_config.go | 38 ++++++++++ metrics/options.go | 22 ++++++ options.go | 16 ++--- otel/trace/options.go | 81 +++++++++++++--------- .../internal/proto/greettriple/greet.triple.go | 3 - server/options.go | 26 ------- 11 files changed, 148 insertions(+), 104 deletions(-) diff --git a/client/options.go b/client/options.go index c4ee1130f..acf1956e9 100644 --- a/client/options.go +++ b/client/options.go @@ -354,12 +354,6 @@ func WithForce(force bool) ClientOption { } } -func WithTracingKey(tracingKey string) ClientOption { - return func(opts *ClientOptions) { - opts.Reference.TracingKey = tracingKey - } -} - func WithMeshProviderPort(port int) ClientOption { return func(opts *ClientOptions) { opts.Reference.MeshProviderPort = port diff --git a/compat.go b/compat.go index d2e138c96..936790add 100644 --- a/compat.go +++ b/compat.go @@ -40,11 +40,6 @@ func compatRootConfig(c *InstanceOptions) *config.RootConfig { regCompat[k] = compatRegistryConfig(v) } - traCompat := make(map[string]*config.TracingConfig) - for k, v := range c.Tracing { - traCompat[k] = compatTracingConfig(v) - } - return &config.RootConfig{ Application: compatApplicationConfig(c.Application), Protocols: proCompat, @@ -54,7 +49,7 @@ func compatRootConfig(c *InstanceOptions) *config.RootConfig { Provider: compatProviderConfig(c.Provider), Consumer: compatConsumerConfig(c.Consumer), Metric: compatMetricConfig(c.Metric), - Tracing: traCompat, + Otel: compatOtelConfig(c.Otel), Logger: compatLoggerConfig(c.Logger), Shutdown: compatShutdownConfig(c.Shutdown), EventDispatcherType: c.EventDispatcherType, @@ -273,24 +268,32 @@ func compatMetricConfig(c *global.MetricConfig) *config.MetricConfig { return nil } return &config.MetricConfig{ - Enable: c.Enable, - Port: c.Port, - Path: c.Path, - Prometheus: compatMetricPrometheusConfig(c.Prometheus), - Aggregation: compatMetricAggregationConfig(c.Aggregation), - Protocol: c.Protocol, + Enable: c.Enable, + Port: c.Port, + Path: c.Path, + Prometheus: compatMetricPrometheusConfig(c.Prometheus), + Aggregation: compatMetricAggregationConfig(c.Aggregation), + Protocol: c.Protocol, + EnableMetadata: c.EnableMetadata, + EnableRegistry: c.EnableRegistry, + EnableConfigCenter: c.EnableConfigCenter, + EnableRpc: c.EnableRpc, } } -func compatTracingConfig(c *global.TracingConfig) *config.TracingConfig { +func compatOtelConfig(c *global.OtelConfig) *config.OtelConfig { if c == nil { return nil } - return &config.TracingConfig{ - Name: c.Name, - ServiceName: c.ServiceName, - Address: c.Address, - UseAgent: c.UseAgent, + return &config.OtelConfig{ + TraceConfig: &config.OtelTraceConfig{ + Enable: c.TraceConfig.Enable, + Exporter: c.TraceConfig.Exporter, + Endpoint: c.TraceConfig.Endpoint, + Propagator: c.TraceConfig.Propagator, + SampleMode: c.TraceConfig.SampleMode, + SampleRatio: c.TraceConfig.SampleRatio, + }, } } diff --git a/config/tracing_config.go b/config/tracing_config.go index b79aef6cc..0150eb425 100644 --- a/config/tracing_config.go +++ b/config/tracing_config.go @@ -26,6 +26,7 @@ import ( ) // TracingConfig is the configuration of the tracing. +// It's designed to be replaced with config.OtelConfig 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"` diff --git a/dubbo.go b/dubbo.go index 6513653d5..c675959e1 100644 --- a/dubbo.go +++ b/dubbo.go @@ -105,7 +105,6 @@ func (ins *Instance) NewServer(opts ...server.ServerOption) (*server.Server, err appCfg := ins.insOpts.Application regsCfg := ins.insOpts.Registries prosCfg := ins.insOpts.Protocols - trasCfg := ins.insOpts.Tracing sdCfg := ins.insOpts.Shutdown if appCfg != nil { srvOpts = append(srvOpts, @@ -126,9 +125,6 @@ func (ins *Instance) NewServer(opts ...server.ServerOption) (*server.Server, err if prosCfg != nil { srvOpts = append(srvOpts, server.SetServer_Protocols(prosCfg)) } - if trasCfg != nil { - srvOpts = append(srvOpts, server.SetServer_Tracings(trasCfg)) - } if sdCfg != nil { srvOpts = append(srvOpts, server.SetServer_Shutdown(sdCfg)) } diff --git a/global/metric_config.go b/global/metric_config.go index eaeec7047..4bcc6b706 100644 --- a/global/metric_config.go +++ b/global/metric_config.go @@ -19,12 +19,16 @@ package global // MetricConfig This is the config struct for all metrics implementation type MetricConfig struct { - Enable *bool `default:"false" yaml:"enable" json:"enable,omitempty" property:"enable"` - Port string `default:"9090" yaml:"port" json:"port,omitempty" property:"port"` - Path string `default:"/metrics" yaml:"path" json:"path,omitempty" property:"path"` - Protocol string `default:"prometheus" yaml:"protocol" json:"protocol,omitempty" property:"protocol"` - Prometheus *PrometheusConfig `yaml:"prometheus" json:"prometheus" property:"prometheus"` - Aggregation *AggregateConfig `yaml:"aggregation" json:"aggregation" property:"aggregation"` + Enable *bool `default:"false" yaml:"enable" json:"enable,omitempty" property:"enable"` + Port string `default:"9090" yaml:"port" json:"port,omitempty" property:"port"` + Path string `default:"/metrics" yaml:"path" json:"path,omitempty" property:"path"` + Protocol string `default:"prometheus" yaml:"protocol" json:"protocol,omitempty" property:"protocol"` + Prometheus *PrometheusConfig `yaml:"prometheus" json:"prometheus" property:"prometheus"` + Aggregation *AggregateConfig `yaml:"aggregation" json:"aggregation" property:"aggregation"` + EnableMetadata *bool `default:"true" yaml:"enable-metadata" json:"enable-metadata,omitempty" property:"enable-metadata"` + EnableRegistry *bool `default:"true" yaml:"enable-registry" json:"enable-registry,omitempty" property:"enable-registry"` + EnableConfigCenter *bool `default:"true" yaml:"enable-config-center" json:"enable-config-center,omitempty" property:"enable-config-center"` + EnableRpc *bool `default:"true" yaml:"enable-rpc" json:"enable-rpc,omitempty" property:"enable-rpc"` } type AggregateConfig struct { diff --git a/global/otel_config.go b/global/otel_config.go new file mode 100644 index 000000000..c84b00821 --- /dev/null +++ b/global/otel_config.go @@ -0,0 +1,38 @@ +/* + * 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 global + +// OtelConfig is the configuration of the tracing. +type OtelConfig struct { + TraceConfig *OtelTraceConfig `yaml:"trace" json:"trace,omitempty" property:"trace"` +} + +type OtelTraceConfig struct { + Enable *bool `default:"false" yaml:"enable" json:"enable,omitempty" property:"enable"` + Exporter string `default:"stdout" yaml:"exporter" json:"exporter,omitempty" property:"exporter"` // stdout, jaeger, zipkin, otlp-http, otlp-grpc + Endpoint string `default:"" yaml:"endpoint" json:"endpoint,omitempty" property:"endpoint"` + Propagator string `default:"w3c" yaml:"propagator" json:"propagator,omitempty" property:"propagator"` // one of w3c(standard), b3(for zipkin), + SampleMode string `default:"ratio" yaml:"sample-mode" json:"sample-mode,omitempty" property:"sample-mode"` // one of always, never, ratio + SampleRatio float64 `default:"0.5" yaml:"sample-ratio" json:"sample-ratio,omitempty" property:"sample-ratio"` // [0.0, 1.0] +} + +func DefaultOtelConfig() *OtelConfig { + return &OtelConfig{ + TraceConfig: &OtelTraceConfig{}, + } +} diff --git a/metrics/options.go b/metrics/options.go index e51d56c7d..fb43a0e48 100644 --- a/metrics/options.go +++ b/metrics/options.go @@ -105,6 +105,28 @@ func WithPrometheusGatewayInterval(interval time.Duration) Option { } } +func WithConfigCenterEnabled() Option { + return func(opts *Options) { + b := true + opts.Metric.EnableConfigCenter = &b + } +} + +func WithMetadataEnabled() Option { + return func(opts *Options) { + b := true + opts.Metric.EnableMetadata = &b + } +} + +func WithRegistryEnabled() Option { + return func(opts *Options) { + b := true + opts.Metric.EnableRegistry = &b + } +} + +// WithEnabled this will enable rpc and tracing by default, config-center, metadata and registry metrics will still be in disable state. func WithEnabled() Option { return func(opts *Options) { b := true diff --git a/options.go b/options.go index ab839748c..55bc57fad 100644 --- a/options.go +++ b/options.go @@ -44,7 +44,7 @@ type InstanceOptions struct { Provider *global.ProviderConfig `yaml:"provider" json:"provider" property:"provider"` Consumer *global.ConsumerConfig `yaml:"consumer" json:"consumer" property:"consumer"` Metric *global.MetricConfig `yaml:"metrics" json:"metrics,omitempty" property:"metrics"` - Tracing map[string]*global.TracingConfig `yaml:"tracing" json:"tracing,omitempty" property:"tracing"` + Otel *global.OtelConfig `yaml:"otel" json:"otel,omitempty" property:"otel"` Logger *global.LoggerConfig `yaml:"logger" json:"logger,omitempty" property:"logger"` Shutdown *global.ShutdownConfig `yaml:"shutdown" json:"shutdown,omitempty" property:"shutdown"` // todo(DMwangnima): router feature would be supported in the future @@ -66,7 +66,7 @@ func defaultInstanceOptions() *InstanceOptions { Provider: global.DefaultProviderConfig(), Consumer: global.DefaultConsumerConfig(), Metric: global.DefaultMetricConfig(), - Tracing: make(map[string]*global.TracingConfig), + Otel: global.DefaultOtelConfig(), Logger: global.DefaultLoggerConfig(), Shutdown: global.DefaultShutdownConfig(), Custom: global.DefaultCustomConfig(), @@ -134,10 +134,8 @@ func (rc *InstanceOptions) init(opts ...InstanceOption) error { if err := rcCompat.Metric.Init(rcCompat); err != nil { return err } - for _, t := range rcCompat.Tracing { - if err := t.Init(); err != nil { - return err - } + if err := rcCompat.Otel.Init(rcCompat.Application); err != nil { + return err } routers := rcCompat.Router @@ -247,14 +245,12 @@ func WithRegistry(opts ...registry.Option) InstanceOption { } } +// WithTracing otel configuration, currently only supports tracing func WithTracing(opts ...trace.Option) InstanceOption { traceOpts := trace.NewOptions(opts...) return func(insOpts *InstanceOptions) { - if insOpts.Tracing == nil { - insOpts.Tracing = make(map[string]*global.TracingConfig) - } - insOpts.Tracing[traceOpts.ID] = traceOpts.Tracing + insOpts.Otel.TraceConfig = traceOpts.Otel.TraceConfig } } diff --git a/otel/trace/options.go b/otel/trace/options.go index 6311bf6bb..0ed054c16 100644 --- a/otel/trace/options.go +++ b/otel/trace/options.go @@ -17,22 +17,16 @@ package trace -import ( - "fmt" -) - import ( "dubbo.apache.org/dubbo-go/v3/global" ) type Options struct { - Tracing *global.TracingConfig - - ID string + Otel *global.OtelConfig } func defaultOptions() *Options { - return &Options{Tracing: &global.TracingConfig{}} + return &Options{Otel: global.DefaultOtelConfig()} } func NewOptions(opts ...Option) *Options { @@ -40,64 +34,89 @@ func NewOptions(opts ...Option) *Options { for _, opt := range opts { opt(defOpts) } + return defOpts +} + +type Option func(*Options) + +func WithEnabled() Option { + return func(opts *Options) { + b := true + opts.Otel.TraceConfig.Enable = &b + } +} - if defOpts.Tracing.Name == "" { - panic(fmt.Sprintf("Please specify the tracing system to use, eg. WithZipkin()")) +func WithStdoutExporter() Option { + return func(opts *Options) { + opts.Otel.TraceConfig.Exporter = "stdout" } - if defOpts.ID == "" { - defOpts.ID = defOpts.Tracing.Name +} + +func WithJaegerExporter() Option { + return func(opts *Options) { + opts.Otel.TraceConfig.Exporter = "jaeger" } +} - return defOpts +func WithZipkinExporter() Option { + return func(opts *Options) { + opts.Otel.TraceConfig.Exporter = "zipkin" + } } -type Option func(*Options) +func WithOtlpHttpExporter() Option { + return func(opts *Options) { + opts.Otel.TraceConfig.Exporter = "otlp-http" + } +} -func WithID(id string) Option { +func WithOtlpGrpcExporter() Option { return func(opts *Options) { - opts.ID = id + opts.Otel.TraceConfig.Exporter = "otlp-grpc" } } -func WithZipkin() Option { +// WithW3cPropagator w3c(standard) +func WithW3cPropagator() Option { return func(opts *Options) { - opts.Tracing.Name = "zipkin" + opts.Otel.TraceConfig.Propagator = "w3c" } } -func WithJaeger() Option { +// WithB3Propagator b3(for zipkin) +func WithB3Propagator() Option { return func(opts *Options) { - opts.Tracing.Name = "jaeger" + opts.Otel.TraceConfig.Propagator = "b3" } } -func WithOltp() Option { +// WithRatio only takes effect when WithRatioMode is set +func WithRatio(ratio float64) Option { return func(opts *Options) { - opts.Tracing.Name = "oltp" + opts.Otel.TraceConfig.SampleRatio = ratio } } -func WithStdout() Option { +func WithRatioMode() Option { return func(opts *Options) { - opts.Tracing.Name = "stdout" + opts.Otel.TraceConfig.Propagator = "ratio" } } -func WithServiceName(name string) Option { +func WithAlwaysMode() Option { return func(opts *Options) { - opts.Tracing.ServiceName = name + opts.Otel.TraceConfig.Propagator = "always" } } -func WithAddress(address string) Option { +func WithNeverMode() Option { return func(opts *Options) { - opts.Tracing.Address = address + opts.Otel.TraceConfig.Propagator = "never" } } -func WithUseAgent() Option { +func WithEndpoint(endpoint string) Option { return func(opts *Options) { - b := true - opts.Tracing.UseAgent = &b + opts.Otel.TraceConfig.Endpoint = endpoint } } diff --git a/protocol/triple/triple-tool/internal/proto/greettriple/greet.triple.go b/protocol/triple/triple-tool/internal/proto/greettriple/greet.triple.go index 7c16eafff..b284e07f3 100644 --- a/protocol/triple/triple-tool/internal/proto/greettriple/greet.triple.go +++ b/protocol/triple/triple-tool/internal/proto/greettriple/greet.triple.go @@ -30,9 +30,6 @@ import ( "dubbo.apache.org/dubbo-go/v3/common/constant" "dubbo.apache.org/dubbo-go/v3/protocol/triple/triple_protocol" "dubbo.apache.org/dubbo-go/v3/server" -) - -import ( proto "dubbo.apache.org/dubbo-go/v3/triple-tool/internal/proto" ) diff --git a/server/options.go b/server/options.go index 2d4004626..51a38a0f1 100644 --- a/server/options.go +++ b/server/options.go @@ -50,7 +50,6 @@ type ServerOptions struct { Application *global.ApplicationConfig Registries map[string]*global.RegistryConfig Protocols map[string]*global.ProtocolConfig - Tracings map[string]*global.TracingConfig Shutdown *global.ShutdownConfig providerCompat *config.ProviderConfig @@ -82,13 +81,6 @@ func (srvOpts *ServerOptions) init(opts ...ServerOption) error { prov.ProtocolIDs = commonCfg.TranslateIds(prov.ProtocolIDs) - if prov.TracingKey == "" && len(srvOpts.Tracings) > 0 { - for key := range srvOpts.Tracings { - prov.TracingKey = key - break - } - } - if err := commonCfg.Verify(prov); err != nil { return err } @@ -157,12 +149,6 @@ func WithServerProtocol(opts ...protocol.Option) ServerOption { } } -func WithServerTracingKey(tracingKey string) ServerOption { - return func(opts *ServerOptions) { - opts.Provider.TracingKey = tracingKey - } -} - // todo(DMwangnima): this configuration would be used by filter/hystrix // think about a more ideal way to configure func WithServerFilterConf(conf interface{}) ServerOption { @@ -204,12 +190,6 @@ func SetServer_Protocols(pros map[string]*global.ProtocolConfig) ServerOption { } } -func SetServer_Tracings(tras map[string]*global.TracingConfig) ServerOption { - return func(opts *ServerOptions) { - opts.Tracings = tras - } -} - func SetServer_Shutdown(shutdown *global.ShutdownConfig) ServerOption { return func(opts *ServerOptions) { opts.Shutdown = shutdown @@ -372,12 +352,6 @@ func WithProtocolIDs(protocolIDs []string) ServiceOption { } } -func WithTracingKey(tracingKey string) ServiceOption { - return func(cfg *ServiceOptions) { - cfg.Service.TracingKey = tracingKey - } -} - // ========== LoadBalance Strategy ========== func WithLoadBalanceConsistentHashing() ServiceOption {