diff --git a/api/core/number.go b/api/core/number.go index 926ac4468b6..97f6c43207b 100644 --- a/api/core/number.go +++ b/api/core/number.go @@ -42,19 +42,6 @@ type Number uint64 // - constructors -// NewZeroNumber -func NewZeroNumber(kind NumberKind) Number { - switch kind { - case Int64NumberKind: - return NewInt64Number(0) - case Float64NumberKind: - return NewFloat64Number(0.) - case Uint64NumberKind: - return NewUint64Number(0) - } - return Number(0) -} - // NewNumberFromRaw creates a new Number from a raw value. func NewNumberFromRaw(r uint64) Number { return Number(r) diff --git a/api/core/number_test.go b/api/core/number_test.go index 5efe86296d9..f2b5abfc3db 100644 --- a/api/core/number_test.go +++ b/api/core/number_test.go @@ -146,3 +146,14 @@ func TestNumber(t *testing.T) { } } } + +func TestNumberZero(t *testing.T) { + zero := Number(0) + zerof := NewFloat64Number(0) + zeroi := NewInt64Number(0) + zerou := NewUint64Number(0) + + if zero != zerof || zero != zeroi || zero != zerou { + t.Errorf("Invalid zero representations") + } +} diff --git a/sdk/metric/aggregator/counter/counter.go b/sdk/metric/aggregator/counter/counter.go index 58d7cee3c69..d8e949a31c6 100644 --- a/sdk/metric/aggregator/counter/counter.go +++ b/sdk/metric/aggregator/counter/counter.go @@ -45,10 +45,7 @@ func (c *Aggregator) AsNumber() core.Number { // Collect checkpoints the current value (atomically) and exports it. func (c *Aggregator) Collect(ctx context.Context, rec export.MetricRecord, exp export.MetricBatcher) { - desc := rec.Descriptor() - kind := desc.NumberKind() - zero := core.NewZeroNumber(kind) - c.checkpoint = c.current.SwapNumberAtomic(zero) + c.checkpoint = c.current.SwapNumberAtomic(core.Number(0)) exp.Export(ctx, rec, c) } diff --git a/sdk/metric/aggregator/maxsumcount/msc.go b/sdk/metric/aggregator/maxsumcount/msc.go index b549a311536..eacc2c3a622 100644 --- a/sdk/metric/aggregator/maxsumcount/msc.go +++ b/sdk/metric/aggregator/maxsumcount/msc.go @@ -60,10 +60,6 @@ func (c *Aggregator) Max() core.Number { // Collect saves the current value (atomically) and exports it. func (c *Aggregator) Collect(ctx context.Context, rec export.MetricRecord, exp export.MetricBatcher) { - desc := rec.Descriptor() - kind := desc.NumberKind() - zero := core.NewZeroNumber(kind) - // N.B. There is no atomic operation that can update all three // values at once, so there are races between Update() and // Collect(). Therefore, atomically swap fields independently, @@ -71,8 +67,8 @@ func (c *Aggregator) Collect(ctx context.Context, rec export.MetricRecord, exp e // could be spread across multiple collections in rare cases. c.save.count.SetUint64(c.live.count.SwapUint64Atomic(0)) - c.save.sum = c.live.sum.SwapNumberAtomic(zero) - c.save.max = c.live.max.SwapNumberAtomic(zero) + c.save.sum = c.live.sum.SwapNumberAtomic(core.Number(0)) + c.save.max = c.live.max.SwapNumberAtomic(core.Number(0)) exp.Export(ctx, rec, c) }