Skip to content

Commit

Permalink
Only copy the build info to the Prom version library once.
Browse files Browse the repository at this point in the history
  • Loading branch information
jaqx0r committed Oct 16, 2023
1 parent c83415e commit 32d70dc
Showing 1 changed file with 9 additions and 3 deletions.
12 changes: 9 additions & 3 deletions internal/mtail/mtail.go
Original file line number Diff line number Diff line change
Expand Up @@ -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...)
Expand All @@ -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
}

Expand Down

0 comments on commit 32d70dc

Please sign in to comment.