Skip to content

Commit

Permalink
adapt rpc module to url config
Browse files Browse the repository at this point in the history
  • Loading branch information
FoghostCn committed Aug 31, 2023
1 parent 12c723d commit 5e75c39
Show file tree
Hide file tree
Showing 4 changed files with 29 additions and 60 deletions.
5 changes: 5 additions & 0 deletions common/constant/metric.go
Original file line number Diff line number Diff line change
Expand Up @@ -55,3 +55,8 @@ const (
PrometheusDefaultJobName = "default_dubbo_job"
MetricFilterStartTime = "metric_filter_start_time"
)

const (
SideProvider = "provider"
SideConsumer = "consumer"
)
28 changes: 14 additions & 14 deletions metrics/rpc/collector.go
Original file line number Diff line number Diff line change
Expand Up @@ -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"
)
Expand All @@ -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),
Expand Down Expand Up @@ -100,60 +100,60 @@ 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)
}
}

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)
}
}

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))
Expand Down
37 changes: 0 additions & 37 deletions metrics/rpc/constant.go

This file was deleted.

19 changes: 10 additions & 9 deletions metrics/rpc/util.go
Original file line number Diff line number Diff line change
Expand Up @@ -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())
Expand Down

0 comments on commit 5e75c39

Please sign in to comment.