Skip to content

Commit

Permalink
add medata and config center metrics (#2357)
Browse files Browse the repository at this point in the history
  • Loading branch information
FoghostCn authored Jul 18, 2023
1 parent 12bcf73 commit 1f4b1c8
Show file tree
Hide file tree
Showing 17 changed files with 1,103 additions and 160 deletions.
7 changes: 7 additions & 0 deletions common/constant/key.go
Original file line number Diff line number Diff line change
Expand Up @@ -177,6 +177,7 @@ const (
const (
ApplicationKey = "application"
ApplicationNameKey = "application_name"
ApplicationVersionKey = "application_version"
HostnameKey = "hostname"
IpKey = "ip"
OrganizationKey = "organization"
Expand All @@ -197,6 +198,10 @@ const (
ProvidersCategory = "providers"
RouterKey = "router"
ExportKey = "export"
GitCommitIdKey = "git_commit_id"
ConfigCenterKey = "config_center"
ChangeTypeKey = "change_type"
KeyKey = "key"
)

// config center keys
Expand Down Expand Up @@ -408,4 +413,6 @@ const (
// metrics key
const (
MetricsRegistry = "dubbo.metrics.registry"
MetricsMetadata = "dubbo.metrics.metadata"
MetricApp = "dubbo.metrics.app"
)
4 changes: 4 additions & 0 deletions config/config_center_config.go
Original file line number Diff line number Diff line change
Expand Up @@ -38,6 +38,9 @@ import (
"dubbo.apache.org/dubbo-go/v3/common/constant"
"dubbo.apache.org/dubbo-go/v3/common/extension"
"dubbo.apache.org/dubbo-go/v3/config_center"
"dubbo.apache.org/dubbo-go/v3/metrics"
metricsConfigCenter "dubbo.apache.org/dubbo-go/v3/metrics/config_center"
"dubbo.apache.org/dubbo-go/v3/remoting"
)

// CenterConfig is configuration for config center
Expand Down Expand Up @@ -146,6 +149,7 @@ func startConfigCenter(rc *RootConfig) error {
logger.Warnf("[Config Center] Dynamic config center has started, but config may not be initialized, because: %s", err)
return nil
}
defer metrics.Publish(metricsConfigCenter.NewIncMetricEvent(cc.DataId, cc.Group, remoting.EventTypeAdd, cc.Protocol))
if len(strConf) == 0 {
logger.Warnf("[Config Center] Dynamic config center has started, but got empty config with config-center configuration %+v\n"+
"Please check if your config-center config is correct.", cc)
Expand Down
9 changes: 4 additions & 5 deletions config/instance/metadata_report.go
Original file line number Diff line number Diff line change
Expand Up @@ -34,11 +34,10 @@ var (
)

func GetMetadataReportInstance() report.MetadataReport {
if instance != nil {
return instance
if instance == nil {
instance = report.NewPubMetricEventReport(GetMetadataReportByRegistryProtocol(""))
}

return GetMetadataReportByRegistryProtocol("")
return instance
}

// SetMetadataReportInstance, init metadat report instance
Expand All @@ -49,7 +48,7 @@ func SetMetadataReportInstance(selectiveUrl ...*common.URL) {
url = selectiveUrl[0]
fac := extension.GetMetadataReportFactory(url.Protocol)
if fac != nil {
instance = fac.CreateMetadataReport(url)
instance = report.NewPubMetricEventReport(fac.CreateMetadataReport(url))
}
reportUrl = url
}
Expand Down
1 change: 1 addition & 0 deletions config/metric_config.go
Original file line number Diff line number Diff line change
Expand Up @@ -69,6 +69,7 @@ func (mc *MetricConfig) Init() error {
if err := verify(mc); err != nil {
return err
}
metrics.InitAppInfo(GetRootConfig().Application.Name, GetRootConfig().Application.Version)
config := mc.ToReporterConfig()
extension.GetMetricReporter(mc.Protocol, config)
metrics.Init(config)
Expand Down
5 changes: 4 additions & 1 deletion config_center/nacos/listener.go
Original file line number Diff line number Diff line change
Expand Up @@ -31,11 +31,14 @@ import (
import (
"dubbo.apache.org/dubbo-go/v3/common/constant"
"dubbo.apache.org/dubbo-go/v3/config_center"
"dubbo.apache.org/dubbo-go/v3/metrics"
metricsConfigCenter "dubbo.apache.org/dubbo-go/v3/metrics/config_center"
"dubbo.apache.org/dubbo-go/v3/remoting"
)

func callback(listener config_center.ConfigurationListener, _, _, dataId, data string) {
func callback(listener config_center.ConfigurationListener, _, group, dataId, data string) {
listener.Process(&config_center.ConfigChangeEvent{Key: dataId, Value: data, ConfigType: remoting.EventTypeUpdate})
metrics.Publish(metricsConfigCenter.NewIncMetricEvent(dataId, group, remoting.EventTypeUpdate, metricsConfigCenter.Nacos))
}

func (n *nacosDynamicConfiguration) addListener(key string, listener config_center.ConfigurationListener) {
Expand Down
13 changes: 9 additions & 4 deletions config_center/zookeeper/listener.go
Original file line number Diff line number Diff line change
Expand Up @@ -25,6 +25,8 @@ import (
import (
"dubbo.apache.org/dubbo-go/v3/common/constant"
"dubbo.apache.org/dubbo-go/v3/config_center"
"dubbo.apache.org/dubbo-go/v3/metrics"
metricsConfigCenter "dubbo.apache.org/dubbo-go/v3/metrics/config_center"
"dubbo.apache.org/dubbo-go/v3/remoting"
"dubbo.apache.org/dubbo-go/v3/remoting/zookeeper"
)
Expand Down Expand Up @@ -73,10 +75,12 @@ func (l *CacheListener) DataChange(event remoting.Event) bool {
changeType = remoting.EventTypeDel
}

key, group := l.pathToKeyGroup(event.Path)
defer metrics.Publish(metricsConfigCenter.NewIncMetricEvent(key, group, changeType, metricsConfigCenter.Zookeeper))
if listeners, ok := l.keyListeners.Load(event.Path); ok {
for listener := range listeners.(map[config_center.ConfigurationListener]struct{}) {
listener.Process(&config_center.ConfigChangeEvent{
Key: l.pathToKey(event.Path),
Key: key,
Value: event.Content,
ConfigType: changeType,
})
Expand All @@ -86,10 +90,11 @@ func (l *CacheListener) DataChange(event remoting.Event) bool {
return false
}

func (l *CacheListener) pathToKey(path string) string {
func (l *CacheListener) pathToKeyGroup(path string) (string, string) {
if len(path) == 0 {
return path
return path, ""
}
groupKey := strings.Replace(strings.Replace(path, l.rootPath+constant.PathSeparator, "", -1), constant.PathSeparator, constant.DotSeparator, -1)
return groupKey[strings.Index(groupKey, constant.DotSeparator)+1:]
index := strings.Index(groupKey, constant.DotSeparator)
return groupKey[index+1:], groupKey[0:index]
}
1 change: 1 addition & 0 deletions go.mod
Original file line number Diff line number Diff line change
Expand Up @@ -46,6 +46,7 @@ require (
github.com/pkg/errors v0.9.1
github.com/polarismesh/polaris-go v1.3.0
github.com/prometheus/client_golang v1.12.2
github.com/prometheus/common v0.32.1
github.com/rogpeppe/go-internal v1.8.0 // indirect
github.com/sirupsen/logrus v1.7.0
github.com/stretchr/testify v1.8.2
Expand Down
Loading

0 comments on commit 1f4b1c8

Please sign in to comment.