Skip to content

Commit

Permalink
fix(adasvc): do not load adaptive service filter if not set (#1735)
Browse files Browse the repository at this point in the history
* fix(adasvc): do not load adaptive service filter if not set

* style: format in dubbo style
  • Loading branch information
justxuewei authored Jan 27, 2022
1 parent bf7c407 commit b5e3805
Show file tree
Hide file tree
Showing 3 changed files with 20 additions and 5 deletions.
3 changes: 1 addition & 2 deletions common/constant/default.go
Original file line number Diff line number Diff line change
Expand Up @@ -57,8 +57,7 @@ const (
// that put the AdaptiveServiceProviderFilterKey at the end.
DefaultServiceFilters = EchoFilterKey + "," +
MetricsFilterKey + "," + TokenFilterKey + "," + AccessLogFilterKey + "," + TpsLimitFilterKey + "," +
GenericServiceFilterKey + "," + ExecuteLimitFilterKey + "," + GracefulShutdownProviderFilterKey + "," +
AdaptiveServiceProviderFilterKey
GenericServiceFilterKey + "," + ExecuteLimitFilterKey + "," + GracefulShutdownProviderFilterKey

DefaultReferenceFilters = GracefulShutdownConsumerFilterKey
)
Expand Down
12 changes: 11 additions & 1 deletion config/provider_config.go
Original file line number Diff line number Diff line change
Expand Up @@ -25,6 +25,8 @@ import (
"github.com/creasty/defaults"

tripleConstant "github.com/dubbogo/triple/pkg/common/constant"

perrors "github.com/pkg/errors"
)

import (
Expand All @@ -49,8 +51,10 @@ type ProviderConfig struct {
FilterConf interface{} `yaml:"filter_conf" json:"filter_conf,omitempty" property:"filter_conf"`
ConfigType map[string]string `yaml:"config_type" json:"config_type,omitempty" property:"config_type"`
// adaptive service
AdaptiveService bool `default:"false" yaml:"adaptive-service" json:"adaptive-service" property:"adaptive-service"`
AdaptiveServiceVerbose bool `default:"false" yaml:"adaptive-service-verbose" json:"adaptive-service-verbose" property:"adaptive-service-verbose"`
rootConfig *RootConfig

rootConfig *RootConfig
}

func (ProviderConfig) Prefix() string {
Expand Down Expand Up @@ -97,6 +101,8 @@ func (c *ProviderConfig) Init(rc *RootConfig) error {
if err := serviceConfig.Init(rc); err != nil {
return err
}

serviceConfig.adaptiveService = c.AdaptiveService
}

for k, v := range rc.Protocols {
Expand All @@ -117,6 +123,10 @@ func (c *ProviderConfig) Init(rc *RootConfig) error {
}
// enable adaptive service verbose
if c.AdaptiveServiceVerbose {
if !c.AdaptiveService {
return perrors.Errorf("The adaptive service is disabled, " +
"adaptive service verbose should be disabled either.")
}
logger.Infof("adaptive service verbose is enabled.")
logger.Debugf("debug-level info could be shown.")
aslimiter.Verbose = true
Expand Down
10 changes: 8 additions & 2 deletions config/service_config.go
Original file line number Diff line number Diff line change
Expand Up @@ -81,6 +81,7 @@ type ServiceConfig struct {
RCProtocolsMap map[string]*ProtocolConfig
RCRegistriesMap map[string]*RegistryConfig
ProxyFactoryKey string
adaptiveService bool
unexported *atomic.Bool
exported *atomic.Bool
export bool // a flag to control whether the current service should export or not
Expand Down Expand Up @@ -378,11 +379,16 @@ func (svc *ServiceConfig) getUrlMap() url.Values {
urlMap.Set(constant.EnvironmentKey, ac.Environment)

// filter
var filters string
if svc.Filter == "" {
urlMap.Set(constant.ServiceFilterKey, constant.DefaultServiceFilters)
filters = constant.DefaultServiceFilters
} else {
urlMap.Set(constant.ServiceFilterKey, svc.Filter)
filters = svc.Filter
}
if svc.adaptiveService {
filters += fmt.Sprintf(",%s", constant.AdaptiveServiceProviderFilterKey)
}
urlMap.Set(constant.ServiceFilterKey, filters)

// filter special config
urlMap.Set(constant.AccessLogFilterKey, svc.AccessLog)
Expand Down

0 comments on commit b5e3805

Please sign in to comment.