mirror of
https://github.com/open-telemetry/opentelemetry-go.git
synced 2025-06-04 23:07:40 +02:00
Move Number to api/metric package (#706)
Co-authored-by: Joshua MacDonald <jmacd@users.noreply.github.com>
This commit is contained in:
parent
2aa6e9ff3d
commit
f0855b7d08
@ -21,6 +21,8 @@ import (
|
|||||||
"fmt"
|
"fmt"
|
||||||
"strconv"
|
"strconv"
|
||||||
"unsafe"
|
"unsafe"
|
||||||
|
|
||||||
|
"go.opentelemetry.io/otel/api/internal"
|
||||||
)
|
)
|
||||||
|
|
||||||
// Key represents the key part in key-value pairs. It's a string. The
|
// Key represents the key part in key-value pairs. It's a string. The
|
||||||
@ -60,7 +62,7 @@ const (
|
|||||||
func Bool(v bool) Value {
|
func Bool(v bool) Value {
|
||||||
return Value{
|
return Value{
|
||||||
vtype: BOOL,
|
vtype: BOOL,
|
||||||
numeric: boolToRaw(v),
|
numeric: internal.BoolToRaw(v),
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
@ -68,7 +70,7 @@ func Bool(v bool) Value {
|
|||||||
func Int64(v int64) Value {
|
func Int64(v int64) Value {
|
||||||
return Value{
|
return Value{
|
||||||
vtype: INT64,
|
vtype: INT64,
|
||||||
numeric: int64ToRaw(v),
|
numeric: internal.Int64ToRaw(v),
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
@ -76,7 +78,7 @@ func Int64(v int64) Value {
|
|||||||
func Uint64(v uint64) Value {
|
func Uint64(v uint64) Value {
|
||||||
return Value{
|
return Value{
|
||||||
vtype: UINT64,
|
vtype: UINT64,
|
||||||
numeric: uint64ToRaw(v),
|
numeric: internal.Uint64ToRaw(v),
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
@ -84,7 +86,7 @@ func Uint64(v uint64) Value {
|
|||||||
func Float64(v float64) Value {
|
func Float64(v float64) Value {
|
||||||
return Value{
|
return Value{
|
||||||
vtype: FLOAT64,
|
vtype: FLOAT64,
|
||||||
numeric: float64ToRaw(v),
|
numeric: internal.Float64ToRaw(v),
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
@ -92,7 +94,7 @@ func Float64(v float64) Value {
|
|||||||
func Int32(v int32) Value {
|
func Int32(v int32) Value {
|
||||||
return Value{
|
return Value{
|
||||||
vtype: INT32,
|
vtype: INT32,
|
||||||
numeric: int32ToRaw(v),
|
numeric: internal.Int32ToRaw(v),
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
@ -100,7 +102,7 @@ func Int32(v int32) Value {
|
|||||||
func Uint32(v uint32) Value {
|
func Uint32(v uint32) Value {
|
||||||
return Value{
|
return Value{
|
||||||
vtype: UINT32,
|
vtype: UINT32,
|
||||||
numeric: uint32ToRaw(v),
|
numeric: internal.Uint32ToRaw(v),
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
@ -108,7 +110,7 @@ func Uint32(v uint32) Value {
|
|||||||
func Float32(v float32) Value {
|
func Float32(v float32) Value {
|
||||||
return Value{
|
return Value{
|
||||||
vtype: FLOAT32,
|
vtype: FLOAT32,
|
||||||
numeric: float32ToRaw(v),
|
numeric: internal.Float32ToRaw(v),
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
@ -283,43 +285,43 @@ func (v Value) Type() ValueType {
|
|||||||
// AsBool returns the bool value. Make sure that the Value's type is
|
// AsBool returns the bool value. Make sure that the Value's type is
|
||||||
// BOOL.
|
// BOOL.
|
||||||
func (v Value) AsBool() bool {
|
func (v Value) AsBool() bool {
|
||||||
return rawToBool(v.numeric)
|
return internal.RawToBool(v.numeric)
|
||||||
}
|
}
|
||||||
|
|
||||||
// AsInt32 returns the int32 value. Make sure that the Value's type is
|
// AsInt32 returns the int32 value. Make sure that the Value's type is
|
||||||
// INT32.
|
// INT32.
|
||||||
func (v Value) AsInt32() int32 {
|
func (v Value) AsInt32() int32 {
|
||||||
return rawToInt32(v.numeric)
|
return internal.RawToInt32(v.numeric)
|
||||||
}
|
}
|
||||||
|
|
||||||
// AsInt64 returns the int64 value. Make sure that the Value's type is
|
// AsInt64 returns the int64 value. Make sure that the Value's type is
|
||||||
// INT64.
|
// INT64.
|
||||||
func (v Value) AsInt64() int64 {
|
func (v Value) AsInt64() int64 {
|
||||||
return rawToInt64(v.numeric)
|
return internal.RawToInt64(v.numeric)
|
||||||
}
|
}
|
||||||
|
|
||||||
// AsUint32 returns the uint32 value. Make sure that the Value's type
|
// AsUint32 returns the uint32 value. Make sure that the Value's type
|
||||||
// is UINT32.
|
// is UINT32.
|
||||||
func (v Value) AsUint32() uint32 {
|
func (v Value) AsUint32() uint32 {
|
||||||
return rawToUint32(v.numeric)
|
return internal.RawToUint32(v.numeric)
|
||||||
}
|
}
|
||||||
|
|
||||||
// AsUint64 returns the uint64 value. Make sure that the Value's type is
|
// AsUint64 returns the uint64 value. Make sure that the Value's type is
|
||||||
// UINT64.
|
// UINT64.
|
||||||
func (v Value) AsUint64() uint64 {
|
func (v Value) AsUint64() uint64 {
|
||||||
return rawToUint64(v.numeric)
|
return internal.RawToUint64(v.numeric)
|
||||||
}
|
}
|
||||||
|
|
||||||
// AsFloat32 returns the float32 value. Make sure that the Value's
|
// AsFloat32 returns the float32 value. Make sure that the Value's
|
||||||
// type is FLOAT32.
|
// type is FLOAT32.
|
||||||
func (v Value) AsFloat32() float32 {
|
func (v Value) AsFloat32() float32 {
|
||||||
return rawToFloat32(v.numeric)
|
return internal.RawToFloat32(v.numeric)
|
||||||
}
|
}
|
||||||
|
|
||||||
// AsFloat64 returns the float64 value. Make sure that the Value's
|
// AsFloat64 returns the float64 value. Make sure that the Value's
|
||||||
// type is FLOAT64.
|
// type is FLOAT64.
|
||||||
func (v Value) AsFloat64() float64 {
|
func (v Value) AsFloat64() float64 {
|
||||||
return rawToFloat64(v.numeric)
|
return internal.RawToFloat64(v.numeric)
|
||||||
}
|
}
|
||||||
|
|
||||||
// AsString returns the string value. Make sure that the Value's type
|
// AsString returns the string value. Make sure that the Value's type
|
||||||
|
@ -332,7 +332,7 @@ func (m *meter) RecordBatch(ctx context.Context, labels []core.KeyValue, measure
|
|||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
func (inst *syncImpl) RecordOne(ctx context.Context, number core.Number, labels []core.KeyValue) {
|
func (inst *syncImpl) RecordOne(ctx context.Context, number metric.Number, labels []core.KeyValue) {
|
||||||
if instPtr := (*metric.SyncImpl)(atomic.LoadPointer(&inst.delegate)); instPtr != nil {
|
if instPtr := (*metric.SyncImpl)(atomic.LoadPointer(&inst.delegate)); instPtr != nil {
|
||||||
(*instPtr).RecordOne(ctx, number, labels)
|
(*instPtr).RecordOne(ctx, number, labels)
|
||||||
}
|
}
|
||||||
@ -340,7 +340,7 @@ func (inst *syncImpl) RecordOne(ctx context.Context, number core.Number, labels
|
|||||||
|
|
||||||
// Bound instrument initialization
|
// Bound instrument initialization
|
||||||
|
|
||||||
func (bound *syncHandle) RecordOne(ctx context.Context, number core.Number) {
|
func (bound *syncHandle) RecordOne(ctx context.Context, number metric.Number) {
|
||||||
instPtr := (*metric.SyncImpl)(atomic.LoadPointer(&bound.inst.delegate))
|
instPtr := (*metric.SyncImpl)(atomic.LoadPointer(&bound.inst.delegate))
|
||||||
if instPtr == nil {
|
if instPtr == nil {
|
||||||
return
|
return
|
||||||
@ -371,7 +371,7 @@ func (m *meter) withName(opts []metric.Option) []metric.Option {
|
|||||||
|
|
||||||
func (m *meter) NewInt64Counter(name string, opts ...metric.Option) (metric.Int64Counter, error) {
|
func (m *meter) NewInt64Counter(name string, opts ...metric.Option) (metric.Int64Counter, error) {
|
||||||
return metric.WrapInt64CounterInstrument(m.newSync(
|
return metric.WrapInt64CounterInstrument(m.newSync(
|
||||||
metric.NewDescriptor(name, metric.CounterKind, core.Int64NumberKind, m.withName(opts)...),
|
metric.NewDescriptor(name, metric.CounterKind, metric.Int64NumberKind, m.withName(opts)...),
|
||||||
func(other metric.Meter) (metric.SyncImpl, error) {
|
func(other metric.Meter) (metric.SyncImpl, error) {
|
||||||
return syncCheck(other.NewInt64Counter(name, opts...))
|
return syncCheck(other.NewInt64Counter(name, opts...))
|
||||||
}))
|
}))
|
||||||
@ -379,7 +379,7 @@ func (m *meter) NewInt64Counter(name string, opts ...metric.Option) (metric.Int6
|
|||||||
|
|
||||||
func (m *meter) NewFloat64Counter(name string, opts ...metric.Option) (metric.Float64Counter, error) {
|
func (m *meter) NewFloat64Counter(name string, opts ...metric.Option) (metric.Float64Counter, error) {
|
||||||
return metric.WrapFloat64CounterInstrument(m.newSync(
|
return metric.WrapFloat64CounterInstrument(m.newSync(
|
||||||
metric.NewDescriptor(name, metric.CounterKind, core.Float64NumberKind, m.withName(opts)...),
|
metric.NewDescriptor(name, metric.CounterKind, metric.Float64NumberKind, m.withName(opts)...),
|
||||||
func(other metric.Meter) (metric.SyncImpl, error) {
|
func(other metric.Meter) (metric.SyncImpl, error) {
|
||||||
return syncCheck(other.NewFloat64Counter(name, opts...))
|
return syncCheck(other.NewFloat64Counter(name, opts...))
|
||||||
}))
|
}))
|
||||||
@ -387,7 +387,7 @@ func (m *meter) NewFloat64Counter(name string, opts ...metric.Option) (metric.Fl
|
|||||||
|
|
||||||
func (m *meter) NewInt64Measure(name string, opts ...metric.Option) (metric.Int64Measure, error) {
|
func (m *meter) NewInt64Measure(name string, opts ...metric.Option) (metric.Int64Measure, error) {
|
||||||
return metric.WrapInt64MeasureInstrument(m.newSync(
|
return metric.WrapInt64MeasureInstrument(m.newSync(
|
||||||
metric.NewDescriptor(name, metric.MeasureKind, core.Int64NumberKind, m.withName(opts)...),
|
metric.NewDescriptor(name, metric.MeasureKind, metric.Int64NumberKind, m.withName(opts)...),
|
||||||
func(other metric.Meter) (metric.SyncImpl, error) {
|
func(other metric.Meter) (metric.SyncImpl, error) {
|
||||||
return syncCheck(other.NewInt64Measure(name, opts...))
|
return syncCheck(other.NewInt64Measure(name, opts...))
|
||||||
}))
|
}))
|
||||||
@ -395,7 +395,7 @@ func (m *meter) NewInt64Measure(name string, opts ...metric.Option) (metric.Int6
|
|||||||
|
|
||||||
func (m *meter) NewFloat64Measure(name string, opts ...metric.Option) (metric.Float64Measure, error) {
|
func (m *meter) NewFloat64Measure(name string, opts ...metric.Option) (metric.Float64Measure, error) {
|
||||||
return metric.WrapFloat64MeasureInstrument(m.newSync(
|
return metric.WrapFloat64MeasureInstrument(m.newSync(
|
||||||
metric.NewDescriptor(name, metric.MeasureKind, core.Float64NumberKind, m.withName(opts)...),
|
metric.NewDescriptor(name, metric.MeasureKind, metric.Float64NumberKind, m.withName(opts)...),
|
||||||
func(other metric.Meter) (metric.SyncImpl, error) {
|
func(other metric.Meter) (metric.SyncImpl, error) {
|
||||||
return syncCheck(other.NewFloat64Measure(name, opts...))
|
return syncCheck(other.NewFloat64Measure(name, opts...))
|
||||||
}))
|
}))
|
||||||
@ -403,7 +403,7 @@ func (m *meter) NewFloat64Measure(name string, opts ...metric.Option) (metric.Fl
|
|||||||
|
|
||||||
func (m *meter) RegisterInt64Observer(name string, callback metric.Int64ObserverCallback, opts ...metric.Option) (metric.Int64Observer, error) {
|
func (m *meter) RegisterInt64Observer(name string, callback metric.Int64ObserverCallback, opts ...metric.Option) (metric.Int64Observer, error) {
|
||||||
return metric.WrapInt64ObserverInstrument(m.newAsync(
|
return metric.WrapInt64ObserverInstrument(m.newAsync(
|
||||||
metric.NewDescriptor(name, metric.ObserverKind, core.Int64NumberKind, m.withName(opts)...),
|
metric.NewDescriptor(name, metric.ObserverKind, metric.Int64NumberKind, m.withName(opts)...),
|
||||||
func(other metric.Meter) (metric.AsyncImpl, error) {
|
func(other metric.Meter) (metric.AsyncImpl, error) {
|
||||||
return asyncCheck(other.RegisterInt64Observer(name, callback, opts...))
|
return asyncCheck(other.RegisterInt64Observer(name, callback, opts...))
|
||||||
}))
|
}))
|
||||||
@ -411,7 +411,7 @@ func (m *meter) RegisterInt64Observer(name string, callback metric.Int64Observer
|
|||||||
|
|
||||||
func (m *meter) RegisterFloat64Observer(name string, callback metric.Float64ObserverCallback, opts ...metric.Option) (metric.Float64Observer, error) {
|
func (m *meter) RegisterFloat64Observer(name string, callback metric.Float64ObserverCallback, opts ...metric.Option) (metric.Float64Observer, error) {
|
||||||
return metric.WrapFloat64ObserverInstrument(m.newAsync(
|
return metric.WrapFloat64ObserverInstrument(m.newAsync(
|
||||||
metric.NewDescriptor(name, metric.ObserverKind, core.Float64NumberKind, m.withName(opts)...),
|
metric.NewDescriptor(name, metric.ObserverKind, metric.Float64NumberKind, m.withName(opts)...),
|
||||||
func(other metric.Meter) (metric.AsyncImpl, error) {
|
func(other metric.Meter) (metric.AsyncImpl, error) {
|
||||||
return asyncCheck(other.RegisterFloat64Observer(name, callback, opts...))
|
return asyncCheck(other.RegisterFloat64Observer(name, callback, opts...))
|
||||||
}))
|
}))
|
||||||
|
@ -38,7 +38,7 @@ type measured struct {
|
|||||||
Name string
|
Name string
|
||||||
LibraryName string
|
LibraryName string
|
||||||
Labels map[core.Key]core.Value
|
Labels map[core.Key]core.Value
|
||||||
Number core.Number
|
Number metric.Number
|
||||||
}
|
}
|
||||||
|
|
||||||
func asStructs(batches []metrictest.Batch) []measured {
|
func asStructs(batches []metrictest.Batch) []measured {
|
||||||
@ -64,8 +64,8 @@ func asMap(kvs ...core.KeyValue) map[core.Key]core.Value {
|
|||||||
return m
|
return m
|
||||||
}
|
}
|
||||||
|
|
||||||
var asInt = core.NewInt64Number
|
var asInt = metric.NewInt64Number
|
||||||
var asFloat = core.NewFloat64Number
|
var asFloat = metric.NewFloat64Number
|
||||||
|
|
||||||
func TestDirect(t *testing.T) {
|
func TestDirect(t *testing.T) {
|
||||||
internal.ResetForTest()
|
internal.ResetForTest()
|
||||||
|
@ -12,80 +12,80 @@
|
|||||||
// See the License for the specific language governing permissions and
|
// See the License for the specific language governing permissions and
|
||||||
// limitations under the License.
|
// limitations under the License.
|
||||||
|
|
||||||
package core
|
package internal
|
||||||
|
|
||||||
import (
|
import (
|
||||||
"math"
|
"math"
|
||||||
"unsafe"
|
"unsafe"
|
||||||
)
|
)
|
||||||
|
|
||||||
func boolToRaw(b bool) uint64 {
|
func BoolToRaw(b bool) uint64 {
|
||||||
if b {
|
if b {
|
||||||
return 1
|
return 1
|
||||||
}
|
}
|
||||||
return 0
|
return 0
|
||||||
}
|
}
|
||||||
|
|
||||||
func rawToBool(r uint64) bool {
|
func RawToBool(r uint64) bool {
|
||||||
return r != 0
|
return r != 0
|
||||||
}
|
}
|
||||||
|
|
||||||
func int64ToRaw(i int64) uint64 {
|
func Int64ToRaw(i int64) uint64 {
|
||||||
return uint64(i)
|
return uint64(i)
|
||||||
}
|
}
|
||||||
|
|
||||||
func rawToInt64(r uint64) int64 {
|
func RawToInt64(r uint64) int64 {
|
||||||
return int64(r)
|
return int64(r)
|
||||||
}
|
}
|
||||||
|
|
||||||
func uint64ToRaw(u uint64) uint64 {
|
func Uint64ToRaw(u uint64) uint64 {
|
||||||
return u
|
return u
|
||||||
}
|
}
|
||||||
|
|
||||||
func rawToUint64(r uint64) uint64 {
|
func RawToUint64(r uint64) uint64 {
|
||||||
return r
|
return r
|
||||||
}
|
}
|
||||||
|
|
||||||
func float64ToRaw(f float64) uint64 {
|
func Float64ToRaw(f float64) uint64 {
|
||||||
return math.Float64bits(f)
|
return math.Float64bits(f)
|
||||||
}
|
}
|
||||||
|
|
||||||
func rawToFloat64(r uint64) float64 {
|
func RawToFloat64(r uint64) float64 {
|
||||||
return math.Float64frombits(r)
|
return math.Float64frombits(r)
|
||||||
}
|
}
|
||||||
|
|
||||||
func int32ToRaw(i int32) uint64 {
|
func Int32ToRaw(i int32) uint64 {
|
||||||
return uint64(i)
|
return uint64(i)
|
||||||
}
|
}
|
||||||
|
|
||||||
func rawToInt32(r uint64) int32 {
|
func RawToInt32(r uint64) int32 {
|
||||||
return int32(r)
|
return int32(r)
|
||||||
}
|
}
|
||||||
|
|
||||||
func uint32ToRaw(u uint32) uint64 {
|
func Uint32ToRaw(u uint32) uint64 {
|
||||||
return uint64(u)
|
return uint64(u)
|
||||||
}
|
}
|
||||||
|
|
||||||
func rawToUint32(r uint64) uint32 {
|
func RawToUint32(r uint64) uint32 {
|
||||||
return uint32(r)
|
return uint32(r)
|
||||||
}
|
}
|
||||||
|
|
||||||
func float32ToRaw(f float32) uint64 {
|
func Float32ToRaw(f float32) uint64 {
|
||||||
return uint32ToRaw(math.Float32bits(f))
|
return Uint32ToRaw(math.Float32bits(f))
|
||||||
}
|
}
|
||||||
|
|
||||||
func rawToFloat32(r uint64) float32 {
|
func RawToFloat32(r uint64) float32 {
|
||||||
return math.Float32frombits(rawToUint32(r))
|
return math.Float32frombits(RawToUint32(r))
|
||||||
}
|
}
|
||||||
|
|
||||||
func rawPtrToFloat64Ptr(r *uint64) *float64 {
|
func RawPtrToFloat64Ptr(r *uint64) *float64 {
|
||||||
return (*float64)(unsafe.Pointer(r))
|
return (*float64)(unsafe.Pointer(r))
|
||||||
}
|
}
|
||||||
|
|
||||||
func rawPtrToInt64Ptr(r *uint64) *int64 {
|
func RawPtrToInt64Ptr(r *uint64) *int64 {
|
||||||
return (*int64)(unsafe.Pointer(r))
|
return (*int64)(unsafe.Pointer(r))
|
||||||
}
|
}
|
||||||
|
|
||||||
func rawPtrToUint64Ptr(r *uint64) *uint64 {
|
func RawPtrToUint64Ptr(r *uint64) *uint64 {
|
||||||
return r
|
return r
|
||||||
}
|
}
|
@ -53,7 +53,7 @@ type Option interface {
|
|||||||
// (e.g., Int64Counter.Measurement()).
|
// (e.g., Int64Counter.Measurement()).
|
||||||
type Measurement struct {
|
type Measurement struct {
|
||||||
// number needs to be aligned for 64-bit atomic operations.
|
// number needs to be aligned for 64-bit atomic operations.
|
||||||
number core.Number
|
number Number
|
||||||
instrument SyncImpl
|
instrument SyncImpl
|
||||||
}
|
}
|
||||||
|
|
||||||
@ -65,7 +65,7 @@ func (m Measurement) SyncImpl() SyncImpl {
|
|||||||
}
|
}
|
||||||
|
|
||||||
// Number returns a number recorded in this measurement.
|
// Number returns a number recorded in this measurement.
|
||||||
func (m Measurement) Number() core.Number {
|
func (m Measurement) Number() Number {
|
||||||
return m.number
|
return m.number
|
||||||
}
|
}
|
||||||
|
|
||||||
@ -87,12 +87,12 @@ const (
|
|||||||
type Descriptor struct {
|
type Descriptor struct {
|
||||||
name string
|
name string
|
||||||
kind Kind
|
kind Kind
|
||||||
numberKind core.NumberKind
|
numberKind NumberKind
|
||||||
config Config
|
config Config
|
||||||
}
|
}
|
||||||
|
|
||||||
// NewDescriptor returns a Descriptor with the given contents.
|
// NewDescriptor returns a Descriptor with the given contents.
|
||||||
func NewDescriptor(name string, mkind Kind, nkind core.NumberKind, opts ...Option) Descriptor {
|
func NewDescriptor(name string, mkind Kind, nkind NumberKind, opts ...Option) Descriptor {
|
||||||
return Descriptor{
|
return Descriptor{
|
||||||
name: name,
|
name: name,
|
||||||
kind: mkind,
|
kind: mkind,
|
||||||
@ -125,7 +125,7 @@ func (d Descriptor) Unit() unit.Unit {
|
|||||||
|
|
||||||
// NumberKind returns whether this instrument is declared over int64,
|
// NumberKind returns whether this instrument is declared over int64,
|
||||||
// float64, or uint64 values.
|
// float64, or uint64 values.
|
||||||
func (d Descriptor) NumberKind() core.NumberKind {
|
func (d Descriptor) NumberKind() NumberKind {
|
||||||
return d.numberKind
|
return d.numberKind
|
||||||
}
|
}
|
||||||
|
|
||||||
|
@ -104,7 +104,7 @@ func TestCounter(t *testing.T) {
|
|||||||
boundInstrument.Add(ctx, 42)
|
boundInstrument.Add(ctx, 42)
|
||||||
meter.RecordBatch(ctx, labels, c.Measurement(42))
|
meter.RecordBatch(ctx, labels, c.Measurement(42))
|
||||||
t.Log("Testing float counter")
|
t.Log("Testing float counter")
|
||||||
checkBatches(t, ctx, labels, mockSDK, core.Float64NumberKind, c.SyncImpl())
|
checkBatches(t, ctx, labels, mockSDK, metric.Float64NumberKind, c.SyncImpl())
|
||||||
}
|
}
|
||||||
{
|
{
|
||||||
mockSDK, meter := mockTest.NewMeter()
|
mockSDK, meter := mockTest.NewMeter()
|
||||||
@ -116,7 +116,7 @@ func TestCounter(t *testing.T) {
|
|||||||
boundInstrument.Add(ctx, 42)
|
boundInstrument.Add(ctx, 42)
|
||||||
meter.RecordBatch(ctx, labels, c.Measurement(42))
|
meter.RecordBatch(ctx, labels, c.Measurement(42))
|
||||||
t.Log("Testing int counter")
|
t.Log("Testing int counter")
|
||||||
checkBatches(t, ctx, labels, mockSDK, core.Int64NumberKind, c.SyncImpl())
|
checkBatches(t, ctx, labels, mockSDK, metric.Int64NumberKind, c.SyncImpl())
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
@ -131,7 +131,7 @@ func TestMeasure(t *testing.T) {
|
|||||||
boundInstrument.Record(ctx, 42)
|
boundInstrument.Record(ctx, 42)
|
||||||
meter.RecordBatch(ctx, labels, m.Measurement(42))
|
meter.RecordBatch(ctx, labels, m.Measurement(42))
|
||||||
t.Log("Testing float measure")
|
t.Log("Testing float measure")
|
||||||
checkBatches(t, ctx, labels, mockSDK, core.Float64NumberKind, m.SyncImpl())
|
checkBatches(t, ctx, labels, mockSDK, metric.Float64NumberKind, m.SyncImpl())
|
||||||
}
|
}
|
||||||
{
|
{
|
||||||
mockSDK, meter := mockTest.NewMeter()
|
mockSDK, meter := mockTest.NewMeter()
|
||||||
@ -143,7 +143,7 @@ func TestMeasure(t *testing.T) {
|
|||||||
boundInstrument.Record(ctx, 42)
|
boundInstrument.Record(ctx, 42)
|
||||||
meter.RecordBatch(ctx, labels, m.Measurement(42))
|
meter.RecordBatch(ctx, labels, m.Measurement(42))
|
||||||
t.Log("Testing int measure")
|
t.Log("Testing int measure")
|
||||||
checkBatches(t, ctx, labels, mockSDK, core.Int64NumberKind, m.SyncImpl())
|
checkBatches(t, ctx, labels, mockSDK, metric.Int64NumberKind, m.SyncImpl())
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
@ -157,7 +157,7 @@ func TestObserver(t *testing.T) {
|
|||||||
t.Log("Testing float observer")
|
t.Log("Testing float observer")
|
||||||
|
|
||||||
mockSDK.RunAsyncInstruments()
|
mockSDK.RunAsyncInstruments()
|
||||||
checkObserverBatch(t, labels, mockSDK, core.Float64NumberKind, o.AsyncImpl())
|
checkObserverBatch(t, labels, mockSDK, metric.Float64NumberKind, o.AsyncImpl())
|
||||||
}
|
}
|
||||||
{
|
{
|
||||||
labels := []core.KeyValue{}
|
labels := []core.KeyValue{}
|
||||||
@ -167,11 +167,11 @@ func TestObserver(t *testing.T) {
|
|||||||
})
|
})
|
||||||
t.Log("Testing int observer")
|
t.Log("Testing int observer")
|
||||||
mockSDK.RunAsyncInstruments()
|
mockSDK.RunAsyncInstruments()
|
||||||
checkObserverBatch(t, labels, mockSDK, core.Int64NumberKind, o.AsyncImpl())
|
checkObserverBatch(t, labels, mockSDK, metric.Int64NumberKind, o.AsyncImpl())
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
func checkBatches(t *testing.T, ctx context.Context, labels []core.KeyValue, mock *mockTest.MeterImpl, kind core.NumberKind, instrument metric.InstrumentImpl) {
|
func checkBatches(t *testing.T, ctx context.Context, labels []core.KeyValue, mock *mockTest.MeterImpl, kind metric.NumberKind, instrument metric.InstrumentImpl) {
|
||||||
t.Helper()
|
t.Helper()
|
||||||
if len(mock.MeasurementBatches) != 3 {
|
if len(mock.MeasurementBatches) != 3 {
|
||||||
t.Errorf("Expected 3 recorded measurement batches, got %d", len(mock.MeasurementBatches))
|
t.Errorf("Expected 3 recorded measurement batches, got %d", len(mock.MeasurementBatches))
|
||||||
@ -211,7 +211,7 @@ func checkBatches(t *testing.T, ctx context.Context, labels []core.KeyValue, moc
|
|||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
func checkObserverBatch(t *testing.T, labels []core.KeyValue, mock *mockTest.MeterImpl, kind core.NumberKind, observer metric.AsyncImpl) {
|
func checkObserverBatch(t *testing.T, labels []core.KeyValue, mock *mockTest.MeterImpl, kind metric.NumberKind, observer metric.AsyncImpl) {
|
||||||
t.Helper()
|
t.Helper()
|
||||||
assert.Len(t, mock.MeasurementBatches, 1)
|
assert.Len(t, mock.MeasurementBatches, 1)
|
||||||
if len(mock.MeasurementBatches) < 1 {
|
if len(mock.MeasurementBatches) < 1 {
|
||||||
@ -233,16 +233,16 @@ func checkObserverBatch(t *testing.T, labels []core.KeyValue, mock *mockTest.Met
|
|||||||
assert.Equal(t, 0, measurement.Number.CompareNumber(kind, ft))
|
assert.Equal(t, 0, measurement.Number.CompareNumber(kind, ft))
|
||||||
}
|
}
|
||||||
|
|
||||||
func fortyTwo(t *testing.T, kind core.NumberKind) core.Number {
|
func fortyTwo(t *testing.T, kind metric.NumberKind) metric.Number {
|
||||||
t.Helper()
|
t.Helper()
|
||||||
switch kind {
|
switch kind {
|
||||||
case core.Int64NumberKind:
|
case metric.Int64NumberKind:
|
||||||
return core.NewInt64Number(42)
|
return metric.NewInt64Number(42)
|
||||||
case core.Float64NumberKind:
|
case metric.Float64NumberKind:
|
||||||
return core.NewFloat64Number(42)
|
return metric.NewFloat64Number(42)
|
||||||
}
|
}
|
||||||
t.Errorf("Invalid value kind %q", kind)
|
t.Errorf("Invalid value kind %q", kind)
|
||||||
return core.NewInt64Number(0)
|
return metric.NewInt64Number(0)
|
||||||
}
|
}
|
||||||
|
|
||||||
type testWrappedMeter struct {
|
type testWrappedMeter struct {
|
||||||
@ -257,7 +257,7 @@ func (testWrappedMeter) NewSyncInstrument(_ metric.Descriptor) (metric.SyncImpl,
|
|||||||
return nil, nil
|
return nil, nil
|
||||||
}
|
}
|
||||||
|
|
||||||
func (testWrappedMeter) NewAsyncInstrument(_ metric.Descriptor, _ func(func(core.Number, []core.KeyValue))) (metric.AsyncImpl, error) {
|
func (testWrappedMeter) NewAsyncInstrument(_ metric.Descriptor, _ func(func(metric.Number, []core.KeyValue))) (metric.AsyncImpl, error) {
|
||||||
return nil, errors.New("Test wrap error")
|
return nil, errors.New("Test wrap error")
|
||||||
}
|
}
|
||||||
|
|
||||||
|
@ -40,14 +40,14 @@ func (s syncInstrument) bind(labels []core.KeyValue) syncBoundInstrument {
|
|||||||
}
|
}
|
||||||
|
|
||||||
func (s syncInstrument) float64Measurement(value float64) Measurement {
|
func (s syncInstrument) float64Measurement(value float64) Measurement {
|
||||||
return newMeasurement(s.instrument, core.NewFloat64Number(value))
|
return newMeasurement(s.instrument, NewFloat64Number(value))
|
||||||
}
|
}
|
||||||
|
|
||||||
func (s syncInstrument) int64Measurement(value int64) Measurement {
|
func (s syncInstrument) int64Measurement(value int64) Measurement {
|
||||||
return newMeasurement(s.instrument, core.NewInt64Number(value))
|
return newMeasurement(s.instrument, NewInt64Number(value))
|
||||||
}
|
}
|
||||||
|
|
||||||
func (s syncInstrument) directRecord(ctx context.Context, number core.Number, labels []core.KeyValue) {
|
func (s syncInstrument) directRecord(ctx context.Context, number Number, labels []core.KeyValue) {
|
||||||
s.instrument.RecordOne(ctx, number, labels)
|
s.instrument.RecordOne(ctx, number, labels)
|
||||||
}
|
}
|
||||||
|
|
||||||
@ -55,7 +55,7 @@ func (s syncInstrument) SyncImpl() SyncImpl {
|
|||||||
return s.instrument
|
return s.instrument
|
||||||
}
|
}
|
||||||
|
|
||||||
func (h syncBoundInstrument) directRecord(ctx context.Context, number core.Number) {
|
func (h syncBoundInstrument) directRecord(ctx context.Context, number Number) {
|
||||||
h.boundInstrument.RecordOne(ctx, number)
|
h.boundInstrument.RecordOne(ctx, number)
|
||||||
}
|
}
|
||||||
|
|
||||||
@ -93,7 +93,7 @@ func newSyncBoundInstrument(boundInstrument BoundSyncImpl) syncBoundInstrument {
|
|||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
func newMeasurement(instrument SyncImpl, number core.Number) Measurement {
|
func newMeasurement(instrument SyncImpl, number Number) Measurement {
|
||||||
return Measurement{
|
return Measurement{
|
||||||
instrument: instrument,
|
instrument: instrument,
|
||||||
number: number,
|
number: number,
|
||||||
|
@ -73,23 +73,23 @@ func (c Int64Counter) Measurement(value int64) Measurement {
|
|||||||
// Add adds the value to the counter's sum. The labels should contain
|
// Add adds the value to the counter's sum. The labels should contain
|
||||||
// the keys and values to be associated with this value.
|
// the keys and values to be associated with this value.
|
||||||
func (c Float64Counter) Add(ctx context.Context, value float64, labels ...core.KeyValue) {
|
func (c Float64Counter) Add(ctx context.Context, value float64, labels ...core.KeyValue) {
|
||||||
c.directRecord(ctx, core.NewFloat64Number(value), labels)
|
c.directRecord(ctx, NewFloat64Number(value), labels)
|
||||||
}
|
}
|
||||||
|
|
||||||
// Add adds the value to the counter's sum. The labels should contain
|
// Add adds the value to the counter's sum. The labels should contain
|
||||||
// the keys and values to be associated with this value.
|
// the keys and values to be associated with this value.
|
||||||
func (c Int64Counter) Add(ctx context.Context, value int64, labels ...core.KeyValue) {
|
func (c Int64Counter) Add(ctx context.Context, value int64, labels ...core.KeyValue) {
|
||||||
c.directRecord(ctx, core.NewInt64Number(value), labels)
|
c.directRecord(ctx, NewInt64Number(value), labels)
|
||||||
}
|
}
|
||||||
|
|
||||||
// Add adds the value to the counter's sum using the labels
|
// Add adds the value to the counter's sum using the labels
|
||||||
// previously bound to this counter via Bind()
|
// previously bound to this counter via Bind()
|
||||||
func (b BoundFloat64Counter) Add(ctx context.Context, value float64) {
|
func (b BoundFloat64Counter) Add(ctx context.Context, value float64) {
|
||||||
b.directRecord(ctx, core.NewFloat64Number(value))
|
b.directRecord(ctx, NewFloat64Number(value))
|
||||||
}
|
}
|
||||||
|
|
||||||
// Add adds the value to the counter's sum using the labels
|
// Add adds the value to the counter's sum using the labels
|
||||||
// previously bound to this counter via Bind()
|
// previously bound to this counter via Bind()
|
||||||
func (b BoundInt64Counter) Add(ctx context.Context, value int64) {
|
func (b BoundInt64Counter) Add(ctx context.Context, value int64) {
|
||||||
b.directRecord(ctx, core.NewInt64Number(value))
|
b.directRecord(ctx, NewInt64Number(value))
|
||||||
}
|
}
|
||||||
|
@ -74,24 +74,24 @@ func (c Int64Measure) Measurement(value int64) Measurement {
|
|||||||
// labels should contain the keys and values to be associated with
|
// labels should contain the keys and values to be associated with
|
||||||
// this value.
|
// this value.
|
||||||
func (c Float64Measure) Record(ctx context.Context, value float64, labels ...core.KeyValue) {
|
func (c Float64Measure) Record(ctx context.Context, value float64, labels ...core.KeyValue) {
|
||||||
c.directRecord(ctx, core.NewFloat64Number(value), labels)
|
c.directRecord(ctx, NewFloat64Number(value), labels)
|
||||||
}
|
}
|
||||||
|
|
||||||
// Record adds a new value to the list of measure's records. The
|
// Record adds a new value to the list of measure's records. The
|
||||||
// labels should contain the keys and values to be associated with
|
// labels should contain the keys and values to be associated with
|
||||||
// this value.
|
// this value.
|
||||||
func (c Int64Measure) Record(ctx context.Context, value int64, labels ...core.KeyValue) {
|
func (c Int64Measure) Record(ctx context.Context, value int64, labels ...core.KeyValue) {
|
||||||
c.directRecord(ctx, core.NewInt64Number(value), labels)
|
c.directRecord(ctx, NewInt64Number(value), labels)
|
||||||
}
|
}
|
||||||
|
|
||||||
// Record adds a new value to the list of measure's records using the labels
|
// Record adds a new value to the list of measure's records using the labels
|
||||||
// previously bound to the measure via Bind()
|
// previously bound to the measure via Bind()
|
||||||
func (b BoundFloat64Measure) Record(ctx context.Context, value float64) {
|
func (b BoundFloat64Measure) Record(ctx context.Context, value float64) {
|
||||||
b.directRecord(ctx, core.NewFloat64Number(value))
|
b.directRecord(ctx, NewFloat64Number(value))
|
||||||
}
|
}
|
||||||
|
|
||||||
// Record adds a new value to the list of measure's records using the labels
|
// Record adds a new value to the list of measure's records using the labels
|
||||||
// previously bound to the measure via Bind()
|
// previously bound to the measure via Bind()
|
||||||
func (b BoundInt64Measure) Record(ctx context.Context, value int64) {
|
func (b BoundInt64Measure) Record(ctx context.Context, value int64) {
|
||||||
b.directRecord(ctx, core.NewInt64Number(value))
|
b.directRecord(ctx, NewInt64Number(value))
|
||||||
}
|
}
|
||||||
|
@ -46,7 +46,7 @@ func (noopInstrument) Descriptor() Descriptor {
|
|||||||
return Descriptor{}
|
return Descriptor{}
|
||||||
}
|
}
|
||||||
|
|
||||||
func (noopBoundInstrument) RecordOne(context.Context, core.Number) {
|
func (noopBoundInstrument) RecordOne(context.Context, Number) {
|
||||||
}
|
}
|
||||||
|
|
||||||
func (noopBoundInstrument) Unbind() {
|
func (noopBoundInstrument) Unbind() {
|
||||||
@ -56,7 +56,7 @@ func (NoopSync) Bind([]core.KeyValue) BoundSyncImpl {
|
|||||||
return noopBoundInstrument{}
|
return noopBoundInstrument{}
|
||||||
}
|
}
|
||||||
|
|
||||||
func (NoopSync) RecordOne(context.Context, core.Number, []core.KeyValue) {
|
func (NoopSync) RecordOne(context.Context, Number, []core.KeyValue) {
|
||||||
}
|
}
|
||||||
|
|
||||||
func (NoopMeter) RecordBatch(context.Context, []core.KeyValue, ...Measurement) {
|
func (NoopMeter) RecordBatch(context.Context, []core.KeyValue, ...Measurement) {
|
||||||
|
@ -12,7 +12,7 @@
|
|||||||
// See the License for the specific language governing permissions and
|
// See the License for the specific language governing permissions and
|
||||||
// limitations under the License.
|
// limitations under the License.
|
||||||
|
|
||||||
package core
|
package metric
|
||||||
|
|
||||||
//go:generate stringer -type=NumberKind
|
//go:generate stringer -type=NumberKind
|
||||||
|
|
||||||
@ -20,6 +20,8 @@ import (
|
|||||||
"fmt"
|
"fmt"
|
||||||
"math"
|
"math"
|
||||||
"sync/atomic"
|
"sync/atomic"
|
||||||
|
|
||||||
|
"go.opentelemetry.io/otel/api/internal"
|
||||||
)
|
)
|
||||||
|
|
||||||
// NumberKind describes the data type of the Number.
|
// NumberKind describes the data type of the Number.
|
||||||
@ -92,17 +94,17 @@ func NewNumberFromRaw(r uint64) Number {
|
|||||||
|
|
||||||
// NewInt64Number creates an integral Number.
|
// NewInt64Number creates an integral Number.
|
||||||
func NewInt64Number(i int64) Number {
|
func NewInt64Number(i int64) Number {
|
||||||
return NewNumberFromRaw(int64ToRaw(i))
|
return NewNumberFromRaw(internal.Int64ToRaw(i))
|
||||||
}
|
}
|
||||||
|
|
||||||
// NewFloat64Number creates a floating point Number.
|
// NewFloat64Number creates a floating point Number.
|
||||||
func NewFloat64Number(f float64) Number {
|
func NewFloat64Number(f float64) Number {
|
||||||
return NewNumberFromRaw(float64ToRaw(f))
|
return NewNumberFromRaw(internal.Float64ToRaw(f))
|
||||||
}
|
}
|
||||||
|
|
||||||
// NewInt64Number creates an integral Number.
|
// NewInt64Number creates an integral Number.
|
||||||
func NewUint64Number(u uint64) Number {
|
func NewUint64Number(u uint64) Number {
|
||||||
return NewNumberFromRaw(uint64ToRaw(u))
|
return NewNumberFromRaw(internal.Uint64ToRaw(u))
|
||||||
}
|
}
|
||||||
|
|
||||||
// - as x
|
// - as x
|
||||||
@ -121,19 +123,19 @@ func (n *Number) AsRaw() uint64 {
|
|||||||
// AsInt64 assumes that the value contains an int64 and returns it as
|
// AsInt64 assumes that the value contains an int64 and returns it as
|
||||||
// such.
|
// such.
|
||||||
func (n *Number) AsInt64() int64 {
|
func (n *Number) AsInt64() int64 {
|
||||||
return rawToInt64(n.AsRaw())
|
return internal.RawToInt64(n.AsRaw())
|
||||||
}
|
}
|
||||||
|
|
||||||
// AsFloat64 assumes that the measurement value contains a float64 and
|
// AsFloat64 assumes that the measurement value contains a float64 and
|
||||||
// returns it as such.
|
// returns it as such.
|
||||||
func (n *Number) AsFloat64() float64 {
|
func (n *Number) AsFloat64() float64 {
|
||||||
return rawToFloat64(n.AsRaw())
|
return internal.RawToFloat64(n.AsRaw())
|
||||||
}
|
}
|
||||||
|
|
||||||
// AsUint64 assumes that the value contains an uint64 and returns it
|
// AsUint64 assumes that the value contains an uint64 and returns it
|
||||||
// as such.
|
// as such.
|
||||||
func (n *Number) AsUint64() uint64 {
|
func (n *Number) AsUint64() uint64 {
|
||||||
return rawToUint64(n.AsRaw())
|
return internal.RawToUint64(n.AsRaw())
|
||||||
}
|
}
|
||||||
|
|
||||||
// - as x atomic
|
// - as x atomic
|
||||||
@ -158,7 +160,7 @@ func (n *Number) AsInt64Atomic() int64 {
|
|||||||
// AsFloat64Atomic assumes that the measurement value contains a
|
// AsFloat64Atomic assumes that the measurement value contains a
|
||||||
// float64 and returns it as such atomically.
|
// float64 and returns it as such atomically.
|
||||||
func (n *Number) AsFloat64Atomic() float64 {
|
func (n *Number) AsFloat64Atomic() float64 {
|
||||||
return rawToFloat64(n.AsRawAtomic())
|
return internal.RawToFloat64(n.AsRawAtomic())
|
||||||
}
|
}
|
||||||
|
|
||||||
// AsUint64Atomic assumes that the number contains a uint64 and
|
// AsUint64Atomic assumes that the number contains a uint64 and
|
||||||
@ -178,19 +180,19 @@ func (n *Number) AsRawPtr() *uint64 {
|
|||||||
// AsInt64Ptr assumes that the number contains an int64 and returns a
|
// AsInt64Ptr assumes that the number contains an int64 and returns a
|
||||||
// pointer to it.
|
// pointer to it.
|
||||||
func (n *Number) AsInt64Ptr() *int64 {
|
func (n *Number) AsInt64Ptr() *int64 {
|
||||||
return rawPtrToInt64Ptr(n.AsRawPtr())
|
return internal.RawPtrToInt64Ptr(n.AsRawPtr())
|
||||||
}
|
}
|
||||||
|
|
||||||
// AsFloat64Ptr assumes that the number contains a float64 and returns a
|
// AsFloat64Ptr assumes that the number contains a float64 and returns a
|
||||||
// pointer to it.
|
// pointer to it.
|
||||||
func (n *Number) AsFloat64Ptr() *float64 {
|
func (n *Number) AsFloat64Ptr() *float64 {
|
||||||
return rawPtrToFloat64Ptr(n.AsRawPtr())
|
return internal.RawPtrToFloat64Ptr(n.AsRawPtr())
|
||||||
}
|
}
|
||||||
|
|
||||||
// AsUint64Ptr assumes that the number contains a uint64 and returns a
|
// AsUint64Ptr assumes that the number contains a uint64 and returns a
|
||||||
// pointer to it.
|
// pointer to it.
|
||||||
func (n *Number) AsUint64Ptr() *uint64 {
|
func (n *Number) AsUint64Ptr() *uint64 {
|
||||||
return rawPtrToUint64Ptr(n.AsRawPtr())
|
return internal.RawPtrToUint64Ptr(n.AsRawPtr())
|
||||||
}
|
}
|
||||||
|
|
||||||
// - coerce
|
// - coerce
|
||||||
@ -299,7 +301,7 @@ func (n *Number) SetInt64Atomic(i int64) {
|
|||||||
// SetFloat64Atomic assumes that the number contains a float64 and
|
// SetFloat64Atomic assumes that the number contains a float64 and
|
||||||
// sets it to the passed value atomically.
|
// sets it to the passed value atomically.
|
||||||
func (n *Number) SetFloat64Atomic(f float64) {
|
func (n *Number) SetFloat64Atomic(f float64) {
|
||||||
atomic.StoreUint64(n.AsRawPtr(), float64ToRaw(f))
|
atomic.StoreUint64(n.AsRawPtr(), internal.Float64ToRaw(f))
|
||||||
}
|
}
|
||||||
|
|
||||||
// SetUint64Atomic assumes that the number contains a uint64 and sets
|
// SetUint64Atomic assumes that the number contains a uint64 and sets
|
||||||
@ -378,7 +380,7 @@ func (n *Number) SwapInt64Atomic(i int64) int64 {
|
|||||||
// it to the passed value and returns the old float64 value
|
// it to the passed value and returns the old float64 value
|
||||||
// atomically.
|
// atomically.
|
||||||
func (n *Number) SwapFloat64Atomic(f float64) float64 {
|
func (n *Number) SwapFloat64Atomic(f float64) float64 {
|
||||||
return rawToFloat64(atomic.SwapUint64(n.AsRawPtr(), float64ToRaw(f)))
|
return internal.RawToFloat64(atomic.SwapUint64(n.AsRawPtr(), internal.Float64ToRaw(f)))
|
||||||
}
|
}
|
||||||
|
|
||||||
// SwapUint64Atomic assumes that the number contains an uint64, sets
|
// SwapUint64Atomic assumes that the number contains an uint64, sets
|
||||||
@ -496,7 +498,7 @@ func (n *Number) CompareAndSwapInt64(oi, ni int64) bool {
|
|||||||
// CompareAndSwapFloat64 assumes that this number contains a float64 and
|
// CompareAndSwapFloat64 assumes that this number contains a float64 and
|
||||||
// does the atomic CAS operation on it.
|
// does the atomic CAS operation on it.
|
||||||
func (n *Number) CompareAndSwapFloat64(of, nf float64) bool {
|
func (n *Number) CompareAndSwapFloat64(of, nf float64) bool {
|
||||||
return atomic.CompareAndSwapUint64(n.AsRawPtr(), float64ToRaw(of), float64ToRaw(nf))
|
return atomic.CompareAndSwapUint64(n.AsRawPtr(), internal.Float64ToRaw(of), internal.Float64ToRaw(nf))
|
||||||
}
|
}
|
||||||
|
|
||||||
// CompareAndSwapUint64 assumes that this number contains a uint64 and
|
// CompareAndSwapUint64 assumes that this number contains a uint64 and
|
@ -12,7 +12,7 @@
|
|||||||
// See the License for the specific language governing permissions and
|
// See the License for the specific language governing permissions and
|
||||||
// limitations under the License.
|
// limitations under the License.
|
||||||
|
|
||||||
package core
|
package metric
|
||||||
|
|
||||||
import (
|
import (
|
||||||
"testing"
|
"testing"
|
@ -1,6 +1,6 @@
|
|||||||
// Code generated by "stringer -type=NumberKind"; DO NOT EDIT.
|
// Code generated by "stringer -type=NumberKind"; DO NOT EDIT.
|
||||||
|
|
||||||
package core
|
package metric
|
||||||
|
|
||||||
import "strconv"
|
import "strconv"
|
||||||
|
|
@ -125,7 +125,7 @@ func (u *uniqueInstrumentMeterImpl) NewSyncInstrument(descriptor metric.Descript
|
|||||||
// NewAsyncInstrument implements metric.MeterImpl.
|
// NewAsyncInstrument implements metric.MeterImpl.
|
||||||
func (u *uniqueInstrumentMeterImpl) NewAsyncInstrument(
|
func (u *uniqueInstrumentMeterImpl) NewAsyncInstrument(
|
||||||
descriptor metric.Descriptor,
|
descriptor metric.Descriptor,
|
||||||
callback func(func(core.Number, []core.KeyValue)),
|
callback func(func(metric.Number, []core.KeyValue)),
|
||||||
) (metric.AsyncImpl, error) {
|
) (metric.AsyncImpl, error) {
|
||||||
u.lock.Lock()
|
u.lock.Lock()
|
||||||
defer u.lock.Unlock()
|
defer u.lock.Unlock()
|
||||||
|
@ -38,7 +38,7 @@ type MeterImpl interface {
|
|||||||
// one occur.
|
// one occur.
|
||||||
NewAsyncInstrument(
|
NewAsyncInstrument(
|
||||||
descriptor Descriptor,
|
descriptor Descriptor,
|
||||||
callback func(func(core.Number, []core.KeyValue)),
|
callback func(func(Number, []core.KeyValue)),
|
||||||
) (AsyncImpl, error)
|
) (AsyncImpl, error)
|
||||||
}
|
}
|
||||||
|
|
||||||
@ -64,7 +64,7 @@ type SyncImpl interface {
|
|||||||
Bind(labels []core.KeyValue) BoundSyncImpl
|
Bind(labels []core.KeyValue) BoundSyncImpl
|
||||||
|
|
||||||
// RecordOne captures a single synchronous metric event.
|
// RecordOne captures a single synchronous metric event.
|
||||||
RecordOne(ctx context.Context, number core.Number, labels []core.KeyValue)
|
RecordOne(ctx context.Context, number Number, labels []core.KeyValue)
|
||||||
}
|
}
|
||||||
|
|
||||||
// BoundSyncImpl is the implementation-level interface to a
|
// BoundSyncImpl is the implementation-level interface to a
|
||||||
@ -72,7 +72,7 @@ type SyncImpl interface {
|
|||||||
type BoundSyncImpl interface {
|
type BoundSyncImpl interface {
|
||||||
|
|
||||||
// RecordOne captures a single synchronous metric event.
|
// RecordOne captures a single synchronous metric event.
|
||||||
RecordOne(ctx context.Context, number core.Number)
|
RecordOne(ctx context.Context, number Number)
|
||||||
|
|
||||||
// Unbind frees the resources associated with this bound instrument. It
|
// Unbind frees the resources associated with this bound instrument. It
|
||||||
// does not affect the metric this bound instrument was created through.
|
// does not affect the metric this bound instrument was created through.
|
||||||
@ -97,13 +97,13 @@ type wrappedMeterImpl struct {
|
|||||||
// int64ObserverResult is an adapter for int64-valued asynchronous
|
// int64ObserverResult is an adapter for int64-valued asynchronous
|
||||||
// callbacks.
|
// callbacks.
|
||||||
type int64ObserverResult struct {
|
type int64ObserverResult struct {
|
||||||
observe func(core.Number, []core.KeyValue)
|
observe func(Number, []core.KeyValue)
|
||||||
}
|
}
|
||||||
|
|
||||||
// float64ObserverResult is an adapter for float64-valued asynchronous
|
// float64ObserverResult is an adapter for float64-valued asynchronous
|
||||||
// callbacks.
|
// callbacks.
|
||||||
type float64ObserverResult struct {
|
type float64ObserverResult struct {
|
||||||
observe func(core.Number, []core.KeyValue)
|
observe func(Number, []core.KeyValue)
|
||||||
}
|
}
|
||||||
|
|
||||||
var (
|
var (
|
||||||
@ -134,7 +134,7 @@ func (m *wrappedMeterImpl) RecordBatch(ctx context.Context, ls []core.KeyValue,
|
|||||||
m.impl.RecordBatch(ctx, ls, ms...)
|
m.impl.RecordBatch(ctx, ls, ms...)
|
||||||
}
|
}
|
||||||
|
|
||||||
func (m *wrappedMeterImpl) newSync(name string, metricKind Kind, numberKind core.NumberKind, opts []Option) (SyncImpl, error) {
|
func (m *wrappedMeterImpl) newSync(name string, metricKind Kind, numberKind NumberKind, opts []Option) (SyncImpl, error) {
|
||||||
desc := NewDescriptor(name, metricKind, numberKind, opts...)
|
desc := NewDescriptor(name, metricKind, numberKind, opts...)
|
||||||
desc.config.LibraryName = m.libraryName
|
desc.config.LibraryName = m.libraryName
|
||||||
return m.impl.NewSyncInstrument(desc)
|
return m.impl.NewSyncInstrument(desc)
|
||||||
@ -142,7 +142,7 @@ func (m *wrappedMeterImpl) newSync(name string, metricKind Kind, numberKind core
|
|||||||
|
|
||||||
func (m *wrappedMeterImpl) NewInt64Counter(name string, opts ...Option) (Int64Counter, error) {
|
func (m *wrappedMeterImpl) NewInt64Counter(name string, opts ...Option) (Int64Counter, error) {
|
||||||
return WrapInt64CounterInstrument(
|
return WrapInt64CounterInstrument(
|
||||||
m.newSync(name, CounterKind, core.Int64NumberKind, opts))
|
m.newSync(name, CounterKind, Int64NumberKind, opts))
|
||||||
}
|
}
|
||||||
|
|
||||||
// WrapInt64CounterInstrument returns an `Int64Counter` from a
|
// WrapInt64CounterInstrument returns an `Int64Counter` from a
|
||||||
@ -156,7 +156,7 @@ func WrapInt64CounterInstrument(syncInst SyncImpl, err error) (Int64Counter, err
|
|||||||
|
|
||||||
func (m *wrappedMeterImpl) NewFloat64Counter(name string, opts ...Option) (Float64Counter, error) {
|
func (m *wrappedMeterImpl) NewFloat64Counter(name string, opts ...Option) (Float64Counter, error) {
|
||||||
return WrapFloat64CounterInstrument(
|
return WrapFloat64CounterInstrument(
|
||||||
m.newSync(name, CounterKind, core.Float64NumberKind, opts))
|
m.newSync(name, CounterKind, Float64NumberKind, opts))
|
||||||
}
|
}
|
||||||
|
|
||||||
// WrapFloat64CounterInstrument returns an `Float64Counter` from a
|
// WrapFloat64CounterInstrument returns an `Float64Counter` from a
|
||||||
@ -170,7 +170,7 @@ func WrapFloat64CounterInstrument(syncInst SyncImpl, err error) (Float64Counter,
|
|||||||
|
|
||||||
func (m *wrappedMeterImpl) NewInt64Measure(name string, opts ...Option) (Int64Measure, error) {
|
func (m *wrappedMeterImpl) NewInt64Measure(name string, opts ...Option) (Int64Measure, error) {
|
||||||
return WrapInt64MeasureInstrument(
|
return WrapInt64MeasureInstrument(
|
||||||
m.newSync(name, MeasureKind, core.Int64NumberKind, opts))
|
m.newSync(name, MeasureKind, Int64NumberKind, opts))
|
||||||
}
|
}
|
||||||
|
|
||||||
// WrapInt64MeasureInstrument returns an `Int64Measure` from a
|
// WrapInt64MeasureInstrument returns an `Int64Measure` from a
|
||||||
@ -184,7 +184,7 @@ func WrapInt64MeasureInstrument(syncInst SyncImpl, err error) (Int64Measure, err
|
|||||||
|
|
||||||
func (m *wrappedMeterImpl) NewFloat64Measure(name string, opts ...Option) (Float64Measure, error) {
|
func (m *wrappedMeterImpl) NewFloat64Measure(name string, opts ...Option) (Float64Measure, error) {
|
||||||
return WrapFloat64MeasureInstrument(
|
return WrapFloat64MeasureInstrument(
|
||||||
m.newSync(name, MeasureKind, core.Float64NumberKind, opts))
|
m.newSync(name, MeasureKind, Float64NumberKind, opts))
|
||||||
}
|
}
|
||||||
|
|
||||||
// WrapFloat64MeasureInstrument returns an `Float64Measure` from a
|
// WrapFloat64MeasureInstrument returns an `Float64Measure` from a
|
||||||
@ -196,7 +196,7 @@ func WrapFloat64MeasureInstrument(syncInst SyncImpl, err error) (Float64Measure,
|
|||||||
return Float64Measure{syncInstrument: common}, err
|
return Float64Measure{syncInstrument: common}, err
|
||||||
}
|
}
|
||||||
|
|
||||||
func (m *wrappedMeterImpl) newAsync(name string, mkind Kind, nkind core.NumberKind, opts []Option, callback func(func(core.Number, []core.KeyValue))) (AsyncImpl, error) {
|
func (m *wrappedMeterImpl) newAsync(name string, mkind Kind, nkind NumberKind, opts []Option, callback func(func(Number, []core.KeyValue))) (AsyncImpl, error) {
|
||||||
desc := NewDescriptor(name, mkind, nkind, opts...)
|
desc := NewDescriptor(name, mkind, nkind, opts...)
|
||||||
desc.config.LibraryName = m.libraryName
|
desc.config.LibraryName = m.libraryName
|
||||||
return m.impl.NewAsyncInstrument(desc, callback)
|
return m.impl.NewAsyncInstrument(desc, callback)
|
||||||
@ -207,8 +207,8 @@ func (m *wrappedMeterImpl) RegisterInt64Observer(name string, callback Int64Obse
|
|||||||
return NoopMeter{}.RegisterInt64Observer("", nil)
|
return NoopMeter{}.RegisterInt64Observer("", nil)
|
||||||
}
|
}
|
||||||
return WrapInt64ObserverInstrument(
|
return WrapInt64ObserverInstrument(
|
||||||
m.newAsync(name, ObserverKind, core.Int64NumberKind, opts,
|
m.newAsync(name, ObserverKind, Int64NumberKind, opts,
|
||||||
func(observe func(core.Number, []core.KeyValue)) {
|
func(observe func(Number, []core.KeyValue)) {
|
||||||
// Note: this memory allocation could be avoided by
|
// Note: this memory allocation could be avoided by
|
||||||
// using a pointer to this object and mutating it
|
// using a pointer to this object and mutating it
|
||||||
// on each collection interval.
|
// on each collection interval.
|
||||||
@ -230,8 +230,8 @@ func (m *wrappedMeterImpl) RegisterFloat64Observer(name string, callback Float64
|
|||||||
return NoopMeter{}.RegisterFloat64Observer("", nil)
|
return NoopMeter{}.RegisterFloat64Observer("", nil)
|
||||||
}
|
}
|
||||||
return WrapFloat64ObserverInstrument(
|
return WrapFloat64ObserverInstrument(
|
||||||
m.newAsync(name, ObserverKind, core.Float64NumberKind, opts,
|
m.newAsync(name, ObserverKind, Float64NumberKind, opts,
|
||||||
func(observe func(core.Number, []core.KeyValue)) {
|
func(observe func(Number, []core.KeyValue)) {
|
||||||
callback(float64ObserverResult{observe})
|
callback(float64ObserverResult{observe})
|
||||||
}))
|
}))
|
||||||
}
|
}
|
||||||
@ -246,9 +246,9 @@ func WrapFloat64ObserverInstrument(asyncInst AsyncImpl, err error) (Float64Obser
|
|||||||
}
|
}
|
||||||
|
|
||||||
func (io int64ObserverResult) Observe(value int64, labels ...core.KeyValue) {
|
func (io int64ObserverResult) Observe(value int64, labels ...core.KeyValue) {
|
||||||
io.observe(core.NewInt64Number(value), labels)
|
io.observe(NewInt64Number(value), labels)
|
||||||
}
|
}
|
||||||
|
|
||||||
func (fo float64ObserverResult) Observe(value float64, labels ...core.KeyValue) {
|
func (fo float64ObserverResult) Observe(value float64, labels ...core.KeyValue) {
|
||||||
fo.observe(core.NewFloat64Number(value), labels)
|
fo.observe(NewFloat64Number(value), labels)
|
||||||
}
|
}
|
||||||
|
@ -20,10 +20,11 @@ import (
|
|||||||
"net/http"
|
"net/http"
|
||||||
"time"
|
"time"
|
||||||
|
|
||||||
|
"go.opentelemetry.io/otel/api/metric"
|
||||||
|
|
||||||
"github.com/prometheus/client_golang/prometheus"
|
"github.com/prometheus/client_golang/prometheus"
|
||||||
"github.com/prometheus/client_golang/prometheus/promhttp"
|
"github.com/prometheus/client_golang/prometheus/promhttp"
|
||||||
|
|
||||||
"go.opentelemetry.io/otel/api/core"
|
|
||||||
"go.opentelemetry.io/otel/api/global"
|
"go.opentelemetry.io/otel/api/global"
|
||||||
"go.opentelemetry.io/otel/api/label"
|
"go.opentelemetry.io/otel/api/label"
|
||||||
export "go.opentelemetry.io/otel/sdk/export/metric"
|
export "go.opentelemetry.io/otel/sdk/export/metric"
|
||||||
@ -46,7 +47,7 @@ type Exporter struct {
|
|||||||
onError func(error)
|
onError func(error)
|
||||||
|
|
||||||
defaultSummaryQuantiles []float64
|
defaultSummaryQuantiles []float64
|
||||||
defaultHistogramBoundaries []core.Number
|
defaultHistogramBoundaries []metric.Number
|
||||||
}
|
}
|
||||||
|
|
||||||
var _ export.Exporter = &Exporter{}
|
var _ export.Exporter = &Exporter{}
|
||||||
@ -78,7 +79,7 @@ type Config struct {
|
|||||||
|
|
||||||
// DefaultHistogramBoundaries defines the default histogram bucket
|
// DefaultHistogramBoundaries defines the default histogram bucket
|
||||||
// boundaries.
|
// boundaries.
|
||||||
DefaultHistogramBoundaries []core.Number
|
DefaultHistogramBoundaries []metric.Number
|
||||||
|
|
||||||
// OnError is a function that handle errors that may occur while exporting metrics.
|
// OnError is a function that handle errors that may occur while exporting metrics.
|
||||||
// TODO: This should be refactored or even removed once we have a better error handling mechanism.
|
// TODO: This should be refactored or even removed once we have a better error handling mechanism.
|
||||||
@ -245,7 +246,7 @@ func (c *collector) Collect(ch chan<- prometheus.Metric) {
|
|||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
func (c *collector) exportLastValue(ch chan<- prometheus.Metric, lvagg aggregator.LastValue, kind core.NumberKind, desc *prometheus.Desc, labels []string) error {
|
func (c *collector) exportLastValue(ch chan<- prometheus.Metric, lvagg aggregator.LastValue, kind metric.NumberKind, desc *prometheus.Desc, labels []string) error {
|
||||||
lv, _, err := lvagg.LastValue()
|
lv, _, err := lvagg.LastValue()
|
||||||
if err != nil {
|
if err != nil {
|
||||||
return fmt.Errorf("error retrieving last value: %w", err)
|
return fmt.Errorf("error retrieving last value: %w", err)
|
||||||
@ -260,7 +261,7 @@ func (c *collector) exportLastValue(ch chan<- prometheus.Metric, lvagg aggregato
|
|||||||
return nil
|
return nil
|
||||||
}
|
}
|
||||||
|
|
||||||
func (c *collector) exportCounter(ch chan<- prometheus.Metric, sum aggregator.Sum, kind core.NumberKind, desc *prometheus.Desc, labels []string) error {
|
func (c *collector) exportCounter(ch chan<- prometheus.Metric, sum aggregator.Sum, kind metric.NumberKind, desc *prometheus.Desc, labels []string) error {
|
||||||
v, err := sum.Sum()
|
v, err := sum.Sum()
|
||||||
if err != nil {
|
if err != nil {
|
||||||
return fmt.Errorf("error retrieving counter: %w", err)
|
return fmt.Errorf("error retrieving counter: %w", err)
|
||||||
@ -275,13 +276,13 @@ func (c *collector) exportCounter(ch chan<- prometheus.Metric, sum aggregator.Su
|
|||||||
return nil
|
return nil
|
||||||
}
|
}
|
||||||
|
|
||||||
func (c *collector) exportSummary(ch chan<- prometheus.Metric, dist aggregator.Distribution, kind core.NumberKind, desc *prometheus.Desc, labels []string) error {
|
func (c *collector) exportSummary(ch chan<- prometheus.Metric, dist aggregator.Distribution, kind metric.NumberKind, desc *prometheus.Desc, labels []string) error {
|
||||||
count, err := dist.Count()
|
count, err := dist.Count()
|
||||||
if err != nil {
|
if err != nil {
|
||||||
return fmt.Errorf("error retrieving count: %w", err)
|
return fmt.Errorf("error retrieving count: %w", err)
|
||||||
}
|
}
|
||||||
|
|
||||||
var sum core.Number
|
var sum metric.Number
|
||||||
sum, err = dist.Sum()
|
sum, err = dist.Sum()
|
||||||
if err != nil {
|
if err != nil {
|
||||||
return fmt.Errorf("error retrieving distribution sum: %w", err)
|
return fmt.Errorf("error retrieving distribution sum: %w", err)
|
||||||
@ -302,7 +303,7 @@ func (c *collector) exportSummary(ch chan<- prometheus.Metric, dist aggregator.D
|
|||||||
return nil
|
return nil
|
||||||
}
|
}
|
||||||
|
|
||||||
func (c *collector) exportHistogram(ch chan<- prometheus.Metric, hist aggregator.Histogram, kind core.NumberKind, desc *prometheus.Desc, labels []string) error {
|
func (c *collector) exportHistogram(ch chan<- prometheus.Metric, hist aggregator.Histogram, kind metric.NumberKind, desc *prometheus.Desc, labels []string) error {
|
||||||
buckets, err := hist.Histogram()
|
buckets, err := hist.Histogram()
|
||||||
if err != nil {
|
if err != nil {
|
||||||
return fmt.Errorf("error retrieving histogram: %w", err)
|
return fmt.Errorf("error retrieving histogram: %w", err)
|
||||||
|
@ -43,13 +43,13 @@ func TestPrometheusExporter(t *testing.T) {
|
|||||||
checkpointSet := test.NewCheckpointSet()
|
checkpointSet := test.NewCheckpointSet()
|
||||||
|
|
||||||
counter := metric.NewDescriptor(
|
counter := metric.NewDescriptor(
|
||||||
"counter", metric.CounterKind, core.Float64NumberKind)
|
"counter", metric.CounterKind, metric.Float64NumberKind)
|
||||||
lastValue := metric.NewDescriptor(
|
lastValue := metric.NewDescriptor(
|
||||||
"lastvalue", metric.ObserverKind, core.Float64NumberKind)
|
"lastvalue", metric.ObserverKind, metric.Float64NumberKind)
|
||||||
measure := metric.NewDescriptor(
|
measure := metric.NewDescriptor(
|
||||||
"measure", metric.MeasureKind, core.Float64NumberKind)
|
"measure", metric.MeasureKind, metric.Float64NumberKind)
|
||||||
histogramMeasure := metric.NewDescriptor(
|
histogramMeasure := metric.NewDescriptor(
|
||||||
"histogram_measure", metric.MeasureKind, core.Float64NumberKind)
|
"histogram_measure", metric.MeasureKind, metric.Float64NumberKind)
|
||||||
|
|
||||||
labels := []core.KeyValue{
|
labels := []core.KeyValue{
|
||||||
key.New("A").String("B"),
|
key.New("A").String("B"),
|
||||||
@ -71,7 +71,7 @@ func TestPrometheusExporter(t *testing.T) {
|
|||||||
expected = append(expected, `measure_sum{A="B",C="D"} 45`)
|
expected = append(expected, `measure_sum{A="B",C="D"} 45`)
|
||||||
expected = append(expected, `measure_count{A="B",C="D"} 3`)
|
expected = append(expected, `measure_count{A="B",C="D"} 3`)
|
||||||
|
|
||||||
boundaries := []core.Number{core.NewFloat64Number(-0.5), core.NewFloat64Number(1)}
|
boundaries := []metric.Number{metric.NewFloat64Number(-0.5), metric.NewFloat64Number(1)}
|
||||||
checkpointSet.AddHistogramMeasure(&histogramMeasure, boundaries, -0.6, labels...)
|
checkpointSet.AddHistogramMeasure(&histogramMeasure, boundaries, -0.6, labels...)
|
||||||
checkpointSet.AddHistogramMeasure(&histogramMeasure, boundaries, -0.4, labels...)
|
checkpointSet.AddHistogramMeasure(&histogramMeasure, boundaries, -0.4, labels...)
|
||||||
checkpointSet.AddHistogramMeasure(&histogramMeasure, boundaries, 0.6, labels...)
|
checkpointSet.AddHistogramMeasure(&histogramMeasure, boundaries, 0.6, labels...)
|
||||||
@ -101,7 +101,7 @@ func TestPrometheusExporter(t *testing.T) {
|
|||||||
expected = append(expected, `measure_count{A="E",C=""} 1`)
|
expected = append(expected, `measure_count{A="E",C=""} 1`)
|
||||||
expected = append(expected, `measure_sum{A="E",C=""} 19`)
|
expected = append(expected, `measure_sum{A="E",C=""} 19`)
|
||||||
|
|
||||||
boundaries = []core.Number{core.NewFloat64Number(0), core.NewFloat64Number(1)}
|
boundaries = []metric.Number{metric.NewFloat64Number(0), metric.NewFloat64Number(1)}
|
||||||
checkpointSet.AddHistogramMeasure(&histogramMeasure, boundaries, -0.6, missingLabels...)
|
checkpointSet.AddHistogramMeasure(&histogramMeasure, boundaries, -0.6, missingLabels...)
|
||||||
checkpointSet.AddHistogramMeasure(&histogramMeasure, boundaries, -0.4, missingLabels...)
|
checkpointSet.AddHistogramMeasure(&histogramMeasure, boundaries, -0.4, missingLabels...)
|
||||||
checkpointSet.AddHistogramMeasure(&histogramMeasure, boundaries, -0.1, missingLabels...)
|
checkpointSet.AddHistogramMeasure(&histogramMeasure, boundaries, -0.1, missingLabels...)
|
||||||
|
@ -99,9 +99,9 @@ func TestStdoutTimestamp(t *testing.T) {
|
|||||||
checkpointSet := test.NewCheckpointSet()
|
checkpointSet := test.NewCheckpointSet()
|
||||||
|
|
||||||
ctx := context.Background()
|
ctx := context.Background()
|
||||||
desc := metric.NewDescriptor("test.name", metric.ObserverKind, core.Int64NumberKind)
|
desc := metric.NewDescriptor("test.name", metric.ObserverKind, metric.Int64NumberKind)
|
||||||
lvagg := lastvalue.New()
|
lvagg := lastvalue.New()
|
||||||
aggtest.CheckedUpdate(t, lvagg, core.NewInt64Number(321), &desc)
|
aggtest.CheckedUpdate(t, lvagg, metric.NewInt64Number(321), &desc)
|
||||||
lvagg.Checkpoint(ctx, &desc)
|
lvagg.Checkpoint(ctx, &desc)
|
||||||
|
|
||||||
checkpointSet.Add(&desc, lvagg)
|
checkpointSet.Add(&desc, lvagg)
|
||||||
@ -144,9 +144,9 @@ func TestStdoutCounterFormat(t *testing.T) {
|
|||||||
|
|
||||||
checkpointSet := test.NewCheckpointSet()
|
checkpointSet := test.NewCheckpointSet()
|
||||||
|
|
||||||
desc := metric.NewDescriptor("test.name", metric.CounterKind, core.Int64NumberKind)
|
desc := metric.NewDescriptor("test.name", metric.CounterKind, metric.Int64NumberKind)
|
||||||
cagg := sum.New()
|
cagg := sum.New()
|
||||||
aggtest.CheckedUpdate(fix.t, cagg, core.NewInt64Number(123), &desc)
|
aggtest.CheckedUpdate(fix.t, cagg, metric.NewInt64Number(123), &desc)
|
||||||
cagg.Checkpoint(fix.ctx, &desc)
|
cagg.Checkpoint(fix.ctx, &desc)
|
||||||
|
|
||||||
checkpointSet.Add(&desc, cagg, key.String("A", "B"), key.String("C", "D"))
|
checkpointSet.Add(&desc, cagg, key.String("A", "B"), key.String("C", "D"))
|
||||||
@ -161,9 +161,9 @@ func TestStdoutLastValueFormat(t *testing.T) {
|
|||||||
|
|
||||||
checkpointSet := test.NewCheckpointSet()
|
checkpointSet := test.NewCheckpointSet()
|
||||||
|
|
||||||
desc := metric.NewDescriptor("test.name", metric.ObserverKind, core.Float64NumberKind)
|
desc := metric.NewDescriptor("test.name", metric.ObserverKind, metric.Float64NumberKind)
|
||||||
lvagg := lastvalue.New()
|
lvagg := lastvalue.New()
|
||||||
aggtest.CheckedUpdate(fix.t, lvagg, core.NewFloat64Number(123.456), &desc)
|
aggtest.CheckedUpdate(fix.t, lvagg, metric.NewFloat64Number(123.456), &desc)
|
||||||
lvagg.Checkpoint(fix.ctx, &desc)
|
lvagg.Checkpoint(fix.ctx, &desc)
|
||||||
|
|
||||||
checkpointSet.Add(&desc, lvagg, key.String("A", "B"), key.String("C", "D"))
|
checkpointSet.Add(&desc, lvagg, key.String("A", "B"), key.String("C", "D"))
|
||||||
@ -178,10 +178,10 @@ func TestStdoutMinMaxSumCount(t *testing.T) {
|
|||||||
|
|
||||||
checkpointSet := test.NewCheckpointSet()
|
checkpointSet := test.NewCheckpointSet()
|
||||||
|
|
||||||
desc := metric.NewDescriptor("test.name", metric.MeasureKind, core.Float64NumberKind)
|
desc := metric.NewDescriptor("test.name", metric.MeasureKind, metric.Float64NumberKind)
|
||||||
magg := minmaxsumcount.New(&desc)
|
magg := minmaxsumcount.New(&desc)
|
||||||
aggtest.CheckedUpdate(fix.t, magg, core.NewFloat64Number(123.456), &desc)
|
aggtest.CheckedUpdate(fix.t, magg, metric.NewFloat64Number(123.456), &desc)
|
||||||
aggtest.CheckedUpdate(fix.t, magg, core.NewFloat64Number(876.543), &desc)
|
aggtest.CheckedUpdate(fix.t, magg, metric.NewFloat64Number(876.543), &desc)
|
||||||
magg.Checkpoint(fix.ctx, &desc)
|
magg.Checkpoint(fix.ctx, &desc)
|
||||||
|
|
||||||
checkpointSet.Add(&desc, magg, key.String("A", "B"), key.String("C", "D"))
|
checkpointSet.Add(&desc, magg, key.String("A", "B"), key.String("C", "D"))
|
||||||
@ -198,11 +198,11 @@ func TestStdoutMeasureFormat(t *testing.T) {
|
|||||||
|
|
||||||
checkpointSet := test.NewCheckpointSet()
|
checkpointSet := test.NewCheckpointSet()
|
||||||
|
|
||||||
desc := metric.NewDescriptor("test.name", metric.MeasureKind, core.Float64NumberKind)
|
desc := metric.NewDescriptor("test.name", metric.MeasureKind, metric.Float64NumberKind)
|
||||||
magg := array.New()
|
magg := array.New()
|
||||||
|
|
||||||
for i := 0; i < 1000; i++ {
|
for i := 0; i < 1000; i++ {
|
||||||
aggtest.CheckedUpdate(fix.t, magg, core.NewFloat64Number(float64(i)+0.5), &desc)
|
aggtest.CheckedUpdate(fix.t, magg, metric.NewFloat64Number(float64(i)+0.5), &desc)
|
||||||
}
|
}
|
||||||
|
|
||||||
magg.Checkpoint(fix.ctx, &desc)
|
magg.Checkpoint(fix.ctx, &desc)
|
||||||
@ -239,7 +239,7 @@ func TestStdoutMeasureFormat(t *testing.T) {
|
|||||||
}
|
}
|
||||||
|
|
||||||
func TestStdoutNoData(t *testing.T) {
|
func TestStdoutNoData(t *testing.T) {
|
||||||
desc := metric.NewDescriptor("test.name", metric.MeasureKind, core.Float64NumberKind)
|
desc := metric.NewDescriptor("test.name", metric.MeasureKind, metric.Float64NumberKind)
|
||||||
for name, tc := range map[string]export.Aggregator{
|
for name, tc := range map[string]export.Aggregator{
|
||||||
"ddsketch": ddsketch.New(ddsketch.NewDefaultConfig(), &desc),
|
"ddsketch": ddsketch.New(ddsketch.NewDefaultConfig(), &desc),
|
||||||
"minmaxsumcount": minmaxsumcount.New(&desc),
|
"minmaxsumcount": minmaxsumcount.New(&desc),
|
||||||
@ -269,7 +269,7 @@ func TestStdoutLastValueNotSet(t *testing.T) {
|
|||||||
|
|
||||||
checkpointSet := test.NewCheckpointSet()
|
checkpointSet := test.NewCheckpointSet()
|
||||||
|
|
||||||
desc := metric.NewDescriptor("test.name", metric.ObserverKind, core.Float64NumberKind)
|
desc := metric.NewDescriptor("test.name", metric.ObserverKind, metric.Float64NumberKind)
|
||||||
lvagg := lastvalue.New()
|
lvagg := lastvalue.New()
|
||||||
lvagg.Checkpoint(fix.ctx, &desc)
|
lvagg.Checkpoint(fix.ctx, &desc)
|
||||||
|
|
||||||
@ -319,9 +319,9 @@ func TestStdoutResource(t *testing.T) {
|
|||||||
|
|
||||||
checkpointSet := test.NewCheckpointSet()
|
checkpointSet := test.NewCheckpointSet()
|
||||||
|
|
||||||
desc := metric.NewDescriptor("test.name", metric.ObserverKind, core.Float64NumberKind)
|
desc := metric.NewDescriptor("test.name", metric.ObserverKind, metric.Float64NumberKind)
|
||||||
lvagg := lastvalue.New()
|
lvagg := lastvalue.New()
|
||||||
aggtest.CheckedUpdate(fix.t, lvagg, core.NewFloat64Number(123.456), &desc)
|
aggtest.CheckedUpdate(fix.t, lvagg, metric.NewFloat64Number(123.456), &desc)
|
||||||
lvagg.Checkpoint(fix.ctx, &desc)
|
lvagg.Checkpoint(fix.ctx, &desc)
|
||||||
|
|
||||||
checkpointSet.Add(&desc, lvagg, tc.attrs...)
|
checkpointSet.Add(&desc, lvagg, tc.attrs...)
|
||||||
|
@ -73,11 +73,11 @@ func (p *CheckpointSet) Add(desc *metric.Descriptor, newAgg export.Aggregator, l
|
|||||||
return newAgg, true
|
return newAgg, true
|
||||||
}
|
}
|
||||||
|
|
||||||
func createNumber(desc *metric.Descriptor, v float64) core.Number {
|
func createNumber(desc *metric.Descriptor, v float64) metric.Number {
|
||||||
if desc.NumberKind() == core.Float64NumberKind {
|
if desc.NumberKind() == metric.Float64NumberKind {
|
||||||
return core.NewFloat64Number(v)
|
return metric.NewFloat64Number(v)
|
||||||
}
|
}
|
||||||
return core.NewInt64Number(int64(v))
|
return metric.NewInt64Number(int64(v))
|
||||||
}
|
}
|
||||||
|
|
||||||
func (p *CheckpointSet) AddLastValue(desc *metric.Descriptor, v float64, labels ...core.KeyValue) {
|
func (p *CheckpointSet) AddLastValue(desc *metric.Descriptor, v float64, labels ...core.KeyValue) {
|
||||||
@ -92,7 +92,7 @@ func (p *CheckpointSet) AddMeasure(desc *metric.Descriptor, v float64, labels ..
|
|||||||
p.updateAggregator(desc, array.New(), v, labels...)
|
p.updateAggregator(desc, array.New(), v, labels...)
|
||||||
}
|
}
|
||||||
|
|
||||||
func (p *CheckpointSet) AddHistogramMeasure(desc *metric.Descriptor, boundaries []core.Number, v float64, labels ...core.KeyValue) {
|
func (p *CheckpointSet) AddHistogramMeasure(desc *metric.Descriptor, boundaries []metric.Number, v float64, labels ...core.KeyValue) {
|
||||||
p.updateAggregator(desc, histogram.New(desc, boundaries), v, labels...)
|
p.updateAggregator(desc, histogram.New(desc, boundaries), v, labels...)
|
||||||
}
|
}
|
||||||
|
|
||||||
|
@ -27,7 +27,6 @@ import (
|
|||||||
metricpb "github.com/open-telemetry/opentelemetry-proto/gen/go/metrics/v1"
|
metricpb "github.com/open-telemetry/opentelemetry-proto/gen/go/metrics/v1"
|
||||||
resourcepb "github.com/open-telemetry/opentelemetry-proto/gen/go/resource/v1"
|
resourcepb "github.com/open-telemetry/opentelemetry-proto/gen/go/resource/v1"
|
||||||
|
|
||||||
"go.opentelemetry.io/otel/api/core"
|
|
||||||
"go.opentelemetry.io/otel/api/label"
|
"go.opentelemetry.io/otel/api/label"
|
||||||
"go.opentelemetry.io/otel/api/metric"
|
"go.opentelemetry.io/otel/api/metric"
|
||||||
export "go.opentelemetry.io/otel/sdk/export/metric"
|
export "go.opentelemetry.io/otel/sdk/export/metric"
|
||||||
@ -257,12 +256,12 @@ func sum(desc *metric.Descriptor, labels *label.Set, a aggregator.Sum) (*metricp
|
|||||||
}
|
}
|
||||||
|
|
||||||
switch n := desc.NumberKind(); n {
|
switch n := desc.NumberKind(); n {
|
||||||
case core.Int64NumberKind, core.Uint64NumberKind:
|
case metric.Int64NumberKind, metric.Uint64NumberKind:
|
||||||
m.MetricDescriptor.Type = metricpb.MetricDescriptor_COUNTER_INT64
|
m.MetricDescriptor.Type = metricpb.MetricDescriptor_COUNTER_INT64
|
||||||
m.Int64DataPoints = []*metricpb.Int64DataPoint{
|
m.Int64DataPoints = []*metricpb.Int64DataPoint{
|
||||||
{Value: sum.CoerceToInt64(n)},
|
{Value: sum.CoerceToInt64(n)},
|
||||||
}
|
}
|
||||||
case core.Float64NumberKind:
|
case metric.Float64NumberKind:
|
||||||
m.MetricDescriptor.Type = metricpb.MetricDescriptor_COUNTER_DOUBLE
|
m.MetricDescriptor.Type = metricpb.MetricDescriptor_COUNTER_DOUBLE
|
||||||
m.DoubleDataPoints = []*metricpb.DoubleDataPoint{
|
m.DoubleDataPoints = []*metricpb.DoubleDataPoint{
|
||||||
{Value: sum.CoerceToFloat64(n)},
|
{Value: sum.CoerceToFloat64(n)},
|
||||||
@ -276,7 +275,7 @@ func sum(desc *metric.Descriptor, labels *label.Set, a aggregator.Sum) (*metricp
|
|||||||
|
|
||||||
// minMaxSumCountValue returns the values of the MinMaxSumCount Aggregator
|
// minMaxSumCountValue returns the values of the MinMaxSumCount Aggregator
|
||||||
// as discret values.
|
// as discret values.
|
||||||
func minMaxSumCountValues(a aggregator.MinMaxSumCount) (min, max, sum core.Number, count int64, err error) {
|
func minMaxSumCountValues(a aggregator.MinMaxSumCount) (min, max, sum metric.Number, count int64, err error) {
|
||||||
if min, err = a.Min(); err != nil {
|
if min, err = a.Min(); err != nil {
|
||||||
return
|
return
|
||||||
}
|
}
|
||||||
|
@ -93,9 +93,9 @@ func TestMinMaxSumCountValue(t *testing.T) {
|
|||||||
mmsc.Checkpoint(context.Background(), &metric.Descriptor{})
|
mmsc.Checkpoint(context.Background(), &metric.Descriptor{})
|
||||||
min, max, sum, count, err := minMaxSumCountValues(mmsc)
|
min, max, sum, count, err := minMaxSumCountValues(mmsc)
|
||||||
if assert.NoError(t, err) {
|
if assert.NoError(t, err) {
|
||||||
assert.Equal(t, min, core.NewInt64Number(1))
|
assert.Equal(t, min, metric.NewInt64Number(1))
|
||||||
assert.Equal(t, max, core.NewInt64Number(10))
|
assert.Equal(t, max, metric.NewInt64Number(10))
|
||||||
assert.Equal(t, sum, core.NewInt64Number(11))
|
assert.Equal(t, sum, metric.NewInt64Number(11))
|
||||||
assert.Equal(t, count, int64(2))
|
assert.Equal(t, count, int64(2))
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
@ -106,7 +106,7 @@ func TestMinMaxSumCountMetricDescriptor(t *testing.T) {
|
|||||||
metricKind metric.Kind
|
metricKind metric.Kind
|
||||||
description string
|
description string
|
||||||
unit unit.Unit
|
unit unit.Unit
|
||||||
numberKind core.NumberKind
|
numberKind metric.NumberKind
|
||||||
labels []core.KeyValue
|
labels []core.KeyValue
|
||||||
expected *metricpb.MetricDescriptor
|
expected *metricpb.MetricDescriptor
|
||||||
}{
|
}{
|
||||||
@ -115,7 +115,7 @@ func TestMinMaxSumCountMetricDescriptor(t *testing.T) {
|
|||||||
metric.MeasureKind,
|
metric.MeasureKind,
|
||||||
"test-a-description",
|
"test-a-description",
|
||||||
unit.Dimensionless,
|
unit.Dimensionless,
|
||||||
core.Int64NumberKind,
|
metric.Int64NumberKind,
|
||||||
[]core.KeyValue{},
|
[]core.KeyValue{},
|
||||||
&metricpb.MetricDescriptor{
|
&metricpb.MetricDescriptor{
|
||||||
Name: "mmsc-test-a",
|
Name: "mmsc-test-a",
|
||||||
@ -130,7 +130,7 @@ func TestMinMaxSumCountMetricDescriptor(t *testing.T) {
|
|||||||
metric.CounterKind, // This shouldn't change anything.
|
metric.CounterKind, // This shouldn't change anything.
|
||||||
"test-b-description",
|
"test-b-description",
|
||||||
unit.Bytes,
|
unit.Bytes,
|
||||||
core.Float64NumberKind, // This shouldn't change anything.
|
metric.Float64NumberKind, // This shouldn't change anything.
|
||||||
[]core.KeyValue{key.String("A", "1")},
|
[]core.KeyValue{key.String("A", "1")},
|
||||||
&metricpb.MetricDescriptor{
|
&metricpb.MetricDescriptor{
|
||||||
Name: "mmsc-test-b",
|
Name: "mmsc-test-b",
|
||||||
@ -161,7 +161,7 @@ func TestMinMaxSumCountMetricDescriptor(t *testing.T) {
|
|||||||
}
|
}
|
||||||
|
|
||||||
func TestMinMaxSumCountDatapoints(t *testing.T) {
|
func TestMinMaxSumCountDatapoints(t *testing.T) {
|
||||||
desc := metric.NewDescriptor("", metric.MeasureKind, core.Int64NumberKind)
|
desc := metric.NewDescriptor("", metric.MeasureKind, metric.Int64NumberKind)
|
||||||
labels := label.NewSet()
|
labels := label.NewSet()
|
||||||
mmsc := minmaxsumcount.New(&desc)
|
mmsc := minmaxsumcount.New(&desc)
|
||||||
assert.NoError(t, mmsc.Update(context.Background(), 1, &desc))
|
assert.NoError(t, mmsc.Update(context.Background(), 1, &desc))
|
||||||
@ -208,7 +208,7 @@ func TestSumMetricDescriptor(t *testing.T) {
|
|||||||
metricKind metric.Kind
|
metricKind metric.Kind
|
||||||
description string
|
description string
|
||||||
unit unit.Unit
|
unit unit.Unit
|
||||||
numberKind core.NumberKind
|
numberKind metric.NumberKind
|
||||||
labels []core.KeyValue
|
labels []core.KeyValue
|
||||||
expected *metricpb.MetricDescriptor
|
expected *metricpb.MetricDescriptor
|
||||||
}{
|
}{
|
||||||
@ -217,7 +217,7 @@ func TestSumMetricDescriptor(t *testing.T) {
|
|||||||
metric.CounterKind,
|
metric.CounterKind,
|
||||||
"test-a-description",
|
"test-a-description",
|
||||||
unit.Dimensionless,
|
unit.Dimensionless,
|
||||||
core.Int64NumberKind,
|
metric.Int64NumberKind,
|
||||||
[]core.KeyValue{},
|
[]core.KeyValue{},
|
||||||
&metricpb.MetricDescriptor{
|
&metricpb.MetricDescriptor{
|
||||||
Name: "sum-test-a",
|
Name: "sum-test-a",
|
||||||
@ -232,7 +232,7 @@ func TestSumMetricDescriptor(t *testing.T) {
|
|||||||
metric.MeasureKind, // This shouldn't change anything.
|
metric.MeasureKind, // This shouldn't change anything.
|
||||||
"test-b-description",
|
"test-b-description",
|
||||||
unit.Milliseconds,
|
unit.Milliseconds,
|
||||||
core.Float64NumberKind,
|
metric.Float64NumberKind,
|
||||||
[]core.KeyValue{key.String("A", "1")},
|
[]core.KeyValue{key.String("A", "1")},
|
||||||
&metricpb.MetricDescriptor{
|
&metricpb.MetricDescriptor{
|
||||||
Name: "sum-test-b",
|
Name: "sum-test-b",
|
||||||
@ -258,10 +258,10 @@ func TestSumMetricDescriptor(t *testing.T) {
|
|||||||
}
|
}
|
||||||
|
|
||||||
func TestSumInt64DataPoints(t *testing.T) {
|
func TestSumInt64DataPoints(t *testing.T) {
|
||||||
desc := metric.NewDescriptor("", metric.MeasureKind, core.Int64NumberKind)
|
desc := metric.NewDescriptor("", metric.MeasureKind, metric.Int64NumberKind)
|
||||||
labels := label.NewSet()
|
labels := label.NewSet()
|
||||||
s := sumAgg.New()
|
s := sumAgg.New()
|
||||||
assert.NoError(t, s.Update(context.Background(), core.Number(1), &desc))
|
assert.NoError(t, s.Update(context.Background(), metric.Number(1), &desc))
|
||||||
s.Checkpoint(context.Background(), &desc)
|
s.Checkpoint(context.Background(), &desc)
|
||||||
if m, err := sum(&desc, &labels, s); assert.NoError(t, err) {
|
if m, err := sum(&desc, &labels, s); assert.NoError(t, err) {
|
||||||
assert.Equal(t, []*metricpb.Int64DataPoint{{Value: 1}}, m.Int64DataPoints)
|
assert.Equal(t, []*metricpb.Int64DataPoint{{Value: 1}}, m.Int64DataPoints)
|
||||||
@ -272,10 +272,10 @@ func TestSumInt64DataPoints(t *testing.T) {
|
|||||||
}
|
}
|
||||||
|
|
||||||
func TestSumFloat64DataPoints(t *testing.T) {
|
func TestSumFloat64DataPoints(t *testing.T) {
|
||||||
desc := metric.NewDescriptor("", metric.MeasureKind, core.Float64NumberKind)
|
desc := metric.NewDescriptor("", metric.MeasureKind, metric.Float64NumberKind)
|
||||||
labels := label.NewSet()
|
labels := label.NewSet()
|
||||||
s := sumAgg.New()
|
s := sumAgg.New()
|
||||||
assert.NoError(t, s.Update(context.Background(), core.NewFloat64Number(1), &desc))
|
assert.NoError(t, s.Update(context.Background(), metric.NewFloat64Number(1), &desc))
|
||||||
s.Checkpoint(context.Background(), &desc)
|
s.Checkpoint(context.Background(), &desc)
|
||||||
if m, err := sum(&desc, &labels, s); assert.NoError(t, err) {
|
if m, err := sum(&desc, &labels, s); assert.NoError(t, err) {
|
||||||
assert.Equal(t, []*metricpb.Int64DataPoint(nil), m.Int64DataPoints)
|
assert.Equal(t, []*metricpb.Int64DataPoint(nil), m.Int64DataPoints)
|
||||||
@ -286,7 +286,7 @@ func TestSumFloat64DataPoints(t *testing.T) {
|
|||||||
}
|
}
|
||||||
|
|
||||||
func TestSumErrUnknownValueType(t *testing.T) {
|
func TestSumErrUnknownValueType(t *testing.T) {
|
||||||
desc := metric.NewDescriptor("", metric.MeasureKind, core.NumberKind(-1))
|
desc := metric.NewDescriptor("", metric.MeasureKind, metric.NumberKind(-1))
|
||||||
labels := label.NewSet()
|
labels := label.NewSet()
|
||||||
s := sumAgg.New()
|
s := sumAgg.New()
|
||||||
_, err := sum(&desc, &labels, s)
|
_, err := sum(&desc, &labels, s)
|
||||||
|
@ -121,45 +121,45 @@ func newExporterEndToEndTest(t *testing.T, additionalOpts []otlp.ExporterOption)
|
|||||||
|
|
||||||
type data struct {
|
type data struct {
|
||||||
iKind metric.Kind
|
iKind metric.Kind
|
||||||
nKind core.NumberKind
|
nKind metricapi.NumberKind
|
||||||
val int64
|
val int64
|
||||||
}
|
}
|
||||||
instruments := map[string]data{
|
instruments := map[string]data{
|
||||||
"test-int64-counter": {metric.CounterKind, core.Int64NumberKind, 1},
|
"test-int64-counter": {metric.CounterKind, metricapi.Int64NumberKind, 1},
|
||||||
"test-float64-counter": {metric.CounterKind, core.Float64NumberKind, 1},
|
"test-float64-counter": {metric.CounterKind, metricapi.Float64NumberKind, 1},
|
||||||
"test-int64-measure": {metric.MeasureKind, core.Int64NumberKind, 2},
|
"test-int64-measure": {metric.MeasureKind, metricapi.Int64NumberKind, 2},
|
||||||
"test-float64-measure": {metric.MeasureKind, core.Float64NumberKind, 2},
|
"test-float64-measure": {metric.MeasureKind, metricapi.Float64NumberKind, 2},
|
||||||
"test-int64-observer": {metric.ObserverKind, core.Int64NumberKind, 3},
|
"test-int64-observer": {metric.ObserverKind, metricapi.Int64NumberKind, 3},
|
||||||
"test-float64-observer": {metric.ObserverKind, core.Float64NumberKind, 3},
|
"test-float64-observer": {metric.ObserverKind, metricapi.Float64NumberKind, 3},
|
||||||
}
|
}
|
||||||
for name, data := range instruments {
|
for name, data := range instruments {
|
||||||
switch data.iKind {
|
switch data.iKind {
|
||||||
case metric.CounterKind:
|
case metric.CounterKind:
|
||||||
switch data.nKind {
|
switch data.nKind {
|
||||||
case core.Int64NumberKind:
|
case metricapi.Int64NumberKind:
|
||||||
metricapi.Must(meter).NewInt64Counter(name).Add(ctx, data.val, labels...)
|
metricapi.Must(meter).NewInt64Counter(name).Add(ctx, data.val, labels...)
|
||||||
case core.Float64NumberKind:
|
case metricapi.Float64NumberKind:
|
||||||
metricapi.Must(meter).NewFloat64Counter(name).Add(ctx, float64(data.val), labels...)
|
metricapi.Must(meter).NewFloat64Counter(name).Add(ctx, float64(data.val), labels...)
|
||||||
default:
|
default:
|
||||||
assert.Failf(t, "unsupported number testing kind", data.nKind.String())
|
assert.Failf(t, "unsupported number testing kind", data.nKind.String())
|
||||||
}
|
}
|
||||||
case metric.MeasureKind:
|
case metric.MeasureKind:
|
||||||
switch data.nKind {
|
switch data.nKind {
|
||||||
case core.Int64NumberKind:
|
case metricapi.Int64NumberKind:
|
||||||
metricapi.Must(meter).NewInt64Measure(name).Record(ctx, data.val, labels...)
|
metricapi.Must(meter).NewInt64Measure(name).Record(ctx, data.val, labels...)
|
||||||
case core.Float64NumberKind:
|
case metricapi.Float64NumberKind:
|
||||||
metricapi.Must(meter).NewFloat64Measure(name).Record(ctx, float64(data.val), labels...)
|
metricapi.Must(meter).NewFloat64Measure(name).Record(ctx, float64(data.val), labels...)
|
||||||
default:
|
default:
|
||||||
assert.Failf(t, "unsupported number testing kind", data.nKind.String())
|
assert.Failf(t, "unsupported number testing kind", data.nKind.String())
|
||||||
}
|
}
|
||||||
case metric.ObserverKind:
|
case metric.ObserverKind:
|
||||||
switch data.nKind {
|
switch data.nKind {
|
||||||
case core.Int64NumberKind:
|
case metricapi.Int64NumberKind:
|
||||||
callback := func(v int64) metricapi.Int64ObserverCallback {
|
callback := func(v int64) metricapi.Int64ObserverCallback {
|
||||||
return metricapi.Int64ObserverCallback(func(result metricapi.Int64ObserverResult) { result.Observe(v, labels...) })
|
return metricapi.Int64ObserverCallback(func(result metricapi.Int64ObserverResult) { result.Observe(v, labels...) })
|
||||||
}(data.val)
|
}(data.val)
|
||||||
metricapi.Must(meter).RegisterInt64Observer(name, callback)
|
metricapi.Must(meter).RegisterInt64Observer(name, callback)
|
||||||
case core.Float64NumberKind:
|
case metricapi.Float64NumberKind:
|
||||||
callback := func(v float64) metricapi.Float64ObserverCallback {
|
callback := func(v float64) metricapi.Float64ObserverCallback {
|
||||||
return metricapi.Float64ObserverCallback(func(result metricapi.Float64ObserverResult) { result.Observe(v, labels...) })
|
return metricapi.Float64ObserverCallback(func(result metricapi.Float64ObserverResult) { result.Observe(v, labels...) })
|
||||||
}(float64(data.val))
|
}(float64(data.val))
|
||||||
@ -234,12 +234,12 @@ func newExporterEndToEndTest(t *testing.T, additionalOpts []otlp.ExporterOption)
|
|||||||
switch data.iKind {
|
switch data.iKind {
|
||||||
case metric.CounterKind:
|
case metric.CounterKind:
|
||||||
switch data.nKind {
|
switch data.nKind {
|
||||||
case core.Int64NumberKind:
|
case metricapi.Int64NumberKind:
|
||||||
assert.Equal(t, metricpb.MetricDescriptor_COUNTER_INT64.String(), desc.GetType().String())
|
assert.Equal(t, metricpb.MetricDescriptor_COUNTER_INT64.String(), desc.GetType().String())
|
||||||
if dp := m.GetInt64DataPoints(); assert.Len(t, dp, 1) {
|
if dp := m.GetInt64DataPoints(); assert.Len(t, dp, 1) {
|
||||||
assert.Equal(t, data.val, dp[0].Value, "invalid value for %q", desc.Name)
|
assert.Equal(t, data.val, dp[0].Value, "invalid value for %q", desc.Name)
|
||||||
}
|
}
|
||||||
case core.Float64NumberKind:
|
case metricapi.Float64NumberKind:
|
||||||
assert.Equal(t, metricpb.MetricDescriptor_COUNTER_DOUBLE.String(), desc.GetType().String())
|
assert.Equal(t, metricpb.MetricDescriptor_COUNTER_DOUBLE.String(), desc.GetType().String())
|
||||||
if dp := m.GetDoubleDataPoints(); assert.Len(t, dp, 1) {
|
if dp := m.GetDoubleDataPoints(); assert.Len(t, dp, 1) {
|
||||||
assert.Equal(t, float64(data.val), dp[0].Value, "invalid value for %q", desc.Name)
|
assert.Equal(t, float64(data.val), dp[0].Value, "invalid value for %q", desc.Name)
|
||||||
|
@ -76,7 +76,7 @@ func (m checkpointSet) ForEach(fn func(metricsdk.Record) error) error {
|
|||||||
type record struct {
|
type record struct {
|
||||||
name string
|
name string
|
||||||
mKind metric.Kind
|
mKind metric.Kind
|
||||||
nKind core.NumberKind
|
nKind metric.NumberKind
|
||||||
resource *resource.Resource
|
resource *resource.Resource
|
||||||
opts []metric.Option
|
opts []metric.Option
|
||||||
labels []core.KeyValue
|
labels []core.KeyValue
|
||||||
@ -145,7 +145,7 @@ func TestNoGroupingExport(t *testing.T) {
|
|||||||
{
|
{
|
||||||
"int64-count",
|
"int64-count",
|
||||||
metric.CounterKind,
|
metric.CounterKind,
|
||||||
core.Int64NumberKind,
|
metric.Int64NumberKind,
|
||||||
nil,
|
nil,
|
||||||
nil,
|
nil,
|
||||||
append(baseKeyValues, cpuKey.Int(1)),
|
append(baseKeyValues, cpuKey.Int(1)),
|
||||||
@ -153,7 +153,7 @@ func TestNoGroupingExport(t *testing.T) {
|
|||||||
{
|
{
|
||||||
"int64-count",
|
"int64-count",
|
||||||
metric.CounterKind,
|
metric.CounterKind,
|
||||||
core.Int64NumberKind,
|
metric.Int64NumberKind,
|
||||||
nil,
|
nil,
|
||||||
nil,
|
nil,
|
||||||
append(baseKeyValues, cpuKey.Int(2)),
|
append(baseKeyValues, cpuKey.Int(2)),
|
||||||
@ -193,7 +193,7 @@ func TestMeasureMetricGroupingExport(t *testing.T) {
|
|||||||
r := record{
|
r := record{
|
||||||
"measure",
|
"measure",
|
||||||
metric.MeasureKind,
|
metric.MeasureKind,
|
||||||
core.Int64NumberKind,
|
metric.Int64NumberKind,
|
||||||
nil,
|
nil,
|
||||||
nil,
|
nil,
|
||||||
append(baseKeyValues, cpuKey.Int(1)),
|
append(baseKeyValues, cpuKey.Int(1)),
|
||||||
@ -257,9 +257,9 @@ func TestMeasureMetricGroupingExport(t *testing.T) {
|
|||||||
}
|
}
|
||||||
runMetricExportTests(t, []record{r, r}, expected)
|
runMetricExportTests(t, []record{r, r}, expected)
|
||||||
//changing the number kind should make no difference.
|
//changing the number kind should make no difference.
|
||||||
r.nKind = core.Uint64NumberKind
|
r.nKind = metric.Uint64NumberKind
|
||||||
runMetricExportTests(t, []record{r, r}, expected)
|
runMetricExportTests(t, []record{r, r}, expected)
|
||||||
r.nKind = core.Float64NumberKind
|
r.nKind = metric.Float64NumberKind
|
||||||
runMetricExportTests(t, []record{r, r}, expected)
|
runMetricExportTests(t, []record{r, r}, expected)
|
||||||
}
|
}
|
||||||
|
|
||||||
@ -267,7 +267,7 @@ func TestCountInt64MetricGroupingExport(t *testing.T) {
|
|||||||
r := record{
|
r := record{
|
||||||
"int64-count",
|
"int64-count",
|
||||||
metric.CounterKind,
|
metric.CounterKind,
|
||||||
core.Int64NumberKind,
|
metric.Int64NumberKind,
|
||||||
nil,
|
nil,
|
||||||
nil,
|
nil,
|
||||||
append(baseKeyValues, cpuKey.Int(1)),
|
append(baseKeyValues, cpuKey.Int(1)),
|
||||||
@ -304,7 +304,7 @@ func TestCountUint64MetricGroupingExport(t *testing.T) {
|
|||||||
r := record{
|
r := record{
|
||||||
"uint64-count",
|
"uint64-count",
|
||||||
metric.CounterKind,
|
metric.CounterKind,
|
||||||
core.Uint64NumberKind,
|
metric.Uint64NumberKind,
|
||||||
nil,
|
nil,
|
||||||
nil,
|
nil,
|
||||||
append(baseKeyValues, cpuKey.Int(1)),
|
append(baseKeyValues, cpuKey.Int(1)),
|
||||||
@ -354,7 +354,7 @@ func TestCountFloat64MetricGroupingExport(t *testing.T) {
|
|||||||
r := record{
|
r := record{
|
||||||
"float64-count",
|
"float64-count",
|
||||||
metric.CounterKind,
|
metric.CounterKind,
|
||||||
core.Float64NumberKind,
|
metric.Float64NumberKind,
|
||||||
nil,
|
nil,
|
||||||
nil,
|
nil,
|
||||||
append(baseKeyValues, cpuKey.Int(1)),
|
append(baseKeyValues, cpuKey.Int(1)),
|
||||||
@ -407,7 +407,7 @@ func TestResourceMetricGroupingExport(t *testing.T) {
|
|||||||
{
|
{
|
||||||
"int64-count",
|
"int64-count",
|
||||||
metric.CounterKind,
|
metric.CounterKind,
|
||||||
core.Int64NumberKind,
|
metric.Int64NumberKind,
|
||||||
testInstA,
|
testInstA,
|
||||||
nil,
|
nil,
|
||||||
append(baseKeyValues, cpuKey.Int(1)),
|
append(baseKeyValues, cpuKey.Int(1)),
|
||||||
@ -415,7 +415,7 @@ func TestResourceMetricGroupingExport(t *testing.T) {
|
|||||||
{
|
{
|
||||||
"int64-count",
|
"int64-count",
|
||||||
metric.CounterKind,
|
metric.CounterKind,
|
||||||
core.Int64NumberKind,
|
metric.Int64NumberKind,
|
||||||
testInstA,
|
testInstA,
|
||||||
nil,
|
nil,
|
||||||
append(baseKeyValues, cpuKey.Int(1)),
|
append(baseKeyValues, cpuKey.Int(1)),
|
||||||
@ -423,7 +423,7 @@ func TestResourceMetricGroupingExport(t *testing.T) {
|
|||||||
{
|
{
|
||||||
"int64-count",
|
"int64-count",
|
||||||
metric.CounterKind,
|
metric.CounterKind,
|
||||||
core.Int64NumberKind,
|
metric.Int64NumberKind,
|
||||||
testInstA,
|
testInstA,
|
||||||
nil,
|
nil,
|
||||||
append(baseKeyValues, cpuKey.Int(2)),
|
append(baseKeyValues, cpuKey.Int(2)),
|
||||||
@ -431,7 +431,7 @@ func TestResourceMetricGroupingExport(t *testing.T) {
|
|||||||
{
|
{
|
||||||
"int64-count",
|
"int64-count",
|
||||||
metric.CounterKind,
|
metric.CounterKind,
|
||||||
core.Int64NumberKind,
|
metric.Int64NumberKind,
|
||||||
testInstB,
|
testInstB,
|
||||||
nil,
|
nil,
|
||||||
append(baseKeyValues, cpuKey.Int(1)),
|
append(baseKeyValues, cpuKey.Int(1)),
|
||||||
@ -494,7 +494,7 @@ func TestResourceInstLibMetricGroupingExport(t *testing.T) {
|
|||||||
{
|
{
|
||||||
"int64-count",
|
"int64-count",
|
||||||
metric.CounterKind,
|
metric.CounterKind,
|
||||||
core.Int64NumberKind,
|
metric.Int64NumberKind,
|
||||||
testInstA,
|
testInstA,
|
||||||
[]metric.Option{
|
[]metric.Option{
|
||||||
metric.WithLibraryName("couting-lib"),
|
metric.WithLibraryName("couting-lib"),
|
||||||
@ -504,7 +504,7 @@ func TestResourceInstLibMetricGroupingExport(t *testing.T) {
|
|||||||
{
|
{
|
||||||
"int64-count",
|
"int64-count",
|
||||||
metric.CounterKind,
|
metric.CounterKind,
|
||||||
core.Int64NumberKind,
|
metric.Int64NumberKind,
|
||||||
testInstA,
|
testInstA,
|
||||||
[]metric.Option{
|
[]metric.Option{
|
||||||
metric.WithLibraryName("couting-lib"),
|
metric.WithLibraryName("couting-lib"),
|
||||||
@ -514,7 +514,7 @@ func TestResourceInstLibMetricGroupingExport(t *testing.T) {
|
|||||||
{
|
{
|
||||||
"int64-count",
|
"int64-count",
|
||||||
metric.CounterKind,
|
metric.CounterKind,
|
||||||
core.Int64NumberKind,
|
metric.Int64NumberKind,
|
||||||
testInstA,
|
testInstA,
|
||||||
[]metric.Option{
|
[]metric.Option{
|
||||||
metric.WithLibraryName("couting-lib"),
|
metric.WithLibraryName("couting-lib"),
|
||||||
@ -524,7 +524,7 @@ func TestResourceInstLibMetricGroupingExport(t *testing.T) {
|
|||||||
{
|
{
|
||||||
"int64-count",
|
"int64-count",
|
||||||
metric.CounterKind,
|
metric.CounterKind,
|
||||||
core.Int64NumberKind,
|
metric.Int64NumberKind,
|
||||||
testInstA,
|
testInstA,
|
||||||
[]metric.Option{
|
[]metric.Option{
|
||||||
metric.WithLibraryName("summing-lib"),
|
metric.WithLibraryName("summing-lib"),
|
||||||
@ -534,7 +534,7 @@ func TestResourceInstLibMetricGroupingExport(t *testing.T) {
|
|||||||
{
|
{
|
||||||
"int64-count",
|
"int64-count",
|
||||||
metric.CounterKind,
|
metric.CounterKind,
|
||||||
core.Int64NumberKind,
|
metric.Int64NumberKind,
|
||||||
testInstB,
|
testInstB,
|
||||||
[]metric.Option{
|
[]metric.Option{
|
||||||
metric.WithLibraryName("couting-lib"),
|
metric.WithLibraryName("couting-lib"),
|
||||||
@ -644,15 +644,15 @@ func runMetricExportTest(t *testing.T, exp *Exporter, rs []record, expected []me
|
|||||||
|
|
||||||
ctx := context.Background()
|
ctx := context.Background()
|
||||||
switch r.nKind {
|
switch r.nKind {
|
||||||
case core.Uint64NumberKind:
|
case metric.Uint64NumberKind:
|
||||||
require.NoError(t, agg.Update(ctx, core.NewUint64Number(1), &desc))
|
require.NoError(t, agg.Update(ctx, metric.NewUint64Number(1), &desc))
|
||||||
require.NoError(t, agg.Update(ctx, core.NewUint64Number(10), &desc))
|
require.NoError(t, agg.Update(ctx, metric.NewUint64Number(10), &desc))
|
||||||
case core.Int64NumberKind:
|
case metric.Int64NumberKind:
|
||||||
require.NoError(t, agg.Update(ctx, core.NewInt64Number(1), &desc))
|
require.NoError(t, agg.Update(ctx, metric.NewInt64Number(1), &desc))
|
||||||
require.NoError(t, agg.Update(ctx, core.NewInt64Number(10), &desc))
|
require.NoError(t, agg.Update(ctx, metric.NewInt64Number(10), &desc))
|
||||||
case core.Float64NumberKind:
|
case metric.Float64NumberKind:
|
||||||
require.NoError(t, agg.Update(ctx, core.NewFloat64Number(1), &desc))
|
require.NoError(t, agg.Update(ctx, metric.NewFloat64Number(1), &desc))
|
||||||
require.NoError(t, agg.Update(ctx, core.NewFloat64Number(10), &desc))
|
require.NoError(t, agg.Update(ctx, metric.NewFloat64Number(10), &desc))
|
||||||
default:
|
default:
|
||||||
t.Fatalf("invalid number kind: %v", r.nKind)
|
t.Fatalf("invalid number kind: %v", r.nKind)
|
||||||
}
|
}
|
||||||
|
@ -52,7 +52,7 @@ type (
|
|||||||
|
|
||||||
Measurement struct {
|
Measurement struct {
|
||||||
// Number needs to be aligned for 64-bit atomic operations.
|
// Number needs to be aligned for 64-bit atomic operations.
|
||||||
Number core.Number
|
Number apimetric.Number
|
||||||
Instrument apimetric.InstrumentImpl
|
Instrument apimetric.InstrumentImpl
|
||||||
}
|
}
|
||||||
|
|
||||||
@ -64,7 +64,7 @@ type (
|
|||||||
Async struct {
|
Async struct {
|
||||||
Instrument
|
Instrument
|
||||||
|
|
||||||
callback func(func(core.Number, []core.KeyValue))
|
callback func(func(apimetric.Number, []core.KeyValue))
|
||||||
}
|
}
|
||||||
|
|
||||||
Sync struct {
|
Sync struct {
|
||||||
@ -98,18 +98,18 @@ func (s *Sync) Bind(labels []core.KeyValue) apimetric.BoundSyncImpl {
|
|||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
func (s *Sync) RecordOne(ctx context.Context, number core.Number, labels []core.KeyValue) {
|
func (s *Sync) RecordOne(ctx context.Context, number apimetric.Number, labels []core.KeyValue) {
|
||||||
s.meter.doRecordSingle(ctx, labels, s, number)
|
s.meter.doRecordSingle(ctx, labels, s, number)
|
||||||
}
|
}
|
||||||
|
|
||||||
func (h *Handle) RecordOne(ctx context.Context, number core.Number) {
|
func (h *Handle) RecordOne(ctx context.Context, number apimetric.Number) {
|
||||||
h.Instrument.meter.doRecordSingle(ctx, h.Labels, h.Instrument, number)
|
h.Instrument.meter.doRecordSingle(ctx, h.Labels, h.Instrument, number)
|
||||||
}
|
}
|
||||||
|
|
||||||
func (h *Handle) Unbind() {
|
func (h *Handle) Unbind() {
|
||||||
}
|
}
|
||||||
|
|
||||||
func (m *MeterImpl) doRecordSingle(ctx context.Context, labels []core.KeyValue, instrument apimetric.InstrumentImpl, number core.Number) {
|
func (m *MeterImpl) doRecordSingle(ctx context.Context, labels []core.KeyValue, instrument apimetric.InstrumentImpl, number apimetric.Number) {
|
||||||
m.recordMockBatch(ctx, labels, Measurement{
|
m.recordMockBatch(ctx, labels, Measurement{
|
||||||
Instrument: instrument,
|
Instrument: instrument,
|
||||||
Number: number,
|
Number: number,
|
||||||
@ -152,7 +152,7 @@ func (m *MeterImpl) NewSyncInstrument(descriptor metric.Descriptor) (apimetric.S
|
|||||||
}, nil
|
}, nil
|
||||||
}
|
}
|
||||||
|
|
||||||
func (m *MeterImpl) NewAsyncInstrument(descriptor metric.Descriptor, callback func(func(core.Number, []core.KeyValue))) (apimetric.AsyncImpl, error) {
|
func (m *MeterImpl) NewAsyncInstrument(descriptor metric.Descriptor, callback func(func(apimetric.Number, []core.KeyValue))) (apimetric.AsyncImpl, error) {
|
||||||
a := &Async{
|
a := &Async{
|
||||||
Instrument: Instrument{
|
Instrument: Instrument{
|
||||||
descriptor: descriptor,
|
descriptor: descriptor,
|
||||||
@ -186,7 +186,7 @@ func (m *MeterImpl) recordMockBatch(ctx context.Context, labels []core.KeyValue,
|
|||||||
|
|
||||||
func (m *MeterImpl) RunAsyncInstruments() {
|
func (m *MeterImpl) RunAsyncInstruments() {
|
||||||
for _, observer := range m.AsyncInstruments {
|
for _, observer := range m.AsyncInstruments {
|
||||||
observer.callback(func(n core.Number, labels []core.KeyValue) {
|
observer.callback(func(n apimetric.Number, labels []core.KeyValue) {
|
||||||
m.doRecordSingle(context.Background(), labels, observer, n)
|
m.doRecordSingle(context.Background(), labels, observer, n)
|
||||||
})
|
})
|
||||||
}
|
}
|
||||||
|
@ -19,7 +19,6 @@ import (
|
|||||||
"math"
|
"math"
|
||||||
"time"
|
"time"
|
||||||
|
|
||||||
"go.opentelemetry.io/otel/api/core"
|
|
||||||
"go.opentelemetry.io/otel/api/metric"
|
"go.opentelemetry.io/otel/api/metric"
|
||||||
export "go.opentelemetry.io/otel/sdk/export/metric"
|
export "go.opentelemetry.io/otel/sdk/export/metric"
|
||||||
)
|
)
|
||||||
@ -30,7 +29,7 @@ import (
|
|||||||
type (
|
type (
|
||||||
// Sum returns an aggregated sum.
|
// Sum returns an aggregated sum.
|
||||||
Sum interface {
|
Sum interface {
|
||||||
Sum() (core.Number, error)
|
Sum() (metric.Number, error)
|
||||||
}
|
}
|
||||||
|
|
||||||
// Sum returns the number of values that were aggregated.
|
// Sum returns the number of values that were aggregated.
|
||||||
@ -40,28 +39,28 @@ type (
|
|||||||
|
|
||||||
// Min returns the minimum value over the set of values that were aggregated.
|
// Min returns the minimum value over the set of values that were aggregated.
|
||||||
Min interface {
|
Min interface {
|
||||||
Min() (core.Number, error)
|
Min() (metric.Number, error)
|
||||||
}
|
}
|
||||||
|
|
||||||
// Max returns the maximum value over the set of values that were aggregated.
|
// Max returns the maximum value over the set of values that were aggregated.
|
||||||
Max interface {
|
Max interface {
|
||||||
Max() (core.Number, error)
|
Max() (metric.Number, error)
|
||||||
}
|
}
|
||||||
|
|
||||||
// Quantile returns an exact or estimated quantile over the
|
// Quantile returns an exact or estimated quantile over the
|
||||||
// set of values that were aggregated.
|
// set of values that were aggregated.
|
||||||
Quantile interface {
|
Quantile interface {
|
||||||
Quantile(float64) (core.Number, error)
|
Quantile(float64) (metric.Number, error)
|
||||||
}
|
}
|
||||||
|
|
||||||
// LastValue returns the latest value that was aggregated.
|
// LastValue returns the latest value that was aggregated.
|
||||||
LastValue interface {
|
LastValue interface {
|
||||||
LastValue() (core.Number, time.Time, error)
|
LastValue() (metric.Number, time.Time, error)
|
||||||
}
|
}
|
||||||
|
|
||||||
// Points returns the raw set of values that were aggregated.
|
// Points returns the raw set of values that were aggregated.
|
||||||
Points interface {
|
Points interface {
|
||||||
Points() ([]core.Number, error)
|
Points() ([]metric.Number, error)
|
||||||
}
|
}
|
||||||
|
|
||||||
// Buckets represents histogram buckets boundaries and counts.
|
// Buckets represents histogram buckets boundaries and counts.
|
||||||
@ -69,8 +68,8 @@ type (
|
|||||||
// For a Histogram with N defined boundaries, e.g, [x, y, z].
|
// For a Histogram with N defined boundaries, e.g, [x, y, z].
|
||||||
// There are N+1 counts: [-inf, x), [x, y), [y, z), [z, +inf]
|
// There are N+1 counts: [-inf, x), [x, y), [y, z), [z, +inf]
|
||||||
Buckets struct {
|
Buckets struct {
|
||||||
Boundaries []core.Number
|
Boundaries []metric.Number
|
||||||
Counts []core.Number
|
Counts []metric.Number
|
||||||
}
|
}
|
||||||
|
|
||||||
// Histogram returns the count of events in pre-determined buckets.
|
// Histogram returns the count of events in pre-determined buckets.
|
||||||
@ -118,10 +117,10 @@ func NewInconsistentMergeError(a1, a2 export.Aggregator) error {
|
|||||||
// This rejects NaN values. This rejects negative values when the
|
// This rejects NaN values. This rejects negative values when the
|
||||||
// metric instrument does not support negative values, including
|
// metric instrument does not support negative values, including
|
||||||
// monotonic counter metrics and absolute measure metrics.
|
// monotonic counter metrics and absolute measure metrics.
|
||||||
func RangeTest(number core.Number, descriptor *metric.Descriptor) error {
|
func RangeTest(number metric.Number, descriptor *metric.Descriptor) error {
|
||||||
numberKind := descriptor.NumberKind()
|
numberKind := descriptor.NumberKind()
|
||||||
|
|
||||||
if numberKind == core.Float64NumberKind && math.IsNaN(number.AsFloat64()) {
|
if numberKind == metric.Float64NumberKind && math.IsNaN(number.AsFloat64()) {
|
||||||
return ErrNaNInput
|
return ErrNaNInput
|
||||||
}
|
}
|
||||||
|
|
||||||
|
@ -21,7 +21,6 @@ import (
|
|||||||
|
|
||||||
"github.com/stretchr/testify/require"
|
"github.com/stretchr/testify/require"
|
||||||
|
|
||||||
"go.opentelemetry.io/otel/api/core"
|
|
||||||
"go.opentelemetry.io/otel/api/metric"
|
"go.opentelemetry.io/otel/api/metric"
|
||||||
"go.opentelemetry.io/otel/sdk/export/metric/aggregator"
|
"go.opentelemetry.io/otel/sdk/export/metric/aggregator"
|
||||||
"go.opentelemetry.io/otel/sdk/metric/aggregator/lastvalue"
|
"go.opentelemetry.io/otel/sdk/metric/aggregator/lastvalue"
|
||||||
@ -40,10 +39,10 @@ func TestInconsistentMergeErr(t *testing.T) {
|
|||||||
|
|
||||||
func testRangeNaN(t *testing.T, desc *metric.Descriptor) {
|
func testRangeNaN(t *testing.T, desc *metric.Descriptor) {
|
||||||
// If the descriptor uses int64 numbers, this won't register as NaN
|
// If the descriptor uses int64 numbers, this won't register as NaN
|
||||||
nan := core.NewFloat64Number(math.NaN())
|
nan := metric.NewFloat64Number(math.NaN())
|
||||||
err := aggregator.RangeTest(nan, desc)
|
err := aggregator.RangeTest(nan, desc)
|
||||||
|
|
||||||
if desc.NumberKind() == core.Float64NumberKind {
|
if desc.NumberKind() == metric.Float64NumberKind {
|
||||||
require.Equal(t, aggregator.ErrNaNInput, err)
|
require.Equal(t, aggregator.ErrNaNInput, err)
|
||||||
} else {
|
} else {
|
||||||
require.Nil(t, err)
|
require.Nil(t, err)
|
||||||
@ -51,14 +50,14 @@ func testRangeNaN(t *testing.T, desc *metric.Descriptor) {
|
|||||||
}
|
}
|
||||||
|
|
||||||
func testRangeNegative(t *testing.T, desc *metric.Descriptor) {
|
func testRangeNegative(t *testing.T, desc *metric.Descriptor) {
|
||||||
var neg, pos core.Number
|
var neg, pos metric.Number
|
||||||
|
|
||||||
if desc.NumberKind() == core.Float64NumberKind {
|
if desc.NumberKind() == metric.Float64NumberKind {
|
||||||
pos = core.NewFloat64Number(+1)
|
pos = metric.NewFloat64Number(+1)
|
||||||
neg = core.NewFloat64Number(-1)
|
neg = metric.NewFloat64Number(-1)
|
||||||
} else {
|
} else {
|
||||||
pos = core.NewInt64Number(+1)
|
pos = metric.NewInt64Number(+1)
|
||||||
neg = core.NewInt64Number(-1)
|
neg = metric.NewInt64Number(-1)
|
||||||
}
|
}
|
||||||
|
|
||||||
posErr := aggregator.RangeTest(pos, desc)
|
posErr := aggregator.RangeTest(pos, desc)
|
||||||
@ -70,7 +69,7 @@ func testRangeNegative(t *testing.T, desc *metric.Descriptor) {
|
|||||||
|
|
||||||
func TestRangeTest(t *testing.T) {
|
func TestRangeTest(t *testing.T) {
|
||||||
// Only Counters implement a range test.
|
// Only Counters implement a range test.
|
||||||
for _, nkind := range []core.NumberKind{core.Float64NumberKind, core.Int64NumberKind} {
|
for _, nkind := range []metric.NumberKind{metric.Float64NumberKind, metric.Int64NumberKind} {
|
||||||
t.Run(nkind.String(), func(t *testing.T) {
|
t.Run(nkind.String(), func(t *testing.T) {
|
||||||
desc := metric.NewDescriptor(
|
desc := metric.NewDescriptor(
|
||||||
"name",
|
"name",
|
||||||
@ -83,7 +82,7 @@ func TestRangeTest(t *testing.T) {
|
|||||||
}
|
}
|
||||||
|
|
||||||
func TestNaNTest(t *testing.T) {
|
func TestNaNTest(t *testing.T) {
|
||||||
for _, nkind := range []core.NumberKind{core.Float64NumberKind, core.Int64NumberKind} {
|
for _, nkind := range []metric.NumberKind{metric.Float64NumberKind, metric.Int64NumberKind} {
|
||||||
t.Run(nkind.String(), func(t *testing.T) {
|
t.Run(nkind.String(), func(t *testing.T) {
|
||||||
for _, mkind := range []metric.Kind{
|
for _, mkind := range []metric.Kind{
|
||||||
metric.CounterKind,
|
metric.CounterKind,
|
||||||
|
@ -17,7 +17,6 @@ package metric // import "go.opentelemetry.io/otel/sdk/export/metric"
|
|||||||
import (
|
import (
|
||||||
"context"
|
"context"
|
||||||
|
|
||||||
"go.opentelemetry.io/otel/api/core"
|
|
||||||
"go.opentelemetry.io/otel/api/label"
|
"go.opentelemetry.io/otel/api/label"
|
||||||
"go.opentelemetry.io/otel/api/metric"
|
"go.opentelemetry.io/otel/api/metric"
|
||||||
"go.opentelemetry.io/otel/sdk/resource"
|
"go.opentelemetry.io/otel/sdk/resource"
|
||||||
@ -127,7 +126,7 @@ type Aggregator interface {
|
|||||||
//
|
//
|
||||||
// The Context argument comes from user-level code and could be
|
// The Context argument comes from user-level code and could be
|
||||||
// inspected for distributed or span context.
|
// inspected for distributed or span context.
|
||||||
Update(context.Context, core.Number, *metric.Descriptor) error
|
Update(context.Context, metric.Number, *metric.Descriptor) error
|
||||||
|
|
||||||
// Checkpoint is called during collection to finish one period
|
// Checkpoint is called during collection to finish one period
|
||||||
// of aggregation by atomically saving the current value.
|
// of aggregation by atomically saving the current value.
|
||||||
|
@ -21,7 +21,6 @@ import (
|
|||||||
"sync"
|
"sync"
|
||||||
"unsafe"
|
"unsafe"
|
||||||
|
|
||||||
"go.opentelemetry.io/otel/api/core"
|
|
||||||
"go.opentelemetry.io/otel/api/metric"
|
"go.opentelemetry.io/otel/api/metric"
|
||||||
export "go.opentelemetry.io/otel/sdk/export/metric"
|
export "go.opentelemetry.io/otel/sdk/export/metric"
|
||||||
"go.opentelemetry.io/otel/sdk/export/metric/aggregator"
|
"go.opentelemetry.io/otel/sdk/export/metric/aggregator"
|
||||||
@ -30,13 +29,13 @@ import (
|
|||||||
type (
|
type (
|
||||||
Aggregator struct {
|
Aggregator struct {
|
||||||
// ckptSum needs to be aligned for 64-bit atomic operations.
|
// ckptSum needs to be aligned for 64-bit atomic operations.
|
||||||
ckptSum core.Number
|
ckptSum metric.Number
|
||||||
lock sync.Mutex
|
lock sync.Mutex
|
||||||
current points
|
current points
|
||||||
checkpoint points
|
checkpoint points
|
||||||
}
|
}
|
||||||
|
|
||||||
points []core.Number
|
points []metric.Number
|
||||||
)
|
)
|
||||||
|
|
||||||
var _ export.Aggregator = &Aggregator{}
|
var _ export.Aggregator = &Aggregator{}
|
||||||
@ -52,7 +51,7 @@ func New() *Aggregator {
|
|||||||
}
|
}
|
||||||
|
|
||||||
// Sum returns the sum of values in the checkpoint.
|
// Sum returns the sum of values in the checkpoint.
|
||||||
func (c *Aggregator) Sum() (core.Number, error) {
|
func (c *Aggregator) Sum() (metric.Number, error) {
|
||||||
return c.ckptSum, nil
|
return c.ckptSum, nil
|
||||||
}
|
}
|
||||||
|
|
||||||
@ -62,23 +61,23 @@ func (c *Aggregator) Count() (int64, error) {
|
|||||||
}
|
}
|
||||||
|
|
||||||
// Max returns the maximum value in the checkpoint.
|
// Max returns the maximum value in the checkpoint.
|
||||||
func (c *Aggregator) Max() (core.Number, error) {
|
func (c *Aggregator) Max() (metric.Number, error) {
|
||||||
return c.checkpoint.Quantile(1)
|
return c.checkpoint.Quantile(1)
|
||||||
}
|
}
|
||||||
|
|
||||||
// Min returns the mininum value in the checkpoint.
|
// Min returns the mininum value in the checkpoint.
|
||||||
func (c *Aggregator) Min() (core.Number, error) {
|
func (c *Aggregator) Min() (metric.Number, error) {
|
||||||
return c.checkpoint.Quantile(0)
|
return c.checkpoint.Quantile(0)
|
||||||
}
|
}
|
||||||
|
|
||||||
// Quantile returns the estimated quantile of data in the checkpoint.
|
// Quantile returns the estimated quantile of data in the checkpoint.
|
||||||
// It is an error if `q` is less than 0 or greated than 1.
|
// It is an error if `q` is less than 0 or greated than 1.
|
||||||
func (c *Aggregator) Quantile(q float64) (core.Number, error) {
|
func (c *Aggregator) Quantile(q float64) (metric.Number, error) {
|
||||||
return c.checkpoint.Quantile(q)
|
return c.checkpoint.Quantile(q)
|
||||||
}
|
}
|
||||||
|
|
||||||
// Points returns access to the raw data set.
|
// Points returns access to the raw data set.
|
||||||
func (c *Aggregator) Points() ([]core.Number, error) {
|
func (c *Aggregator) Points() ([]metric.Number, error) {
|
||||||
return c.checkpoint, nil
|
return c.checkpoint, nil
|
||||||
}
|
}
|
||||||
|
|
||||||
@ -97,7 +96,7 @@ func (c *Aggregator) Checkpoint(ctx context.Context, desc *metric.Descriptor) {
|
|||||||
// received as an alternative to requesting quantile information.
|
// received as an alternative to requesting quantile information.
|
||||||
c.sort(kind)
|
c.sort(kind)
|
||||||
|
|
||||||
c.ckptSum = core.Number(0)
|
c.ckptSum = metric.Number(0)
|
||||||
|
|
||||||
for _, v := range c.checkpoint {
|
for _, v := range c.checkpoint {
|
||||||
c.ckptSum.AddNumber(kind, v)
|
c.ckptSum.AddNumber(kind, v)
|
||||||
@ -107,7 +106,7 @@ func (c *Aggregator) Checkpoint(ctx context.Context, desc *metric.Descriptor) {
|
|||||||
// Update adds the recorded measurement to the current data set.
|
// Update adds the recorded measurement to the current data set.
|
||||||
// Update takes a lock to prevent concurrent Update() and Checkpoint()
|
// Update takes a lock to prevent concurrent Update() and Checkpoint()
|
||||||
// calls.
|
// calls.
|
||||||
func (c *Aggregator) Update(_ context.Context, number core.Number, desc *metric.Descriptor) error {
|
func (c *Aggregator) Update(_ context.Context, number metric.Number, desc *metric.Descriptor) error {
|
||||||
c.lock.Lock()
|
c.lock.Lock()
|
||||||
c.current = append(c.current, number)
|
c.current = append(c.current, number)
|
||||||
c.lock.Unlock()
|
c.lock.Unlock()
|
||||||
@ -126,12 +125,12 @@ func (c *Aggregator) Merge(oa export.Aggregator, desc *metric.Descriptor) error
|
|||||||
return nil
|
return nil
|
||||||
}
|
}
|
||||||
|
|
||||||
func (c *Aggregator) sort(kind core.NumberKind) {
|
func (c *Aggregator) sort(kind metric.NumberKind) {
|
||||||
switch kind {
|
switch kind {
|
||||||
case core.Float64NumberKind:
|
case metric.Float64NumberKind:
|
||||||
sort.Float64s(*(*[]float64)(unsafe.Pointer(&c.checkpoint)))
|
sort.Float64s(*(*[]float64)(unsafe.Pointer(&c.checkpoint)))
|
||||||
|
|
||||||
case core.Int64NumberKind:
|
case metric.Int64NumberKind:
|
||||||
sort.Sort(&c.checkpoint)
|
sort.Sort(&c.checkpoint)
|
||||||
|
|
||||||
default:
|
default:
|
||||||
@ -141,7 +140,7 @@ func (c *Aggregator) sort(kind core.NumberKind) {
|
|||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
func combine(a, b points, kind core.NumberKind) points {
|
func combine(a, b points, kind metric.NumberKind) points {
|
||||||
result := make(points, 0, len(a)+len(b))
|
result := make(points, 0, len(a)+len(b))
|
||||||
|
|
||||||
for len(a) != 0 && len(b) != 0 {
|
for len(a) != 0 && len(b) != 0 {
|
||||||
@ -176,13 +175,13 @@ func (p *points) Swap(i, j int) {
|
|||||||
// Quantile returns the least X such that Pr(x<X)>=q, where X is an
|
// Quantile returns the least X such that Pr(x<X)>=q, where X is an
|
||||||
// element of the data set. This uses the "Nearest-Rank" definition
|
// element of the data set. This uses the "Nearest-Rank" definition
|
||||||
// of a quantile.
|
// of a quantile.
|
||||||
func (p *points) Quantile(q float64) (core.Number, error) {
|
func (p *points) Quantile(q float64) (metric.Number, error) {
|
||||||
if len(*p) == 0 {
|
if len(*p) == 0 {
|
||||||
return core.Number(0), aggregator.ErrNoData
|
return metric.Number(0), aggregator.ErrNoData
|
||||||
}
|
}
|
||||||
|
|
||||||
if q < 0 || q > 1 {
|
if q < 0 || q > 1 {
|
||||||
return core.Number(0), aggregator.ErrInvalidQuantile
|
return metric.Number(0), aggregator.ErrInvalidQuantile
|
||||||
}
|
}
|
||||||
|
|
||||||
if q == 0 || len(*p) == 1 {
|
if q == 0 || len(*p) == 1 {
|
||||||
|
@ -24,7 +24,6 @@ import (
|
|||||||
|
|
||||||
"github.com/stretchr/testify/require"
|
"github.com/stretchr/testify/require"
|
||||||
|
|
||||||
"go.opentelemetry.io/otel/api/core"
|
|
||||||
"go.opentelemetry.io/otel/api/metric"
|
"go.opentelemetry.io/otel/api/metric"
|
||||||
ottest "go.opentelemetry.io/otel/internal/testing"
|
ottest "go.opentelemetry.io/otel/internal/testing"
|
||||||
"go.opentelemetry.io/otel/sdk/export/metric/aggregator"
|
"go.opentelemetry.io/otel/sdk/export/metric/aggregator"
|
||||||
@ -218,10 +217,10 @@ func TestArrayErrors(t *testing.T) {
|
|||||||
|
|
||||||
descriptor := test.NewAggregatorTest(metric.MeasureKind, profile.NumberKind)
|
descriptor := test.NewAggregatorTest(metric.MeasureKind, profile.NumberKind)
|
||||||
|
|
||||||
test.CheckedUpdate(t, agg, core.Number(0), descriptor)
|
test.CheckedUpdate(t, agg, metric.Number(0), descriptor)
|
||||||
|
|
||||||
if profile.NumberKind == core.Float64NumberKind {
|
if profile.NumberKind == metric.Float64NumberKind {
|
||||||
test.CheckedUpdate(t, agg, core.NewFloat64Number(math.NaN()), descriptor)
|
test.CheckedUpdate(t, agg, metric.NewFloat64Number(math.NaN()), descriptor)
|
||||||
}
|
}
|
||||||
agg.Checkpoint(ctx, descriptor)
|
agg.Checkpoint(ctx, descriptor)
|
||||||
|
|
||||||
@ -231,7 +230,7 @@ func TestArrayErrors(t *testing.T) {
|
|||||||
|
|
||||||
num, err := agg.Quantile(0)
|
num, err := agg.Quantile(0)
|
||||||
require.Nil(t, err)
|
require.Nil(t, err)
|
||||||
require.Equal(t, num, core.Number(0))
|
require.Equal(t, num, metric.Number(0))
|
||||||
|
|
||||||
_, err = agg.Quantile(-0.0001)
|
_, err = agg.Quantile(-0.0001)
|
||||||
require.Error(t, err)
|
require.Error(t, err)
|
||||||
@ -244,7 +243,7 @@ func TestArrayErrors(t *testing.T) {
|
|||||||
}
|
}
|
||||||
|
|
||||||
func TestArrayFloat64(t *testing.T) {
|
func TestArrayFloat64(t *testing.T) {
|
||||||
descriptor := test.NewAggregatorTest(metric.MeasureKind, core.Float64NumberKind)
|
descriptor := test.NewAggregatorTest(metric.MeasureKind, metric.Float64NumberKind)
|
||||||
|
|
||||||
fpsf := func(sign int) []float64 {
|
fpsf := func(sign int) []float64 {
|
||||||
// Check behavior of a bunch of odd floating
|
// Check behavior of a bunch of odd floating
|
||||||
@ -274,19 +273,19 @@ func TestArrayFloat64(t *testing.T) {
|
|||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
all := test.NewNumbers(core.Float64NumberKind)
|
all := test.NewNumbers(metric.Float64NumberKind)
|
||||||
|
|
||||||
ctx := context.Background()
|
ctx := context.Background()
|
||||||
agg := New()
|
agg := New()
|
||||||
|
|
||||||
for _, f := range fpsf(1) {
|
for _, f := range fpsf(1) {
|
||||||
all.Append(core.NewFloat64Number(f))
|
all.Append(metric.NewFloat64Number(f))
|
||||||
test.CheckedUpdate(t, agg, core.NewFloat64Number(f), descriptor)
|
test.CheckedUpdate(t, agg, metric.NewFloat64Number(f), descriptor)
|
||||||
}
|
}
|
||||||
|
|
||||||
for _, f := range fpsf(-1) {
|
for _, f := range fpsf(-1) {
|
||||||
all.Append(core.NewFloat64Number(f))
|
all.Append(metric.NewFloat64Number(f))
|
||||||
test.CheckedUpdate(t, agg, core.NewFloat64Number(f), descriptor)
|
test.CheckedUpdate(t, agg, metric.NewFloat64Number(f), descriptor)
|
||||||
}
|
}
|
||||||
|
|
||||||
agg.Checkpoint(ctx, descriptor)
|
agg.Checkpoint(ctx, descriptor)
|
||||||
|
@ -20,7 +20,6 @@ import (
|
|||||||
|
|
||||||
sdk "github.com/DataDog/sketches-go/ddsketch"
|
sdk "github.com/DataDog/sketches-go/ddsketch"
|
||||||
|
|
||||||
"go.opentelemetry.io/otel/api/core"
|
|
||||||
"go.opentelemetry.io/otel/api/metric"
|
"go.opentelemetry.io/otel/api/metric"
|
||||||
|
|
||||||
export "go.opentelemetry.io/otel/sdk/export/metric"
|
export "go.opentelemetry.io/otel/sdk/export/metric"
|
||||||
@ -34,7 +33,7 @@ type Config = sdk.Config
|
|||||||
type Aggregator struct {
|
type Aggregator struct {
|
||||||
lock sync.Mutex
|
lock sync.Mutex
|
||||||
cfg *Config
|
cfg *Config
|
||||||
kind core.NumberKind
|
kind metric.NumberKind
|
||||||
current *sdk.DDSketch
|
current *sdk.DDSketch
|
||||||
checkpoint *sdk.DDSketch
|
checkpoint *sdk.DDSketch
|
||||||
}
|
}
|
||||||
@ -63,7 +62,7 @@ func NewDefaultConfig() *Config {
|
|||||||
}
|
}
|
||||||
|
|
||||||
// Sum returns the sum of values in the checkpoint.
|
// Sum returns the sum of values in the checkpoint.
|
||||||
func (c *Aggregator) Sum() (core.Number, error) {
|
func (c *Aggregator) Sum() (metric.Number, error) {
|
||||||
return c.toNumber(c.checkpoint.Sum()), nil
|
return c.toNumber(c.checkpoint.Sum()), nil
|
||||||
}
|
}
|
||||||
|
|
||||||
@ -73,33 +72,33 @@ func (c *Aggregator) Count() (int64, error) {
|
|||||||
}
|
}
|
||||||
|
|
||||||
// Max returns the maximum value in the checkpoint.
|
// Max returns the maximum value in the checkpoint.
|
||||||
func (c *Aggregator) Max() (core.Number, error) {
|
func (c *Aggregator) Max() (metric.Number, error) {
|
||||||
return c.Quantile(1)
|
return c.Quantile(1)
|
||||||
}
|
}
|
||||||
|
|
||||||
// Min returns the minimum value in the checkpoint.
|
// Min returns the minimum value in the checkpoint.
|
||||||
func (c *Aggregator) Min() (core.Number, error) {
|
func (c *Aggregator) Min() (metric.Number, error) {
|
||||||
return c.Quantile(0)
|
return c.Quantile(0)
|
||||||
}
|
}
|
||||||
|
|
||||||
// Quantile returns the estimated quantile of data in the checkpoint.
|
// Quantile returns the estimated quantile of data in the checkpoint.
|
||||||
// It is an error if `q` is less than 0 or greated than 1.
|
// It is an error if `q` is less than 0 or greated than 1.
|
||||||
func (c *Aggregator) Quantile(q float64) (core.Number, error) {
|
func (c *Aggregator) Quantile(q float64) (metric.Number, error) {
|
||||||
if c.checkpoint.Count() == 0 {
|
if c.checkpoint.Count() == 0 {
|
||||||
return core.Number(0), aggregator.ErrNoData
|
return metric.Number(0), aggregator.ErrNoData
|
||||||
}
|
}
|
||||||
f := c.checkpoint.Quantile(q)
|
f := c.checkpoint.Quantile(q)
|
||||||
if math.IsNaN(f) {
|
if math.IsNaN(f) {
|
||||||
return core.Number(0), aggregator.ErrInvalidQuantile
|
return metric.Number(0), aggregator.ErrInvalidQuantile
|
||||||
}
|
}
|
||||||
return c.toNumber(f), nil
|
return c.toNumber(f), nil
|
||||||
}
|
}
|
||||||
|
|
||||||
func (c *Aggregator) toNumber(f float64) core.Number {
|
func (c *Aggregator) toNumber(f float64) metric.Number {
|
||||||
if c.kind == core.Float64NumberKind {
|
if c.kind == metric.Float64NumberKind {
|
||||||
return core.NewFloat64Number(f)
|
return metric.NewFloat64Number(f)
|
||||||
}
|
}
|
||||||
return core.NewInt64Number(int64(f))
|
return metric.NewInt64Number(int64(f))
|
||||||
}
|
}
|
||||||
|
|
||||||
// Checkpoint saves the current state and resets the current state to
|
// Checkpoint saves the current state and resets the current state to
|
||||||
@ -116,7 +115,7 @@ func (c *Aggregator) Checkpoint(ctx context.Context, _ *metric.Descriptor) {
|
|||||||
// Update adds the recorded measurement to the current data set.
|
// Update adds the recorded measurement to the current data set.
|
||||||
// Update takes a lock to prevent concurrent Update() and Checkpoint()
|
// Update takes a lock to prevent concurrent Update() and Checkpoint()
|
||||||
// calls.
|
// calls.
|
||||||
func (c *Aggregator) Update(_ context.Context, number core.Number, desc *metric.Descriptor) error {
|
func (c *Aggregator) Update(_ context.Context, number metric.Number, desc *metric.Descriptor) error {
|
||||||
c.lock.Lock()
|
c.lock.Lock()
|
||||||
defer c.lock.Unlock()
|
defer c.lock.Unlock()
|
||||||
c.current.Add(number.CoerceToFloat64(desc.NumberKind()))
|
c.current.Add(number.CoerceToFloat64(desc.NumberKind()))
|
||||||
|
@ -19,7 +19,6 @@ import (
|
|||||||
"sort"
|
"sort"
|
||||||
"sync"
|
"sync"
|
||||||
|
|
||||||
"go.opentelemetry.io/otel/api/core"
|
|
||||||
"go.opentelemetry.io/otel/api/metric"
|
"go.opentelemetry.io/otel/api/metric"
|
||||||
export "go.opentelemetry.io/otel/sdk/export/metric"
|
export "go.opentelemetry.io/otel/sdk/export/metric"
|
||||||
"go.opentelemetry.io/otel/sdk/export/metric/aggregator"
|
"go.opentelemetry.io/otel/sdk/export/metric/aggregator"
|
||||||
@ -32,8 +31,8 @@ type (
|
|||||||
lock sync.Mutex
|
lock sync.Mutex
|
||||||
current state
|
current state
|
||||||
checkpoint state
|
checkpoint state
|
||||||
boundaries []core.Number
|
boundaries []metric.Number
|
||||||
kind core.NumberKind
|
kind metric.NumberKind
|
||||||
}
|
}
|
||||||
|
|
||||||
// state represents the state of a histogram, consisting of
|
// state represents the state of a histogram, consisting of
|
||||||
@ -42,8 +41,8 @@ type (
|
|||||||
state struct {
|
state struct {
|
||||||
// all fields have to be aligned for 64-bit atomic operations.
|
// all fields have to be aligned for 64-bit atomic operations.
|
||||||
buckets aggregator.Buckets
|
buckets aggregator.Buckets
|
||||||
count core.Number
|
count metric.Number
|
||||||
sum core.Number
|
sum metric.Number
|
||||||
}
|
}
|
||||||
)
|
)
|
||||||
|
|
||||||
@ -60,11 +59,11 @@ var _ aggregator.Histogram = &Aggregator{}
|
|||||||
// Note that this aggregator maintains each value using independent
|
// Note that this aggregator maintains each value using independent
|
||||||
// atomic operations, which introduces the possibility that
|
// atomic operations, which introduces the possibility that
|
||||||
// checkpoints are inconsistent.
|
// checkpoints are inconsistent.
|
||||||
func New(desc *metric.Descriptor, boundaries []core.Number) *Aggregator {
|
func New(desc *metric.Descriptor, boundaries []metric.Number) *Aggregator {
|
||||||
// Boundaries MUST be ordered otherwise the histogram could not
|
// Boundaries MUST be ordered otherwise the histogram could not
|
||||||
// be properly computed.
|
// be properly computed.
|
||||||
sortedBoundaries := numbers{
|
sortedBoundaries := numbers{
|
||||||
numbers: make([]core.Number, len(boundaries)),
|
numbers: make([]metric.Number, len(boundaries)),
|
||||||
kind: desc.NumberKind(),
|
kind: desc.NumberKind(),
|
||||||
}
|
}
|
||||||
|
|
||||||
@ -78,7 +77,7 @@ func New(desc *metric.Descriptor, boundaries []core.Number) *Aggregator {
|
|||||||
current: state{
|
current: state{
|
||||||
buckets: aggregator.Buckets{
|
buckets: aggregator.Buckets{
|
||||||
Boundaries: boundaries,
|
Boundaries: boundaries,
|
||||||
Counts: make([]core.Number, len(boundaries)+1),
|
Counts: make([]metric.Number, len(boundaries)+1),
|
||||||
},
|
},
|
||||||
},
|
},
|
||||||
}
|
}
|
||||||
@ -86,7 +85,7 @@ func New(desc *metric.Descriptor, boundaries []core.Number) *Aggregator {
|
|||||||
}
|
}
|
||||||
|
|
||||||
// Sum returns the sum of all values in the checkpoint.
|
// Sum returns the sum of all values in the checkpoint.
|
||||||
func (c *Aggregator) Sum() (core.Number, error) {
|
func (c *Aggregator) Sum() (metric.Number, error) {
|
||||||
c.lock.Lock()
|
c.lock.Lock()
|
||||||
defer c.lock.Unlock()
|
defer c.lock.Unlock()
|
||||||
return c.checkpoint.sum, nil
|
return c.checkpoint.sum, nil
|
||||||
@ -120,13 +119,13 @@ func (c *Aggregator) emptyState() state {
|
|||||||
return state{
|
return state{
|
||||||
buckets: aggregator.Buckets{
|
buckets: aggregator.Buckets{
|
||||||
Boundaries: c.boundaries,
|
Boundaries: c.boundaries,
|
||||||
Counts: make([]core.Number, len(c.boundaries)+1),
|
Counts: make([]metric.Number, len(c.boundaries)+1),
|
||||||
},
|
},
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
// Update adds the recorded measurement to the current data set.
|
// Update adds the recorded measurement to the current data set.
|
||||||
func (c *Aggregator) Update(_ context.Context, number core.Number, desc *metric.Descriptor) error {
|
func (c *Aggregator) Update(_ context.Context, number metric.Number, desc *metric.Descriptor) error {
|
||||||
kind := desc.NumberKind()
|
kind := desc.NumberKind()
|
||||||
|
|
||||||
bucketID := len(c.boundaries)
|
bucketID := len(c.boundaries)
|
||||||
@ -155,18 +154,18 @@ func (c *Aggregator) Merge(oa export.Aggregator, desc *metric.Descriptor) error
|
|||||||
}
|
}
|
||||||
|
|
||||||
c.checkpoint.sum.AddNumber(desc.NumberKind(), o.checkpoint.sum)
|
c.checkpoint.sum.AddNumber(desc.NumberKind(), o.checkpoint.sum)
|
||||||
c.checkpoint.count.AddNumber(core.Uint64NumberKind, o.checkpoint.count)
|
c.checkpoint.count.AddNumber(metric.Uint64NumberKind, o.checkpoint.count)
|
||||||
|
|
||||||
for i := 0; i < len(c.checkpoint.buckets.Counts); i++ {
|
for i := 0; i < len(c.checkpoint.buckets.Counts); i++ {
|
||||||
c.checkpoint.buckets.Counts[i].AddNumber(core.Uint64NumberKind, o.checkpoint.buckets.Counts[i])
|
c.checkpoint.buckets.Counts[i].AddNumber(metric.Uint64NumberKind, o.checkpoint.buckets.Counts[i])
|
||||||
}
|
}
|
||||||
return nil
|
return nil
|
||||||
}
|
}
|
||||||
|
|
||||||
// numbers is an auxiliary struct to order histogram bucket boundaries (slice of core.Number)
|
// numbers is an auxiliary struct to order histogram bucket boundaries (slice of core.Number)
|
||||||
type numbers struct {
|
type numbers struct {
|
||||||
numbers []core.Number
|
numbers []metric.Number
|
||||||
kind core.NumberKind
|
kind metric.NumberKind
|
||||||
}
|
}
|
||||||
|
|
||||||
var _ sort.Interface = (*numbers)(nil)
|
var _ sort.Interface = (*numbers)(nil)
|
||||||
|
@ -23,7 +23,6 @@ import (
|
|||||||
|
|
||||||
"github.com/stretchr/testify/require"
|
"github.com/stretchr/testify/require"
|
||||||
|
|
||||||
"go.opentelemetry.io/otel/api/core"
|
|
||||||
"go.opentelemetry.io/otel/api/metric"
|
"go.opentelemetry.io/otel/api/metric"
|
||||||
"go.opentelemetry.io/otel/sdk/metric/aggregator/test"
|
"go.opentelemetry.io/otel/sdk/metric/aggregator/test"
|
||||||
)
|
)
|
||||||
@ -58,9 +57,9 @@ var (
|
|||||||
},
|
},
|
||||||
}
|
}
|
||||||
|
|
||||||
boundaries = map[core.NumberKind][]core.Number{
|
boundaries = map[metric.NumberKind][]metric.Number{
|
||||||
core.Float64NumberKind: {core.NewFloat64Number(500), core.NewFloat64Number(250), core.NewFloat64Number(750)},
|
metric.Float64NumberKind: {metric.NewFloat64Number(500), metric.NewFloat64Number(250), metric.NewFloat64Number(750)},
|
||||||
core.Int64NumberKind: {core.NewInt64Number(500), core.NewInt64Number(250), core.NewInt64Number(750)},
|
metric.Int64NumberKind: {metric.NewInt64Number(500), metric.NewInt64Number(250), metric.NewInt64Number(750)},
|
||||||
}
|
}
|
||||||
)
|
)
|
||||||
|
|
||||||
@ -185,7 +184,7 @@ func TestHistogramNotSet(t *testing.T) {
|
|||||||
agg.Checkpoint(ctx, descriptor)
|
agg.Checkpoint(ctx, descriptor)
|
||||||
|
|
||||||
asum, err := agg.Sum()
|
asum, err := agg.Sum()
|
||||||
require.Equal(t, core.Number(0), asum, "Empty checkpoint sum = 0")
|
require.Equal(t, metric.Number(0), asum, "Empty checkpoint sum = 0")
|
||||||
require.Nil(t, err)
|
require.Nil(t, err)
|
||||||
|
|
||||||
count, err := agg.Count()
|
count, err := agg.Count()
|
||||||
@ -199,9 +198,9 @@ func TestHistogramNotSet(t *testing.T) {
|
|||||||
})
|
})
|
||||||
}
|
}
|
||||||
|
|
||||||
func calcBuckets(points []core.Number, profile test.Profile) []uint64 {
|
func calcBuckets(points []metric.Number, profile test.Profile) []uint64 {
|
||||||
sortedBoundaries := numbers{
|
sortedBoundaries := numbers{
|
||||||
numbers: make([]core.Number, len(boundaries[profile.NumberKind])),
|
numbers: make([]metric.Number, len(boundaries[profile.NumberKind])),
|
||||||
kind: profile.NumberKind,
|
kind: profile.NumberKind,
|
||||||
}
|
}
|
||||||
|
|
||||||
|
@ -20,7 +20,6 @@ import (
|
|||||||
"time"
|
"time"
|
||||||
"unsafe"
|
"unsafe"
|
||||||
|
|
||||||
"go.opentelemetry.io/otel/api/core"
|
|
||||||
"go.opentelemetry.io/otel/api/metric"
|
"go.opentelemetry.io/otel/api/metric"
|
||||||
export "go.opentelemetry.io/otel/sdk/export/metric"
|
export "go.opentelemetry.io/otel/sdk/export/metric"
|
||||||
"go.opentelemetry.io/otel/sdk/export/metric/aggregator"
|
"go.opentelemetry.io/otel/sdk/export/metric/aggregator"
|
||||||
@ -43,7 +42,7 @@ type (
|
|||||||
// value is the int64- or float64-encoded Set() data
|
// value is the int64- or float64-encoded Set() data
|
||||||
//
|
//
|
||||||
// value needs to be aligned for 64-bit atomic operations.
|
// value needs to be aligned for 64-bit atomic operations.
|
||||||
value core.Number
|
value metric.Number
|
||||||
|
|
||||||
// timestamp indicates when this record was submitted.
|
// timestamp indicates when this record was submitted.
|
||||||
// this can be used to pick a winner when multiple
|
// this can be used to pick a winner when multiple
|
||||||
@ -72,10 +71,10 @@ func New() *Aggregator {
|
|||||||
// corresponding timestamp. The error value aggregator.ErrNoData
|
// corresponding timestamp. The error value aggregator.ErrNoData
|
||||||
// will be returned if (due to a race condition) the checkpoint was
|
// will be returned if (due to a race condition) the checkpoint was
|
||||||
// computed before the first value was set.
|
// computed before the first value was set.
|
||||||
func (g *Aggregator) LastValue() (core.Number, time.Time, error) {
|
func (g *Aggregator) LastValue() (metric.Number, time.Time, error) {
|
||||||
gd := (*lastValueData)(g.checkpoint)
|
gd := (*lastValueData)(g.checkpoint)
|
||||||
if gd == unsetLastValue {
|
if gd == unsetLastValue {
|
||||||
return core.Number(0), time.Time{}, aggregator.ErrNoData
|
return metric.Number(0), time.Time{}, aggregator.ErrNoData
|
||||||
}
|
}
|
||||||
return gd.value.AsNumber(), gd.timestamp, nil
|
return gd.value.AsNumber(), gd.timestamp, nil
|
||||||
}
|
}
|
||||||
@ -86,7 +85,7 @@ func (g *Aggregator) Checkpoint(ctx context.Context, _ *metric.Descriptor) {
|
|||||||
}
|
}
|
||||||
|
|
||||||
// Update atomically sets the current "last" value.
|
// Update atomically sets the current "last" value.
|
||||||
func (g *Aggregator) Update(_ context.Context, number core.Number, desc *metric.Descriptor) error {
|
func (g *Aggregator) Update(_ context.Context, number metric.Number, desc *metric.Descriptor) error {
|
||||||
ngd := &lastValueData{
|
ngd := &lastValueData{
|
||||||
value: number,
|
value: number,
|
||||||
timestamp: time.Now(),
|
timestamp: time.Now(),
|
||||||
|
@ -23,7 +23,6 @@ import (
|
|||||||
|
|
||||||
"github.com/stretchr/testify/require"
|
"github.com/stretchr/testify/require"
|
||||||
|
|
||||||
"go.opentelemetry.io/otel/api/core"
|
|
||||||
"go.opentelemetry.io/otel/api/metric"
|
"go.opentelemetry.io/otel/api/metric"
|
||||||
ottest "go.opentelemetry.io/otel/internal/testing"
|
ottest "go.opentelemetry.io/otel/internal/testing"
|
||||||
export "go.opentelemetry.io/otel/sdk/export/metric"
|
export "go.opentelemetry.io/otel/sdk/export/metric"
|
||||||
@ -58,7 +57,7 @@ func TestLastValueUpdate(t *testing.T) {
|
|||||||
|
|
||||||
record := test.NewAggregatorTest(metric.ObserverKind, profile.NumberKind)
|
record := test.NewAggregatorTest(metric.ObserverKind, profile.NumberKind)
|
||||||
|
|
||||||
var last core.Number
|
var last metric.Number
|
||||||
for i := 0; i < count; i++ {
|
for i := 0; i < count; i++ {
|
||||||
x := profile.Random(rand.Intn(1)*2 - 1)
|
x := profile.Random(rand.Intn(1)*2 - 1)
|
||||||
last = x
|
last = x
|
||||||
@ -108,7 +107,7 @@ func TestLastValueMerge(t *testing.T) {
|
|||||||
}
|
}
|
||||||
|
|
||||||
func TestLastValueNotSet(t *testing.T) {
|
func TestLastValueNotSet(t *testing.T) {
|
||||||
descriptor := test.NewAggregatorTest(metric.ObserverKind, core.Int64NumberKind)
|
descriptor := test.NewAggregatorTest(metric.ObserverKind, metric.Int64NumberKind)
|
||||||
|
|
||||||
g := New()
|
g := New()
|
||||||
g.Checkpoint(context.Background(), descriptor)
|
g.Checkpoint(context.Background(), descriptor)
|
||||||
@ -116,5 +115,5 @@ func TestLastValueNotSet(t *testing.T) {
|
|||||||
value, timestamp, err := g.LastValue()
|
value, timestamp, err := g.LastValue()
|
||||||
require.Equal(t, aggregator.ErrNoData, err)
|
require.Equal(t, aggregator.ErrNoData, err)
|
||||||
require.True(t, timestamp.IsZero())
|
require.True(t, timestamp.IsZero())
|
||||||
require.Equal(t, core.Number(0), value)
|
require.Equal(t, metric.Number(0), value)
|
||||||
}
|
}
|
||||||
|
@ -18,7 +18,6 @@ import (
|
|||||||
"context"
|
"context"
|
||||||
"sync"
|
"sync"
|
||||||
|
|
||||||
"go.opentelemetry.io/otel/api/core"
|
|
||||||
"go.opentelemetry.io/otel/api/metric"
|
"go.opentelemetry.io/otel/api/metric"
|
||||||
export "go.opentelemetry.io/otel/sdk/export/metric"
|
export "go.opentelemetry.io/otel/sdk/export/metric"
|
||||||
"go.opentelemetry.io/otel/sdk/export/metric/aggregator"
|
"go.opentelemetry.io/otel/sdk/export/metric/aggregator"
|
||||||
@ -31,14 +30,14 @@ type (
|
|||||||
lock sync.Mutex
|
lock sync.Mutex
|
||||||
current state
|
current state
|
||||||
checkpoint state
|
checkpoint state
|
||||||
kind core.NumberKind
|
kind metric.NumberKind
|
||||||
}
|
}
|
||||||
|
|
||||||
state struct {
|
state struct {
|
||||||
count core.Number
|
count metric.Number
|
||||||
sum core.Number
|
sum metric.Number
|
||||||
min core.Number
|
min metric.Number
|
||||||
max core.Number
|
max metric.Number
|
||||||
}
|
}
|
||||||
)
|
)
|
||||||
|
|
||||||
@ -54,7 +53,7 @@ func New(desc *metric.Descriptor) *Aggregator {
|
|||||||
return &Aggregator{
|
return &Aggregator{
|
||||||
kind: kind,
|
kind: kind,
|
||||||
current: state{
|
current: state{
|
||||||
count: core.NewUint64Number(0),
|
count: metric.NewUint64Number(0),
|
||||||
sum: kind.Zero(),
|
sum: kind.Zero(),
|
||||||
min: kind.Maximum(),
|
min: kind.Maximum(),
|
||||||
max: kind.Minimum(),
|
max: kind.Minimum(),
|
||||||
@ -63,7 +62,7 @@ func New(desc *metric.Descriptor) *Aggregator {
|
|||||||
}
|
}
|
||||||
|
|
||||||
// Sum returns the sum of values in the checkpoint.
|
// Sum returns the sum of values in the checkpoint.
|
||||||
func (c *Aggregator) Sum() (core.Number, error) {
|
func (c *Aggregator) Sum() (metric.Number, error) {
|
||||||
c.lock.Lock()
|
c.lock.Lock()
|
||||||
defer c.lock.Unlock()
|
defer c.lock.Unlock()
|
||||||
return c.checkpoint.sum, nil
|
return c.checkpoint.sum, nil
|
||||||
@ -73,16 +72,16 @@ func (c *Aggregator) Sum() (core.Number, error) {
|
|||||||
func (c *Aggregator) Count() (int64, error) {
|
func (c *Aggregator) Count() (int64, error) {
|
||||||
c.lock.Lock()
|
c.lock.Lock()
|
||||||
defer c.lock.Unlock()
|
defer c.lock.Unlock()
|
||||||
return c.checkpoint.count.CoerceToInt64(core.Uint64NumberKind), nil
|
return c.checkpoint.count.CoerceToInt64(metric.Uint64NumberKind), nil
|
||||||
}
|
}
|
||||||
|
|
||||||
// Min returns the minimum value in the checkpoint.
|
// Min returns the minimum value in the checkpoint.
|
||||||
// The error value aggregator.ErrNoData will be returned
|
// The error value aggregator.ErrNoData will be returned
|
||||||
// if there were no measurements recorded during the checkpoint.
|
// if there were no measurements recorded during the checkpoint.
|
||||||
func (c *Aggregator) Min() (core.Number, error) {
|
func (c *Aggregator) Min() (metric.Number, error) {
|
||||||
c.lock.Lock()
|
c.lock.Lock()
|
||||||
defer c.lock.Unlock()
|
defer c.lock.Unlock()
|
||||||
if c.checkpoint.count.IsZero(core.Uint64NumberKind) {
|
if c.checkpoint.count.IsZero(metric.Uint64NumberKind) {
|
||||||
return c.kind.Zero(), aggregator.ErrNoData
|
return c.kind.Zero(), aggregator.ErrNoData
|
||||||
}
|
}
|
||||||
return c.checkpoint.min, nil
|
return c.checkpoint.min, nil
|
||||||
@ -91,10 +90,10 @@ func (c *Aggregator) Min() (core.Number, error) {
|
|||||||
// Max returns the maximum value in the checkpoint.
|
// Max returns the maximum value in the checkpoint.
|
||||||
// The error value aggregator.ErrNoData will be returned
|
// The error value aggregator.ErrNoData will be returned
|
||||||
// if there were no measurements recorded during the checkpoint.
|
// if there were no measurements recorded during the checkpoint.
|
||||||
func (c *Aggregator) Max() (core.Number, error) {
|
func (c *Aggregator) Max() (metric.Number, error) {
|
||||||
c.lock.Lock()
|
c.lock.Lock()
|
||||||
defer c.lock.Unlock()
|
defer c.lock.Unlock()
|
||||||
if c.checkpoint.count.IsZero(core.Uint64NumberKind) {
|
if c.checkpoint.count.IsZero(metric.Uint64NumberKind) {
|
||||||
return c.kind.Zero(), aggregator.ErrNoData
|
return c.kind.Zero(), aggregator.ErrNoData
|
||||||
}
|
}
|
||||||
return c.checkpoint.max, nil
|
return c.checkpoint.max, nil
|
||||||
@ -111,7 +110,7 @@ func (c *Aggregator) Checkpoint(ctx context.Context, desc *metric.Descriptor) {
|
|||||||
func (c *Aggregator) emptyState() state {
|
func (c *Aggregator) emptyState() state {
|
||||||
kind := c.kind
|
kind := c.kind
|
||||||
return state{
|
return state{
|
||||||
count: core.NewUint64Number(0),
|
count: metric.NewUint64Number(0),
|
||||||
sum: kind.Zero(),
|
sum: kind.Zero(),
|
||||||
min: kind.Maximum(),
|
min: kind.Maximum(),
|
||||||
max: kind.Minimum(),
|
max: kind.Minimum(),
|
||||||
@ -119,7 +118,7 @@ func (c *Aggregator) emptyState() state {
|
|||||||
}
|
}
|
||||||
|
|
||||||
// Update adds the recorded measurement to the current data set.
|
// Update adds the recorded measurement to the current data set.
|
||||||
func (c *Aggregator) Update(_ context.Context, number core.Number, desc *metric.Descriptor) error {
|
func (c *Aggregator) Update(_ context.Context, number metric.Number, desc *metric.Descriptor) error {
|
||||||
kind := desc.NumberKind()
|
kind := desc.NumberKind()
|
||||||
|
|
||||||
c.lock.Lock()
|
c.lock.Lock()
|
||||||
@ -142,7 +141,7 @@ func (c *Aggregator) Merge(oa export.Aggregator, desc *metric.Descriptor) error
|
|||||||
return aggregator.NewInconsistentMergeError(c, oa)
|
return aggregator.NewInconsistentMergeError(c, oa)
|
||||||
}
|
}
|
||||||
|
|
||||||
c.checkpoint.count.AddNumber(core.Uint64NumberKind, o.checkpoint.count)
|
c.checkpoint.count.AddNumber(metric.Uint64NumberKind, o.checkpoint.count)
|
||||||
c.checkpoint.sum.AddNumber(desc.NumberKind(), o.checkpoint.sum)
|
c.checkpoint.sum.AddNumber(desc.NumberKind(), o.checkpoint.sum)
|
||||||
|
|
||||||
if c.checkpoint.min.CompareNumber(desc.NumberKind(), o.checkpoint.min) > 0 {
|
if c.checkpoint.min.CompareNumber(desc.NumberKind(), o.checkpoint.min) > 0 {
|
||||||
|
@ -22,7 +22,6 @@ import (
|
|||||||
|
|
||||||
"github.com/stretchr/testify/require"
|
"github.com/stretchr/testify/require"
|
||||||
|
|
||||||
"go.opentelemetry.io/otel/api/core"
|
|
||||||
"go.opentelemetry.io/otel/api/metric"
|
"go.opentelemetry.io/otel/api/metric"
|
||||||
"go.opentelemetry.io/otel/sdk/export/metric/aggregator"
|
"go.opentelemetry.io/otel/sdk/export/metric/aggregator"
|
||||||
"go.opentelemetry.io/otel/sdk/metric/aggregator/test"
|
"go.opentelemetry.io/otel/sdk/metric/aggregator/test"
|
||||||
@ -192,7 +191,7 @@ func TestMaxSumCountNotSet(t *testing.T) {
|
|||||||
agg.Checkpoint(ctx, descriptor)
|
agg.Checkpoint(ctx, descriptor)
|
||||||
|
|
||||||
asum, err := agg.Sum()
|
asum, err := agg.Sum()
|
||||||
require.Equal(t, core.Number(0), asum, "Empty checkpoint sum = 0")
|
require.Equal(t, metric.Number(0), asum, "Empty checkpoint sum = 0")
|
||||||
require.Nil(t, err)
|
require.Nil(t, err)
|
||||||
|
|
||||||
count, err := agg.Count()
|
count, err := agg.Count()
|
||||||
@ -201,6 +200,6 @@ func TestMaxSumCountNotSet(t *testing.T) {
|
|||||||
|
|
||||||
max, err := agg.Max()
|
max, err := agg.Max()
|
||||||
require.Equal(t, aggregator.ErrNoData, err)
|
require.Equal(t, aggregator.ErrNoData, err)
|
||||||
require.Equal(t, core.Number(0), max)
|
require.Equal(t, metric.Number(0), max)
|
||||||
})
|
})
|
||||||
}
|
}
|
||||||
|
@ -17,7 +17,6 @@ package sum // import "go.opentelemetry.io/otel/sdk/metric/aggregator/sum"
|
|||||||
import (
|
import (
|
||||||
"context"
|
"context"
|
||||||
|
|
||||||
"go.opentelemetry.io/otel/api/core"
|
|
||||||
"go.opentelemetry.io/otel/api/metric"
|
"go.opentelemetry.io/otel/api/metric"
|
||||||
export "go.opentelemetry.io/otel/sdk/export/metric"
|
export "go.opentelemetry.io/otel/sdk/export/metric"
|
||||||
"go.opentelemetry.io/otel/sdk/export/metric/aggregator"
|
"go.opentelemetry.io/otel/sdk/export/metric/aggregator"
|
||||||
@ -27,11 +26,11 @@ import (
|
|||||||
type Aggregator struct {
|
type Aggregator struct {
|
||||||
// current holds current increments to this counter record
|
// current holds current increments to this counter record
|
||||||
// current needs to be aligned for 64-bit atomic operations.
|
// current needs to be aligned for 64-bit atomic operations.
|
||||||
current core.Number
|
current metric.Number
|
||||||
|
|
||||||
// checkpoint is a temporary used during Checkpoint()
|
// checkpoint is a temporary used during Checkpoint()
|
||||||
// checkpoint needs to be aligned for 64-bit atomic operations.
|
// checkpoint needs to be aligned for 64-bit atomic operations.
|
||||||
checkpoint core.Number
|
checkpoint metric.Number
|
||||||
}
|
}
|
||||||
|
|
||||||
var _ export.Aggregator = &Aggregator{}
|
var _ export.Aggregator = &Aggregator{}
|
||||||
@ -46,18 +45,18 @@ func New() *Aggregator {
|
|||||||
|
|
||||||
// Sum returns the last-checkpointed sum. This will never return an
|
// Sum returns the last-checkpointed sum. This will never return an
|
||||||
// error.
|
// error.
|
||||||
func (c *Aggregator) Sum() (core.Number, error) {
|
func (c *Aggregator) Sum() (metric.Number, error) {
|
||||||
return c.checkpoint, nil
|
return c.checkpoint, nil
|
||||||
}
|
}
|
||||||
|
|
||||||
// Checkpoint atomically saves the current value and resets the
|
// Checkpoint atomically saves the current value and resets the
|
||||||
// current sum to zero.
|
// current sum to zero.
|
||||||
func (c *Aggregator) Checkpoint(ctx context.Context, _ *metric.Descriptor) {
|
func (c *Aggregator) Checkpoint(ctx context.Context, _ *metric.Descriptor) {
|
||||||
c.checkpoint = c.current.SwapNumberAtomic(core.Number(0))
|
c.checkpoint = c.current.SwapNumberAtomic(metric.Number(0))
|
||||||
}
|
}
|
||||||
|
|
||||||
// Update atomically adds to the current value.
|
// Update atomically adds to the current value.
|
||||||
func (c *Aggregator) Update(_ context.Context, number core.Number, desc *metric.Descriptor) error {
|
func (c *Aggregator) Update(_ context.Context, number metric.Number, desc *metric.Descriptor) error {
|
||||||
c.current.AddNumberAtomic(desc.NumberKind(), number)
|
c.current.AddNumberAtomic(desc.NumberKind(), number)
|
||||||
return nil
|
return nil
|
||||||
}
|
}
|
||||||
|
@ -22,7 +22,6 @@ import (
|
|||||||
|
|
||||||
"github.com/stretchr/testify/require"
|
"github.com/stretchr/testify/require"
|
||||||
|
|
||||||
"go.opentelemetry.io/otel/api/core"
|
|
||||||
"go.opentelemetry.io/otel/api/metric"
|
"go.opentelemetry.io/otel/api/metric"
|
||||||
ottest "go.opentelemetry.io/otel/internal/testing"
|
ottest "go.opentelemetry.io/otel/internal/testing"
|
||||||
"go.opentelemetry.io/otel/sdk/metric/aggregator/test"
|
"go.opentelemetry.io/otel/sdk/metric/aggregator/test"
|
||||||
@ -57,7 +56,7 @@ func TestCounterSum(t *testing.T) {
|
|||||||
|
|
||||||
descriptor := test.NewAggregatorTest(metric.CounterKind, profile.NumberKind)
|
descriptor := test.NewAggregatorTest(metric.CounterKind, profile.NumberKind)
|
||||||
|
|
||||||
sum := core.Number(0)
|
sum := metric.Number(0)
|
||||||
for i := 0; i < count; i++ {
|
for i := 0; i < count; i++ {
|
||||||
x := profile.Random(+1)
|
x := profile.Random(+1)
|
||||||
sum.AddNumber(profile.NumberKind, x)
|
sum.AddNumber(profile.NumberKind, x)
|
||||||
@ -80,7 +79,7 @@ func TestMeasureSum(t *testing.T) {
|
|||||||
|
|
||||||
descriptor := test.NewAggregatorTest(metric.MeasureKind, profile.NumberKind)
|
descriptor := test.NewAggregatorTest(metric.MeasureKind, profile.NumberKind)
|
||||||
|
|
||||||
sum := core.Number(0)
|
sum := metric.Number(0)
|
||||||
|
|
||||||
for i := 0; i < count; i++ {
|
for i := 0; i < count; i++ {
|
||||||
r1 := profile.Random(+1)
|
r1 := profile.Random(+1)
|
||||||
@ -108,7 +107,7 @@ func TestCounterMerge(t *testing.T) {
|
|||||||
|
|
||||||
descriptor := test.NewAggregatorTest(metric.CounterKind, profile.NumberKind)
|
descriptor := test.NewAggregatorTest(metric.CounterKind, profile.NumberKind)
|
||||||
|
|
||||||
sum := core.Number(0)
|
sum := metric.Number(0)
|
||||||
for i := 0; i < count; i++ {
|
for i := 0; i < count; i++ {
|
||||||
x := profile.Random(+1)
|
x := profile.Random(+1)
|
||||||
sum.AddNumber(profile.NumberKind, x)
|
sum.AddNumber(profile.NumberKind, x)
|
||||||
|
@ -22,7 +22,6 @@ import (
|
|||||||
"testing"
|
"testing"
|
||||||
"unsafe"
|
"unsafe"
|
||||||
|
|
||||||
"go.opentelemetry.io/otel/api/core"
|
|
||||||
"go.opentelemetry.io/otel/api/metric"
|
"go.opentelemetry.io/otel/api/metric"
|
||||||
ottest "go.opentelemetry.io/otel/internal/testing"
|
ottest "go.opentelemetry.io/otel/internal/testing"
|
||||||
export "go.opentelemetry.io/otel/sdk/export/metric"
|
export "go.opentelemetry.io/otel/sdk/export/metric"
|
||||||
@ -32,29 +31,29 @@ import (
|
|||||||
const Magnitude = 1000
|
const Magnitude = 1000
|
||||||
|
|
||||||
type Profile struct {
|
type Profile struct {
|
||||||
NumberKind core.NumberKind
|
NumberKind metric.NumberKind
|
||||||
Random func(sign int) core.Number
|
Random func(sign int) metric.Number
|
||||||
}
|
}
|
||||||
|
|
||||||
func newProfiles() []Profile {
|
func newProfiles() []Profile {
|
||||||
rnd := rand.New(rand.NewSource(rand.Int63()))
|
rnd := rand.New(rand.NewSource(rand.Int63()))
|
||||||
return []Profile{
|
return []Profile{
|
||||||
{
|
{
|
||||||
NumberKind: core.Int64NumberKind,
|
NumberKind: metric.Int64NumberKind,
|
||||||
Random: func(sign int) core.Number {
|
Random: func(sign int) metric.Number {
|
||||||
return core.NewInt64Number(int64(sign) * int64(rnd.Intn(Magnitude+1)))
|
return metric.NewInt64Number(int64(sign) * int64(rnd.Intn(Magnitude+1)))
|
||||||
},
|
},
|
||||||
},
|
},
|
||||||
{
|
{
|
||||||
NumberKind: core.Float64NumberKind,
|
NumberKind: metric.Float64NumberKind,
|
||||||
Random: func(sign int) core.Number {
|
Random: func(sign int) metric.Number {
|
||||||
return core.NewFloat64Number(float64(sign) * rnd.Float64() * Magnitude)
|
return metric.NewFloat64Number(float64(sign) * rnd.Float64() * Magnitude)
|
||||||
},
|
},
|
||||||
},
|
},
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
func NewAggregatorTest(mkind metric.Kind, nkind core.NumberKind) *metric.Descriptor {
|
func NewAggregatorTest(mkind metric.Kind, nkind metric.NumberKind) *metric.Descriptor {
|
||||||
desc := metric.NewDescriptor("test.name", mkind, nkind)
|
desc := metric.NewDescriptor("test.name", mkind, nkind)
|
||||||
return &desc
|
return &desc
|
||||||
}
|
}
|
||||||
@ -84,17 +83,17 @@ func TestMain(m *testing.M) {
|
|||||||
|
|
||||||
type Numbers struct {
|
type Numbers struct {
|
||||||
// numbers has to be aligned for 64-bit atomic operations.
|
// numbers has to be aligned for 64-bit atomic operations.
|
||||||
numbers []core.Number
|
numbers []metric.Number
|
||||||
kind core.NumberKind
|
kind metric.NumberKind
|
||||||
}
|
}
|
||||||
|
|
||||||
func NewNumbers(kind core.NumberKind) Numbers {
|
func NewNumbers(kind metric.NumberKind) Numbers {
|
||||||
return Numbers{
|
return Numbers{
|
||||||
kind: kind,
|
kind: kind,
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
func (n *Numbers) Append(v core.Number) {
|
func (n *Numbers) Append(v metric.Number) {
|
||||||
n.numbers = append(n.numbers, v)
|
n.numbers = append(n.numbers, v)
|
||||||
}
|
}
|
||||||
|
|
||||||
@ -114,8 +113,8 @@ func (n *Numbers) Swap(i, j int) {
|
|||||||
n.numbers[i], n.numbers[j] = n.numbers[j], n.numbers[i]
|
n.numbers[i], n.numbers[j] = n.numbers[j], n.numbers[i]
|
||||||
}
|
}
|
||||||
|
|
||||||
func (n *Numbers) Sum() core.Number {
|
func (n *Numbers) Sum() metric.Number {
|
||||||
var sum core.Number
|
var sum metric.Number
|
||||||
for _, num := range n.numbers {
|
for _, num := range n.numbers {
|
||||||
sum.AddNumber(n.kind, num)
|
sum.AddNumber(n.kind, num)
|
||||||
}
|
}
|
||||||
@ -126,16 +125,16 @@ func (n *Numbers) Count() int64 {
|
|||||||
return int64(len(n.numbers))
|
return int64(len(n.numbers))
|
||||||
}
|
}
|
||||||
|
|
||||||
func (n *Numbers) Min() core.Number {
|
func (n *Numbers) Min() metric.Number {
|
||||||
return n.numbers[0]
|
return n.numbers[0]
|
||||||
}
|
}
|
||||||
|
|
||||||
func (n *Numbers) Max() core.Number {
|
func (n *Numbers) Max() metric.Number {
|
||||||
return n.numbers[len(n.numbers)-1]
|
return n.numbers[len(n.numbers)-1]
|
||||||
}
|
}
|
||||||
|
|
||||||
// Median() is an alias for Quantile(0.5).
|
// Median() is an alias for Quantile(0.5).
|
||||||
func (n *Numbers) Median() core.Number {
|
func (n *Numbers) Median() metric.Number {
|
||||||
// Note that len(n.numbers) is 1 greater than the max element
|
// Note that len(n.numbers) is 1 greater than the max element
|
||||||
// index, so dividing by two rounds up. This gives the
|
// index, so dividing by two rounds up. This gives the
|
||||||
// intended definition for Quantile() in tests, which is to
|
// intended definition for Quantile() in tests, which is to
|
||||||
@ -144,12 +143,12 @@ func (n *Numbers) Median() core.Number {
|
|||||||
return n.numbers[len(n.numbers)/2]
|
return n.numbers[len(n.numbers)/2]
|
||||||
}
|
}
|
||||||
|
|
||||||
func (n *Numbers) Points() []core.Number {
|
func (n *Numbers) Points() []metric.Number {
|
||||||
return n.numbers
|
return n.numbers
|
||||||
}
|
}
|
||||||
|
|
||||||
// Performs the same range test the SDK does on behalf of the aggregator.
|
// Performs the same range test the SDK does on behalf of the aggregator.
|
||||||
func CheckedUpdate(t *testing.T, agg export.Aggregator, number core.Number, descriptor *metric.Descriptor) {
|
func CheckedUpdate(t *testing.T, agg export.Aggregator, number metric.Number, descriptor *metric.Descriptor) {
|
||||||
ctx := context.Background()
|
ctx := context.Background()
|
||||||
|
|
||||||
// Note: Aggregator tests are written assuming that the SDK
|
// Note: Aggregator tests are written assuming that the SDK
|
||||||
|
@ -48,14 +48,14 @@ type (
|
|||||||
var (
|
var (
|
||||||
// LastValueADesc and LastValueBDesc group by "G"
|
// LastValueADesc and LastValueBDesc group by "G"
|
||||||
LastValueADesc = metric.NewDescriptor(
|
LastValueADesc = metric.NewDescriptor(
|
||||||
"lastvalue.a", metric.ObserverKind, core.Int64NumberKind)
|
"lastvalue.a", metric.ObserverKind, metric.Int64NumberKind)
|
||||||
LastValueBDesc = metric.NewDescriptor(
|
LastValueBDesc = metric.NewDescriptor(
|
||||||
"lastvalue.b", metric.ObserverKind, core.Int64NumberKind)
|
"lastvalue.b", metric.ObserverKind, metric.Int64NumberKind)
|
||||||
// CounterADesc and CounterBDesc group by "C"
|
// CounterADesc and CounterBDesc group by "C"
|
||||||
CounterADesc = metric.NewDescriptor(
|
CounterADesc = metric.NewDescriptor(
|
||||||
"sum.a", metric.CounterKind, core.Int64NumberKind)
|
"sum.a", metric.CounterKind, metric.Int64NumberKind)
|
||||||
CounterBDesc = metric.NewDescriptor(
|
CounterBDesc = metric.NewDescriptor(
|
||||||
"sum.b", metric.CounterKind, core.Int64NumberKind)
|
"sum.b", metric.CounterKind, metric.Int64NumberKind)
|
||||||
|
|
||||||
// SdkEncoder uses a non-standard encoder like K1~V1&K2~V2
|
// SdkEncoder uses a non-standard encoder like K1~V1&K2~V2
|
||||||
SdkEncoder = &Encoder{}
|
SdkEncoder = &Encoder{}
|
||||||
@ -127,7 +127,7 @@ func (Encoder) ID() label.EncoderID {
|
|||||||
func LastValueAgg(desc *metric.Descriptor, v int64) export.Aggregator {
|
func LastValueAgg(desc *metric.Descriptor, v int64) export.Aggregator {
|
||||||
ctx := context.Background()
|
ctx := context.Background()
|
||||||
gagg := lastvalue.New()
|
gagg := lastvalue.New()
|
||||||
_ = gagg.Update(ctx, core.NewInt64Number(v), desc)
|
_ = gagg.Update(ctx, metric.NewInt64Number(v), desc)
|
||||||
gagg.Checkpoint(ctx, desc)
|
gagg.Checkpoint(ctx, desc)
|
||||||
return gagg
|
return gagg
|
||||||
}
|
}
|
||||||
@ -146,7 +146,7 @@ func NewCounterRecord(desc *metric.Descriptor, labels *label.Set, value int64) e
|
|||||||
func CounterAgg(desc *metric.Descriptor, v int64) export.Aggregator {
|
func CounterAgg(desc *metric.Descriptor, v int64) export.Aggregator {
|
||||||
ctx := context.Background()
|
ctx := context.Background()
|
||||||
cagg := sum.New()
|
cagg := sum.New()
|
||||||
_ = cagg.Update(ctx, core.NewInt64Number(v), desc)
|
_ = cagg.Update(ctx, metric.NewInt64Number(v), desc)
|
||||||
cagg.Checkpoint(ctx, desc)
|
cagg.Checkpoint(ctx, desc)
|
||||||
return cagg
|
return cagg
|
||||||
}
|
}
|
||||||
|
@ -18,9 +18,10 @@ import (
|
|||||||
"context"
|
"context"
|
||||||
"testing"
|
"testing"
|
||||||
|
|
||||||
|
"go.opentelemetry.io/otel/api/metric"
|
||||||
|
|
||||||
"github.com/stretchr/testify/require"
|
"github.com/stretchr/testify/require"
|
||||||
|
|
||||||
"go.opentelemetry.io/otel/api/core"
|
|
||||||
export "go.opentelemetry.io/otel/sdk/export/metric"
|
export "go.opentelemetry.io/otel/sdk/export/metric"
|
||||||
"go.opentelemetry.io/otel/sdk/metric/batcher/test"
|
"go.opentelemetry.io/otel/sdk/metric/batcher/test"
|
||||||
"go.opentelemetry.io/otel/sdk/metric/batcher/ungrouped"
|
"go.opentelemetry.io/otel/sdk/metric/batcher/ungrouped"
|
||||||
@ -123,8 +124,8 @@ func TestUngroupedStateful(t *testing.T) {
|
|||||||
require.EqualValues(t, records1.Map, records2.Map)
|
require.EqualValues(t, records1.Map, records2.Map)
|
||||||
|
|
||||||
// Update and re-checkpoint the original record.
|
// Update and re-checkpoint the original record.
|
||||||
_ = caggA.Update(ctx, core.NewInt64Number(20), &test.CounterADesc)
|
_ = caggA.Update(ctx, metric.NewInt64Number(20), &test.CounterADesc)
|
||||||
_ = caggB.Update(ctx, core.NewInt64Number(20), &test.CounterBDesc)
|
_ = caggB.Update(ctx, metric.NewInt64Number(20), &test.CounterBDesc)
|
||||||
caggA.Checkpoint(ctx, &test.CounterADesc)
|
caggA.Checkpoint(ctx, &test.CounterADesc)
|
||||||
caggB.Checkpoint(ctx, &test.CounterBDesc)
|
caggB.Checkpoint(ctx, &test.CounterBDesc)
|
||||||
|
|
||||||
|
@ -240,7 +240,7 @@ func TestSDKLabelsDeduplication(t *testing.T) {
|
|||||||
var actual [][]core.KeyValue
|
var actual [][]core.KeyValue
|
||||||
for _, rec := range batcher.records {
|
for _, rec := range batcher.records {
|
||||||
sum, _ := rec.Aggregator().(aggregator.Sum).Sum()
|
sum, _ := rec.Aggregator().(aggregator.Sum).Sum()
|
||||||
require.Equal(t, sum, core.NewInt64Number(2))
|
require.Equal(t, sum, metric.NewInt64Number(2))
|
||||||
|
|
||||||
kvs := rec.Labels().ToSlice()
|
kvs := rec.Labels().ToSlice()
|
||||||
actual = append(actual, kvs)
|
actual = append(actual, kvs)
|
||||||
|
@ -20,14 +20,13 @@ import (
|
|||||||
"testing"
|
"testing"
|
||||||
"time"
|
"time"
|
||||||
|
|
||||||
"go.opentelemetry.io/otel/api/core"
|
|
||||||
"go.opentelemetry.io/otel/api/metric"
|
"go.opentelemetry.io/otel/api/metric"
|
||||||
"go.opentelemetry.io/otel/sdk/metric/aggregator/histogram"
|
"go.opentelemetry.io/otel/sdk/metric/aggregator/histogram"
|
||||||
)
|
)
|
||||||
|
|
||||||
func TestStressInt64Histogram(t *testing.T) {
|
func TestStressInt64Histogram(t *testing.T) {
|
||||||
desc := metric.NewDescriptor("some_metric", metric.MeasureKind, core.Int64NumberKind)
|
desc := metric.NewDescriptor("some_metric", metric.MeasureKind, metric.Int64NumberKind)
|
||||||
h := histogram.New(&desc, []core.Number{core.NewInt64Number(25), core.NewInt64Number(50), core.NewInt64Number(75)})
|
h := histogram.New(&desc, []metric.Number{metric.NewInt64Number(25), metric.NewInt64Number(50), metric.NewInt64Number(75)})
|
||||||
|
|
||||||
ctx, cancelFunc := context.WithCancel(context.Background())
|
ctx, cancelFunc := context.WithCancel(context.Background())
|
||||||
defer cancelFunc()
|
defer cancelFunc()
|
||||||
@ -38,7 +37,7 @@ func TestStressInt64Histogram(t *testing.T) {
|
|||||||
case <-ctx.Done():
|
case <-ctx.Done():
|
||||||
return
|
return
|
||||||
default:
|
default:
|
||||||
_ = h.Update(ctx, core.NewInt64Number(rnd.Int63()%100), &desc)
|
_ = h.Update(ctx, metric.NewInt64Number(rnd.Int63()%100), &desc)
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
}()
|
}()
|
||||||
|
@ -20,13 +20,12 @@ import (
|
|||||||
"testing"
|
"testing"
|
||||||
"time"
|
"time"
|
||||||
|
|
||||||
"go.opentelemetry.io/otel/api/core"
|
|
||||||
"go.opentelemetry.io/otel/api/metric"
|
"go.opentelemetry.io/otel/api/metric"
|
||||||
"go.opentelemetry.io/otel/sdk/metric/aggregator/minmaxsumcount"
|
"go.opentelemetry.io/otel/sdk/metric/aggregator/minmaxsumcount"
|
||||||
)
|
)
|
||||||
|
|
||||||
func TestStressInt64MinMaxSumCount(t *testing.T) {
|
func TestStressInt64MinMaxSumCount(t *testing.T) {
|
||||||
desc := metric.NewDescriptor("some_metric", metric.MeasureKind, core.Int64NumberKind)
|
desc := metric.NewDescriptor("some_metric", metric.MeasureKind, metric.Int64NumberKind)
|
||||||
mmsc := minmaxsumcount.New(&desc)
|
mmsc := minmaxsumcount.New(&desc)
|
||||||
|
|
||||||
ctx, cancel := context.WithCancel(context.Background())
|
ctx, cancel := context.WithCancel(context.Background())
|
||||||
@ -39,7 +38,7 @@ func TestStressInt64MinMaxSumCount(t *testing.T) {
|
|||||||
case <-ctx.Done():
|
case <-ctx.Done():
|
||||||
return
|
return
|
||||||
default:
|
default:
|
||||||
_ = mmsc.Update(ctx, core.NewInt64Number(v), &desc)
|
_ = mmsc.Update(ctx, metric.NewInt64Number(v), &desc)
|
||||||
}
|
}
|
||||||
v++
|
v++
|
||||||
}
|
}
|
||||||
|
@ -129,7 +129,7 @@ type (
|
|||||||
// labelset and recorder
|
// labelset and recorder
|
||||||
recorders map[label.Distinct]*labeledRecorder
|
recorders map[label.Distinct]*labeledRecorder
|
||||||
|
|
||||||
callback func(func(core.Number, []core.KeyValue))
|
callback func(func(api.Number, []core.KeyValue))
|
||||||
}
|
}
|
||||||
|
|
||||||
labeledRecorder struct {
|
labeledRecorder struct {
|
||||||
@ -160,7 +160,7 @@ func (s *syncInstrument) Implementation() interface{} {
|
|||||||
return s
|
return s
|
||||||
}
|
}
|
||||||
|
|
||||||
func (a *asyncInstrument) observe(number core.Number, labels []core.KeyValue) {
|
func (a *asyncInstrument) observe(number api.Number, labels []core.KeyValue) {
|
||||||
if err := aggregator.RangeTest(number, &a.descriptor); err != nil {
|
if err := aggregator.RangeTest(number, &a.descriptor); err != nil {
|
||||||
a.meter.errorHandler(err)
|
a.meter.errorHandler(err)
|
||||||
return
|
return
|
||||||
@ -295,7 +295,7 @@ func (s *syncInstrument) Bind(kvs []core.KeyValue) api.BoundSyncImpl {
|
|||||||
return s.acquireHandle(kvs, nil)
|
return s.acquireHandle(kvs, nil)
|
||||||
}
|
}
|
||||||
|
|
||||||
func (s *syncInstrument) RecordOne(ctx context.Context, number core.Number, kvs []core.KeyValue) {
|
func (s *syncInstrument) RecordOne(ctx context.Context, number api.Number, kvs []core.KeyValue) {
|
||||||
h := s.acquireHandle(kvs, nil)
|
h := s.acquireHandle(kvs, nil)
|
||||||
defer h.Unbind()
|
defer h.Unbind()
|
||||||
h.RecordOne(ctx, number)
|
h.RecordOne(ctx, number)
|
||||||
@ -335,7 +335,7 @@ func (m *SDK) NewSyncInstrument(descriptor api.Descriptor) (api.SyncImpl, error)
|
|||||||
}, nil
|
}, nil
|
||||||
}
|
}
|
||||||
|
|
||||||
func (m *SDK) NewAsyncInstrument(descriptor api.Descriptor, callback func(func(core.Number, []core.KeyValue))) (api.AsyncImpl, error) {
|
func (m *SDK) NewAsyncInstrument(descriptor api.Descriptor, callback func(func(api.Number, []core.KeyValue))) (api.AsyncImpl, error) {
|
||||||
a := &asyncInstrument{
|
a := &asyncInstrument{
|
||||||
instrument: instrument{
|
instrument: instrument{
|
||||||
descriptor: descriptor,
|
descriptor: descriptor,
|
||||||
@ -484,7 +484,7 @@ func (m *SDK) RecordBatch(ctx context.Context, kvs []core.KeyValue, measurements
|
|||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
func (r *record) RecordOne(ctx context.Context, number core.Number) {
|
func (r *record) RecordOne(ctx context.Context, number api.Number) {
|
||||||
if r.recorder == nil {
|
if r.recorder == nil {
|
||||||
// The instrument is disabled according to the AggregationSelector.
|
// The instrument is disabled according to the AggregationSelector.
|
||||||
return
|
return
|
||||||
|
@ -15,7 +15,6 @@
|
|||||||
package simple // import "go.opentelemetry.io/otel/sdk/metric/selector/simple"
|
package simple // import "go.opentelemetry.io/otel/sdk/metric/selector/simple"
|
||||||
|
|
||||||
import (
|
import (
|
||||||
"go.opentelemetry.io/otel/api/core"
|
|
||||||
"go.opentelemetry.io/otel/api/metric"
|
"go.opentelemetry.io/otel/api/metric"
|
||||||
export "go.opentelemetry.io/otel/sdk/export/metric"
|
export "go.opentelemetry.io/otel/sdk/export/metric"
|
||||||
"go.opentelemetry.io/otel/sdk/metric/aggregator/array"
|
"go.opentelemetry.io/otel/sdk/metric/aggregator/array"
|
||||||
@ -32,7 +31,7 @@ type (
|
|||||||
config *ddsketch.Config
|
config *ddsketch.Config
|
||||||
}
|
}
|
||||||
selectorHistogram struct {
|
selectorHistogram struct {
|
||||||
boundaries []core.Number
|
boundaries []metric.Number
|
||||||
}
|
}
|
||||||
)
|
)
|
||||||
|
|
||||||
@ -76,7 +75,7 @@ func NewWithExactMeasure() export.AggregationSelector {
|
|||||||
// histogram, and histogram aggregators for the three kinds of metric. This
|
// histogram, and histogram aggregators for the three kinds of metric. This
|
||||||
// selector uses more memory than the NewWithInexpensiveMeasure because it
|
// selector uses more memory than the NewWithInexpensiveMeasure because it
|
||||||
// uses a counter per bucket.
|
// uses a counter per bucket.
|
||||||
func NewWithHistogramMeasure(boundaries []core.Number) export.AggregationSelector {
|
func NewWithHistogramMeasure(boundaries []metric.Number) export.AggregationSelector {
|
||||||
return selectorHistogram{boundaries: boundaries}
|
return selectorHistogram{boundaries: boundaries}
|
||||||
}
|
}
|
||||||
|
|
||||||
|
@ -19,7 +19,6 @@ import (
|
|||||||
|
|
||||||
"github.com/stretchr/testify/require"
|
"github.com/stretchr/testify/require"
|
||||||
|
|
||||||
"go.opentelemetry.io/otel/api/core"
|
|
||||||
"go.opentelemetry.io/otel/api/metric"
|
"go.opentelemetry.io/otel/api/metric"
|
||||||
"go.opentelemetry.io/otel/sdk/metric/aggregator/array"
|
"go.opentelemetry.io/otel/sdk/metric/aggregator/array"
|
||||||
"go.opentelemetry.io/otel/sdk/metric/aggregator/ddsketch"
|
"go.opentelemetry.io/otel/sdk/metric/aggregator/ddsketch"
|
||||||
@ -30,9 +29,9 @@ import (
|
|||||||
)
|
)
|
||||||
|
|
||||||
var (
|
var (
|
||||||
testCounterDesc = metric.NewDescriptor("counter", metric.CounterKind, core.Int64NumberKind)
|
testCounterDesc = metric.NewDescriptor("counter", metric.CounterKind, metric.Int64NumberKind)
|
||||||
testMeasureDesc = metric.NewDescriptor("measure", metric.MeasureKind, core.Int64NumberKind)
|
testMeasureDesc = metric.NewDescriptor("measure", metric.MeasureKind, metric.Int64NumberKind)
|
||||||
testObserverDesc = metric.NewDescriptor("observer", metric.ObserverKind, core.Int64NumberKind)
|
testObserverDesc = metric.NewDescriptor("observer", metric.ObserverKind, metric.Int64NumberKind)
|
||||||
)
|
)
|
||||||
|
|
||||||
func TestInexpensiveMeasure(t *testing.T) {
|
func TestInexpensiveMeasure(t *testing.T) {
|
||||||
@ -57,7 +56,7 @@ func TestExactMeasure(t *testing.T) {
|
|||||||
}
|
}
|
||||||
|
|
||||||
func TestHistogramMeasure(t *testing.T) {
|
func TestHistogramMeasure(t *testing.T) {
|
||||||
ex := simple.NewWithHistogramMeasure([]core.Number{})
|
ex := simple.NewWithHistogramMeasure([]metric.Number{})
|
||||||
require.NotPanics(t, func() { _ = ex.AggregatorFor(&testCounterDesc).(*sum.Aggregator) })
|
require.NotPanics(t, func() { _ = ex.AggregatorFor(&testCounterDesc).(*sum.Aggregator) })
|
||||||
require.NotPanics(t, func() { _ = ex.AggregatorFor(&testMeasureDesc).(*histogram.Aggregator) })
|
require.NotPanics(t, func() { _ = ex.AggregatorFor(&testMeasureDesc).(*histogram.Aggregator) })
|
||||||
require.NotPanics(t, func() { _ = ex.AggregatorFor(&testObserverDesc).(*histogram.Aggregator) })
|
require.NotPanics(t, func() { _ = ex.AggregatorFor(&testObserverDesc).(*histogram.Aggregator) })
|
||||||
|
@ -74,17 +74,17 @@ type (
|
|||||||
|
|
||||||
testImpl struct {
|
testImpl struct {
|
||||||
newInstrument func(meter api.Meter, name string) SyncImpler
|
newInstrument func(meter api.Meter, name string) SyncImpler
|
||||||
getUpdateValue func() core.Number
|
getUpdateValue func() api.Number
|
||||||
operate func(interface{}, context.Context, core.Number, []core.KeyValue)
|
operate func(interface{}, context.Context, api.Number, []core.KeyValue)
|
||||||
newStore func() interface{}
|
newStore func() interface{}
|
||||||
|
|
||||||
// storeCollect and storeExpect are the same for
|
// storeCollect and storeExpect are the same for
|
||||||
// counters, different for lastValues, to ensure we are
|
// counters, different for lastValues, to ensure we are
|
||||||
// testing the timestamps correctly.
|
// testing the timestamps correctly.
|
||||||
storeCollect func(store interface{}, value core.Number, ts time.Time)
|
storeCollect func(store interface{}, value api.Number, ts time.Time)
|
||||||
storeExpect func(store interface{}, value core.Number)
|
storeExpect func(store interface{}, value api.Number)
|
||||||
readStore func(store interface{}) core.Number
|
readStore func(store interface{}) api.Number
|
||||||
equalValues func(a, b core.Number) bool
|
equalValues func(a, b api.Number) bool
|
||||||
}
|
}
|
||||||
|
|
||||||
SyncImpler interface {
|
SyncImpler interface {
|
||||||
@ -96,7 +96,7 @@ type (
|
|||||||
// take the later timestamp.
|
// take the later timestamp.
|
||||||
lastValueState struct {
|
lastValueState struct {
|
||||||
// raw has to be aligned for 64-bit atomic operations.
|
// raw has to be aligned for 64-bit atomic operations.
|
||||||
raw core.Number
|
raw api.Number
|
||||||
ts time.Time
|
ts time.Time
|
||||||
}
|
}
|
||||||
)
|
)
|
||||||
@ -340,11 +340,11 @@ func stressTest(t *testing.T, impl testImpl) {
|
|||||||
fixture.assertTest(numCollect)
|
fixture.assertTest(numCollect)
|
||||||
}
|
}
|
||||||
|
|
||||||
func int64sEqual(a, b core.Number) bool {
|
func int64sEqual(a, b api.Number) bool {
|
||||||
return a.AsInt64() == b.AsInt64()
|
return a.AsInt64() == b.AsInt64()
|
||||||
}
|
}
|
||||||
|
|
||||||
func float64sEqual(a, b core.Number) bool {
|
func float64sEqual(a, b api.Number) bool {
|
||||||
diff := math.Abs(a.AsFloat64() - b.AsFloat64())
|
diff := math.Abs(a.AsFloat64() - b.AsFloat64())
|
||||||
return diff < math.Abs(a.AsFloat64())*epsilon
|
return diff < math.Abs(a.AsFloat64())*epsilon
|
||||||
}
|
}
|
||||||
@ -356,30 +356,30 @@ func intCounterTestImpl() testImpl {
|
|||||||
newInstrument: func(meter api.Meter, name string) SyncImpler {
|
newInstrument: func(meter api.Meter, name string) SyncImpler {
|
||||||
return Must(meter).NewInt64Counter(name + ".counter")
|
return Must(meter).NewInt64Counter(name + ".counter")
|
||||||
},
|
},
|
||||||
getUpdateValue: func() core.Number {
|
getUpdateValue: func() api.Number {
|
||||||
for {
|
for {
|
||||||
x := int64(rand.Intn(100))
|
x := int64(rand.Intn(100))
|
||||||
if x != 0 {
|
if x != 0 {
|
||||||
return core.NewInt64Number(x)
|
return api.NewInt64Number(x)
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
},
|
},
|
||||||
operate: func(inst interface{}, ctx context.Context, value core.Number, labels []core.KeyValue) {
|
operate: func(inst interface{}, ctx context.Context, value api.Number, labels []core.KeyValue) {
|
||||||
counter := inst.(api.Int64Counter)
|
counter := inst.(api.Int64Counter)
|
||||||
counter.Add(ctx, value.AsInt64(), labels...)
|
counter.Add(ctx, value.AsInt64(), labels...)
|
||||||
},
|
},
|
||||||
newStore: func() interface{} {
|
newStore: func() interface{} {
|
||||||
n := core.NewInt64Number(0)
|
n := api.NewInt64Number(0)
|
||||||
return &n
|
return &n
|
||||||
},
|
},
|
||||||
storeCollect: func(store interface{}, value core.Number, _ time.Time) {
|
storeCollect: func(store interface{}, value api.Number, _ time.Time) {
|
||||||
store.(*core.Number).AddInt64Atomic(value.AsInt64())
|
store.(*api.Number).AddInt64Atomic(value.AsInt64())
|
||||||
},
|
},
|
||||||
storeExpect: func(store interface{}, value core.Number) {
|
storeExpect: func(store interface{}, value api.Number) {
|
||||||
store.(*core.Number).AddInt64Atomic(value.AsInt64())
|
store.(*api.Number).AddInt64Atomic(value.AsInt64())
|
||||||
},
|
},
|
||||||
readStore: func(store interface{}) core.Number {
|
readStore: func(store interface{}) api.Number {
|
||||||
return store.(*core.Number).AsNumberAtomic()
|
return store.(*api.Number).AsNumberAtomic()
|
||||||
},
|
},
|
||||||
equalValues: int64sEqual,
|
equalValues: int64sEqual,
|
||||||
}
|
}
|
||||||
@ -394,30 +394,30 @@ func floatCounterTestImpl() testImpl {
|
|||||||
newInstrument: func(meter api.Meter, name string) SyncImpler {
|
newInstrument: func(meter api.Meter, name string) SyncImpler {
|
||||||
return Must(meter).NewFloat64Counter(name + ".counter")
|
return Must(meter).NewFloat64Counter(name + ".counter")
|
||||||
},
|
},
|
||||||
getUpdateValue: func() core.Number {
|
getUpdateValue: func() api.Number {
|
||||||
for {
|
for {
|
||||||
x := rand.Float64()
|
x := rand.Float64()
|
||||||
if x != 0 {
|
if x != 0 {
|
||||||
return core.NewFloat64Number(x)
|
return api.NewFloat64Number(x)
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
},
|
},
|
||||||
operate: func(inst interface{}, ctx context.Context, value core.Number, labels []core.KeyValue) {
|
operate: func(inst interface{}, ctx context.Context, value api.Number, labels []core.KeyValue) {
|
||||||
counter := inst.(api.Float64Counter)
|
counter := inst.(api.Float64Counter)
|
||||||
counter.Add(ctx, value.AsFloat64(), labels...)
|
counter.Add(ctx, value.AsFloat64(), labels...)
|
||||||
},
|
},
|
||||||
newStore: func() interface{} {
|
newStore: func() interface{} {
|
||||||
n := core.NewFloat64Number(0.0)
|
n := api.NewFloat64Number(0.0)
|
||||||
return &n
|
return &n
|
||||||
},
|
},
|
||||||
storeCollect: func(store interface{}, value core.Number, _ time.Time) {
|
storeCollect: func(store interface{}, value api.Number, _ time.Time) {
|
||||||
store.(*core.Number).AddFloat64Atomic(value.AsFloat64())
|
store.(*api.Number).AddFloat64Atomic(value.AsFloat64())
|
||||||
},
|
},
|
||||||
storeExpect: func(store interface{}, value core.Number) {
|
storeExpect: func(store interface{}, value api.Number) {
|
||||||
store.(*core.Number).AddFloat64Atomic(value.AsFloat64())
|
store.(*api.Number).AddFloat64Atomic(value.AsFloat64())
|
||||||
},
|
},
|
||||||
readStore: func(store interface{}) core.Number {
|
readStore: func(store interface{}) api.Number {
|
||||||
return store.(*core.Number).AsNumberAtomic()
|
return store.(*api.Number).AsNumberAtomic()
|
||||||
},
|
},
|
||||||
equalValues: float64sEqual,
|
equalValues: float64sEqual,
|
||||||
}
|
}
|
||||||
@ -434,20 +434,20 @@ func intLastValueTestImpl() testImpl {
|
|||||||
newInstrument: func(meter api.Meter, name string) SyncImpler {
|
newInstrument: func(meter api.Meter, name string) SyncImpler {
|
||||||
return Must(meter).NewInt64Measure(name + ".lastvalue")
|
return Must(meter).NewInt64Measure(name + ".lastvalue")
|
||||||
},
|
},
|
||||||
getUpdateValue: func() core.Number {
|
getUpdateValue: func() api.Number {
|
||||||
r1 := rand.Int63()
|
r1 := rand.Int63()
|
||||||
return core.NewInt64Number(rand.Int63() - r1)
|
return api.NewInt64Number(rand.Int63() - r1)
|
||||||
},
|
},
|
||||||
operate: func(inst interface{}, ctx context.Context, value core.Number, labels []core.KeyValue) {
|
operate: func(inst interface{}, ctx context.Context, value api.Number, labels []core.KeyValue) {
|
||||||
measure := inst.(api.Int64Measure)
|
measure := inst.(api.Int64Measure)
|
||||||
measure.Record(ctx, value.AsInt64(), labels...)
|
measure.Record(ctx, value.AsInt64(), labels...)
|
||||||
},
|
},
|
||||||
newStore: func() interface{} {
|
newStore: func() interface{} {
|
||||||
return &lastValueState{
|
return &lastValueState{
|
||||||
raw: core.NewInt64Number(0),
|
raw: api.NewInt64Number(0),
|
||||||
}
|
}
|
||||||
},
|
},
|
||||||
storeCollect: func(store interface{}, value core.Number, ts time.Time) {
|
storeCollect: func(store interface{}, value api.Number, ts time.Time) {
|
||||||
gs := store.(*lastValueState)
|
gs := store.(*lastValueState)
|
||||||
|
|
||||||
if !ts.Before(gs.ts) {
|
if !ts.Before(gs.ts) {
|
||||||
@ -455,11 +455,11 @@ func intLastValueTestImpl() testImpl {
|
|||||||
gs.raw.SetInt64Atomic(value.AsInt64())
|
gs.raw.SetInt64Atomic(value.AsInt64())
|
||||||
}
|
}
|
||||||
},
|
},
|
||||||
storeExpect: func(store interface{}, value core.Number) {
|
storeExpect: func(store interface{}, value api.Number) {
|
||||||
gs := store.(*lastValueState)
|
gs := store.(*lastValueState)
|
||||||
gs.raw.SetInt64Atomic(value.AsInt64())
|
gs.raw.SetInt64Atomic(value.AsInt64())
|
||||||
},
|
},
|
||||||
readStore: func(store interface{}) core.Number {
|
readStore: func(store interface{}) api.Number {
|
||||||
gs := store.(*lastValueState)
|
gs := store.(*lastValueState)
|
||||||
return gs.raw.AsNumberAtomic()
|
return gs.raw.AsNumberAtomic()
|
||||||
},
|
},
|
||||||
@ -476,19 +476,19 @@ func floatLastValueTestImpl() testImpl {
|
|||||||
newInstrument: func(meter api.Meter, name string) SyncImpler {
|
newInstrument: func(meter api.Meter, name string) SyncImpler {
|
||||||
return Must(meter).NewFloat64Measure(name + ".lastvalue")
|
return Must(meter).NewFloat64Measure(name + ".lastvalue")
|
||||||
},
|
},
|
||||||
getUpdateValue: func() core.Number {
|
getUpdateValue: func() api.Number {
|
||||||
return core.NewFloat64Number((-0.5 + rand.Float64()) * 100000)
|
return api.NewFloat64Number((-0.5 + rand.Float64()) * 100000)
|
||||||
},
|
},
|
||||||
operate: func(inst interface{}, ctx context.Context, value core.Number, labels []core.KeyValue) {
|
operate: func(inst interface{}, ctx context.Context, value api.Number, labels []core.KeyValue) {
|
||||||
measure := inst.(api.Float64Measure)
|
measure := inst.(api.Float64Measure)
|
||||||
measure.Record(ctx, value.AsFloat64(), labels...)
|
measure.Record(ctx, value.AsFloat64(), labels...)
|
||||||
},
|
},
|
||||||
newStore: func() interface{} {
|
newStore: func() interface{} {
|
||||||
return &lastValueState{
|
return &lastValueState{
|
||||||
raw: core.NewFloat64Number(0),
|
raw: api.NewFloat64Number(0),
|
||||||
}
|
}
|
||||||
},
|
},
|
||||||
storeCollect: func(store interface{}, value core.Number, ts time.Time) {
|
storeCollect: func(store interface{}, value api.Number, ts time.Time) {
|
||||||
gs := store.(*lastValueState)
|
gs := store.(*lastValueState)
|
||||||
|
|
||||||
if !ts.Before(gs.ts) {
|
if !ts.Before(gs.ts) {
|
||||||
@ -496,11 +496,11 @@ func floatLastValueTestImpl() testImpl {
|
|||||||
gs.raw.SetFloat64Atomic(value.AsFloat64())
|
gs.raw.SetFloat64Atomic(value.AsFloat64())
|
||||||
}
|
}
|
||||||
},
|
},
|
||||||
storeExpect: func(store interface{}, value core.Number) {
|
storeExpect: func(store interface{}, value api.Number) {
|
||||||
gs := store.(*lastValueState)
|
gs := store.(*lastValueState)
|
||||||
gs.raw.SetFloat64Atomic(value.AsFloat64())
|
gs.raw.SetFloat64Atomic(value.AsFloat64())
|
||||||
},
|
},
|
||||||
readStore: func(store interface{}) core.Number {
|
readStore: func(store interface{}) api.Number {
|
||||||
gs := store.(*lastValueState)
|
gs := store.(*lastValueState)
|
||||||
return gs.raw.AsNumberAtomic()
|
return gs.raw.AsNumberAtomic()
|
||||||
},
|
},
|
||||||
|
Loading…
x
Reference in New Issue
Block a user