1
0
mirror of https://github.com/open-telemetry/opentelemetry-go.git synced 2025-01-20 03:30:02 +02:00

Update metric types to not use pointer receivers (#462)

The methods on the `Float64Gauge`, `Int64Gauge`, `Float64Counter`,
`Int64Counter`, `Float64Measure`, and `Int64Measure` `struct`s do not
need to mutate the internal state of the `struct` and can therefore be
defined with value receivers instead. This aligns closer to the function
signatures of each instruments constructor function. Additionally, this
change means calls to these methods do not need an allocation to the
heap.

Resolves #440

Co-authored-by: Rahul Patel <rghetia@yahoo.com>
This commit is contained in:
Tyler Yahn 2020-02-04 10:27:03 -08:00 committed by GitHub
parent 942713a02d
commit 493e13f834
No known key found for this signature in database
GPG Key ID: 4AEE18F83AFDEB23
3 changed files with 24 additions and 24 deletions

View File

@ -51,7 +51,7 @@ type BoundInt64Counter struct {
// If the labels do not contain a value for the key specified in the
// counter with the WithKeys option, then the missing value will be
// treated as unspecified.
func (c *Float64Counter) Bind(labels LabelSet) (h BoundFloat64Counter) {
func (c Float64Counter) Bind(labels LabelSet) (h BoundFloat64Counter) {
h.commonBoundInstrument = c.bind(labels)
return
}
@ -63,20 +63,20 @@ func (c *Float64Counter) Bind(labels LabelSet) (h BoundFloat64Counter) {
// If the labels do not contain a value for the key specified in the
// counter with the WithKeys option, then the missing value will be
// treated as unspecified.
func (c *Int64Counter) Bind(labels LabelSet) (h BoundInt64Counter) {
func (c Int64Counter) Bind(labels LabelSet) (h BoundInt64Counter) {
h.commonBoundInstrument = c.bind(labels)
return
}
// Measurement creates a Measurement object to use with batch
// recording.
func (c *Float64Counter) Measurement(value float64) Measurement {
func (c Float64Counter) Measurement(value float64) Measurement {
return c.float64Measurement(value)
}
// Measurement creates a Measurement object to use with batch
// recording.
func (c *Int64Counter) Measurement(value int64) Measurement {
func (c Int64Counter) Measurement(value int64) Measurement {
return c.int64Measurement(value)
}
@ -87,7 +87,7 @@ func (c *Int64Counter) Measurement(value int64) Measurement {
// If the labels do not contain a value for the key specified in the
// counter with the WithKeys option, then the missing value will be
// treated as unspecified.
func (c *Float64Counter) Add(ctx context.Context, value float64, labels LabelSet) {
func (c Float64Counter) Add(ctx context.Context, value float64, labels LabelSet) {
c.directRecord(ctx, core.NewFloat64Number(value), labels)
}
@ -98,16 +98,16 @@ func (c *Float64Counter) Add(ctx context.Context, value float64, labels LabelSet
// If the labels do not contain a value for the key specified in the
// counter with the WithKeys option, then the missing value will be
// treated as unspecified.
func (c *Int64Counter) Add(ctx context.Context, value int64, labels LabelSet) {
func (c Int64Counter) Add(ctx context.Context, value int64, labels LabelSet) {
c.directRecord(ctx, core.NewInt64Number(value), labels)
}
// Add adds the value to the counter's sum.
func (b *BoundFloat64Counter) Add(ctx context.Context, value float64) {
func (b BoundFloat64Counter) Add(ctx context.Context, value float64) {
b.directRecord(ctx, core.NewFloat64Number(value))
}
// Add adds the value to the counter's sum.
func (b *BoundInt64Counter) Add(ctx context.Context, value int64) {
func (b BoundInt64Counter) Add(ctx context.Context, value int64) {
b.directRecord(ctx, core.NewInt64Number(value))
}

View File

@ -51,7 +51,7 @@ type BoundInt64Gauge struct {
// If the labels do not contain a value for the key specified in the
// gauge with the WithKeys option, then the missing value will be
// treated as unspecified.
func (g *Float64Gauge) Bind(labels LabelSet) (h BoundFloat64Gauge) {
func (g Float64Gauge) Bind(labels LabelSet) (h BoundFloat64Gauge) {
h.commonBoundInstrument = g.bind(labels)
return
}
@ -63,20 +63,20 @@ func (g *Float64Gauge) Bind(labels LabelSet) (h BoundFloat64Gauge) {
// If the labels do not contain a value for the key specified in the
// gauge with the WithKeys option, then the missing value will be
// treated as unspecified.
func (g *Int64Gauge) Bind(labels LabelSet) (h BoundInt64Gauge) {
func (g Int64Gauge) Bind(labels LabelSet) (h BoundInt64Gauge) {
h.commonBoundInstrument = g.bind(labels)
return
}
// Measurement creates a Measurement object to use with batch
// recording.
func (g *Float64Gauge) Measurement(value float64) Measurement {
func (g Float64Gauge) Measurement(value float64) Measurement {
return g.float64Measurement(value)
}
// Measurement creates a Measurement object to use with batch
// recording.
func (g *Int64Gauge) Measurement(value int64) Measurement {
func (g Int64Gauge) Measurement(value int64) Measurement {
return g.int64Measurement(value)
}
@ -87,7 +87,7 @@ func (g *Int64Gauge) Measurement(value int64) Measurement {
// If the labels do not contain a value for the key specified in the
// gauge with the WithKeys option, then the missing value will be
// treated as unspecified.
func (g *Float64Gauge) Set(ctx context.Context, value float64, labels LabelSet) {
func (g Float64Gauge) Set(ctx context.Context, value float64, labels LabelSet) {
g.directRecord(ctx, core.NewFloat64Number(value), labels)
}
@ -98,16 +98,16 @@ func (g *Float64Gauge) Set(ctx context.Context, value float64, labels LabelSet)
// If the labels do not contain a value for the key specified in the
// gauge with the WithKeys option, then the missing value will be
// treated as unspecified.
func (g *Int64Gauge) Set(ctx context.Context, value int64, labels LabelSet) {
func (g Int64Gauge) Set(ctx context.Context, value int64, labels LabelSet) {
g.directRecord(ctx, core.NewInt64Number(value), labels)
}
// Set assigns the passed value to the value of the gauge.
func (b *BoundFloat64Gauge) Set(ctx context.Context, value float64) {
func (b BoundFloat64Gauge) Set(ctx context.Context, value float64) {
b.directRecord(ctx, core.NewFloat64Number(value))
}
// Set assigns the passed value to the value of the gauge.
func (b *BoundInt64Gauge) Set(ctx context.Context, value int64) {
func (b BoundInt64Gauge) Set(ctx context.Context, value int64) {
b.directRecord(ctx, core.NewInt64Number(value))
}

View File

@ -51,7 +51,7 @@ type BoundInt64Measure struct {
// If the labels do not contain a value for the key specified in the
// measure with the WithKeys option, then the missing value will be
// treated as unspecified.
func (c *Float64Measure) Bind(labels LabelSet) (h BoundFloat64Measure) {
func (c Float64Measure) Bind(labels LabelSet) (h BoundFloat64Measure) {
h.commonBoundInstrument = c.bind(labels)
return
}
@ -63,20 +63,20 @@ func (c *Float64Measure) Bind(labels LabelSet) (h BoundFloat64Measure) {
// If the labels do not contain a value for the key specified in the
// measure with the WithKeys option, then the missing value will be
// treated as unspecified.
func (c *Int64Measure) Bind(labels LabelSet) (h BoundInt64Measure) {
func (c Int64Measure) Bind(labels LabelSet) (h BoundInt64Measure) {
h.commonBoundInstrument = c.bind(labels)
return
}
// Measurement creates a Measurement object to use with batch
// recording.
func (c *Float64Measure) Measurement(value float64) Measurement {
func (c Float64Measure) Measurement(value float64) Measurement {
return c.float64Measurement(value)
}
// Measurement creates a Measurement object to use with batch
// recording.
func (c *Int64Measure) Measurement(value int64) Measurement {
func (c Int64Measure) Measurement(value int64) Measurement {
return c.int64Measurement(value)
}
@ -87,7 +87,7 @@ func (c *Int64Measure) Measurement(value int64) Measurement {
// If the labels do not contain a value for the key specified in the
// measure with the WithKeys option, then the missing value will be
// treated as unspecified.
func (c *Float64Measure) Record(ctx context.Context, value float64, labels LabelSet) {
func (c Float64Measure) Record(ctx context.Context, value float64, labels LabelSet) {
c.directRecord(ctx, core.NewFloat64Number(value), labels)
}
@ -98,16 +98,16 @@ func (c *Float64Measure) Record(ctx context.Context, value float64, labels Label
// If the labels do not contain a value for the key specified in the
// measure with the WithKeys option, then the missing value will be
// treated as unspecified.
func (c *Int64Measure) Record(ctx context.Context, value int64, labels LabelSet) {
func (c Int64Measure) Record(ctx context.Context, value int64, labels LabelSet) {
c.directRecord(ctx, core.NewInt64Number(value), labels)
}
// Record adds a new value to the list of measure's records.
func (b *BoundFloat64Measure) Record(ctx context.Context, value float64) {
func (b BoundFloat64Measure) Record(ctx context.Context, value float64) {
b.directRecord(ctx, core.NewFloat64Number(value))
}
// Record adds a new value to the list of measure's records.
func (b *BoundInt64Measure) Record(ctx context.Context, value int64) {
func (b BoundInt64Measure) Record(ctx context.Context, value int64) {
b.directRecord(ctx, core.NewInt64Number(value))
}