From 32d70dce21e4dfa0d14ccf42659cb47ba97e6450 Mon Sep 17 00:00:00 2001 From: Jamie Wilkinson Date: Mon, 16 Oct 2023 12:02:50 +1100 Subject: [PATCH] Only copy the build info to the Prom version library once. --- internal/mtail/mtail.go | 12 +++++++++--- 1 file changed, 9 insertions(+), 3 deletions(-) diff --git a/internal/mtail/mtail.go b/internal/mtail/mtail.go index 8f1ac0c2f..fa274bb3d 100644 --- a/internal/mtail/mtail.go +++ b/internal/mtail/mtail.go @@ -54,6 +54,9 @@ type Server struct { httpInfoEndpoints bool // if set, mtail will enable info endpoints for progz and varz } +// We can only copy the build info once to the version library. Protects tests from data races. +var buildInfoOnce sync.Once + // initRuntime constructs a new runtime and performs the initial load of program files in the program directory. func (m *Server) initRuntime() (err error) { m.r, err = runtime.New(m.lines, &m.wg, m.programPath, m.store, m.rOpts...) @@ -69,10 +72,13 @@ func (m *Server) initExporter() (err error) { m.reg.MustRegister(m.e) // Create mtail_build_info metric. - version.Branch = m.buildInfo.Branch - version.Version = m.buildInfo.Version - version.Revision = m.buildInfo.Revision + buildInfoOnce.Do(func() { + version.Branch = m.buildInfo.Branch + version.Version = m.buildInfo.Version + version.Revision = m.buildInfo.Revision + }) m.reg.MustRegister(version.NewCollector("mtail")) + return nil }