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

refactor: simplify configuration when enable metrics #2408

Merged
merged 2 commits into from
Sep 4, 2023
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
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: 1 addition & 1 deletion common/constant/default.go
Original file line number Diff line number Diff line change
Expand Up @@ -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
Expand Down
7 changes: 7 additions & 0 deletions config/reference_config.go
Original file line number Diff line number Diff line change
Expand Up @@ -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"`
}

Expand Down Expand Up @@ -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
}
Expand Down Expand Up @@ -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 {
Expand Down
7 changes: 7 additions & 0 deletions config/service_config.go
Original file line number Diff line number Diff line change
Expand Up @@ -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
Expand Down Expand Up @@ -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)
Expand Down Expand Up @@ -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
Expand Down
2 changes: 1 addition & 1 deletion config/service_config_test.go
Original file line number Diff line number Diff line change
Expand Up @@ -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) {
Expand Down
Loading