mirror of
https://github.com/hanzoai/telemetry.git
synced 2026-10-30 20:01:49 +00:00
This changes how to handle optional primitive fields, instead of using a
"oneof" like style, define a metadata for each message that for the
moment only contains information if the optional fields are present of
not.
Alternative considered to use a pointer to the value instead of "any"
that would reduce the size of the field from 16B to 8B but would keep an
extra allocation.
**Before:**
```
BenchmarkMarshalAndUnmarshal/empty
BenchmarkMarshalAndUnmarshal/empty-12 16115462 73.64 ns/op 224 B/op 1 allocs/op
BenchmarkMarshalAndUnmarshal/all
BenchmarkMarshalAndUnmarshal/all-12 1844172 641.0 ns/op 800 B/op 21 allocs/op
```
**After:**
```
BenchmarkMarshalAndUnmarshal/empty
BenchmarkMarshalAndUnmarshal/empty-12 18948967 62.91 ns/op 208 B/op 1 allocs/op
BenchmarkMarshalAndUnmarshal/all
BenchmarkMarshalAndUnmarshal/all-12 1914825 624.3 ns/op 760 B/op 18 allocs/op
```
**Bechmark code:**
```golang
func BenchmarkMarshalAndUnmarshal(b *testing.B) {
tests := map[string]*ExponentialHistogramDataPoint{
"empty": NewExponentialHistogramDataPoint(),
"all": GenTestExponentialHistogramDataPoint(),
}
for name, src := range tests {
b.Run(name, func(b *testing.B) {
buf := make([]byte, src.SizeProto())
b.ReportAllocs()
b.ResetTimer()
for b.Loop() {
gotSize := src.MarshalProto(buf)
if len(buf) != gotSize {
b.Fatalf("size mismatch: %d vs %d", len(buf), gotSize)
}
dest := NewExponentialHistogramDataPoint()
if err := dest.UnmarshalProto(buf); err != nil {
b.Fatal(err)
}
}
})
}
}
```
Signed-off-by: Bogdan Drutu <[email protected]>
225 lines
8.1 KiB
Go
225 lines
8.1 KiB
Go
// Copyright The OpenTelemetry Authors
|
|
// SPDX-License-Identifier: Apache-2.0
|
|
|
|
// Code generated by "internal/cmd/pdatagen/main.go". DO NOT EDIT.
|
|
// To regenerate this file run "make genpdata".
|
|
|
|
package pmetric
|
|
|
|
import (
|
|
"go.opentelemetry.io/collector/pdata/internal"
|
|
"go.opentelemetry.io/collector/pdata/pcommon"
|
|
)
|
|
|
|
// ExponentialHistogramDataPoint is a single data point in a timeseries that describes the
|
|
// time-varying values of a ExponentialHistogram of double values. A ExponentialHistogram contains
|
|
// summary statistics for a population of values, it may optionally contain the
|
|
// distribution of those values across a set of buckets.
|
|
//
|
|
// This is a reference type, if passed by value and callee modifies it the
|
|
// caller will see the modification.
|
|
//
|
|
// Must use NewExponentialHistogramDataPoint function to create new instances.
|
|
// Important: zero-initialized instance is not valid for use.
|
|
type ExponentialHistogramDataPoint struct {
|
|
orig *internal.ExponentialHistogramDataPoint
|
|
state *internal.State
|
|
}
|
|
|
|
func newExponentialHistogramDataPoint(orig *internal.ExponentialHistogramDataPoint, state *internal.State) ExponentialHistogramDataPoint {
|
|
return ExponentialHistogramDataPoint{orig: orig, state: state}
|
|
}
|
|
|
|
// NewExponentialHistogramDataPoint creates a new empty ExponentialHistogramDataPoint.
|
|
//
|
|
// This must be used only in testing code. Users should use "AppendEmpty" when part of a Slice,
|
|
// OR directly access the member if this is embedded in another struct.
|
|
func NewExponentialHistogramDataPoint() ExponentialHistogramDataPoint {
|
|
return newExponentialHistogramDataPoint(internal.NewExponentialHistogramDataPoint(), internal.NewState())
|
|
}
|
|
|
|
// MoveTo moves all properties from the current struct overriding the destination and
|
|
// resetting the current instance to its zero value
|
|
func (ms ExponentialHistogramDataPoint) MoveTo(dest ExponentialHistogramDataPoint) {
|
|
ms.state.AssertMutable()
|
|
dest.state.AssertMutable()
|
|
// If they point to the same data, they are the same, nothing to do.
|
|
if ms.orig == dest.orig {
|
|
return
|
|
}
|
|
internal.DeleteExponentialHistogramDataPoint(dest.orig, false)
|
|
*dest.orig, *ms.orig = *ms.orig, *dest.orig
|
|
}
|
|
|
|
// Attributes returns the Attributes associated with this ExponentialHistogramDataPoint.
|
|
func (ms ExponentialHistogramDataPoint) Attributes() pcommon.Map {
|
|
return pcommon.Map(internal.NewMapWrapper(&ms.orig.Attributes, ms.state))
|
|
}
|
|
|
|
// StartTimestamp returns the starttimestamp associated with this ExponentialHistogramDataPoint.
|
|
func (ms ExponentialHistogramDataPoint) StartTimestamp() pcommon.Timestamp {
|
|
return pcommon.Timestamp(ms.orig.StartTimeUnixNano)
|
|
}
|
|
|
|
// SetStartTimestamp replaces the starttimestamp associated with this ExponentialHistogramDataPoint.
|
|
func (ms ExponentialHistogramDataPoint) SetStartTimestamp(v pcommon.Timestamp) {
|
|
ms.state.AssertMutable()
|
|
ms.orig.StartTimeUnixNano = uint64(v)
|
|
}
|
|
|
|
// Timestamp returns the timestamp associated with this ExponentialHistogramDataPoint.
|
|
func (ms ExponentialHistogramDataPoint) Timestamp() pcommon.Timestamp {
|
|
return pcommon.Timestamp(ms.orig.TimeUnixNano)
|
|
}
|
|
|
|
// SetTimestamp replaces the timestamp associated with this ExponentialHistogramDataPoint.
|
|
func (ms ExponentialHistogramDataPoint) SetTimestamp(v pcommon.Timestamp) {
|
|
ms.state.AssertMutable()
|
|
ms.orig.TimeUnixNano = uint64(v)
|
|
}
|
|
|
|
// Count returns the count associated with this ExponentialHistogramDataPoint.
|
|
func (ms ExponentialHistogramDataPoint) Count() uint64 {
|
|
return ms.orig.Count
|
|
}
|
|
|
|
// SetCount replaces the count associated with this ExponentialHistogramDataPoint.
|
|
func (ms ExponentialHistogramDataPoint) SetCount(v uint64) {
|
|
ms.state.AssertMutable()
|
|
ms.orig.Count = v
|
|
}
|
|
|
|
// Sum returns the sum associated with this ExponentialHistogramDataPoint.
|
|
func (ms ExponentialHistogramDataPoint) Sum() float64 {
|
|
return ms.orig.Sum
|
|
}
|
|
|
|
// HasSum returns true if the ExponentialHistogramDataPoint contains a
|
|
// Sum value otherwise.
|
|
func (ms ExponentialHistogramDataPoint) HasSum() bool {
|
|
return ms.orig.HasSum()
|
|
}
|
|
|
|
// SetSum replaces the sum associated with this ExponentialHistogramDataPoint.
|
|
func (ms ExponentialHistogramDataPoint) SetSum(v float64) {
|
|
ms.state.AssertMutable()
|
|
ms.orig.SetSum(v)
|
|
}
|
|
|
|
// RemoveSum removes the sum associated with this ExponentialHistogramDataPoint.
|
|
func (ms ExponentialHistogramDataPoint) RemoveSum() {
|
|
ms.state.AssertMutable()
|
|
ms.orig.RemoveSum()
|
|
}
|
|
|
|
// Scale returns the scale associated with this ExponentialHistogramDataPoint.
|
|
func (ms ExponentialHistogramDataPoint) Scale() int32 {
|
|
return ms.orig.Scale
|
|
}
|
|
|
|
// SetScale replaces the scale associated with this ExponentialHistogramDataPoint.
|
|
func (ms ExponentialHistogramDataPoint) SetScale(v int32) {
|
|
ms.state.AssertMutable()
|
|
ms.orig.Scale = v
|
|
}
|
|
|
|
// ZeroCount returns the zerocount associated with this ExponentialHistogramDataPoint.
|
|
func (ms ExponentialHistogramDataPoint) ZeroCount() uint64 {
|
|
return ms.orig.ZeroCount
|
|
}
|
|
|
|
// SetZeroCount replaces the zerocount associated with this ExponentialHistogramDataPoint.
|
|
func (ms ExponentialHistogramDataPoint) SetZeroCount(v uint64) {
|
|
ms.state.AssertMutable()
|
|
ms.orig.ZeroCount = v
|
|
}
|
|
|
|
// Positive returns the positive associated with this ExponentialHistogramDataPoint.
|
|
func (ms ExponentialHistogramDataPoint) Positive() ExponentialHistogramDataPointBuckets {
|
|
return newExponentialHistogramDataPointBuckets(&ms.orig.Positive, ms.state)
|
|
}
|
|
|
|
// Negative returns the negative associated with this ExponentialHistogramDataPoint.
|
|
func (ms ExponentialHistogramDataPoint) Negative() ExponentialHistogramDataPointBuckets {
|
|
return newExponentialHistogramDataPointBuckets(&ms.orig.Negative, ms.state)
|
|
}
|
|
|
|
// Flags returns the flags associated with this ExponentialHistogramDataPoint.
|
|
func (ms ExponentialHistogramDataPoint) Flags() DataPointFlags {
|
|
return DataPointFlags(ms.orig.Flags)
|
|
}
|
|
|
|
// SetFlags replaces the flags associated with this ExponentialHistogramDataPoint.
|
|
func (ms ExponentialHistogramDataPoint) SetFlags(v DataPointFlags) {
|
|
ms.state.AssertMutable()
|
|
ms.orig.Flags = uint32(v)
|
|
}
|
|
|
|
// Exemplars returns the Exemplars associated with this ExponentialHistogramDataPoint.
|
|
func (ms ExponentialHistogramDataPoint) Exemplars() ExemplarSlice {
|
|
return newExemplarSlice(&ms.orig.Exemplars, ms.state)
|
|
}
|
|
|
|
// Min returns the min associated with this ExponentialHistogramDataPoint.
|
|
func (ms ExponentialHistogramDataPoint) Min() float64 {
|
|
return ms.orig.Min
|
|
}
|
|
|
|
// HasMin returns true if the ExponentialHistogramDataPoint contains a
|
|
// Min value otherwise.
|
|
func (ms ExponentialHistogramDataPoint) HasMin() bool {
|
|
return ms.orig.HasMin()
|
|
}
|
|
|
|
// SetMin replaces the min associated with this ExponentialHistogramDataPoint.
|
|
func (ms ExponentialHistogramDataPoint) SetMin(v float64) {
|
|
ms.state.AssertMutable()
|
|
ms.orig.SetMin(v)
|
|
}
|
|
|
|
// RemoveMin removes the min associated with this ExponentialHistogramDataPoint.
|
|
func (ms ExponentialHistogramDataPoint) RemoveMin() {
|
|
ms.state.AssertMutable()
|
|
ms.orig.RemoveMin()
|
|
}
|
|
|
|
// Max returns the max associated with this ExponentialHistogramDataPoint.
|
|
func (ms ExponentialHistogramDataPoint) Max() float64 {
|
|
return ms.orig.Max
|
|
}
|
|
|
|
// HasMax returns true if the ExponentialHistogramDataPoint contains a
|
|
// Max value otherwise.
|
|
func (ms ExponentialHistogramDataPoint) HasMax() bool {
|
|
return ms.orig.HasMax()
|
|
}
|
|
|
|
// SetMax replaces the max associated with this ExponentialHistogramDataPoint.
|
|
func (ms ExponentialHistogramDataPoint) SetMax(v float64) {
|
|
ms.state.AssertMutable()
|
|
ms.orig.SetMax(v)
|
|
}
|
|
|
|
// RemoveMax removes the max associated with this ExponentialHistogramDataPoint.
|
|
func (ms ExponentialHistogramDataPoint) RemoveMax() {
|
|
ms.state.AssertMutable()
|
|
ms.orig.RemoveMax()
|
|
}
|
|
|
|
// ZeroThreshold returns the zerothreshold associated with this ExponentialHistogramDataPoint.
|
|
func (ms ExponentialHistogramDataPoint) ZeroThreshold() float64 {
|
|
return ms.orig.ZeroThreshold
|
|
}
|
|
|
|
// SetZeroThreshold replaces the zerothreshold associated with this ExponentialHistogramDataPoint.
|
|
func (ms ExponentialHistogramDataPoint) SetZeroThreshold(v float64) {
|
|
ms.state.AssertMutable()
|
|
ms.orig.ZeroThreshold = v
|
|
}
|
|
|
|
// CopyTo copies all properties from the current struct overriding the destination.
|
|
func (ms ExponentialHistogramDataPoint) CopyTo(dest ExponentialHistogramDataPoint) {
|
|
dest.state.AssertMutable()
|
|
internal.CopyExponentialHistogramDataPoint(dest.orig, ms.orig)
|
|
}
|