mirror of
https://github.com/octoleo/syncthing.git
synced 2024-11-10 15:20:56 +00:00
65aaa607ab
Change made by: - running "gvt fetch" on each of the packages mentioned in Godeps/Godeps.json - `rm -rf Godeps` - tweaking the build scripts to not mention Godeps - tweaking the build scripts to test `./lib/...`, `./cmd/...` explicitly (to avoid testing vendor) - tweaking the build scripts to not juggle GOPATH for Godeps and instead set GO15VENDOREXPERIMENT. This also results in some updated packages at the same time I bet. Building with Go 1.3 and 1.4 still *works* but won't use our vendored dependencies - the user needs to have the actual packages in their GOPATH then, which they'll get with a normal "go get". Building with Go 1.6+ will get our vendored dependencies by default even when not using our build script, which is nice. By doing this we gain some freedom in that we can pick and choose manually what to include in vendor, as it's not based on just dependency analysis of our own code. This is also a risk as we might pick up dependencies we are unaware of, as the build may work locally with those packages present in GOPATH. On the other hand the build server will detect this as it has no packages in it's GOPATH beyond what is included in the repo. Recommended tool to manage dependencies is github.com/FiloSottile/gvt.
92 lines
2.3 KiB
Go
92 lines
2.3 KiB
Go
package metrics
|
|
|
|
import "sync"
|
|
|
|
// GaugeFloat64s hold a float64 value that can be set arbitrarily.
|
|
type GaugeFloat64 interface {
|
|
Snapshot() GaugeFloat64
|
|
Update(float64)
|
|
Value() float64
|
|
}
|
|
|
|
// GetOrRegisterGaugeFloat64 returns an existing GaugeFloat64 or constructs and registers a
|
|
// new StandardGaugeFloat64.
|
|
func GetOrRegisterGaugeFloat64(name string, r Registry) GaugeFloat64 {
|
|
if nil == r {
|
|
r = DefaultRegistry
|
|
}
|
|
return r.GetOrRegister(name, NewGaugeFloat64()).(GaugeFloat64)
|
|
}
|
|
|
|
// NewGaugeFloat64 constructs a new StandardGaugeFloat64.
|
|
func NewGaugeFloat64() GaugeFloat64 {
|
|
if UseNilMetrics {
|
|
return NilGaugeFloat64{}
|
|
}
|
|
return &StandardGaugeFloat64{
|
|
value: 0.0,
|
|
}
|
|
}
|
|
|
|
// NewRegisteredGaugeFloat64 constructs and registers a new StandardGaugeFloat64.
|
|
func NewRegisteredGaugeFloat64(name string, r Registry) GaugeFloat64 {
|
|
c := NewGaugeFloat64()
|
|
if nil == r {
|
|
r = DefaultRegistry
|
|
}
|
|
r.Register(name, c)
|
|
return c
|
|
}
|
|
|
|
// GaugeFloat64Snapshot is a read-only copy of another GaugeFloat64.
|
|
type GaugeFloat64Snapshot float64
|
|
|
|
// Snapshot returns the snapshot.
|
|
func (g GaugeFloat64Snapshot) Snapshot() GaugeFloat64 { return g }
|
|
|
|
// Update panics.
|
|
func (GaugeFloat64Snapshot) Update(float64) {
|
|
panic("Update called on a GaugeFloat64Snapshot")
|
|
}
|
|
|
|
// Value returns the value at the time the snapshot was taken.
|
|
func (g GaugeFloat64Snapshot) Value() float64 { return float64(g) }
|
|
|
|
// NilGauge is a no-op Gauge.
|
|
type NilGaugeFloat64 struct{}
|
|
|
|
// Snapshot is a no-op.
|
|
func (NilGaugeFloat64) Snapshot() GaugeFloat64 { return NilGaugeFloat64{} }
|
|
|
|
// Update is a no-op.
|
|
func (NilGaugeFloat64) Update(v float64) {}
|
|
|
|
// Value is a no-op.
|
|
func (NilGaugeFloat64) Value() float64 { return 0.0 }
|
|
|
|
// StandardGaugeFloat64 is the standard implementation of a GaugeFloat64 and uses
|
|
// sync.Mutex to manage a single float64 value.
|
|
type StandardGaugeFloat64 struct {
|
|
mutex sync.Mutex
|
|
value float64
|
|
}
|
|
|
|
// Snapshot returns a read-only copy of the gauge.
|
|
func (g *StandardGaugeFloat64) Snapshot() GaugeFloat64 {
|
|
return GaugeFloat64Snapshot(g.Value())
|
|
}
|
|
|
|
// Update updates the gauge's value.
|
|
func (g *StandardGaugeFloat64) Update(v float64) {
|
|
g.mutex.Lock()
|
|
defer g.mutex.Unlock()
|
|
g.value = v
|
|
}
|
|
|
|
// Value returns the gauge's current value.
|
|
func (g *StandardGaugeFloat64) Value() float64 {
|
|
g.mutex.Lock()
|
|
defer g.mutex.Unlock()
|
|
return g.value
|
|
}
|