This is an automated email from the ASF dual-hosted git repository.

liujun pushed a commit to branch main
in repository https://gitbox.apache.org/repos/asf/dubbo-go.git


The following commit(s) were added to refs/heads/main by this push:
     new 3d97d4c07 refactor: metrics config (#2465)
3d97d4c07 is described below

commit 3d97d4c07298566c52979891510048ebacd641d3
Author: Wang Guan <wg1024c...@gmail.com>
AuthorDate: Mon Oct 30 14:39:50 2023 +0800

    refactor: metrics config (#2465)
---
 config/metric_config.go      | 23 +++++++++--------------
 config/metric_config_test.go |  2 --
 2 files changed, 9 insertions(+), 16 deletions(-)

diff --git a/config/metric_config.go b/config/metric_config.go
index af41eb853..145200072 100644
--- a/config/metric_config.go
+++ b/config/metric_config.go
@@ -39,10 +39,9 @@ type MetricConfig struct {
        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"`
-       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"`
+       EnableMetadata     *bool             `default:"false" 
yaml:"enable-metadata" json:"enable-metadata,omitempty" 
property:"enable-metadata"`
+       EnableRegistry     *bool             `default:"false" 
yaml:"enable-registry" json:"enable-registry,omitempty" 
property:"enable-registry"`
+       EnableConfigCenter *bool             `default:"false" 
yaml:"enable-config-center" json:"enable-config-center,omitempty" 
property:"enable-config-center"`
        Prometheus         *PrometheusConfig `yaml:"prometheus" 
json:"prometheus" property:"prometheus"`
        Aggregation        *AggregateConfig  `yaml:"aggregation" 
json:"aggregation" property:"aggregation"`
        rootConfig         *RootConfig
@@ -60,7 +59,7 @@ type PrometheusConfig struct {
 }
 
 type Exporter struct {
-       Enabled *bool `default:"false" yaml:"enabled" json:"enabled,omitempty" 
property:"enabled"`
+       Enabled *bool `default:"true" yaml:"enabled" json:"enabled,omitempty" 
property:"enabled"`
 }
 
 type PushgatewayConfig struct {
@@ -93,7 +92,9 @@ func (mc *MetricConfig) Init(rc *RootConfig) error {
                return err
        }
        mc.rootConfig = rc
-       metrics.Init(mc.toURL())
+       if *mc.Enable {
+               metrics.Init(mc.toURL())
+       }
        return nil
 }
 
@@ -120,11 +121,6 @@ func (mcb *MetricConfigBuilder) 
SetConfigCenterEnabled(enabled bool) *MetricConf
        return mcb
 }
 
-func (mcb *MetricConfigBuilder) SetRpcEnabled(enabled bool) 
*MetricConfigBuilder {
-       mcb.metricConfig.EnableRpc = &enabled
-       return mcb
-}
-
 func (mcb *MetricConfigBuilder) Build() *MetricConfig {
        return mcb.metricConfig
 }
@@ -137,15 +133,14 @@ func (mc *MetricConfig) 
DynamicUpdateProperties(newMetricConfig *MetricConfig) {
 // 
prometheus://localhost:9090?&histogram.enabled=false&prometheus.exporter.enabled=false
 func (mc *MetricConfig) toURL() *common.URL {
        url, _ := common.NewURL("localhost", common.WithProtocol(mc.Protocol))
-       url.SetParam(constant.PrometheusExporterEnabledKey, 
strconv.FormatBool(*mc.Enable)) // for compatibility
        url.SetParam(constant.PrometheusExporterMetricsPortKey, mc.Port)
        url.SetParam(constant.PrometheusExporterMetricsPathKey, mc.Path)
        url.SetParam(constant.ApplicationKey, mc.rootConfig.Application.Name)
        url.SetParam(constant.AppVersionKey, mc.rootConfig.Application.Version)
+       url.SetParam(constant.RpcEnabledKey, strconv.FormatBool(*mc.Enable))
        url.SetParam(constant.MetadataEnabledKey, 
strconv.FormatBool(*mc.EnableMetadata))
        url.SetParam(constant.RegistryEnabledKey, 
strconv.FormatBool(*mc.EnableRegistry))
        url.SetParam(constant.ConfigCenterEnabledKey, 
strconv.FormatBool(*mc.EnableConfigCenter))
-       url.SetParam(constant.RpcEnabledKey, strconv.FormatBool(*mc.EnableRpc))
        if mc.Aggregation != nil {
                url.SetParam(constant.AggregationEnabledKey, 
strconv.FormatBool(*mc.Aggregation.Enabled))
                url.SetParam(constant.AggregationBucketNumKey, 
strconv.Itoa(mc.Aggregation.BucketNum))
@@ -154,7 +149,7 @@ func (mc *MetricConfig) toURL() *common.URL {
        if mc.Prometheus != nil {
                if mc.Prometheus.Exporter != nil {
                        exporter := mc.Prometheus.Exporter
-                       url.SetParam(constant.PrometheusExporterEnabledKey, 
strconv.FormatBool(*exporter.Enabled || *mc.Enable)) // for compatibility
+                       url.SetParam(constant.PrometheusExporterEnabledKey, 
strconv.FormatBool(*exporter.Enabled))
                }
                if mc.Prometheus.Pushgateway != nil {
                        pushGateWay := mc.Prometheus.Pushgateway
diff --git a/config/metric_config_test.go b/config/metric_config_test.go
index 31a0ac6b7..1dfd3af63 100644
--- a/config/metric_config_test.go
+++ b/config/metric_config_test.go
@@ -30,13 +30,11 @@ func TestMetricConfigBuilder(t *testing.T) {
                SetConfigCenterEnabled(false).
                SetMetadataEnabled(false).
                SetRegistryEnabled(false).
-               SetRpcEnabled(false).
                Build()
        enable := false
        assert.Equal(t, &MetricConfig{
                EnableConfigCenter: &enable,
                EnableMetadata:     &enable,
                EnableRegistry:     &enable,
-               EnableRpc:          &enable,
        }, config)
 }

Reply via email to