Skip to content

Commit

Permalink
Rename Callback Function.
Browse files Browse the repository at this point in the history
  • Loading branch information
dengliming authored and evantorrie committed Sep 10, 2020
1 parent 9d60956 commit 718ac5d
Show file tree
Hide file tree
Showing 5 changed files with 43 additions and 43 deletions.
38 changes: 19 additions & 19 deletions api/metric/async.go
Original file line number Diff line number Diff line change
Expand Up @@ -40,18 +40,18 @@ type Observation struct {
instrument AsyncImpl
}

// Int64ObserverCallback is a type of callback that integral
// Int64ObserverFunc is a type of callback that integral
// observers run.
type Int64ObserverCallback func(context.Context, Int64ObserverResult)
type Int64ObserverFunc func(context.Context, Int64ObserverResult)

// Float64ObserverCallback is a type of callback that floating point
// Float64ObserverFunc is a type of callback that floating point
// observers run.
type Float64ObserverCallback func(context.Context, Float64ObserverResult)
type Float64ObserverFunc func(context.Context, Float64ObserverResult)

// BatchObserverCallback is a callback argument for use with any
// BatchObserverFunc is a callback argument for use with any
// Observer instrument that will be reported as a batch of
// observations.
type BatchObserverCallback func(context.Context, BatchObserverResult)
type BatchObserverFunc func(context.Context, BatchObserverResult)

// Int64ObserverResult is passed to an observer callback to capture
// observations for one asynchronous integer metric instrument.
Expand All @@ -60,7 +60,7 @@ type Int64ObserverResult struct {
function func([]kv.KeyValue, ...Observation)
}

// Float64ObserverResult is passed to an observer callback to capture
// Float64ObserverResult is passed to an observer callback to captureGetHookFunc
// observations for one asynchronous floating point metric instrument.
type Float64ObserverResult struct {
instrument AsyncImpl
Expand Down Expand Up @@ -129,52 +129,52 @@ type AsyncBatchRunner interface {
AsyncRunner
}

var _ AsyncSingleRunner = (*Int64ObserverCallback)(nil)
var _ AsyncSingleRunner = (*Float64ObserverCallback)(nil)
var _ AsyncBatchRunner = (*BatchObserverCallback)(nil)
var _ AsyncSingleRunner = (*Int64ObserverFunc)(nil)
var _ AsyncSingleRunner = (*Float64ObserverFunc)(nil)
var _ AsyncBatchRunner = (*BatchObserverFunc)(nil)

// newInt64AsyncRunner returns a single-observer callback for integer Observer instruments.
func newInt64AsyncRunner(c Int64ObserverCallback) AsyncSingleRunner {
func newInt64AsyncRunner(c Int64ObserverFunc) AsyncSingleRunner {
return &c
}

// newFloat64AsyncRunner returns a single-observer callback for floating point Observer instruments.
func newFloat64AsyncRunner(c Float64ObserverCallback) AsyncSingleRunner {
func newFloat64AsyncRunner(c Float64ObserverFunc) AsyncSingleRunner {
return &c
}

// newBatchAsyncRunner returns a batch-observer callback use with multiple Observer instruments.
func newBatchAsyncRunner(c BatchObserverCallback) AsyncBatchRunner {
func newBatchAsyncRunner(c BatchObserverFunc) AsyncBatchRunner {
return &c
}

// AnyRunner implements AsyncRunner.
func (*Int64ObserverCallback) AnyRunner() {}
func (*Int64ObserverFunc) AnyRunner() {}

// AnyRunner implements AsyncRunner.
func (*Float64ObserverCallback) AnyRunner() {}
func (*Float64ObserverFunc) AnyRunner() {}

// AnyRunner implements AsyncRunner.
func (*BatchObserverCallback) AnyRunner() {}
func (*BatchObserverFunc) AnyRunner() {}

// Run implements AsyncSingleRunner.
func (i *Int64ObserverCallback) Run(ctx context.Context, impl AsyncImpl, function func([]kv.KeyValue, ...Observation)) {
func (i *Int64ObserverFunc) Run(ctx context.Context, impl AsyncImpl, function func([]kv.KeyValue, ...Observation)) {
(*i)(ctx, Int64ObserverResult{
instrument: impl,
function: function,
})
}

// Run implements AsyncSingleRunner.
func (f *Float64ObserverCallback) Run(ctx context.Context, impl AsyncImpl, function func([]kv.KeyValue, ...Observation)) {
func (f *Float64ObserverFunc) Run(ctx context.Context, impl AsyncImpl, function func([]kv.KeyValue, ...Observation)) {
(*f)(ctx, Float64ObserverResult{
instrument: impl,
function: function,
})
}

// Run implements AsyncBatchRunner.
func (b *BatchObserverCallback) Run(ctx context.Context, function func([]kv.KeyValue, ...Observation)) {
func (b *BatchObserverFunc) Run(ctx context.Context, function func([]kv.KeyValue, ...Observation)) {
(*b)(ctx, BatchObserverResult{
function: function,
})
Expand Down
14 changes: 7 additions & 7 deletions api/metric/meter.go
Original file line number Diff line number Diff line change
Expand Up @@ -61,7 +61,7 @@ func (m Meter) RecordBatch(ctx context.Context, ls []kv.KeyValue, ms ...Measurem

// NewBatchObserver creates a new BatchObserver that supports
// making batches of observations for multiple instruments.
func (m Meter) NewBatchObserver(callback BatchObserverCallback) BatchObserver {
func (m Meter) NewBatchObserver(callback BatchObserverFunc) BatchObserver {
return BatchObserver{
meter: m,
runner: newBatchAsyncRunner(callback),
Expand Down Expand Up @@ -126,7 +126,7 @@ func (m Meter) NewFloat64ValueRecorder(name string, opts ...InstrumentOption) (F
// with the given name, running a given callback, and customized with
// options. May return an error if the name is invalid (e.g., empty)
// or improperly registered (e.g., duplicate registration).
func (m Meter) NewInt64ValueObserver(name string, callback Int64ObserverCallback, opts ...InstrumentOption) (Int64ValueObserver, error) {
func (m Meter) NewInt64ValueObserver(name string, callback Int64ObserverFunc, opts ...InstrumentOption) (Int64ValueObserver, error) {
if callback == nil {
return wrapInt64ValueObserverInstrument(NoopAsync{}, nil)
}
Expand All @@ -139,7 +139,7 @@ func (m Meter) NewInt64ValueObserver(name string, callback Int64ObserverCallback
// the given name, running a given callback, and customized with
// options. May return an error if the name is invalid (e.g., empty)
// or improperly registered (e.g., duplicate registration).
func (m Meter) NewFloat64ValueObserver(name string, callback Float64ObserverCallback, opts ...InstrumentOption) (Float64ValueObserver, error) {
func (m Meter) NewFloat64ValueObserver(name string, callback Float64ObserverFunc, opts ...InstrumentOption) (Float64ValueObserver, error) {
if callback == nil {
return wrapFloat64ValueObserverInstrument(NoopAsync{}, nil)
}
Expand All @@ -152,7 +152,7 @@ func (m Meter) NewFloat64ValueObserver(name string, callback Float64ObserverCall
// with the given name, running a given callback, and customized with
// options. May return an error if the name is invalid (e.g., empty)
// or improperly registered (e.g., duplicate registration).
func (m Meter) NewInt64SumObserver(name string, callback Int64ObserverCallback, opts ...InstrumentOption) (Int64SumObserver, error) {
func (m Meter) NewInt64SumObserver(name string, callback Int64ObserverFunc, opts ...InstrumentOption) (Int64SumObserver, error) {
if callback == nil {
return wrapInt64SumObserverInstrument(NoopAsync{}, nil)
}
Expand All @@ -165,7 +165,7 @@ func (m Meter) NewInt64SumObserver(name string, callback Int64ObserverCallback,
// the given name, running a given callback, and customized with
// options. May return an error if the name is invalid (e.g., empty)
// or improperly registered (e.g., duplicate registration).
func (m Meter) NewFloat64SumObserver(name string, callback Float64ObserverCallback, opts ...InstrumentOption) (Float64SumObserver, error) {
func (m Meter) NewFloat64SumObserver(name string, callback Float64ObserverFunc, opts ...InstrumentOption) (Float64SumObserver, error) {
if callback == nil {
return wrapFloat64SumObserverInstrument(NoopAsync{}, nil)
}
Expand All @@ -178,7 +178,7 @@ func (m Meter) NewFloat64SumObserver(name string, callback Float64ObserverCallba
// with the given name, running a given callback, and customized with
// options. May return an error if the name is invalid (e.g., empty)
// or improperly registered (e.g., duplicate registration).
func (m Meter) NewInt64UpDownSumObserver(name string, callback Int64ObserverCallback, opts ...InstrumentOption) (Int64UpDownSumObserver, error) {
func (m Meter) NewInt64UpDownSumObserver(name string, callback Int64ObserverFunc, opts ...InstrumentOption) (Int64UpDownSumObserver, error) {
if callback == nil {
return wrapInt64UpDownSumObserverInstrument(NoopAsync{}, nil)
}
Expand All @@ -191,7 +191,7 @@ func (m Meter) NewInt64UpDownSumObserver(name string, callback Int64ObserverCall
// the given name, running a given callback, and customized with
// options. May return an error if the name is invalid (e.g., empty)
// or improperly registered (e.g., duplicate registration).
func (m Meter) NewFloat64UpDownSumObserver(name string, callback Float64ObserverCallback, opts ...InstrumentOption) (Float64UpDownSumObserver, error) {
func (m Meter) NewFloat64UpDownSumObserver(name string, callback Float64ObserverFunc, opts ...InstrumentOption) (Float64UpDownSumObserver, error) {
if callback == nil {
return wrapFloat64UpDownSumObserverInstrument(NoopAsync{}, nil)
}
Expand Down
14 changes: 7 additions & 7 deletions api/metric/must.go
Original file line number Diff line number Diff line change
Expand Up @@ -95,7 +95,7 @@ func (mm MeterMust) NewFloat64ValueRecorder(name string, mos ...InstrumentOption

// NewInt64ValueObserver calls `Meter.NewInt64ValueObserver` and
// returns the instrument, panicking if it encounters an error.
func (mm MeterMust) NewInt64ValueObserver(name string, callback Int64ObserverCallback, oos ...InstrumentOption) Int64ValueObserver {
func (mm MeterMust) NewInt64ValueObserver(name string, callback Int64ObserverFunc, oos ...InstrumentOption) Int64ValueObserver {
if inst, err := mm.meter.NewInt64ValueObserver(name, callback, oos...); err != nil {
panic(err)
} else {
Expand All @@ -105,7 +105,7 @@ func (mm MeterMust) NewInt64ValueObserver(name string, callback Int64ObserverCal

// NewFloat64ValueObserver calls `Meter.NewFloat64ValueObserver` and
// returns the instrument, panicking if it encounters an error.
func (mm MeterMust) NewFloat64ValueObserver(name string, callback Float64ObserverCallback, oos ...InstrumentOption) Float64ValueObserver {
func (mm MeterMust) NewFloat64ValueObserver(name string, callback Float64ObserverFunc, oos ...InstrumentOption) Float64ValueObserver {
if inst, err := mm.meter.NewFloat64ValueObserver(name, callback, oos...); err != nil {
panic(err)
} else {
Expand All @@ -115,7 +115,7 @@ func (mm MeterMust) NewFloat64ValueObserver(name string, callback Float64Observe

// NewInt64SumObserver calls `Meter.NewInt64SumObserver` and
// returns the instrument, panicking if it encounters an error.
func (mm MeterMust) NewInt64SumObserver(name string, callback Int64ObserverCallback, oos ...InstrumentOption) Int64SumObserver {
func (mm MeterMust) NewInt64SumObserver(name string, callback Int64ObserverFunc, oos ...InstrumentOption) Int64SumObserver {
if inst, err := mm.meter.NewInt64SumObserver(name, callback, oos...); err != nil {
panic(err)
} else {
Expand All @@ -125,7 +125,7 @@ func (mm MeterMust) NewInt64SumObserver(name string, callback Int64ObserverCallb

// NewFloat64SumObserver calls `Meter.NewFloat64SumObserver` and
// returns the instrument, panicking if it encounters an error.
func (mm MeterMust) NewFloat64SumObserver(name string, callback Float64ObserverCallback, oos ...InstrumentOption) Float64SumObserver {
func (mm MeterMust) NewFloat64SumObserver(name string, callback Float64ObserverFunc, oos ...InstrumentOption) Float64SumObserver {
if inst, err := mm.meter.NewFloat64SumObserver(name, callback, oos...); err != nil {
panic(err)
} else {
Expand All @@ -135,7 +135,7 @@ func (mm MeterMust) NewFloat64SumObserver(name string, callback Float64ObserverC

// NewInt64UpDownSumObserver calls `Meter.NewInt64UpDownSumObserver` and
// returns the instrument, panicking if it encounters an error.
func (mm MeterMust) NewInt64UpDownSumObserver(name string, callback Int64ObserverCallback, oos ...InstrumentOption) Int64UpDownSumObserver {
func (mm MeterMust) NewInt64UpDownSumObserver(name string, callback Int64ObserverFunc, oos ...InstrumentOption) Int64UpDownSumObserver {
if inst, err := mm.meter.NewInt64UpDownSumObserver(name, callback, oos...); err != nil {
panic(err)
} else {
Expand All @@ -145,7 +145,7 @@ func (mm MeterMust) NewInt64UpDownSumObserver(name string, callback Int64Observe

// NewFloat64UpDownSumObserver calls `Meter.NewFloat64UpDownSumObserver` and
// returns the instrument, panicking if it encounters an error.
func (mm MeterMust) NewFloat64UpDownSumObserver(name string, callback Float64ObserverCallback, oos ...InstrumentOption) Float64UpDownSumObserver {
func (mm MeterMust) NewFloat64UpDownSumObserver(name string, callback Float64ObserverFunc, oos ...InstrumentOption) Float64UpDownSumObserver {
if inst, err := mm.meter.NewFloat64UpDownSumObserver(name, callback, oos...); err != nil {
panic(err)
} else {
Expand All @@ -155,7 +155,7 @@ func (mm MeterMust) NewFloat64UpDownSumObserver(name string, callback Float64Obs

// NewBatchObserver returns a wrapper around BatchObserver that panics
// when any instrument constructor returns an error.
func (mm MeterMust) NewBatchObserver(callback BatchObserverCallback) BatchObserverMust {
func (mm MeterMust) NewBatchObserver(callback BatchObserverFunc) BatchObserverMust {
return BatchObserverMust{
batch: mm.meter.NewBatchObserver(callback),
}
Expand Down
12 changes: 6 additions & 6 deletions api/metric/observer.go
Original file line number Diff line number Diff line change
Expand Up @@ -57,7 +57,7 @@ type Float64UpDownSumObserver struct {
asyncInstrument
}

// Observation returns an Observation, a BatchObserverCallback
// Observation returns an Observation, a BatchObserverFunc
// argument, for an asynchronous integer instrument.
// This returns an implementation-level object for use by the SDK,
// users should not refer to this.
Expand All @@ -68,7 +68,7 @@ func (i Int64ValueObserver) Observation(v int64) Observation {
}
}

// Observation returns an Observation, a BatchObserverCallback
// Observation returns an Observation, a BatchObserverFunc
// argument, for an asynchronous integer instrument.
// This returns an implementation-level object for use by the SDK,
// users should not refer to this.
Expand All @@ -79,7 +79,7 @@ func (f Float64ValueObserver) Observation(v float64) Observation {
}
}

// Observation returns an Observation, a BatchObserverCallback
// Observation returns an Observation, a BatchObserverFunc
// argument, for an asynchronous integer instrument.
// This returns an implementation-level object for use by the SDK,
// users should not refer to this.
Expand All @@ -90,7 +90,7 @@ func (i Int64SumObserver) Observation(v int64) Observation {
}
}

// Observation returns an Observation, a BatchObserverCallback
// Observation returns an Observation, a BatchObserverFunc
// argument, for an asynchronous integer instrument.
// This returns an implementation-level object for use by the SDK,
// users should not refer to this.
Expand All @@ -101,7 +101,7 @@ func (f Float64SumObserver) Observation(v float64) Observation {
}
}

// Observation returns an Observation, a BatchObserverCallback
// Observation returns an Observation, a BatchObserverFunc
// argument, for an asynchronous integer instrument.
// This returns an implementation-level object for use by the SDK,
// users should not refer to this.
Expand All @@ -112,7 +112,7 @@ func (i Int64UpDownSumObserver) Observation(v int64) Observation {
}
}

// Observation returns an Observation, a BatchObserverCallback
// Observation returns an Observation, a BatchObserverFunc
// argument, for an asynchronous integer instrument.
// This returns an implementation-level object for use by the SDK,
// users should not refer to this.
Expand Down
8 changes: 4 additions & 4 deletions exporters/otlp/otlp_integration_test.go
Original file line number Diff line number Diff line change
Expand Up @@ -162,13 +162,13 @@ func newExporterEndToEndTest(t *testing.T, additionalOpts []otlp.ExporterOption)
case metric.ValueObserverKind:
switch data.nKind {
case metricapi.Int64NumberKind:
callback := func(v int64) metricapi.Int64ObserverCallback {
return metricapi.Int64ObserverCallback(func(_ context.Context, result metricapi.Int64ObserverResult) { result.Observe(v, labels...) })
callback := func(v int64) metricapi.Int64ObserverFunc {
return metricapi.Int64ObserverFunc(func(_ context.Context, result metricapi.Int64ObserverResult) { result.Observe(v, labels...) })
}(data.val)
metricapi.Must(meter).NewInt64ValueObserver(name, callback)
case metricapi.Float64NumberKind:
callback := func(v float64) metricapi.Float64ObserverCallback {
return metricapi.Float64ObserverCallback(func(_ context.Context, result metricapi.Float64ObserverResult) { result.Observe(v, labels...) })
callback := func(v float64) metricapi.Float64ObserverFunc {
return metricapi.Float64ObserverFunc(func(_ context.Context, result metricapi.Float64ObserverResult) { result.Observe(v, labels...) })
}(float64(data.val))
metricapi.Must(meter).NewFloat64ValueObserver(name, callback)
default:
Expand Down

0 comments on commit 718ac5d

Please sign in to comment.