diff --git a/common/constant/default.go b/common/constant/default.go index 8f5ca5584a..a27da2f4d1 100644 --- a/common/constant/default.go +++ b/common/constant/default.go @@ -59,7 +59,7 @@ const ( // DefaultServiceFilters defines default service filters, it is highly recommended // that put the AdaptiveServiceProviderFilterKey at the end. DefaultServiceFilters = EchoFilterKey + "," + - MetricsFilterKey + "," + TokenFilterKey + "," + AccessLogFilterKey + "," + TpsLimitFilterKey + "," + + TokenFilterKey + "," + AccessLogFilterKey + "," + TpsLimitFilterKey + "," + GenericServiceFilterKey + "," + ExecuteLimitFilterKey + "," + GracefulShutdownProviderFilterKey DefaultReferenceFilters = GracefulShutdownConsumerFilterKey diff --git a/config/reference_config.go b/config/reference_config.go index 06797a8ece..64d7c53a3d 100644 --- a/config/reference_config.go +++ b/config/reference_config.go @@ -74,6 +74,7 @@ type ReferenceConfig struct { TracingKey string `yaml:"tracing-key" json:"tracing-key,omitempty" propertiy:"tracing-key"` rootConfig *RootConfig metaDataType string + metricsEnable bool MeshProviderPort int `yaml:"mesh-provider-port" json:"mesh-provider-port,omitempty" propertiy:"mesh-provider-port"` } @@ -118,6 +119,9 @@ func (rc *ReferenceConfig) Init(root *RootConfig) error { if rc.TracingKey == "" { rc.TracingKey = root.Consumer.TracingKey } + if root.Metric.Enable != nil { + rc.metricsEnable = *root.Metric.Enable + } if rc.Check == nil { rc.Check = &root.Consumer.Check } @@ -355,6 +359,9 @@ func (rc *ReferenceConfig) getURLMap() url.Values { if rc.Generic != "" { defaultReferenceFilter = constant.GenericFilterKey + "," + defaultReferenceFilter } + if rc.metricsEnable { + defaultReferenceFilter += fmt.Sprintf(",%s", constant.MetricsFilterKey) + } urlMap.Set(constant.ReferenceFilterKey, mergeValue(rc.Filter, "", defaultReferenceFilter)) for _, v := range rc.Methods { diff --git a/config/service_config.go b/config/service_config.go index 976071a2bf..1b0038ed06 100644 --- a/config/service_config.go +++ b/config/service_config.go @@ -82,6 +82,7 @@ type ServiceConfig struct { RCRegistriesMap map[string]*RegistryConfig ProxyFactoryKey string adaptiveService bool + metricsEnable bool // whether append metrics filter to filter chain unexported *atomic.Bool exported *atomic.Bool export bool // a flag to control whether the current service should export or not @@ -144,6 +145,9 @@ func (s *ServiceConfig) Init(rc *RootConfig) error { if s.TracingKey == "" { s.TracingKey = rc.Provider.TracingKey } + if rc.Metric.Enable != nil { + s.metricsEnable = *rc.Metric.Enable + } err := s.check() if err != nil { panic(err) @@ -427,6 +431,9 @@ func (s *ServiceConfig) getUrlMap() url.Values { if s.adaptiveService { filters += fmt.Sprintf(",%s", constant.AdaptiveServiceProviderFilterKey) } + if s.metricsEnable { + filters += fmt.Sprintf(",%s", constant.MetricsFilterKey) + } urlMap.Set(constant.ServiceFilterKey, filters) // filter special config diff --git a/config/service_config_test.go b/config/service_config_test.go index da6b5af0dd..4f5954acfa 100644 --- a/config/service_config_test.go +++ b/config/service_config_test.go @@ -114,7 +114,7 @@ func TestNewServiceConfigBuilder(t *testing.T) { values := serviceConfig.getUrlMap() assert.Equal(t, values.Get("methods.Say.weight"), "0") assert.Equal(t, values.Get("methods.Say.tps.limit.rate"), "") - assert.Equal(t, values.Get(constant.ServiceFilterKey), "echo,metrics,token,accesslog,tps,generic_service,execute,pshutdown") + assert.Equal(t, values.Get(constant.ServiceFilterKey), "echo,token,accesslog,tps,generic_service,execute,pshutdown") }) t.Run("Implement", func(t *testing.T) {