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.
This commit is contained in:
Arlo Breault 2021-05-20 15:36:08 -04:00
parent 160ae2dd71
commit 7ef49272fa

View file

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