This is an automated email from the ASF dual-hosted git repository.

wangdan pushed a commit to branch master
in repository https://gitbox.apache.org/repos/asf/incubator-pegasus.git


The following commit(s) were added to refs/heads/master by this push:
     new db68a2bdd refactor(collector): define prometheus registry as 
non-global variable (#1861)
db68a2bdd is described below

commit db68a2bddd241468beaa2776b115c9624b9271dc
Author: Wang Guangshuo <[email protected]>
AuthorDate: Fri Jan 19 16:04:11 2024 +0800

    refactor(collector): define prometheus registry as non-global variable 
(#1861)
---
 collector/main.go            | 5 ++++-
 collector/webui/webserver.go | 3 +--
 2 files changed, 5 insertions(+), 3 deletions(-)

diff --git a/collector/main.go b/collector/main.go
index e42881adf..efc2fc98b 100644
--- a/collector/main.go
+++ b/collector/main.go
@@ -29,6 +29,7 @@ import (
        "github.com/apache/incubator-pegasus/collector/avail"
        "github.com/apache/incubator-pegasus/collector/metrics"
        "github.com/apache/incubator-pegasus/collector/webui"
+       "github.com/prometheus/client_golang/prometheus"
        log "github.com/sirupsen/logrus"
        "github.com/spf13/viper"
        "gopkg.in/natefinch/lumberjack.v2"
@@ -81,7 +82,8 @@ func main() {
                return
        }
 
-       webui.StartWebServer()
+       registry := prometheus.NewRegistry()
+       webui.StartWebServer(registry)
 
        tom := &tomb.Tomb{}
        setupSignalHandler(func() {
@@ -97,5 +99,6 @@ func main() {
        tom.Go(func() error {
                return metrics.NewReplicaServerMetricCollector().Start(tom)
        })
+
        <-tom.Dead() // gracefully wait until all goroutines dead
 }
diff --git a/collector/webui/webserver.go b/collector/webui/webserver.go
index 8783f0cac..b83adfd34 100644
--- a/collector/webui/webserver.go
+++ b/collector/webui/webserver.go
@@ -28,8 +28,7 @@ import (
 )
 
 // StartWebServer starts an iris-powered HTTP server.
-func StartWebServer() {
-       registry := prometheus.NewRegistry()
+func StartWebServer(registry prometheus.Registerer) {
        for _, cV := range metrics.CounterMetricsMap {
                registry.MustRegister(cV)
        }


---------------------------------------------------------------------
To unsubscribe, e-mail: [email protected]
For additional commands, e-mail: [email protected]

Reply via email to