Skip to content
This repository was archived by the owner on Jul 31, 2023. It is now read-only.

Commit 9e14c87

Browse files
authored
remove Set method for cumulatives. (#1120)
1 parent 9f66137 commit 9e14c87

File tree

2 files changed

+3
-51
lines changed

2 files changed

+3
-51
lines changed

metric/cumulative.go

Lines changed: 0 additions & 36 deletions
Original file line numberDiff line numberDiff line change
@@ -59,25 +59,6 @@ func (c *Float64Cumulative) GetEntry(labelVals ...metricdata.LabelValue) (*Float
5959
return entry.(*Float64CumulativeEntry), nil
6060
}
6161

62-
// Set sets the cumulative entry value to provided val. It returns without updating if the value is
63-
// negative or lower than previously stored value.
64-
func (e *Float64CumulativeEntry) Set(val float64) {
65-
var swapped, equalOrLess bool
66-
if val <= 0.0 {
67-
return
68-
}
69-
for !swapped && !equalOrLess {
70-
oldBits := atomic.LoadUint64(&e.val)
71-
oldVal := math.Float64frombits(oldBits)
72-
if val > oldVal {
73-
valBits := math.Float64bits(val)
74-
swapped = atomic.CompareAndSwapUint64(&e.val, oldBits, valBits)
75-
} else {
76-
equalOrLess = true
77-
}
78-
}
79-
}
80-
8162
// Inc increments the cumulative entry value by val. It returns without incrementing if the val
8263
// is negative.
8364
func (e *Float64CumulativeEntry) Inc(val float64) {
@@ -129,23 +110,6 @@ func (c *Int64Cumulative) GetEntry(labelVals ...metricdata.LabelValue) (*Int64Cu
129110
return entry.(*Int64CumulativeEntry), nil
130111
}
131112

132-
// Set sets the value of the cumulative entry to the provided value. It returns without updating
133-
// if the val is negative or if the val is lower than previously stored value.
134-
func (e *Int64CumulativeEntry) Set(val int64) {
135-
var swapped, equalOrLess bool
136-
if val <= 0 {
137-
return
138-
}
139-
for !swapped && !equalOrLess {
140-
old := atomic.LoadInt64(&e.val)
141-
if val > old {
142-
swapped = atomic.CompareAndSwapInt64(&e.val, old, val)
143-
} else {
144-
equalOrLess = true
145-
}
146-
}
147-
}
148-
149113
// Inc increments the current cumulative entry value by val. It returns without incrementing if
150114
// the val is negative.
151115
func (e *Int64CumulativeEntry) Inc(val int64) {

metric/cumulative_test.go

Lines changed: 3 additions & 15 deletions
Original file line numberDiff line numberDiff line change
@@ -28,7 +28,7 @@ func TestCumulative(t *testing.T) {
2828
f, _ := r.AddFloat64Cumulative("TestCumulative",
2929
WithLabelKeys("k1", "k2"))
3030
e, _ := f.GetEntry(metricdata.LabelValue{}, metricdata.LabelValue{})
31-
e.Set(5)
31+
e.Inc(5)
3232
e, _ = f.GetEntry(metricdata.NewLabelValue("k1v1"), metricdata.LabelValue{})
3333
e.Inc(1)
3434
e, _ = f.GetEntry(metricdata.NewLabelValue("k1v1"), metricdata.LabelValue{})
@@ -103,20 +103,14 @@ func readAndCompareInt64Val(testname string, r *Registry, want int64, t *testing
103103
}
104104
}
105105

106-
func TestInt64CumulativeEntry_IncAndSet(t *testing.T) {
106+
func TestInt64CumulativeEntry_IncNegative(t *testing.T) {
107107
r := NewRegistry()
108108
g, _ := r.AddInt64Cumulative("bm")
109109
e, _ := g.GetEntry()
110110
e.Inc(5)
111111
readAndCompareInt64Val("inc", r, 5, t)
112112
e.Inc(-2)
113113
readAndCompareInt64Val("inc negative", r, 5, t)
114-
e.Set(-2)
115-
readAndCompareInt64Val("set negative", r, 5, t)
116-
e.Set(4)
117-
readAndCompareInt64Val("set lower", r, 5, t)
118-
e.Set(9)
119-
readAndCompareInt64Val("set higher", r, 9, t)
120114
}
121115

122116
func readAndCompareFloat64Val(testname string, r *Registry, want float64, t *testing.T) {
@@ -126,20 +120,14 @@ func readAndCompareFloat64Val(testname string, r *Registry, want float64, t *tes
126120
}
127121
}
128122

129-
func TestFloat64CumulativeEntry_IncAndSet(t *testing.T) {
123+
func TestFloat64CumulativeEntry_IncNegative(t *testing.T) {
130124
r := NewRegistry()
131125
g, _ := r.AddFloat64Cumulative("bm")
132126
e, _ := g.GetEntry()
133127
e.Inc(5.0)
134128
readAndCompareFloat64Val("inc", r, 5.0, t)
135129
e.Inc(-2.0)
136130
readAndCompareFloat64Val("inc negative", r, 5.0, t)
137-
e.Set(-2.0)
138-
readAndCompareFloat64Val("set negative", r, 5.0, t)
139-
e.Set(4.0)
140-
readAndCompareFloat64Val("set lower", r, 5.0, t)
141-
e.Set(9.9)
142-
readAndCompareFloat64Val("set higher", r, 9.9, t)
143131
}
144132

145133
func TestCumulativeWithSameNameDiffType(t *testing.T) {

0 commit comments

Comments
 (0)