File tree Expand file tree Collapse file tree 2 files changed +5
-18
lines changed Expand file tree Collapse file tree 2 files changed +5
-18
lines changed Original file line number Diff line number Diff line change @@ -15,9 +15,7 @@ const (
15
15
)
16
16
17
17
// PersistentGauge will report on an interval the value to the metrics collector.
18
- // Every call to the methods to modify the value immediately report, but if we
19
- // don't have a change inside the window (default 10s) after the last report
20
- // we will report the current value.
18
+ //
21
19
type PersistentGauge struct {
22
20
name string
23
21
value int32
@@ -31,24 +29,17 @@ type PersistentGauge struct {
31
29
32
30
// Set will replace the value with a new one, it returns the old value
33
31
func (g * PersistentGauge ) Set (value int32 ) int32 {
34
- v := atomic .SwapInt32 (& g .value , value )
35
- g .report (value )
36
-
37
- return v
32
+ return atomic .SwapInt32 (& g .value , value )
38
33
}
39
34
40
35
// Inc will +1 to the current value and return the new value
41
36
func (g * PersistentGauge ) Inc () int32 {
42
- v := atomic .AddInt32 (& g .value , 1 )
43
- g .report (v )
44
- return v
37
+ return atomic .AddInt32 (& g .value , 1 )
45
38
}
46
39
47
40
// Dec will -1 to the current value and return the new value
48
41
func (g * PersistentGauge ) Dec () int32 {
49
- v := atomic .AddInt32 (& g .value , - 1 )
50
- g .report (v )
51
- return v
42
+ return atomic .AddInt32 (& g .value , - 1 )
52
43
}
53
44
54
45
func (g * PersistentGauge ) report (v int32 ) {
Original file line number Diff line number Diff line change @@ -23,15 +23,11 @@ func TestPersistentGauge(t *testing.T) {
23
23
assert .EqualValues (t , 0 , g .Set (10 ))
24
24
25
25
expectedValues := []string {
26
- // these values should be reported everytime we make a call
27
- "test.some_gauge.b:1.000000|g" ,
28
- "test.some_gauge.b:0.000000|g" ,
29
- "test.some_gauge.b:10.000000|g" ,
30
26
// this value should be reported after an interval
31
27
"test.some_gauge.b:10.000000|g" ,
32
28
}
33
29
34
- for i := 0 ; i < 4 ; i ++ {
30
+ for i := 0 ; i < len ( expectedValues ) ; i ++ {
35
31
select {
36
32
case msg := <- res :
37
33
assert .Equal (t , expectedValues [i ], msg )
You can’t perform that action at this time.
0 commit comments