You are viewing a plain text version of this content. The canonical link for it is here.
Posted to commits@dubbo.apache.org by al...@apache.org on 2022/05/08 10:53:22 UTC
[dubbo-go] branch 3.0 updated: Use summary type to observe p99 (#1875)
This is an automated email from the ASF dual-hosted git repository.
alexstocks pushed a commit to branch 3.0
in repository https://gitbox.apache.org/repos/asf/dubbo-go.git
The following commit(s) were added to refs/heads/3.0 by this push:
new b27ec53b7 Use summary type to observe p99 (#1875)
b27ec53b7 is described below
commit b27ec53b7babdbb94933e017885083035ce70829
Author: Alkaid <38...@users.noreply.github.com>
AuthorDate: Sun May 8 18:53:16 2022 +0800
Use summary type to observe p99 (#1875)
* use summary to observe p99
Signed-off-by: jyz0309 <45...@qq.com>
* fix var name
Signed-off-by: jyz0309 <45...@qq.com>
* format code
Signed-off-by: jyz0309 <45...@qq.com>
* change-metric-type
Signed-off-by: jyz0309 <45...@qq.com>
* format code
Signed-off-by: jyz0309 <45...@qq.com>
* rollback import change
Signed-off-by: jyz0309 <45...@qq.com>
---
config/metric_config.go | 2 ++
metrics/prometheus/reporter.go | 28 +++++++++++++++-------------
metrics/reporter.go | 4 ++++
3 files changed, 21 insertions(+), 13 deletions(-)
diff --git a/config/metric_config.go b/config/metric_config.go
index 291e4c7bc..8b8a04415 100644
--- a/config/metric_config.go
+++ b/config/metric_config.go
@@ -36,6 +36,7 @@ type MetricConfig struct {
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"`
}
func (mc *MetricConfig) ToReporterConfig() *metrics.ReporterConfig {
@@ -51,6 +52,7 @@ func (mc *MetricConfig) ToReporterConfig() *metrics.ReporterConfig {
defaultMetricsReportConfig.Port = mc.Port
defaultMetricsReportConfig.Path = mc.Path
defaultMetricsReportConfig.PushGatewayAddress = mc.PushGatewayAddress
+ defaultMetricsReportConfig.SummaryMaxAge = mc.SummaryMaxAge
return defaultMetricsReportConfig
}
diff --git a/metrics/prometheus/reporter.go b/metrics/prometheus/reporter.go
index 845f6a8fc..cee640ebd 100644
--- a/metrics/prometheus/reporter.go
+++ b/metrics/prometheus/reporter.go
@@ -77,10 +77,11 @@ func init() {
// if you want to use this feature, you need to initialize your prometheus.
// https://prometheus.io/docs/guides/go-application/
type PrometheusReporter struct {
+ reporterConfig *metrics.ReporterConfig
// report the consumer-side's rt gauge data
- consumerRTGaugeVec *prometheus.GaugeVec
+ consumerRTSummaryVec *prometheus.SummaryVec
// report the provider-side's rt gauge data
- providerRTGaugeVec *prometheus.GaugeVec
+ providerRTSummaryVec *prometheus.SummaryVec
// todo tps support
// report the consumer-side's tps gauge data
consumerTPSGaugeVec *prometheus.GaugeVec
@@ -102,11 +103,11 @@ type PrometheusReporter struct {
// or it will be ignored
func (reporter *PrometheusReporter) Report(ctx context.Context, invoker protocol.Invoker, invocation protocol.Invocation, cost time.Duration, res protocol.Result) {
url := invoker.GetURL()
- var rtVec *prometheus.GaugeVec
+ var rtVec *prometheus.SummaryVec
if isProvider(url) {
- rtVec = reporter.providerRTGaugeVec
+ rtVec = reporter.providerRTSummaryVec
} else if isConsumer(url) {
- rtVec = reporter.consumerRTGaugeVec
+ rtVec = reporter.consumerRTSummaryVec
} else {
logger.Warnf("The url belongs neither the consumer nor the provider, "+
"so the invocation will be ignored. url: %s", url.String())
@@ -121,7 +122,7 @@ func (reporter *PrometheusReporter) Report(ctx context.Context, invoker protocol
timeoutKey: url.GetParam(timeoutKey, ""),
}
costMs := cost.Nanoseconds()
- rtVec.With(labels).Set(float64(costMs))
+ rtVec.With(labels).Observe(float64(costMs))
}
func newHistogramVec(name, namespace string, labels []string) *prometheus.HistogramVec {
@@ -176,7 +177,7 @@ func newSummary(name, namespace string) prometheus.Summary {
// newSummaryVec create SummaryVec, the Namespace is dubbo
// the objectives is from my experience.
-func newSummaryVec(name, namespace string, labels []string) *prometheus.SummaryVec {
+func newSummaryVec(name, namespace string, labels []string, maxAge int64) *prometheus.SummaryVec {
return prometheus.NewSummaryVec(
prometheus.SummaryOpts{
Namespace: namespace,
@@ -189,6 +190,7 @@ func newSummaryVec(name, namespace string, labels []string) *prometheus.SummaryV
0.99: 0.001,
0.999: 0.0001,
},
+ MaxAge: time.Duration(maxAge),
},
labels,
)
@@ -212,12 +214,12 @@ func newPrometheusReporter(reporterConfig *metrics.ReporterConfig) metrics.Repor
if reporterInstance == nil {
reporterInitOnce.Do(func() {
reporterInstance = &PrometheusReporter{
- namespace: reporterConfig.Namespace,
- consumerRTGaugeVec: newGaugeVec(consumerPrefix+serviceKey+rtSuffix, reporterConfig.Namespace, labelNames),
- providerRTGaugeVec: newGaugeVec(providerPrefix+serviceKey+rtSuffix, reporterConfig.Namespace, labelNames),
+ reporterConfig: reporterConfig,
+ namespace: reporterConfig.Namespace,
+ consumerRTSummaryVec: newSummaryVec(consumerPrefix+serviceKey+rtSuffix, reporterConfig.Namespace, labelNames, reporterConfig.SummaryMaxAge),
+ providerRTSummaryVec: newSummaryVec(providerPrefix+serviceKey+rtSuffix, reporterConfig.Namespace, labelNames, reporterConfig.SummaryMaxAge),
}
-
- prom.DefaultRegisterer.MustRegister(reporterInstance.consumerRTGaugeVec, reporterInstance.providerRTGaugeVec)
+ prom.DefaultRegisterer.MustRegister(reporterInstance.consumerRTSummaryVec, reporterInstance.providerRTSummaryVec)
metricsExporter, err := ocprom.NewExporter(ocprom.Options{
Registry: prom.DefaultRegisterer.(*prom.Registry),
})
@@ -328,7 +330,7 @@ func (reporter *PrometheusReporter) incSummary(summaryName string, toSetValue fl
for k, _ := range labelMap {
keyList = append(keyList, k)
}
- newSummaryVec := newSummaryVec(summaryName, reporter.namespace, keyList)
+ newSummaryVec := newSummaryVec(summaryName, reporter.namespace, keyList, reporter.reporterConfig.SummaryMaxAge)
_ = prom.DefaultRegisterer.Register(newSummaryVec)
reporter.userSummaryVec.Store(summaryName, newSummaryVec)
newSummaryVec.With(labelMap).Observe(toSetValue)
diff --git a/metrics/reporter.go b/metrics/reporter.go
index 277cc82bf..b0e661743 100644
--- a/metrics/reporter.go
+++ b/metrics/reporter.go
@@ -26,6 +26,8 @@ import (
"dubbo.apache.org/dubbo-go/v3/protocol"
)
+const DefMaxAge = 600000000000
+
type ReporterConfig struct {
Enable bool
Namespace string
@@ -33,6 +35,7 @@ type ReporterConfig struct {
Port string
Path string
PushGatewayAddress string
+ SummaryMaxAge int64
}
type ReportMode string
@@ -50,6 +53,7 @@ func NewReporterConfig() *ReporterConfig {
Path: "/metrics",
Mode: ReportModePull,
PushGatewayAddress: "",
+ SummaryMaxAge: DefMaxAge,
}
}