This is an automated email from the ASF dual-hosted git repository.
liujun pushed a commit to branch main
in repository https://gitbox.apache.org/repos/asf/dubbo-go.git
The following commit(s) were added to refs/heads/main by this push:
new da40230e3 refactor: change metric config to url like other module
(#2396)
da40230e3 is described below
commit da40230e3bf8530801d4dbfcf32719f02d5a67e1
Author: foghost <[email protected]>
AuthorDate: Sat Sep 2 10:56:50 2023 +0800
refactor: change metric config to url like other module (#2396)
---
common/constant/key.go | 25 +++++++--------
common/constant/metric.go | 62 ++++++++++++++++++++++++++++++++++++++
config/metric_config.go | 24 +++++++++++++--
config/metric_config_test.go | 2 +-
config/root_config.go | 2 +-
metrics/api.go | 24 +++++++++------
metrics/app_info/collector.go | 3 +-
metrics/common.go | 32 ++++++++++----------
metrics/config_center/collector.go | 5 +--
metrics/metadata/collector.go | 3 +-
metrics/prometheus/registry.go | 4 ++-
metrics/registry/collector.go | 3 +-
metrics/rpc/collector.go | 28 ++++++++---------
metrics/rpc/constant.go | 37 -----------------------
metrics/rpc/util.go | 19 ++++++------
15 files changed, 164 insertions(+), 109 deletions(-)
diff --git a/common/constant/key.go b/common/constant/key.go
index 0db06c01d..f20052878 100644
--- a/common/constant/key.go
+++ b/common/constant/key.go
@@ -176,10 +176,6 @@ const (
const (
ApplicationKey = "application"
- ApplicationNameKey = "application_name"
- ApplicationVersionKey = "application_version"
- HostnameKey = "hostname"
- IpKey = "ip"
OrganizationKey = "organization"
NameKey = "name"
ModuleKey = "module"
@@ -198,10 +194,6 @@ const (
ProvidersCategory = "providers"
RouterKey = "router"
ExportKey = "export"
- GitCommitIdKey = "git_commit_id"
- ConfigCenterKey = "config_center"
- ChangeTypeKey = "change_type"
- KeyKey = "key"
)
// config center keys
@@ -412,10 +404,19 @@ const (
// metrics key
const (
- MetricsRpc = "dubbo.metrics.rpc"
- MetricsRegistry = "dubbo.metrics.registry"
- MetricsMetadata = "dubbo.metrics.metadata"
- MetricApp = "dubbo.metrics.app"
+ AggregationEnabledKey = "aggregation.enabled"
+ AggregationBucketNumKey = "aggregation.bucket.num"
+ AggregationTimeWindowSecondsKey = "aggregation.time.window.seconds"
+ HistogramEnabledKey = "histogram.enabled"
+ PrometheusExporterEnabledKey = "prometheus.exporter.enabled"
+ PrometheusExporterMetricsPortKey =
"prometheus.exporter.metrics.port"
+ PrometheusExporterMetricsPathKey =
"prometheus.exporter.metrics.path"
+ PrometheusPushgatewayEnabledKey = "prometheus.pushgateway.enabled"
+ PrometheusPushgatewayBaseUrlKey = "prometheus.pushgateway.base.url"
+ PrometheusPushgatewayUsernameKey = "prometheus.pushgateway.username"
+ PrometheusPushgatewayPasswordKey = "prometheus.pushgateway.password"
+ PrometheusPushgatewayPushIntervalKey =
"prometheus.pushgateway.push.interval"
+ PrometheusPushgatewayJobKey = "prometheus.pushgateway.job"
)
// default meta cache config
diff --git a/common/constant/metric.go b/common/constant/metric.go
new file mode 100644
index 000000000..4b35721eb
--- /dev/null
+++ b/common/constant/metric.go
@@ -0,0 +1,62 @@
+/*
+ * 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 constant
+
+// metrics type
+const (
+ MetricsRegistry = "dubbo.metrics.registry"
+ MetricsMetadata = "dubbo.metrics.metadata"
+ MetricsApp = "dubbo.metrics.app"
+ MetricsConfigCenter = "dubbo.metrics.configCenter"
+ MetricsRpc = "dubbo.metrics.rpc"
+)
+
+const (
+ TagApplicationName = "application_name"
+ TagApplicationVersion = "application_version"
+ TagHostname = "hostname"
+ TagIp = "ip"
+ TagGitCommitId = "git_commit_id"
+ TagConfigCenter = "config_center"
+ TagChangeType = "change_type"
+ TagKey = "key"
+ TagPid = "pid"
+ TagInterface = "interface"
+ TagMethod = "method"
+ TagGroup = "group"
+ TagVersion = "version"
+ TagErrorCode = "error"
+)
+const (
+ MetricNamespace = "dubbo"
+ ProtocolPrometheus = "prometheus"
+ ProtocolDefault = ProtocolPrometheus
+ AggregationCollectorKey = "aggregation"
+ AggregationDefaultBucketNum = 10
+ AggregationDefaultTimeWindowSeconds = 120
+ PrometheusDefaultMetricsPath = "/metrics"
+ PrometheusDefaultMetricsPort = "9090"
+ PrometheusDefaultPushInterval = 30
+ PrometheusDefaultJobName = "default_dubbo_job"
+ MetricFilterStartTime = "metric_filter_start_time"
+)
+
+const (
+ SideProvider = "provider"
+ SideConsumer = "consumer"
+)
diff --git a/config/metric_config.go b/config/metric_config.go
index a6b874987..b0e45d06a 100644
--- a/config/metric_config.go
+++ b/config/metric_config.go
@@ -17,6 +17,10 @@
package config
+import (
+ "strconv"
+)
+
import (
"github.com/creasty/defaults"
@@ -26,6 +30,8 @@ import (
)
import (
+ "dubbo.apache.org/dubbo-go/v3/common"
+ "dubbo.apache.org/dubbo-go/v3/common/constant"
"dubbo.apache.org/dubbo-go/v3/common/extension"
"dubbo.apache.org/dubbo-go/v3/metrics"
)
@@ -40,6 +46,7 @@ type MetricConfig struct {
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"`
+ rootConfig *RootConfig
}
func (mc *MetricConfig) ToReporterConfig() *metrics.ReporterConfig {
@@ -60,7 +67,7 @@ func (mc *MetricConfig) ToReporterConfig()
*metrics.ReporterConfig {
return defaultMetricsReportConfig
}
-func (mc *MetricConfig) Init() error {
+func (mc *MetricConfig) Init(rc *RootConfig) error {
if mc == nil {
return errors.New("metrics config is null")
}
@@ -70,10 +77,10 @@ func (mc *MetricConfig) Init() error {
if err := verify(mc); err != nil {
return err
}
- metrics.InitAppInfo(GetRootConfig().Application.Name,
GetRootConfig().Application.Version)
+ mc.rootConfig = rc
config := mc.ToReporterConfig()
extension.GetMetricReporter(mc.Protocol, config)
- metrics.Init(config)
+ metrics.Init(mc.toURL())
return nil
}
@@ -100,3 +107,14 @@ func (mc *MetricConfig)
DynamicUpdateProperties(newMetricConfig *MetricConfig) {
}
}
}
+
+//
prometheus://localhost:9090?&histogram.enabled=false&prometheus.exporter.enabled=false
+func (mc *MetricConfig) toURL() *common.URL {
+ url, _ := common.NewURL("localhost", common.WithProtocol(mc.Protocol))
+ url.SetParam(constant.PrometheusExporterEnabledKey,
strconv.FormatBool(*mc.Enable))
+ url.SetParam(constant.PrometheusExporterMetricsPortKey, mc.Port)
+ url.SetParam(constant.PrometheusExporterMetricsPathKey, mc.Path)
+ url.SetParam(constant.ApplicationKey, mc.rootConfig.Application.Name)
+ url.SetParam(constant.AppVersionKey, mc.rootConfig.Application.Version)
+ return url
+}
diff --git a/config/metric_config_test.go b/config/metric_config_test.go
index 14804b3c7..70dce11b1 100644
--- a/config/metric_config_test.go
+++ b/config/metric_config_test.go
@@ -27,7 +27,7 @@ import (
func TestMetricConfigBuilder(t *testing.T) {
config := NewMetricConfigBuilder().Build()
- err := config.Init()
+ err := config.Init(&RootConfig{Application: &ApplicationConfig{Name:
"dubbo", Version: "1.0.0"}})
assert.NoError(t, err)
reporterConfig := config.ToReporterConfig()
assert.Equal(t, string(reporterConfig.Mode), "pull")
diff --git a/config/root_config.go b/config/root_config.go
index 724af48ab..e578464fe 100644
--- a/config/root_config.go
+++ b/config/root_config.go
@@ -182,7 +182,7 @@ func (rc *RootConfig) Init() error {
if err := rc.Otel.Init(rc.Application); err != nil {
return err
}
- if err := rc.Metric.Init(); err != nil {
+ if err := rc.Metric.Init(rc); err != nil {
return err
}
for _, t := range rc.Tracing {
diff --git a/metrics/api.go b/metrics/api.go
index d0c7f729e..6a1f51907 100644
--- a/metrics/api.go
+++ b/metrics/api.go
@@ -27,6 +27,8 @@ import (
)
import (
+ "dubbo.apache.org/dubbo-go/v3/common"
+ "dubbo.apache.org/dubbo-go/v3/common/constant"
"dubbo.apache.org/dubbo-go/v3/metrics/util/aggregate"
)
@@ -37,31 +39,33 @@ const (
)
var (
- registries = make(map[string]func(*ReporterConfig) MetricRegistry)
+ registries = make(map[string]func(*common.URL) MetricRegistry)
collectors = make([]CollectorFunc, 0)
registry MetricRegistry
+ once sync.Once
)
// CollectorFunc used to extend more indicators
-type CollectorFunc func(MetricRegistry, *ReporterConfig)
+type CollectorFunc func(MetricRegistry, *common.URL)
// Init Metrics module
-func Init(config *ReporterConfig) {
- if config.Enable {
+func Init(url *common.URL) {
+ once.Do(func() {
+ InitAppInfo(url.GetParam(constant.ApplicationKey, ""),
url.GetParam(constant.AppVersionKey, ""))
// default protocol is already set in metricConfig
- regFunc, ok := registries[config.Protocol]
+ regFunc, ok := registries[url.Protocol]
if ok {
- registry = regFunc(config)
+ registry = regFunc(url)
for _, co := range collectors {
- co(registry, config)
+ co(registry, url)
}
registry.Export()
}
- }
+ })
}
// SetRegistry extend more MetricRegistry, default PrometheusRegistry
-func SetRegistry(name string, v func(*ReporterConfig) MetricRegistry) {
+func SetRegistry(name string, v func(*common.URL) MetricRegistry) {
registries[name] = v
}
@@ -93,7 +97,7 @@ type RtOpts struct {
// rs []MetricRegistry
// }
-// Type metric type, save with micrometer
+// Type metric type, same with micrometer
type Type uint8 // TODO check if Type is is useful
const (
diff --git a/metrics/app_info/collector.go b/metrics/app_info/collector.go
index a2bae022f..98abeb409 100644
--- a/metrics/app_info/collector.go
+++ b/metrics/app_info/collector.go
@@ -18,6 +18,7 @@
package app_info
import (
+ "dubbo.apache.org/dubbo-go/v3/common"
"dubbo.apache.org/dubbo-go/v3/metrics"
)
@@ -29,7 +30,7 @@ import (
var info = metrics.NewMetricKey("dubbo_application_info_total", "Total
Application Info") // Total Application Info include application
namećversion etc
func init() {
- metrics.AddCollector("application_info", func(mr
metrics.MetricRegistry, config *metrics.ReporterConfig) {
+ metrics.AddCollector("application_info", func(mr
metrics.MetricRegistry, _ *common.URL) {
mr.Counter(&metrics.MetricId{Name: info.Name, Desc: info.Desc,
Tags: metrics.GetApplicationLevel().Tags()}).Inc()
})
}
diff --git a/metrics/common.go b/metrics/common.go
index 3dbe51bd1..8d8562e86 100644
--- a/metrics/common.go
+++ b/metrics/common.go
@@ -64,11 +64,11 @@ func GetApplicationLevel() *ApplicationMetricLevel {
func (m *ApplicationMetricLevel) Tags() map[string]string {
tags := make(map[string]string)
- tags[constant.IpKey] = m.Ip
- tags[constant.HostnameKey] = m.HostName
- tags[constant.ApplicationNameKey] = m.ApplicationName
- tags[constant.ApplicationVersionKey] = m.Version
- tags[constant.GitCommitIdKey] = m.GitCommitId
+ tags[constant.TagIp] = m.Ip
+ tags[constant.TagHostname] = m.HostName
+ tags[constant.TagApplicationName] = m.ApplicationName
+ tags[constant.TagApplicationVersion] = m.Version
+ tags[constant.TagGitCommitId] = m.GitCommitId
return tags
}
@@ -83,7 +83,7 @@ func NewServiceMetric(interfaceName string)
*ServiceMetricLevel {
func (m ServiceMetricLevel) Tags() map[string]string {
tags := m.ApplicationMetricLevel.Tags()
- tags[constant.InterfaceKey] = m.Interface
+ tags[constant.TagInterface] = m.Interface
return tags
}
@@ -96,9 +96,9 @@ type MethodMetricLevel struct {
func (m MethodMetricLevel) Tags() map[string]string {
tags := m.ServiceMetricLevel.Tags()
- tags[constant.MethodKey] = m.Method
- tags[constant.GroupKey] = m.Group
- tags[constant.VersionKey] = m.Version
+ tags[constant.TagMethod] = m.Method
+ tags[constant.TagGroup] = m.Group
+ tags[constant.TagVersion] = m.Version
return tags
}
@@ -126,12 +126,12 @@ func NewConfigCenterLevel(key string, group string,
configCenter string, changeT
func (l ConfigCenterLevel) Tags() map[string]string {
tags := make(map[string]string)
- tags[constant.ApplicationKey] = l.ApplicationName
- tags[constant.IpKey] = l.Ip
- tags[constant.HostnameKey] = l.HostName
- tags[constant.KeyKey] = l.Key
- tags[constant.GroupKey] = l.Group
- tags[constant.ConfigCenterKey] = l.ConfigCenter
- tags[constant.ChangeTypeKey] = l.ChangeType
+ tags[constant.TagApplicationName] = l.ApplicationName
+ tags[constant.TagIp] = l.Ip
+ tags[constant.TagHostname] = l.HostName
+ tags[constant.TagKey] = l.Key
+ tags[constant.TagGroup] = l.Group
+ tags[constant.TagConfigCenter] = l.ConfigCenter
+ tags[constant.TagChangeType] = l.ChangeType
return tags
}
diff --git a/metrics/config_center/collector.go
b/metrics/config_center/collector.go
index 723650188..9ae551f0e 100644
--- a/metrics/config_center/collector.go
+++ b/metrics/config_center/collector.go
@@ -18,18 +18,19 @@
package metrics
import (
+ "dubbo.apache.org/dubbo-go/v3/common"
"dubbo.apache.org/dubbo-go/v3/common/constant"
"dubbo.apache.org/dubbo-go/v3/metrics"
"dubbo.apache.org/dubbo-go/v3/remoting"
)
-const eventType = constant.MetricApp
+const eventType = constant.MetricsConfigCenter
var ch = make(chan metrics.MetricsEvent, 10)
var info = metrics.NewMetricKey("dubbo_configcenter_total", "Config Changed
Total")
func init() {
- metrics.AddCollector("application_info", func(mr
metrics.MetricRegistry, config *metrics.ReporterConfig) {
+ metrics.AddCollector("config_center", func(mr metrics.MetricRegistry, _
*common.URL) {
c := &configCenterCollector{r: mr}
c.start()
})
diff --git a/metrics/metadata/collector.go b/metrics/metadata/collector.go
index 23921242f..7125fb1f1 100644
--- a/metrics/metadata/collector.go
+++ b/metrics/metadata/collector.go
@@ -22,6 +22,7 @@ import (
)
import (
+ "dubbo.apache.org/dubbo-go/v3/common"
"dubbo.apache.org/dubbo-go/v3/common/constant"
"dubbo.apache.org/dubbo-go/v3/metrics"
)
@@ -31,7 +32,7 @@ const eventType = constant.MetricsMetadata
var ch = make(chan metrics.MetricsEvent, 10)
func init() {
- metrics.AddCollector("metadata", func(mr metrics.MetricRegistry, rc
*metrics.ReporterConfig) {
+ metrics.AddCollector("metadata", func(mr metrics.MetricRegistry, _
*common.URL) {
l := &MetadataMetricCollector{metrics.BaseCollector{R: mr}}
l.start()
})
diff --git a/metrics/prometheus/registry.go b/metrics/prometheus/registry.go
index 144a3a059..2a4c71243 100644
--- a/metrics/prometheus/registry.go
+++ b/metrics/prometheus/registry.go
@@ -29,11 +29,13 @@ import (
)
import (
+ "dubbo.apache.org/dubbo-go/v3/common"
+ "dubbo.apache.org/dubbo-go/v3/common/constant"
"dubbo.apache.org/dubbo-go/v3/metrics"
)
func init() {
- metrics.SetRegistry("prometheus", func(rc *metrics.ReporterConfig)
metrics.MetricRegistry {
+ metrics.SetRegistry(constant.ProtocolPrometheus, func(url *common.URL)
metrics.MetricRegistry {
return &promMetricRegistry{r: prom.DefaultRegisterer}
})
}
diff --git a/metrics/registry/collector.go b/metrics/registry/collector.go
index fcd94b974..53a5d71b3 100644
--- a/metrics/registry/collector.go
+++ b/metrics/registry/collector.go
@@ -18,6 +18,7 @@
package registry
import (
+ "dubbo.apache.org/dubbo-go/v3/common"
"dubbo.apache.org/dubbo-go/v3/common/constant"
"dubbo.apache.org/dubbo-go/v3/metrics"
)
@@ -27,7 +28,7 @@ var (
)
func init() {
- metrics.AddCollector("registry", func(m metrics.MetricRegistry, c
*metrics.ReporterConfig) {
+ metrics.AddCollector("registry", func(m metrics.MetricRegistry, _
*common.URL) {
rc := ®istryCollector{metrics.BaseCollector{R: m}}
go rc.start()
})
diff --git a/metrics/rpc/collector.go b/metrics/rpc/collector.go
index f59779f6b..dc9fb5334 100644
--- a/metrics/rpc/collector.go
+++ b/metrics/rpc/collector.go
@@ -22,6 +22,7 @@ import (
)
import (
+ "dubbo.apache.org/dubbo-go/v3/common"
"dubbo.apache.org/dubbo-go/v3/common/constant"
"dubbo.apache.org/dubbo-go/v3/metrics"
)
@@ -32,8 +33,7 @@ var (
// init will add the rpc collectorFunc to metrics.collectors slice, and lazy
start the rpc collector goroutine
func init() {
- var collectorFunc metrics.CollectorFunc
- collectorFunc = func(registry metrics.MetricRegistry, c
*metrics.ReporterConfig) {
+ collectorFunc := func(registry metrics.MetricRegistry, c *common.URL) {
rc := &rpcCollector{
registry: registry,
metricSet: buildMetricSet(registry),
@@ -100,19 +100,19 @@ func (c *rpcCollector) afterInvokeHandler(event
*metricsEvent) {
func (c *rpcCollector) recordQps(role string, labels map[string]string) {
switch role {
- case providerField:
+ case constant.SideProvider:
c.metricSet.provider.qpsTotal.Record(labels)
- case consumerField:
+ case constant.SideConsumer:
c.metricSet.consumer.qpsTotal.Record(labels)
}
}
func (c *rpcCollector) incRequestsTotal(role string, labels map[string]string)
{
switch role {
- case providerField:
+ case constant.SideProvider:
c.metricSet.provider.requestsTotal.Inc(labels)
c.metricSet.provider.requestsTotalAggregate.Inc(labels)
- case consumerField:
+ case constant.SideConsumer:
c.metricSet.consumer.requestsTotal.Inc(labels)
c.metricSet.consumer.requestsTotalAggregate.Inc(labels)
}
@@ -120,28 +120,28 @@ func (c *rpcCollector) incRequestsTotal(role string,
labels map[string]string) {
func (c *rpcCollector) incRequestsProcessingTotal(role string, labels
map[string]string) {
switch role {
- case providerField:
+ case constant.SideProvider:
c.metricSet.provider.requestsProcessingTotal.Inc(labels)
- case consumerField:
+ case constant.SideConsumer:
c.metricSet.consumer.requestsProcessingTotal.Inc(labels)
}
}
func (c *rpcCollector) decRequestsProcessingTotal(role string, labels
map[string]string) {
switch role {
- case providerField:
+ case constant.SideProvider:
c.metricSet.provider.requestsProcessingTotal.Dec(labels)
- case consumerField:
+ case constant.SideConsumer:
c.metricSet.consumer.requestsProcessingTotal.Dec(labels)
}
}
func (c *rpcCollector) incRequestsSucceedTotal(role string, labels
map[string]string) {
switch role {
- case providerField:
+ case constant.SideProvider:
c.metricSet.provider.requestsSucceedTotal.Inc(labels)
c.metricSet.provider.requestsSucceedTotalAggregate.Inc(labels)
- case consumerField:
+ case constant.SideConsumer:
c.metricSet.consumer.requestsSucceedTotal.Inc(labels)
c.metricSet.consumer.requestsSucceedTotalAggregate.Inc(labels)
}
@@ -149,11 +149,11 @@ func (c *rpcCollector) incRequestsSucceedTotal(role
string, labels map[string]st
func (c *rpcCollector) reportRTMilliseconds(role string, labels
map[string]string, cost int64) {
switch role {
- case providerField:
+ case constant.SideProvider:
c.metricSet.provider.rtMilliseconds.Record(labels,
float64(cost))
c.metricSet.provider.rtMillisecondsAggregate.Record(labels,
float64(cost))
c.metricSet.provider.rtMillisecondsQuantiles.Record(labels,
float64(cost))
- case consumerField:
+ case constant.SideConsumer:
c.metricSet.consumer.rtMilliseconds.Record(labels,
float64(cost))
c.metricSet.consumer.rtMillisecondsAggregate.Record(labels,
float64(cost))
c.metricSet.consumer.rtMillisecondsQuantiles.Record(labels,
float64(cost))
diff --git a/metrics/rpc/constant.go b/metrics/rpc/constant.go
deleted file mode 100644
index 450febef1..000000000
--- a/metrics/rpc/constant.go
+++ /dev/null
@@ -1,37 +0,0 @@
-/*
- * 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 rpc
-
-import (
- "dubbo.apache.org/dubbo-go/v3/common/constant"
-)
-
-const (
- applicationNameKey = constant.ApplicationNameKey
- groupKey = constant.GroupKey
- hostnameKey = constant.HostnameKey
- interfaceKey = constant.InterfaceKey
- ipKey = constant.IpKey
- methodKey = constant.MethodKey
- versionKey = constant.VersionKey
-)
-
-const (
- providerField = "provider"
- consumerField = "consumer"
-)
diff --git a/metrics/rpc/util.go b/metrics/rpc/util.go
index 7422b390f..e8437bf95 100644
--- a/metrics/rpc/util.go
+++ b/metrics/rpc/util.go
@@ -35,22 +35,23 @@ import (
// buildLabels will build the labels for the rpc metrics
func buildLabels(url *common.URL, invocation protocol.Invocation)
map[string]string {
return map[string]string{
- applicationNameKey: url.GetParam(constant.ApplicationKey, ""),
- groupKey: url.Group(),
- hostnameKey: common.GetLocalHostName(),
- interfaceKey: url.Service(),
- ipKey: common.GetLocalIp(),
- versionKey: url.GetParam(constant.AppVersionKey, ""),
- methodKey: invocation.MethodName(),
+ constant.TagApplicationName:
url.GetParam(constant.ApplicationKey, ""),
+ constant.TagApplicationVersion:
url.GetParam(constant.AppVersionKey, ""),
+ constant.TagHostname: common.GetLocalHostName(),
+ constant.TagIp: common.GetLocalIp(),
+ constant.TagInterface: url.Service(),
+ constant.TagMethod: invocation.MethodName(),
+ constant.TagGroup: url.Group(),
+ constant.TagVersion:
url.GetParam(constant.VersionKey, ""),
}
}
// getRole will get the application role from the url
func getRole(url *common.URL) (role string) {
if isProvider(url) {
- role = providerField
+ role = constant.SideProvider
} else if isConsumer(url) {
- role = consumerField
+ role = constant.SideConsumer
} else {
logger.Warnf("The url belongs neither the consumer nor the
provider, "+
"so the invocation will be ignored. url: %s",
url.String())