chickenlj commented on code in PR #2447: URL: https://github.com/apache/dubbo-go/pull/2447#discussion_r1369850409
########## metrics/options.go: ########## @@ -0,0 +1,124 @@ +/* + * Licensed to the Apache Software Foundation (ASF) under one or more + * contributor license agreements. See the NOTICE file distributed with + * this work for additional information regarding copyright ownership. + * The ASF licenses this file to You under the Apache License, Version 2.0 + * (the "License"); you may not use this file except in compliance with + * the License. You may obtain a copy of the License at + * + * http://www.apache.org/licenses/LICENSE-2.0 + * + * Unless required by applicable law or agreed to in writing, software + * distributed under the License is distributed on an "AS IS" BASIS, + * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. + * See the License for the specific language governing permissions and + * limitations under the License. + */ + +package metrics + +import ( + "time" +) + +import ( + "dubbo.apache.org/dubbo-go/v3/global" +) + +type Options struct { + Metric *global.MetricConfig +} + +func defaultOptions() *Options { + return &Options{Metric: global.DefaultMetricConfig()} +} + +func NewOptions(opts ...Option) *Options { + MetricOptions := defaultOptions() + for _, opt := range opts { + opt(MetricOptions) + } + return MetricOptions +} + +type Option func(*Options) + +func WithAggregationEnabled() Option { + return func(opts *Options) { + enabled := true + opts.Metric.Aggregation.Enabled = &enabled + } +} + +func WithAggregationBucketNum(num int) Option { + return func(opts *Options) { + opts.Metric.Aggregation.BucketNum = num + } +} + +func WithAggregationTimeWindowSeconds(seconds int) Option { + return func(opts *Options) { + opts.Metric.Aggregation.TimeWindowSeconds = seconds + } +} + +func WithPrometheus() Option { + return func(opts *Options) { + opts.Metric.Protocol = "prometheus" + } +} + +func WithPrometheusExporterEnabled() Option { + return func(opts *Options) { + enabled := true + opts.Metric.Prometheus.Exporter.Enabled = &enabled + } +} + +func WithPrometheusGatewayUrl(url string) Option { + return func(opts *Options) { + opts.Metric.Prometheus.Pushgateway.BaseUrl = url + } +} + +func WithPrometheusGatewayJob(job string) Option { + return func(opts *Options) { + opts.Metric.Prometheus.Pushgateway.Job = job + } +} + +func WithPrometheusGatewayUsername(username string) Option { + return func(opts *Options) { + opts.Metric.Prometheus.Pushgateway.Username = username + } +} + +func WithPrometheusGatewayPassword(password string) Option { + return func(opts *Options) { + opts.Metric.Prometheus.Pushgateway.Password = password + } +} +func WithPrometheusGatewayInterval(interval time.Duration) Option { + return func(opts *Options) { + opts.Metric.Prometheus.Pushgateway.PushInterval = int(interval.Seconds()) + } +} + +func WithEnabled() Option { + return func(opts *Options) { + b := true + opts.Metric.Enable = &b + } +} Review Comment: If that's the case, how about we keep `WithEnabled` and remove `WithPrometheusExporterEnabled `. -- This is an automated message from the Apache Git Service. To respond to the message, please log on to GitHub and use the URL above to go to the specific comment. To unsubscribe, e-mail: [email protected] For queries about this service, please contact Infrastructure at: [email protected] --------------------------------------------------------------------- To unsubscribe, e-mail: [email protected] For additional commands, e-mail: [email protected]
