This is an automated email from the ASF dual-hosted git repository.

liujun pushed a commit to branch feature-triple
in repository https://gitbox.apache.org/repos/asf/dubbo-go.git

commit 51c1aab0b9fc1a180938167a70db9ef1ab8bf02f
Author: chickenlj <[email protected]>
AuthorDate: Wed Oct 11 19:48:55 2023 +0800

    Update global metric config to match with change in main
---
 compat.go                    |  58 +++++++++++++++++---
 config/application_config.go |   2 +-
 global/metric_config.go      | 128 +++++++++++++++++++++++++++++++++++--------
 go.mod                       |   1 +
 options.go                   |   2 +-
 5 files changed, 159 insertions(+), 32 deletions(-)

diff --git a/compat.go b/compat.go
index 19202bfee..d2e138c96 100644
--- a/compat.go
+++ b/compat.go
@@ -273,14 +273,12 @@ func compatMetricConfig(c *global.MetricConfig) 
*config.MetricConfig {
                return nil
        }
        return &config.MetricConfig{
-               Mode:               c.Mode,
-               Namespace:          c.Namespace,
-               Enable:             c.Enable,
-               Port:               c.Port,
-               Path:               c.Path,
-               PushGatewayAddress: c.PushGatewayAddress,
-               SummaryMaxAge:      c.SummaryMaxAge,
-               Protocol:           c.Protocol,
+               Enable:      c.Enable,
+               Port:        c.Port,
+               Path:        c.Path,
+               Prometheus:  compatMetricPrometheusConfig(c.Prometheus),
+               Aggregation: compatMetricAggregationConfig(c.Aggregation),
+               Protocol:    c.Protocol,
        }
 }
 
@@ -369,3 +367,47 @@ func compatTLSConfig(c *global.TLSConfig) 
*config.TLSConfig {
                TLSServerName: c.TLSServerName,
        }
 }
+
+func compatMetricAggregationConfig(a *global.AggregateConfig) 
*config.AggregateConfig {
+       if a == nil {
+               return nil
+       }
+       return &config.AggregateConfig{
+               Enabled:           a.Enabled,
+               BucketNum:         a.BucketNum,
+               TimeWindowSeconds: a.TimeWindowSeconds,
+       }
+}
+
+func compatMetricPrometheusConfig(c *global.PrometheusConfig) 
*config.PrometheusConfig {
+       if c == nil {
+               return nil
+       }
+       return &config.PrometheusConfig{
+               Exporter:    compatMetricPrometheusExporter(c.Exporter),
+               Pushgateway: compatMetricPrometheusGateway(c.Pushgateway),
+       }
+}
+
+func compatMetricPrometheusExporter(e *global.Exporter) *config.Exporter {
+       if e == nil {
+               return nil
+       }
+       return &config.Exporter{
+               Enabled: e.Enabled,
+       }
+}
+
+func compatMetricPrometheusGateway(g *global.PushgatewayConfig) 
*config.PushgatewayConfig {
+       if g == nil {
+               return nil
+       }
+       return &config.PushgatewayConfig{
+               Enabled:      g.Enabled,
+               BaseUrl:      g.BaseUrl,
+               Job:          g.Job,
+               Username:     g.Username,
+               Password:     g.Password,
+               PushInterval: g.PushInterval,
+       }
+}
diff --git a/config/application_config.go b/config/application_config.go
index 60ea32f1f..5bbdbdd3e 100644
--- a/config/application_config.go
+++ b/config/application_config.go
@@ -30,7 +30,7 @@ import (
 // ApplicationConfig is a configuration for current applicationConfig, whether 
the applicationConfig is a provider or a consumer
 type ApplicationConfig struct {
        Organization string `default:"dubbo-go" yaml:"organization" 
json:"organization,omitempty" property:"organization"`
-       Name         string `default:"dubbo.io" yaml:"name" 
json:"name,omitempty" property:"name"`
+       Name         string `yaml:"name" json:"name,omitempty" property:"name"`
        Module       string `default:"sample" yaml:"module" 
json:"module,omitempty" property:"module"`
        Group        string `yaml:"group" json:"group,omitempty" 
property:"module"`
        Version      string `yaml:"version" json:"version,omitempty" 
property:"version"`
diff --git a/global/metric_config.go b/global/metric_config.go
index 17df20aa9..ce6124c34 100644
--- a/global/metric_config.go
+++ b/global/metric_config.go
@@ -19,14 +19,36 @@ package global
 
 // MetricConfig This is the config struct for all metrics implementation
 type MetricConfig struct {
-       Mode               string `default:"pull" yaml:"mode" 
json:"mode,omitempty" property:"mode"` // push or pull,
-       Namespace          string `default:"dubbo" yaml:"namespace" 
json:"namespace,omitempty" property:"namespace"`
-       Enable             *bool  `default:"false" yaml:"enable" 
json:"enable,omitempty" property:"enable"`
-       Port               string `default:"9090" yaml:"port" 
json:"port,omitempty" property:"port"`
-       Path               string `default:"/metrics" yaml:"path" 
json:"path,omitempty" property:"path"`
-       PushGatewayAddress string `default:"" yaml:"push-gateway-address" 
json:"push-gateway-address,omitempty" property:"push-gateway-address"`
-       SummaryMaxAge      int64  `default:"600000000000" 
yaml:"summary-max-age" json:"summary-max-age,omitempty" 
property:"summary-max-age"`
-       Protocol           string `default:"prometheus" yaml:"protocol" 
json:"protocol,omitempty" property:"protocol"`
+       Enable      *bool             `default:"false" yaml:"enable" 
json:"enable,omitempty" property:"enable"`
+       Port        string            `default:"9090" yaml:"port" 
json:"port,omitempty" property:"port"`
+       Path        string            `default:"/metrics" yaml:"path" 
json:"path,omitempty" property:"path"`
+       Protocol    string            `default:"prometheus" yaml:"protocol" 
json:"protocol,omitempty" property:"protocol"`
+       Prometheus  *PrometheusConfig `yaml:"prometheus" json:"prometheus" 
property:"prometheus"`
+       Aggregation *AggregateConfig  `yaml:"aggregation" json:"aggregation" 
property:"aggregation"`
+}
+
+type AggregateConfig struct {
+       Enabled           *bool `default:"false" yaml:"enabled" 
json:"enabled,omitempty" property:"enabled"`
+       BucketNum         int   `default:"10" yaml:"bucket-num" 
json:"bucket-num,omitempty" property:"bucket-num"`
+       TimeWindowSeconds int   `default:"120" yaml:"time-window-seconds" 
json:"time-window-seconds,omitempty" property:"time-window-seconds"`
+}
+
+type PrometheusConfig struct {
+       Exporter    *Exporter          `yaml:"exporter" 
json:"exporter,omitempty" property:"exporter"`
+       Pushgateway *PushgatewayConfig `yaml:"pushgateway" 
json:"pushgateway,omitempty" property:"pushgateway"`
+}
+
+type Exporter struct {
+       Enabled *bool `default:"false" yaml:"enabled" json:"enabled,omitempty" 
property:"enabled"`
+}
+
+type PushgatewayConfig struct {
+       Enabled      *bool  `default:"false" yaml:"enabled" 
json:"enabled,omitempty" property:"enabled"`
+       BaseUrl      string `default:"" yaml:"base-url" 
json:"base-url,omitempty" property:"base-url"`
+       Job          string `default:"default_dubbo_job" yaml:"job" 
json:"job,omitempty" property:"job"`
+       Username     string `default:"" yaml:"username" 
json:"username,omitempty" property:"username"`
+       Password     string `default:"" yaml:"password" 
json:"password,omitempty" property:"password"`
+       PushInterval int    `default:"30" yaml:"push-interval" 
json:"push-interval,omitempty" property:"push-interval"`
 }
 
 func DefaultMetricConfig() *MetricConfig {
@@ -34,47 +56,109 @@ func DefaultMetricConfig() *MetricConfig {
        return &MetricConfig{}
 }
 
+func defaultPrometheusConfig() *PrometheusConfig {
+       return &PrometheusConfig{Exporter: &Exporter{}, Pushgateway: 
&PushgatewayConfig{}}
+}
+
 type MetricOption func(*MetricConfig)
 
-func WithMetric_Mode(mode string) MetricOption {
+func WithMetric_AggregateEnabled() MetricOption {
        return func(cfg *MetricConfig) {
-               cfg.Mode = mode
+               if cfg.Aggregation == nil {
+                       cfg.Aggregation = &AggregateConfig{}
+               }
+               enabled := true
+               cfg.Aggregation.Enabled = &enabled
        }
 }
 
-func WithMetric_Namespace(namespace string) MetricOption {
+func WithMetric_AggregateBucketNum(num int) MetricOption {
        return func(cfg *MetricConfig) {
-               cfg.Namespace = namespace
+               if cfg.Aggregation == nil {
+                       cfg.Aggregation = &AggregateConfig{}
+               }
+               cfg.Aggregation.BucketNum = num
        }
 }
 
-func WithMetric_Enable(enable bool) MetricOption {
+func WithMetric_AggregateTimeWindowSeconds(seconds int) MetricOption {
        return func(cfg *MetricConfig) {
-               cfg.Enable = &enable
+               if cfg.Aggregation == nil {
+                       cfg.Aggregation = &AggregateConfig{}
+               }
+               cfg.Aggregation.TimeWindowSeconds = seconds
        }
 }
 
-func WithMetric_Port(port string) MetricOption {
+func WithMetric_PrometheusEnabled() MetricOption {
        return func(cfg *MetricConfig) {
-               cfg.Port = port
+               if cfg.Prometheus == nil {
+                       cfg.Prometheus.Exporter = &Exporter{}
+               }
+               enabled := true
+               cfg.Prometheus.Exporter.Enabled = &enabled
        }
 }
 
-func WithMetric_Path(path string) MetricOption {
+func WithMetric_PrometheusGatewayUrl(url string) MetricOption {
        return func(cfg *MetricConfig) {
-               cfg.Path = path
+               if cfg.Prometheus == nil {
+                       cfg.Prometheus = defaultPrometheusConfig()
+               }
+               cfg.Prometheus.Pushgateway.BaseUrl = url
        }
 }
 
-func WithMetric_PushGatewayAddress(address string) MetricOption {
+func WithMetric_PrometheusGatewayJob(job string) MetricOption {
        return func(cfg *MetricConfig) {
-               cfg.PushGatewayAddress = address
+               if cfg.Prometheus == nil {
+                       cfg.Prometheus = defaultPrometheusConfig()
+               }
+               cfg.Prometheus.Pushgateway.Job = job
        }
 }
 
-func WithMetric_SummaryMaxAge(age int64) MetricOption {
+func WithMetric_PrometheusGatewayUsername(username string) MetricOption {
        return func(cfg *MetricConfig) {
-               cfg.SummaryMaxAge = age
+               if cfg.Prometheus == nil {
+                       cfg.Prometheus = defaultPrometheusConfig()
+               }
+               cfg.Prometheus.Pushgateway.Username = username
+       }
+}
+
+func WithMetric_PrometheusGatewayPassword(password string) MetricOption {
+       return func(cfg *MetricConfig) {
+               if cfg.Prometheus == nil {
+                       cfg.Prometheus = defaultPrometheusConfig()
+               }
+               cfg.Prometheus.Pushgateway.Password = password
+       }
+}
+func WithMetric_PrometheusGatewayInterval(interval int) MetricOption {
+       return func(cfg *MetricConfig) {
+               if cfg.Prometheus == nil {
+                       cfg.Prometheus = defaultPrometheusConfig()
+               }
+               cfg.Prometheus.Pushgateway.PushInterval = interval
+       }
+}
+
+func WithMetric_Enable(enable bool) MetricOption {
+       return func(cfg *MetricConfig) {
+               cfg.Enable = &enable
+       }
+}
+
+func WithMetric_Port(port string) MetricOption {
+       return func(cfg *MetricConfig) {
+               cfg.Port = port
+       }
+}
+
+func WithMetric_Path(path string) MetricOption {
+       return func(cfg *MetricConfig) {
+               cfg.Path = path
        }
 }
 
diff --git a/go.mod b/go.mod
index 6c534697d..e64da0801 100644
--- a/go.mod
+++ b/go.mod
@@ -70,6 +70,7 @@ require (
        go.uber.org/atomic v1.10.0
        go.uber.org/multierr v1.8.0 // indirect
        go.uber.org/zap v1.21.0
+       golang.org/x/net v0.8.0
        golang.org/x/oauth2 v0.6.0 // indirect
        google.golang.org/genproto v0.0.0-20221227171554-f9683d7f8bef
        google.golang.org/grpc v1.52.0
diff --git a/options.go b/options.go
index 51e9b2df0..b47173202 100644
--- a/options.go
+++ b/options.go
@@ -126,7 +126,7 @@ func (rc *InstanceOptions) init(opts ...InstanceOption) 
error {
        if err := rcCompat.MetadataReport.Init(rcCompat); err != nil {
                return err
        }
-       if err := rcCompat.Metric.Init(); err != nil {
+       if err := rcCompat.Metric.Init(rcCompat); err != nil {
                return err
        }
        for _, t := range rcCompat.Tracing {

Reply via email to