Skip to content

Commit

Permalink
feat(config): add consumer&provider&metric&metadata&remote_route&logg…
Browse files Browse the repository at this point in the history
…er config api
  • Loading branch information
dongjianhui03 committed Oct 1, 2021
1 parent a264187 commit 59ee8ea
Show file tree
Hide file tree
Showing 12 changed files with 480 additions and 27 deletions.
55 changes: 55 additions & 0 deletions config/consumer_config.go
Original file line number Diff line number Diff line change
Expand Up @@ -272,3 +272,58 @@ func WithConsumerConfigCheck(check bool) ConsumerConfigOpt {
return config
}
}

type ConsumerConfigBuilder struct {
consumerConfig *ConsumerConfig
}

func NewConsumerConfigBuilder() *ConsumerConfigBuilder {
return &ConsumerConfigBuilder{consumerConfig: &ConsumerConfig{}}
}

func (ccb *ConsumerConfigBuilder) SetFilter(filter string) *ConsumerConfigBuilder {
ccb.consumerConfig.Filter = filter
return ccb
}

func (ccb *ConsumerConfigBuilder) SetRegistry(registry []string) *ConsumerConfigBuilder {
ccb.consumerConfig.Registry = registry
return ccb
}

func (ccb *ConsumerConfigBuilder) SetRequestTimeout(requestTimeout string) *ConsumerConfigBuilder {
ccb.consumerConfig.RequestTimeout = requestTimeout
return ccb
}

func (ccb *ConsumerConfigBuilder) SetProxyFactory(proxyFactory string) *ConsumerConfigBuilder {
ccb.consumerConfig.ProxyFactory = proxyFactory
return ccb
}

func (ccb *ConsumerConfigBuilder) SetCheck(check bool) *ConsumerConfigBuilder {
ccb.consumerConfig.Check = check
return ccb
}

func (ccb *ConsumerConfigBuilder) SetReferences(references map[string]*ReferenceConfig) *ConsumerConfigBuilder {
ccb.consumerConfig.References = references
return ccb
}

func (ccb *ConsumerConfigBuilder) SetFilterConf(filterConf interface{}) *ConsumerConfigBuilder {
ccb.consumerConfig.FilterConf = filterConf
return ccb
}

func (ccb *ConsumerConfigBuilder) SetRootConfig(rootConfig *RootConfig) *ConsumerConfigBuilder {
ccb.consumerConfig.rootConfig = rootConfig
return ccb
}

func (ccb *ConsumerConfigBuilder) Build() *ConsumerConfig {
if err := ccb.consumerConfig.Init(ccb.consumerConfig.rootConfig); err != nil {
panic(err)
}
return ccb.consumerConfig
}
2 changes: 1 addition & 1 deletion config/dubbo_bootstrap.go
Original file line number Diff line number Diff line change
Expand Up @@ -110,7 +110,7 @@ func (rc *RootConfig) Init() error {
if err := rc.MetadataReport.Init(rc); err != nil {
return err
}
if err := initMetricConfig(rc); err != nil {
if err := rc.Metric.Init(); err != nil {
return err
}
if err := initRouterConfig(rc); err != nil {
Expand Down
37 changes: 37 additions & 0 deletions config/graceful_shutdown_config.go
Original file line number Diff line number Diff line change
Expand Up @@ -83,3 +83,40 @@ func (config *ShutdownConfig) GetStepTimeout() time.Duration {
}
return result
}

type ShutdownConfigBuilder struct {
shutdownConfig *ShutdownConfig
}

func NewShutDownConfigBuilder() *ShutdownConfigBuilder {
return &ShutdownConfigBuilder{shutdownConfig: &ShutdownConfig{}}
}

func (scb *ShutdownConfigBuilder) SetTimeout(timeout string) *ShutdownConfigBuilder {
scb.shutdownConfig.Timeout = timeout
return scb
}

func (scb *ShutdownConfigBuilder) SetStepTimeout(stepTimeout string) *ShutdownConfigBuilder {
scb.shutdownConfig.StepTimeout = stepTimeout
return scb
}

func (scb *ShutdownConfigBuilder) SetRejectRequestHandler(rejectRequestHandler string) *ShutdownConfigBuilder {
scb.shutdownConfig.RejectRequestHandler = rejectRequestHandler
return scb
}

func (scb *ShutdownConfigBuilder) SetRequestsFinished(requestsFinished bool) *ShutdownConfigBuilder {
scb.shutdownConfig.RequestsFinished = requestsFinished
return scb
}

func (scb *ShutdownConfigBuilder) SetRejectRequest(rejectRequest bool) *ShutdownConfigBuilder {
scb.shutdownConfig.RejectRequest = rejectRequest
return scb
}

func (scb *ShutdownConfigBuilder) Build() *ShutdownConfig {
return scb.shutdownConfig
}
26 changes: 26 additions & 0 deletions config/logger_config.go
Original file line number Diff line number Diff line change
Expand Up @@ -153,3 +153,29 @@ func (lc *LoggerConfig) getUrlMap() url.Values {
}
return urlMap
}

type LoggerConfigBuilder struct {
loggerConfig *LoggerConfig
}

// nolint
func NewLoggerConfigBuilder() *LoggerConfigBuilder {
return &LoggerConfigBuilder{loggerConfig: &LoggerConfig{}}
}

// nolint
func (lcb *LoggerConfigBuilder) SetLumberjackConfig(lumberjackConfig *lumberjack.Logger) *LoggerConfigBuilder {
lcb.loggerConfig.LumberjackConfig = lumberjackConfig
return lcb
}

// nolint
func (lcb *LoggerConfigBuilder) SetZapConfig(zapConfig ZapConfig) *LoggerConfigBuilder {
lcb.loggerConfig.ZapConfig = zapConfig
return lcb
}

// nolint
func (lcb *LoggerConfigBuilder) Build() *LoggerConfig {
return lcb.loggerConfig
}
57 changes: 57 additions & 0 deletions config/metadata_report_config.go
Original file line number Diff line number Diff line change
Expand Up @@ -122,3 +122,60 @@ func selectMetadataServiceExportedURL() *common.URL {
}
return selectedUrl
}

type MetadataReportConfigBuilder struct {
metadataReportConfig *MetadataReportConfig
}

// nolint
func NewMetadataReportConfigBuilder() *MetadataReportConfigBuilder {
return &MetadataReportConfigBuilder{metadataReportConfig: &MetadataReportConfig{}}
}

// nolint
func (mrcb *MetadataReportConfigBuilder) SetProtocol(protocol string) *MetadataReportConfigBuilder {
mrcb.metadataReportConfig.Protocol = protocol
return mrcb
}

// nolint
func (mrcb *MetadataReportConfigBuilder) SetAddress(address string) *MetadataReportConfigBuilder {
mrcb.metadataReportConfig.Address = address
return mrcb
}

// nolint
func (mrcb *MetadataReportConfigBuilder) SetUsername(username string) *MetadataReportConfigBuilder {
mrcb.metadataReportConfig.Username = username
return mrcb
}

// nolint
func (mrcb *MetadataReportConfigBuilder) SetPassword(password string) *MetadataReportConfigBuilder {
mrcb.metadataReportConfig.Password = password
return mrcb
}

// nolint
func (mrcb *MetadataReportConfigBuilder) SetTimeout(timeout string) *MetadataReportConfigBuilder {
mrcb.metadataReportConfig.Timeout = timeout
return mrcb
}

// nolint
func (mrcb *MetadataReportConfigBuilder) SetGroup(group string) *MetadataReportConfigBuilder {
mrcb.metadataReportConfig.Group = group
return mrcb
}

// nolint
func (mrcb *MetadataReportConfigBuilder) SetMetadataType(metadataType string) *MetadataReportConfigBuilder {
mrcb.metadataReportConfig.MetadataType = metadataType
return mrcb
}

// nolint
func (mrcb *MetadataReportConfigBuilder) Build() *MetadataReportConfig {
// TODO Init
return mrcb.metadataReportConfig
}
57 changes: 53 additions & 4 deletions config/metric_config.go
Original file line number Diff line number Diff line change
Expand Up @@ -19,21 +19,70 @@ package config

var defaultHistogramBucket = []float64{10, 50, 100, 200, 500, 1000, 10000}

// This is the config struct for all metrics implementation
// MetricConfig This is the config struct for all metrics implementation
type MetricConfig struct {
Reporters []string `yaml:"reporters" json:"reporters,omitempty"`
Reporters []string `yaml:"reporters" json:"reporters,omitempty"`
// TODO s?
HistogramBucket []float64 `yaml:"histogram_bucket" json:"histogram_bucket,omitempty"`
}

func initMetricConfig(rc *RootConfig) error {
// nolint
func (mc *MetricConfig) Init() error {
return nil
}

// find the histogram bucket
// GetHistogramBucket find the histogram bucket
// if it's empty, the default value will be return
func (mc *MetricConfig) GetHistogramBucket() []float64 {
if len(mc.HistogramBucket) == 0 {
mc.HistogramBucket = defaultHistogramBucket
}
return mc.HistogramBucket
}

type MetricConfigBuilder struct {
metricConfig *MetricConfig
}

// nolint
func NewMetricConfigBuilder() *MetricConfigBuilder {
return &MetricConfigBuilder{metricConfig: &MetricConfig{}}
}

// nolint
func (mcb *MetricConfigBuilder) SetReporters(reporters []string) *MetricConfigBuilder {
mcb.metricConfig.Reporters = reporters
return mcb
}

// nolint
func (mcb *MetricConfigBuilder) AddReporter(reporter string) *MetricConfigBuilder {
if mcb.metricConfig.Reporters == nil {
mcb.metricConfig.Reporters = make([]string, 0)
}
mcb.metricConfig.Reporters = append(mcb.metricConfig.Reporters, reporter)
return mcb
}

// nolint
func (mcb *MetricConfigBuilder) SetHistogramBucket(histogramBucket []float64) *MetricConfigBuilder {
mcb.metricConfig.HistogramBucket = histogramBucket
return mcb
}

// nolint
func (mcb *MetricConfigBuilder) AddBucket(bucket float64) *MetricConfigBuilder {
if mcb.metricConfig.HistogramBucket == nil {
mcb.metricConfig.HistogramBucket = make([]float64, 0)
}
mcb.metricConfig.HistogramBucket = append(mcb.metricConfig.HistogramBucket, bucket)
return mcb
}

// nolint
func (mcb *MetricConfigBuilder) Build() *MetricConfig {
if err := mcb.metricConfig.Init(); err != nil {
panic(err)
}
return mcb.metricConfig
}
Loading

0 comments on commit 59ee8ea

Please sign in to comment.