remove Set method for cumulatives. (#1120)
diff --git a/metric/cumulative.go b/metric/cumulative.go
index 6d3be3f..549d091 100644
--- a/metric/cumulative.go
+++ b/metric/cumulative.go
@@ -59,25 +59,6 @@
return entry.(*Float64CumulativeEntry), nil
}
-// Set sets the cumulative entry value to provided val. It returns without updating if the value is
-// negative or lower than previously stored value.
-func (e *Float64CumulativeEntry) Set(val float64) {
- var swapped, equalOrLess bool
- if val <= 0.0 {
- return
- }
- for !swapped && !equalOrLess {
- oldBits := atomic.LoadUint64(&e.val)
- oldVal := math.Float64frombits(oldBits)
- if val > oldVal {
- valBits := math.Float64bits(val)
- swapped = atomic.CompareAndSwapUint64(&e.val, oldBits, valBits)
- } else {
- equalOrLess = true
- }
- }
-}
-
// Inc increments the cumulative entry value by val. It returns without incrementing if the val
// is negative.
func (e *Float64CumulativeEntry) Inc(val float64) {
@@ -129,23 +110,6 @@
return entry.(*Int64CumulativeEntry), nil
}
-// Set sets the value of the cumulative entry to the provided value. It returns without updating
-// if the val is negative or if the val is lower than previously stored value.
-func (e *Int64CumulativeEntry) Set(val int64) {
- var swapped, equalOrLess bool
- if val <= 0 {
- return
- }
- for !swapped && !equalOrLess {
- old := atomic.LoadInt64(&e.val)
- if val > old {
- swapped = atomic.CompareAndSwapInt64(&e.val, old, val)
- } else {
- equalOrLess = true
- }
- }
-}
-
// Inc increments the current cumulative entry value by val. It returns without incrementing if
// the val is negative.
func (e *Int64CumulativeEntry) Inc(val int64) {
diff --git a/metric/cumulative_test.go b/metric/cumulative_test.go
index 538320c..6b2110d 100644
--- a/metric/cumulative_test.go
+++ b/metric/cumulative_test.go
@@ -28,7 +28,7 @@
f, _ := r.AddFloat64Cumulative("TestCumulative",
WithLabelKeys("k1", "k2"))
e, _ := f.GetEntry(metricdata.LabelValue{}, metricdata.LabelValue{})
- e.Set(5)
+ e.Inc(5)
e, _ = f.GetEntry(metricdata.NewLabelValue("k1v1"), metricdata.LabelValue{})
e.Inc(1)
e, _ = f.GetEntry(metricdata.NewLabelValue("k1v1"), metricdata.LabelValue{})
@@ -103,7 +103,7 @@
}
}
-func TestInt64CumulativeEntry_IncAndSet(t *testing.T) {
+func TestInt64CumulativeEntry_IncNegative(t *testing.T) {
r := NewRegistry()
g, _ := r.AddInt64Cumulative("bm")
e, _ := g.GetEntry()
@@ -111,12 +111,6 @@
readAndCompareInt64Val("inc", r, 5, t)
e.Inc(-2)
readAndCompareInt64Val("inc negative", r, 5, t)
- e.Set(-2)
- readAndCompareInt64Val("set negative", r, 5, t)
- e.Set(4)
- readAndCompareInt64Val("set lower", r, 5, t)
- e.Set(9)
- readAndCompareInt64Val("set higher", r, 9, t)
}
func readAndCompareFloat64Val(testname string, r *Registry, want float64, t *testing.T) {
@@ -126,7 +120,7 @@
}
}
-func TestFloat64CumulativeEntry_IncAndSet(t *testing.T) {
+func TestFloat64CumulativeEntry_IncNegative(t *testing.T) {
r := NewRegistry()
g, _ := r.AddFloat64Cumulative("bm")
e, _ := g.GetEntry()
@@ -134,12 +128,6 @@
readAndCompareFloat64Val("inc", r, 5.0, t)
e.Inc(-2.0)
readAndCompareFloat64Val("inc negative", r, 5.0, t)
- e.Set(-2.0)
- readAndCompareFloat64Val("set negative", r, 5.0, t)
- e.Set(4.0)
- readAndCompareFloat64Val("set lower", r, 5.0, t)
- e.Set(9.9)
- readAndCompareFloat64Val("set higher", r, 9.9, t)
}
func TestCumulativeWithSameNameDiffType(t *testing.T) {