monitoring: Add option to derive build info from `debug.BuildInfo`
Starting with Go 1.18 the Go toolchain has started to automatically
attach build information to binaries unless -buildvcs=false
is passed
as an option to go build
. This build information contains various
pieces of information and has the benefit that it is a standardized way
to obtain it.
Introduce a new WithGoBuildInformation()
option that gives callers the
ability to pass in the build information. Right now it exposes the
following information:
- The commit from which the software was built from.
- The date when the commit was committed.
- The Go version used to build the binary.
- The module path of the binary's main module.
- The module version of the binary's main module.
So it contains more information than what WithBuildInformation()
would
expose right now. There is some difference in behaviour though:
- While both expose the commit the binary was built from the format
may change. The Go build information contains the full object ID
of the commit, whereas e.g. Gitaly would have used the result of
`git describe` instead.
- The old way of doing things embedded the build time instead of the
commit time. This had the major downside though that builds are
not reproducible and furthermore significantly slowed down build
times.
So it's a bit of a mixed bag, but overall it feels like the right thing to do to expose the build information instead of data customly embedded into variables at build time.