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