[Author Prev][Author Next][Thread Prev][Thread Next][Author Index][Thread Index]

[tor-commits] [snowflake/main] Remove sync.Once from around logMetrics



commit 7ef49272fa8c4169a5ec13988a71011dbe14bbfb
Author: Arlo Breault <abreault@xxxxxxxxxxxxx>
Date:   Thu May 20 15:36:08 2021 -0400

    Remove sync.Once from around logMetrics
    
    Follow up to 160ae2d
    
    Analysis by @dcf,
    
    > I don't think the sync.Once around logMetrics is necessary anymore.
    Its original purpose was to inhibit logging on later file handles of
    metrics.log, if there were more than one opened. See 171c55a9 and #29734
    (comment 2593039) "Making a singleton *Metrics variable causes problems
    with how Convey does tests. It shouldn't be called more than once, but
    for now I'm using sync.Once on the logging at least so it's explicit."
    Commit ba4fe1a7 changed it so that metrics.log is opened in main, used
    to create a *log.Logger, and that same instance of *log.Logger is passed
    to both NewMetrics and NewBrokerContext. It's safe to share the same
    *log.Logger across multiple BrokerContext.
---
 broker/metrics.go | 3 +--
 1 file changed, 1 insertion(+), 2 deletions(-)

diff --git a/broker/metrics.go b/broker/metrics.go
index a79a1c4..e8a6b0c 100644
--- a/broker/metrics.go
+++ b/broker/metrics.go
@@ -53,7 +53,6 @@ type Metrics struct {
 	lock sync.Mutex
 
 	promMetrics *PromMetrics
-	once        sync.Once
 }
 
 type record struct {
@@ -202,7 +201,7 @@ func NewMetrics(metricsLogger *log.Logger) (*Metrics, error) {
 	m.promMetrics = initPrometheus()
 
 	// Write to log file every hour with updated metrics
-	go m.once.Do(m.logMetrics)
+	go m.logMetrics()
 
 	return m, nil
 }

_______________________________________________
tor-commits mailing list
tor-commits@xxxxxxxxxxxxxxxxxxxx
https://lists.torproject.org/cgi-bin/mailman/listinfo/tor-commits