storj/internal/version/stats.go
JT Olio 27ec69eb79 add ability to inspect version to all binaries (#1685)
* add ability to inspect version to all binaries

Change-Id: I09d83b0e6ddd145dc02ae6619f842fcc7c3a0469

* add monitoring

Change-Id: I14ceca4cd7706f4c33fa67f7b34ebb8297fc76ad

* review comments

Change-Id: I255c5559be78b92cba4b23e22cf92f459bbd16b7

* switch to atomic

Change-Id: Ibdab950c59b974f64b129d783b283abe025ab0ff

* linting

Change-Id: Ia2407172e64c2cc92e78ad8b48c371e61ae67278
2019-04-10 08:38:26 +02:00

36 lines
799 B
Go

// Copyright (C) 2019 Storj Labs, Inc.
// See LICENSE for copying information.
package version
import (
"hash/crc32"
"sync/atomic"
)
// Stats implements the monkit.StatSource interface
func (v *Info) Stats(reportValue func(name string, val float64)) {
if v.Release {
reportValue("release", 1)
} else {
reportValue("release", 0)
}
reportValue("timestamp", float64(v.Timestamp.Unix()))
crc := atomic.LoadUint32(&v.commitHashCRC)
if crc == 0 {
c := crc32.NewIEEE()
_, err := c.Write([]byte(buildCommitHash))
if err != nil {
panic(err)
}
atomic.StoreUint32(&v.commitHashCRC, c.Sum32())
}
reportValue("commit", float64(crc))
reportValue("major", float64(v.Version.Major))
reportValue("minor", float64(v.Version.Minor))
reportValue("patch", float64(v.Version.Patch))
}