mirror of
https://github.com/open-telemetry/opentelemetry-go.git
synced 2025-06-04 23:07:40 +02:00
Remove NewZeroNumber in favor of Number(0) (#255)
This commit is contained in:
parent
320c62a780
commit
88dafbbb16
@ -42,19 +42,6 @@ type Number uint64
|
|||||||
|
|
||||||
// - constructors
|
// - 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.
|
// NewNumberFromRaw creates a new Number from a raw value.
|
||||||
func NewNumberFromRaw(r uint64) Number {
|
func NewNumberFromRaw(r uint64) Number {
|
||||||
return Number(r)
|
return Number(r)
|
||||||
|
@ -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")
|
||||||
|
}
|
||||||
|
}
|
||||||
|
@ -45,10 +45,7 @@ func (c *Aggregator) AsNumber() core.Number {
|
|||||||
|
|
||||||
// Collect checkpoints the current value (atomically) and exports it.
|
// Collect checkpoints the current value (atomically) and exports it.
|
||||||
func (c *Aggregator) Collect(ctx context.Context, rec export.MetricRecord, exp export.MetricBatcher) {
|
func (c *Aggregator) Collect(ctx context.Context, rec export.MetricRecord, exp export.MetricBatcher) {
|
||||||
desc := rec.Descriptor()
|
c.checkpoint = c.current.SwapNumberAtomic(core.Number(0))
|
||||||
kind := desc.NumberKind()
|
|
||||||
zero := core.NewZeroNumber(kind)
|
|
||||||
c.checkpoint = c.current.SwapNumberAtomic(zero)
|
|
||||||
|
|
||||||
exp.Export(ctx, rec, c)
|
exp.Export(ctx, rec, c)
|
||||||
}
|
}
|
||||||
|
@ -60,10 +60,6 @@ func (c *Aggregator) Max() core.Number {
|
|||||||
|
|
||||||
// Collect saves the current value (atomically) and exports it.
|
// Collect saves the current value (atomically) and exports it.
|
||||||
func (c *Aggregator) Collect(ctx context.Context, rec export.MetricRecord, exp export.MetricBatcher) {
|
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
|
// N.B. There is no atomic operation that can update all three
|
||||||
// values at once, so there are races between Update() and
|
// values at once, so there are races between Update() and
|
||||||
// Collect(). Therefore, atomically swap fields independently,
|
// 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.
|
// could be spread across multiple collections in rare cases.
|
||||||
|
|
||||||
c.save.count.SetUint64(c.live.count.SwapUint64Atomic(0))
|
c.save.count.SetUint64(c.live.count.SwapUint64Atomic(0))
|
||||||
c.save.sum = c.live.sum.SwapNumberAtomic(zero)
|
c.save.sum = c.live.sum.SwapNumberAtomic(core.Number(0))
|
||||||
c.save.max = c.live.max.SwapNumberAtomic(zero)
|
c.save.max = c.live.max.SwapNumberAtomic(core.Number(0))
|
||||||
|
|
||||||
exp.Export(ctx, rec, c)
|
exp.Export(ctx, rec, c)
|
||||||
}
|
}
|
||||||
|
Loading…
x
Reference in New Issue
Block a user