Skip to content

Commit

Permalink
refactor: simplify configuration when enable metrics
Browse files Browse the repository at this point in the history
  • Loading branch information
ev1lQuark committed Aug 31, 2023
1 parent 0a02805 commit 8c24ab3
Show file tree
Hide file tree
Showing 3 changed files with 15 additions and 1 deletion.
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

0 comments on commit 8c24ab3

Please sign in to comment.