You are viewing a plain text version of this content. The canonical link for it is here.
Posted to commits@dubbo.apache.org by ju...@apache.org on 2023/02/01 06:15:49 UTC
[dubbo-go] branch revert-2180-dynamic_update_config created (now b216a4421)
This is an automated email from the ASF dual-hosted git repository.
justxuewei pushed a change to branch revert-2180-dynamic_update_config
in repository https://gitbox.apache.org/repos/asf/dubbo-go.git
at b216a4421 Revert "Dynamic update config for logger level & metric enable (#2180)"
This branch includes the following new commits:
new b216a4421 Revert "Dynamic update config for logger level & metric enable (#2180)"
The 1 revisions listed above as "new" are entirely new to this
repository and will be described in separate emails. The revisions
listed as "add" were already present in the repository and have only
been added to this reference.
[dubbo-go] 01/01: Revert "Dynamic update config for logger level & metric enable (#2180)"
Posted by ju...@apache.org.
This is an automated email from the ASF dual-hosted git repository.
justxuewei pushed a commit to branch revert-2180-dynamic_update_config
in repository https://gitbox.apache.org/repos/asf/dubbo-go.git
commit b216a44212fafcb8e9e8655cf33031fb80cb7bcd
Author: Xuewei Niu <ju...@apache.org>
AuthorDate: Wed Feb 1 14:15:44 2023 +0800
Revert "Dynamic update config for logger level & metric enable (#2180)"
This reverts commit 4c6a99bee53e64e6d883673d2f7f463b42b5c42b.
---
config/logger_config.go | 8 ----
config/metric_config.go | 13 -------
config/root_config.go | 6 ---
metrics/prometheus/reporter.go | 88 +++++++++++++-----------------------------
4 files changed, 26 insertions(+), 89 deletions(-)
diff --git a/config/logger_config.go b/config/logger_config.go
index 872c444c6..5a499b9cb 100644
--- a/config/logger_config.go
+++ b/config/logger_config.go
@@ -170,11 +170,3 @@ func (lcb *LoggerConfigBuilder) SetZapConfig(zapConfig ZapConfig) *LoggerConfigB
func (lcb *LoggerConfigBuilder) Build() *LoggerConfig {
return lcb.loggerConfig
}
-
-// DynamicUpdateProperties dynamically update properties.
-func (lc *LoggerConfig) DynamicUpdateProperties(newLoggerConfig *LoggerConfig) {
- if newLoggerConfig != nil && lc.ZapConfig.Level != newLoggerConfig.ZapConfig.Level {
- lc.ZapConfig.Level = newLoggerConfig.ZapConfig.Level
- logger.Infof("LoggerConfig's ZapConfig Level was dynamically updated, new value:%v", lc.ZapConfig.Level)
- }
-}
diff --git a/config/metric_config.go b/config/metric_config.go
index 509907007..8b8a04415 100644
--- a/config/metric_config.go
+++ b/config/metric_config.go
@@ -19,7 +19,6 @@ package config
import (
"github.com/creasty/defaults"
- "github.com/dubbogo/gost/log/logger"
"github.com/pkg/errors"
)
@@ -82,15 +81,3 @@ func NewMetricConfigBuilder() *MetricConfigBuilder {
func (mcb *MetricConfigBuilder) Build() *MetricConfig {
return mcb.metricConfig
}
-
-// DynamicUpdateProperties dynamically update properties.
-func (mc *MetricConfig) DynamicUpdateProperties(newMetricConfig *MetricConfig) {
- if newMetricConfig != nil {
- if newMetricConfig.Enable != mc.Enable {
- mc.Enable = newMetricConfig.Enable
- logger.Infof("MetricConfig's Enable was dynamically updated, new value:%v", mc.Enable)
-
- extension.GetMetricReporter("prometheus", mc.ToReporterConfig())
- }
- }
-}
diff --git a/config/root_config.go b/config/root_config.go
index ee0387575..88cd00e36 100644
--- a/config/root_config.go
+++ b/config/root_config.go
@@ -395,10 +395,4 @@ func (rc *RootConfig) Process(event *config_center.ConfigChangeEvent) {
}
// dynamically update consumer
rc.Consumer.DynamicUpdateProperties(updateRootConfig.Consumer)
-
- // dynamically update logger
- rc.Logger.DynamicUpdateProperties(updateRootConfig.Logger)
-
- // dynamically update metric
- rc.Metric.DynamicUpdateProperties(updateRootConfig.Metric)
}
diff --git a/metrics/prometheus/reporter.go b/metrics/prometheus/reporter.go
index 666670312..9777c740e 100644
--- a/metrics/prometheus/reporter.go
+++ b/metrics/prometheus/reporter.go
@@ -78,7 +78,6 @@ 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 {
- reporterServer *http.Server
reporterConfig *metrics.ReporterConfig
// report the consumer-side's rt gauge data
consumerRTSummaryVec *prometheus.SummaryVec
@@ -104,10 +103,6 @@ type PrometheusReporter struct {
// the role in url must be consumer or provider
// or it will be ignored
func (reporter *PrometheusReporter) Report(ctx context.Context, invoker protocol.Invoker, invocation protocol.Invocation, cost time.Duration, res protocol.Result) {
- if !reporter.reporterConfig.Enable {
- return
- }
-
url := invoker.GetURL()
var rtVec *prometheus.SummaryVec
if isProvider(url) {
@@ -225,20 +220,29 @@ func newPrometheusReporter(reporterConfig *metrics.ReporterConfig) metrics.Repor
consumerRTSummaryVec: newSummaryVec(consumerPrefix+serviceKey+rtSuffix, reporterConfig.Namespace, labelNames, reporterConfig.SummaryMaxAge),
providerRTSummaryVec: newSummaryVec(providerPrefix+serviceKey+rtSuffix, reporterConfig.Namespace, labelNames, reporterConfig.SummaryMaxAge),
}
-
prom.DefaultRegisterer.MustRegister(reporterInstance.consumerRTSummaryVec, reporterInstance.providerRTSummaryVec)
- })
- }
+ metricsExporter, err := ocprom.NewExporter(ocprom.Options{
+ Registry: prom.DefaultRegisterer.(*prom.Registry),
+ })
+ if err != nil {
+ logger.Errorf("new prometheus reporter with error = %s", err)
+ return
+ }
- if reporterConfig.Enable {
- if reporterConfig.Mode == metrics.ReportModePull {
- go reporterInstance.startupServer(reporterConfig)
- }
- // todo pushgateway support
- } else {
- reporterInstance.shutdownServer()
+ if reporterConfig.Enable {
+ if reporterConfig.Mode == metrics.ReportModePull {
+ go func() {
+ mux := http.NewServeMux()
+ mux.Handle(reporterConfig.Path, metricsExporter)
+ if err := http.ListenAndServe(":"+reporterConfig.Port, mux); err != nil {
+ logger.Warnf("new prometheus reporter with error = %s", err)
+ }
+ }()
+ }
+ // todo pushgateway support
+ }
+ })
}
-
return reporterInstance
}
@@ -373,65 +377,25 @@ func (reporter *PrometheusReporter) incSummary(summaryName string, toSetValue fl
}
func SetGaugeWithLabel(gaugeName string, val float64, label prometheus.Labels) {
- if reporterInstance.reporterConfig.Enable {
- reporterInstance.setGauge(gaugeName, val, label)
- }
+ reporterInstance.setGauge(gaugeName, val, label)
}
func SetGauge(gaugeName string, val float64) {
- if reporterInstance.reporterConfig.Enable {
- reporterInstance.setGauge(gaugeName, val, make(prometheus.Labels))
- }
+ reporterInstance.setGauge(gaugeName, val, make(prometheus.Labels))
}
func IncCounterWithLabel(counterName string, label prometheus.Labels) {
- if reporterInstance.reporterConfig.Enable {
- reporterInstance.incCounter(counterName, label)
- }
+ reporterInstance.incCounter(counterName, label)
}
func IncCounter(summaryName string) {
- if reporterInstance.reporterConfig.Enable {
- reporterInstance.incCounter(summaryName, make(prometheus.Labels))
- }
+ reporterInstance.incCounter(summaryName, make(prometheus.Labels))
}
func IncSummaryWithLabel(counterName string, val float64, label prometheus.Labels) {
- if reporterInstance.reporterConfig.Enable {
- reporterInstance.incSummary(counterName, val, label)
- }
+ reporterInstance.incSummary(counterName, val, label)
}
func IncSummary(summaryName string, val float64) {
- if reporterInstance.reporterConfig.Enable {
- reporterInstance.incSummary(summaryName, val, make(prometheus.Labels))
- }
-}
-
-func (reporter *PrometheusReporter) startupServer(reporterConfig *metrics.ReporterConfig) {
- metricsExporter, err := ocprom.NewExporter(ocprom.Options{
- Registry: prom.DefaultRegisterer.(*prom.Registry),
- })
- if err != nil {
- logger.Errorf("new prometheus reporter with error = %s", err)
- return
- }
-
- // start server
- mux := http.NewServeMux()
- mux.Handle(reporterConfig.Path, metricsExporter)
- reporterInstance.reporterServer = &http.Server{Addr: ":" + reporterConfig.Port, Handler: mux}
- if err := reporterInstance.reporterServer.ListenAndServe(); err != nil {
- logger.Warnf("new prometheus reporter with error = %s", err)
- }
-}
-
-func (reporter *PrometheusReporter) shutdownServer() {
- if reporterInstance.reporterServer != nil {
- err := reporterInstance.reporterServer.Shutdown(context.Background())
- if err != nil {
- logger.Errorf("shutdown prometheus reporter with error = %s, prometheus reporter close now", err)
- reporterInstance.reporterServer.Close()
- }
- }
+ reporterInstance.incSummary(summaryName, val, make(prometheus.Labels))
}