Skip to content

Commit

Permalink
Merge branch 'develop'
Browse files Browse the repository at this point in the history
  • Loading branch information
michaeltrobinson committed Apr 14, 2016
2 parents 8d84288 + 8b934bc commit f83efb0
Show file tree
Hide file tree
Showing 2 changed files with 18 additions and 1 deletion.
3 changes: 2 additions & 1 deletion gauge.go
Original file line number Diff line number Diff line change
@@ -1,6 +1,7 @@
package signalfx

import (
"math"
"sync/atomic"
"time"
)
Expand Down Expand Up @@ -90,7 +91,7 @@ type StableGauge struct {

// NewStableGauge returns a new StableGauge with the indicated initial state.
func NewStableGauge(metric string, dimensions map[string]string, value int64) *StableGauge {
return &StableGauge{gauge: NewGauge(metric, dimensions, value)}
return &StableGauge{gauge: NewGauge(metric, dimensions, value), prevValue: math.MaxInt64}
}

// Record sets a gauge's internal state to the indicated value.
Expand Down
16 changes: 16 additions & 0 deletions gauge_test.go
Original file line number Diff line number Diff line change
Expand Up @@ -69,6 +69,22 @@ func TestGauge(t *testing.T) {
So(gdp.Value, ShouldEqual, 8)
So(g.prevValue, ShouldEqual, 8)
So(t.Before(gdp.Timestamp), ShouldBeTrue)

Convey("reports a 0 if it is the first report", func() {
g := NewStableGauge("stable-gauge", nil, 0)
So(g, ShouldNotBeNil)
So(g.gauge.metric, ShouldEqual, "stable-gauge")
So(g.gauge.dimensions, ShouldBeNil)
So(g.gauge.value, ShouldEqual, 0)

g.Record(0)
gdp := g.DataPoint()
So(gdp, ShouldNotBeNil)
So(gdp.Metric, ShouldEqual, "stable-gauge")
So(gdp.Dimensions, ShouldBeNil)
So(gdp.Value, ShouldEqual, 0)
So(g.prevValue, ShouldEqual, 0)
})
})
Convey("Broken wrapped gauges break cleanly", t, func() {
g := WrapGauge("broken", nil, GetterFunc(func() (interface{}, error) {
Expand Down

0 comments on commit f83efb0

Please sign in to comment.