diff --git a/cmd/pdatagen/internal/metrics_structs.go b/cmd/pdatagen/internal/metrics_structs.go index 507ae6ce3cc..142b02f0c8c 100644 --- a/cmd/pdatagen/internal/metrics_structs.go +++ b/cmd/pdatagen/internal/metrics_structs.go @@ -127,7 +127,7 @@ var metric = &messagePtrStruct{ }, } -var intGauge = &messagePtrStruct{ +var intGauge = &messageValueStruct{ structName: "IntGauge", description: "// IntGauge represents the type of a int scalar metric that always exports the \"current value\" for every data point.", originFullName: "otlpmetrics.IntGauge", @@ -140,7 +140,7 @@ var intGauge = &messagePtrStruct{ }, } -var doubleGauge = &messagePtrStruct{ +var doubleGauge = &messageValueStruct{ structName: "DoubleGauge", description: "// DoubleGauge represents the type of a double scalar metric that always exports the \"current value\" for every data point.", originFullName: "otlpmetrics.DoubleGauge", @@ -153,7 +153,7 @@ var doubleGauge = &messagePtrStruct{ }, } -var intSum = &messagePtrStruct{ +var intSum = &messageValueStruct{ structName: "IntSum", description: "// IntSum represents the type of a numeric int scalar metric that is calculated as a sum of all reported measurements over a time interval.", originFullName: "otlpmetrics.IntSum", @@ -168,7 +168,7 @@ var intSum = &messagePtrStruct{ }, } -var doubleSum = &messagePtrStruct{ +var doubleSum = &messageValueStruct{ structName: "DoubleSum", description: "// DoubleSum represents the type of a numeric double scalar metric that is calculated as a sum of all reported measurements over a time interval.", originFullName: "otlpmetrics.DoubleSum", @@ -183,7 +183,7 @@ var doubleSum = &messagePtrStruct{ }, } -var intHistogram = &messagePtrStruct{ +var intHistogram = &messageValueStruct{ structName: "IntHistogram", description: "// IntHistogram represents the type of a metric that is calculated by aggregating as a Histogram of all reported double measurements over a time interval.", originFullName: "otlpmetrics.IntHistogram", @@ -197,7 +197,7 @@ var intHistogram = &messagePtrStruct{ }, } -var doubleHistogram = &messagePtrStruct{ +var doubleHistogram = &messageValueStruct{ structName: "DoubleHistogram", description: "// DoubleHistogram represents the type of a metric that is calculated by aggregating as a Histogram of all reported double measurements over a time interval.", originFullName: "otlpmetrics.DoubleHistogram", @@ -211,7 +211,7 @@ var doubleHistogram = &messagePtrStruct{ }, } -var doubleSummary = &messagePtrStruct{ +var doubleSummary = &messageValueStruct{ structName: "DoubleSummary", description: "// DoubleSummary represents the type of a metric that is calculated by aggregating as a Summary of all reported double measurements over a time interval.", originFullName: "otlpmetrics.DoubleSummary", @@ -488,6 +488,6 @@ var aggregationTemporalityField = &primitiveTypedField{ var oneofDataField = &oneofField{ copyFuncName: "copyData", originFieldName: "Data", - testVal: "&otlpmetrics.Metric_IntGauge{}", + testVal: "&otlpmetrics.Metric_IntGauge{IntGauge: &otlpmetrics.IntGauge{}}", fillTestName: "IntGauge", } diff --git a/cmd/pdatagen/internal/trace_structs.go b/cmd/pdatagen/internal/trace_structs.go index 086e0c1ec88..3b70231cb2e 100644 --- a/cmd/pdatagen/internal/trace_structs.go +++ b/cmd/pdatagen/internal/trace_structs.go @@ -17,6 +17,7 @@ package internal var traceFile = &File{ Name: "trace", imports: []string{ + `"go.opentelemetry.io/collector/internal/data"`, `otlpcommon "go.opentelemetry.io/collector/internal/data/opentelemetry-proto-gen/common/v1"`, `otlptrace "go.opentelemetry.io/collector/internal/data/opentelemetry-proto-gen/trace/v1"`, }, @@ -217,7 +218,7 @@ var traceIDField = &primitiveTypedField{ fieldName: "TraceID", originFieldName: "TraceId", returnType: "TraceID", - rawType: "otlpcommon.TraceID", + rawType: "data.TraceID", defaultVal: "NewTraceID([16]byte{})", testVal: "NewTraceID([16]byte{1, 2, 3, 4, 5, 6, 7, 8, 8, 7, 6, 5, 4, 3, 2, 1})", } @@ -226,7 +227,7 @@ var spanIDField = &primitiveTypedField{ fieldName: "SpanID", originFieldName: "SpanId", returnType: "SpanID", - rawType: "otlpcommon.SpanID", + rawType: "data.SpanID", defaultVal: "NewSpanID([8]byte{})", testVal: "NewSpanID([8]byte{1, 2, 3, 4, 5, 6, 7, 8})", } @@ -235,7 +236,7 @@ var parentSpanIDField = &primitiveTypedField{ fieldName: "ParentSpanID", originFieldName: "ParentSpanId", returnType: "SpanID", - rawType: "otlpcommon.SpanID", + rawType: "data.SpanID", defaultVal: "NewSpanID([8]byte{})", testVal: "NewSpanID([8]byte{8, 7, 6, 5, 4, 3, 2, 1})", } diff --git a/consumer/pdata/generated_metrics.go b/consumer/pdata/generated_metrics.go index bca1c4c7894..814f5c4ff1c 100644 --- a/consumer/pdata/generated_metrics.go +++ b/consumer/pdata/generated_metrics.go @@ -601,33 +601,23 @@ func (ms Metric) CopyTo(dest Metric) { // Important: zero-initialized instance is not valid for use. type IntGauge struct { // orig points to the pointer otlpmetrics.IntGauge field contained somewhere else. - // We use pointer-to-pointer to be able to modify it in InitEmpty func. - orig **otlpmetrics.IntGauge + orig *otlpmetrics.IntGauge } -func newIntGauge(orig **otlpmetrics.IntGauge) IntGauge { - return IntGauge{orig} +func newIntGauge(orig *otlpmetrics.IntGauge) IntGauge { + return IntGauge{orig: orig} } -// NewIntGauge creates a new "nil" IntGauge. -// To initialize the struct call "InitEmpty". +// NewIntGauge creates a new empty IntGauge. // // This must be used only in testing code since no "Set" method available. func NewIntGauge() IntGauge { - orig := (*otlpmetrics.IntGauge)(nil) - return newIntGauge(&orig) + return newIntGauge(&otlpmetrics.IntGauge{}) } -// InitEmpty overwrites the current value with empty. +// Deprecated: This function will be removed soon. func (ms IntGauge) InitEmpty() { - *ms.orig = &otlpmetrics.IntGauge{} -} - -// IsNil returns true if the underlying data are nil. -// -// Important: All other functions will cause a runtime error if this returns "true". -func (ms IntGauge) IsNil() bool { - return *ms.orig == nil + *ms.orig = otlpmetrics.IntGauge{} } // DataPoints returns the DataPoints associated with this IntGauge. @@ -639,13 +629,6 @@ func (ms IntGauge) DataPoints() IntDataPointSlice { // CopyTo copies all properties from the current struct to the dest. func (ms IntGauge) CopyTo(dest IntGauge) { - if ms.IsNil() { - *dest.orig = nil - return - } - if dest.IsNil() { - dest.InitEmpty() - } ms.DataPoints().CopyTo(dest.DataPoints()) } @@ -658,33 +641,23 @@ func (ms IntGauge) CopyTo(dest IntGauge) { // Important: zero-initialized instance is not valid for use. type DoubleGauge struct { // orig points to the pointer otlpmetrics.DoubleGauge field contained somewhere else. - // We use pointer-to-pointer to be able to modify it in InitEmpty func. - orig **otlpmetrics.DoubleGauge + orig *otlpmetrics.DoubleGauge } -func newDoubleGauge(orig **otlpmetrics.DoubleGauge) DoubleGauge { - return DoubleGauge{orig} +func newDoubleGauge(orig *otlpmetrics.DoubleGauge) DoubleGauge { + return DoubleGauge{orig: orig} } -// NewDoubleGauge creates a new "nil" DoubleGauge. -// To initialize the struct call "InitEmpty". +// NewDoubleGauge creates a new empty DoubleGauge. // // This must be used only in testing code since no "Set" method available. func NewDoubleGauge() DoubleGauge { - orig := (*otlpmetrics.DoubleGauge)(nil) - return newDoubleGauge(&orig) + return newDoubleGauge(&otlpmetrics.DoubleGauge{}) } -// InitEmpty overwrites the current value with empty. +// Deprecated: This function will be removed soon. func (ms DoubleGauge) InitEmpty() { - *ms.orig = &otlpmetrics.DoubleGauge{} -} - -// IsNil returns true if the underlying data are nil. -// -// Important: All other functions will cause a runtime error if this returns "true". -func (ms DoubleGauge) IsNil() bool { - return *ms.orig == nil + *ms.orig = otlpmetrics.DoubleGauge{} } // DataPoints returns the DataPoints associated with this DoubleGauge. @@ -696,13 +669,6 @@ func (ms DoubleGauge) DataPoints() DoubleDataPointSlice { // CopyTo copies all properties from the current struct to the dest. func (ms DoubleGauge) CopyTo(dest DoubleGauge) { - if ms.IsNil() { - *dest.orig = nil - return - } - if dest.IsNil() { - dest.InitEmpty() - } ms.DataPoints().CopyTo(dest.DataPoints()) } @@ -715,33 +681,23 @@ func (ms DoubleGauge) CopyTo(dest DoubleGauge) { // Important: zero-initialized instance is not valid for use. type IntSum struct { // orig points to the pointer otlpmetrics.IntSum field contained somewhere else. - // We use pointer-to-pointer to be able to modify it in InitEmpty func. - orig **otlpmetrics.IntSum + orig *otlpmetrics.IntSum } -func newIntSum(orig **otlpmetrics.IntSum) IntSum { - return IntSum{orig} +func newIntSum(orig *otlpmetrics.IntSum) IntSum { + return IntSum{orig: orig} } -// NewIntSum creates a new "nil" IntSum. -// To initialize the struct call "InitEmpty". +// NewIntSum creates a new empty IntSum. // // This must be used only in testing code since no "Set" method available. func NewIntSum() IntSum { - orig := (*otlpmetrics.IntSum)(nil) - return newIntSum(&orig) + return newIntSum(&otlpmetrics.IntSum{}) } -// InitEmpty overwrites the current value with empty. +// Deprecated: This function will be removed soon. func (ms IntSum) InitEmpty() { - *ms.orig = &otlpmetrics.IntSum{} -} - -// IsNil returns true if the underlying data are nil. -// -// Important: All other functions will cause a runtime error if this returns "true". -func (ms IntSum) IsNil() bool { - return *ms.orig == nil + *ms.orig = otlpmetrics.IntSum{} } // AggregationTemporality returns the aggregationtemporality associated with this IntSum. @@ -781,13 +737,6 @@ func (ms IntSum) DataPoints() IntDataPointSlice { // CopyTo copies all properties from the current struct to the dest. func (ms IntSum) CopyTo(dest IntSum) { - if ms.IsNil() { - *dest.orig = nil - return - } - if dest.IsNil() { - dest.InitEmpty() - } dest.SetAggregationTemporality(ms.AggregationTemporality()) dest.SetIsMonotonic(ms.IsMonotonic()) ms.DataPoints().CopyTo(dest.DataPoints()) @@ -802,33 +751,23 @@ func (ms IntSum) CopyTo(dest IntSum) { // Important: zero-initialized instance is not valid for use. type DoubleSum struct { // orig points to the pointer otlpmetrics.DoubleSum field contained somewhere else. - // We use pointer-to-pointer to be able to modify it in InitEmpty func. - orig **otlpmetrics.DoubleSum + orig *otlpmetrics.DoubleSum } -func newDoubleSum(orig **otlpmetrics.DoubleSum) DoubleSum { - return DoubleSum{orig} +func newDoubleSum(orig *otlpmetrics.DoubleSum) DoubleSum { + return DoubleSum{orig: orig} } -// NewDoubleSum creates a new "nil" DoubleSum. -// To initialize the struct call "InitEmpty". +// NewDoubleSum creates a new empty DoubleSum. // // This must be used only in testing code since no "Set" method available. func NewDoubleSum() DoubleSum { - orig := (*otlpmetrics.DoubleSum)(nil) - return newDoubleSum(&orig) + return newDoubleSum(&otlpmetrics.DoubleSum{}) } -// InitEmpty overwrites the current value with empty. +// Deprecated: This function will be removed soon. func (ms DoubleSum) InitEmpty() { - *ms.orig = &otlpmetrics.DoubleSum{} -} - -// IsNil returns true if the underlying data are nil. -// -// Important: All other functions will cause a runtime error if this returns "true". -func (ms DoubleSum) IsNil() bool { - return *ms.orig == nil + *ms.orig = otlpmetrics.DoubleSum{} } // AggregationTemporality returns the aggregationtemporality associated with this DoubleSum. @@ -868,13 +807,6 @@ func (ms DoubleSum) DataPoints() DoubleDataPointSlice { // CopyTo copies all properties from the current struct to the dest. func (ms DoubleSum) CopyTo(dest DoubleSum) { - if ms.IsNil() { - *dest.orig = nil - return - } - if dest.IsNil() { - dest.InitEmpty() - } dest.SetAggregationTemporality(ms.AggregationTemporality()) dest.SetIsMonotonic(ms.IsMonotonic()) ms.DataPoints().CopyTo(dest.DataPoints()) @@ -889,33 +821,23 @@ func (ms DoubleSum) CopyTo(dest DoubleSum) { // Important: zero-initialized instance is not valid for use. type IntHistogram struct { // orig points to the pointer otlpmetrics.IntHistogram field contained somewhere else. - // We use pointer-to-pointer to be able to modify it in InitEmpty func. - orig **otlpmetrics.IntHistogram + orig *otlpmetrics.IntHistogram } -func newIntHistogram(orig **otlpmetrics.IntHistogram) IntHistogram { - return IntHistogram{orig} +func newIntHistogram(orig *otlpmetrics.IntHistogram) IntHistogram { + return IntHistogram{orig: orig} } -// NewIntHistogram creates a new "nil" IntHistogram. -// To initialize the struct call "InitEmpty". +// NewIntHistogram creates a new empty IntHistogram. // // This must be used only in testing code since no "Set" method available. func NewIntHistogram() IntHistogram { - orig := (*otlpmetrics.IntHistogram)(nil) - return newIntHistogram(&orig) + return newIntHistogram(&otlpmetrics.IntHistogram{}) } -// InitEmpty overwrites the current value with empty. +// Deprecated: This function will be removed soon. func (ms IntHistogram) InitEmpty() { - *ms.orig = &otlpmetrics.IntHistogram{} -} - -// IsNil returns true if the underlying data are nil. -// -// Important: All other functions will cause a runtime error if this returns "true". -func (ms IntHistogram) IsNil() bool { - return *ms.orig == nil + *ms.orig = otlpmetrics.IntHistogram{} } // AggregationTemporality returns the aggregationtemporality associated with this IntHistogram. @@ -941,13 +863,6 @@ func (ms IntHistogram) DataPoints() IntHistogramDataPointSlice { // CopyTo copies all properties from the current struct to the dest. func (ms IntHistogram) CopyTo(dest IntHistogram) { - if ms.IsNil() { - *dest.orig = nil - return - } - if dest.IsNil() { - dest.InitEmpty() - } dest.SetAggregationTemporality(ms.AggregationTemporality()) ms.DataPoints().CopyTo(dest.DataPoints()) } @@ -961,33 +876,23 @@ func (ms IntHistogram) CopyTo(dest IntHistogram) { // Important: zero-initialized instance is not valid for use. type DoubleHistogram struct { // orig points to the pointer otlpmetrics.DoubleHistogram field contained somewhere else. - // We use pointer-to-pointer to be able to modify it in InitEmpty func. - orig **otlpmetrics.DoubleHistogram + orig *otlpmetrics.DoubleHistogram } -func newDoubleHistogram(orig **otlpmetrics.DoubleHistogram) DoubleHistogram { - return DoubleHistogram{orig} +func newDoubleHistogram(orig *otlpmetrics.DoubleHistogram) DoubleHistogram { + return DoubleHistogram{orig: orig} } -// NewDoubleHistogram creates a new "nil" DoubleHistogram. -// To initialize the struct call "InitEmpty". +// NewDoubleHistogram creates a new empty DoubleHistogram. // // This must be used only in testing code since no "Set" method available. func NewDoubleHistogram() DoubleHistogram { - orig := (*otlpmetrics.DoubleHistogram)(nil) - return newDoubleHistogram(&orig) + return newDoubleHistogram(&otlpmetrics.DoubleHistogram{}) } -// InitEmpty overwrites the current value with empty. +// Deprecated: This function will be removed soon. func (ms DoubleHistogram) InitEmpty() { - *ms.orig = &otlpmetrics.DoubleHistogram{} -} - -// IsNil returns true if the underlying data are nil. -// -// Important: All other functions will cause a runtime error if this returns "true". -func (ms DoubleHistogram) IsNil() bool { - return *ms.orig == nil + *ms.orig = otlpmetrics.DoubleHistogram{} } // AggregationTemporality returns the aggregationtemporality associated with this DoubleHistogram. @@ -1013,13 +918,6 @@ func (ms DoubleHistogram) DataPoints() DoubleHistogramDataPointSlice { // CopyTo copies all properties from the current struct to the dest. func (ms DoubleHistogram) CopyTo(dest DoubleHistogram) { - if ms.IsNil() { - *dest.orig = nil - return - } - if dest.IsNil() { - dest.InitEmpty() - } dest.SetAggregationTemporality(ms.AggregationTemporality()) ms.DataPoints().CopyTo(dest.DataPoints()) } @@ -1033,33 +931,23 @@ func (ms DoubleHistogram) CopyTo(dest DoubleHistogram) { // Important: zero-initialized instance is not valid for use. type DoubleSummary struct { // orig points to the pointer otlpmetrics.DoubleSummary field contained somewhere else. - // We use pointer-to-pointer to be able to modify it in InitEmpty func. - orig **otlpmetrics.DoubleSummary + orig *otlpmetrics.DoubleSummary } -func newDoubleSummary(orig **otlpmetrics.DoubleSummary) DoubleSummary { - return DoubleSummary{orig} +func newDoubleSummary(orig *otlpmetrics.DoubleSummary) DoubleSummary { + return DoubleSummary{orig: orig} } -// NewDoubleSummary creates a new "nil" DoubleSummary. -// To initialize the struct call "InitEmpty". +// NewDoubleSummary creates a new empty DoubleSummary. // // This must be used only in testing code since no "Set" method available. func NewDoubleSummary() DoubleSummary { - orig := (*otlpmetrics.DoubleSummary)(nil) - return newDoubleSummary(&orig) + return newDoubleSummary(&otlpmetrics.DoubleSummary{}) } -// InitEmpty overwrites the current value with empty. +// Deprecated: This function will be removed soon. func (ms DoubleSummary) InitEmpty() { - *ms.orig = &otlpmetrics.DoubleSummary{} -} - -// IsNil returns true if the underlying data are nil. -// -// Important: All other functions will cause a runtime error if this returns "true". -func (ms DoubleSummary) IsNil() bool { - return *ms.orig == nil + *ms.orig = otlpmetrics.DoubleSummary{} } // DataPoints returns the DataPoints associated with this DoubleSummary. @@ -1071,13 +959,6 @@ func (ms DoubleSummary) DataPoints() DoubleSummaryDataPointSlice { // CopyTo copies all properties from the current struct to the dest. func (ms DoubleSummary) CopyTo(dest DoubleSummary) { - if ms.IsNil() { - *dest.orig = nil - return - } - if dest.IsNil() { - dest.InitEmpty() - } ms.DataPoints().CopyTo(dest.DataPoints()) } diff --git a/consumer/pdata/generated_metrics_test.go b/consumer/pdata/generated_metrics_test.go index 8ff0e45fb15..4166fde6c3c 100644 --- a/consumer/pdata/generated_metrics_test.go +++ b/consumer/pdata/generated_metrics_test.go @@ -486,17 +486,8 @@ func TestMetric_Unit(t *testing.T) { assert.EqualValues(t, testValUnit, ms.Unit()) } -func TestIntGauge_InitEmpty(t *testing.T) { - ms := NewIntGauge() - assert.True(t, ms.IsNil()) - ms.InitEmpty() - assert.False(t, ms.IsNil()) -} - func TestIntGauge_CopyTo(t *testing.T) { ms := NewIntGauge() - NewIntGauge().CopyTo(ms) - assert.True(t, ms.IsNil()) generateTestIntGauge().CopyTo(ms) assert.EqualValues(t, generateTestIntGauge(), ms) } @@ -510,17 +501,8 @@ func TestIntGauge_DataPoints(t *testing.T) { assert.EqualValues(t, testValDataPoints, ms.DataPoints()) } -func TestDoubleGauge_InitEmpty(t *testing.T) { - ms := NewDoubleGauge() - assert.True(t, ms.IsNil()) - ms.InitEmpty() - assert.False(t, ms.IsNil()) -} - func TestDoubleGauge_CopyTo(t *testing.T) { ms := NewDoubleGauge() - NewDoubleGauge().CopyTo(ms) - assert.True(t, ms.IsNil()) generateTestDoubleGauge().CopyTo(ms) assert.EqualValues(t, generateTestDoubleGauge(), ms) } @@ -534,17 +516,8 @@ func TestDoubleGauge_DataPoints(t *testing.T) { assert.EqualValues(t, testValDataPoints, ms.DataPoints()) } -func TestIntSum_InitEmpty(t *testing.T) { - ms := NewIntSum() - assert.True(t, ms.IsNil()) - ms.InitEmpty() - assert.False(t, ms.IsNil()) -} - func TestIntSum_CopyTo(t *testing.T) { ms := NewIntSum() - NewIntSum().CopyTo(ms) - assert.True(t, ms.IsNil()) generateTestIntSum().CopyTo(ms) assert.EqualValues(t, generateTestIntSum(), ms) } @@ -576,17 +549,8 @@ func TestIntSum_DataPoints(t *testing.T) { assert.EqualValues(t, testValDataPoints, ms.DataPoints()) } -func TestDoubleSum_InitEmpty(t *testing.T) { - ms := NewDoubleSum() - assert.True(t, ms.IsNil()) - ms.InitEmpty() - assert.False(t, ms.IsNil()) -} - func TestDoubleSum_CopyTo(t *testing.T) { ms := NewDoubleSum() - NewDoubleSum().CopyTo(ms) - assert.True(t, ms.IsNil()) generateTestDoubleSum().CopyTo(ms) assert.EqualValues(t, generateTestDoubleSum(), ms) } @@ -618,17 +582,8 @@ func TestDoubleSum_DataPoints(t *testing.T) { assert.EqualValues(t, testValDataPoints, ms.DataPoints()) } -func TestIntHistogram_InitEmpty(t *testing.T) { - ms := NewIntHistogram() - assert.True(t, ms.IsNil()) - ms.InitEmpty() - assert.False(t, ms.IsNil()) -} - func TestIntHistogram_CopyTo(t *testing.T) { ms := NewIntHistogram() - NewIntHistogram().CopyTo(ms) - assert.True(t, ms.IsNil()) generateTestIntHistogram().CopyTo(ms) assert.EqualValues(t, generateTestIntHistogram(), ms) } @@ -651,17 +606,8 @@ func TestIntHistogram_DataPoints(t *testing.T) { assert.EqualValues(t, testValDataPoints, ms.DataPoints()) } -func TestDoubleHistogram_InitEmpty(t *testing.T) { - ms := NewDoubleHistogram() - assert.True(t, ms.IsNil()) - ms.InitEmpty() - assert.False(t, ms.IsNil()) -} - func TestDoubleHistogram_CopyTo(t *testing.T) { ms := NewDoubleHistogram() - NewDoubleHistogram().CopyTo(ms) - assert.True(t, ms.IsNil()) generateTestDoubleHistogram().CopyTo(ms) assert.EqualValues(t, generateTestDoubleHistogram(), ms) } @@ -684,17 +630,8 @@ func TestDoubleHistogram_DataPoints(t *testing.T) { assert.EqualValues(t, testValDataPoints, ms.DataPoints()) } -func TestDoubleSummary_InitEmpty(t *testing.T) { - ms := NewDoubleSummary() - assert.True(t, ms.IsNil()) - ms.InitEmpty() - assert.False(t, ms.IsNil()) -} - func TestDoubleSummary_CopyTo(t *testing.T) { ms := NewDoubleSummary() - NewDoubleSummary().CopyTo(ms) - assert.True(t, ms.IsNil()) generateTestDoubleSummary().CopyTo(ms) assert.EqualValues(t, generateTestDoubleSummary(), ms) } @@ -2207,14 +2144,13 @@ func fillTestMetric(tv Metric) { tv.SetName("test_name") tv.SetDescription("test_description") tv.SetUnit("1") - (*tv.orig).Data = &otlpmetrics.Metric_IntGauge{} + (*tv.orig).Data = &otlpmetrics.Metric_IntGauge{IntGauge: &otlpmetrics.IntGauge{}} tv.IntGauge().InitEmpty() fillTestIntGauge(tv.IntGauge()) } func generateTestIntGauge() IntGauge { tv := NewIntGauge() - tv.InitEmpty() fillTestIntGauge(tv) return tv } @@ -2225,7 +2161,6 @@ func fillTestIntGauge(tv IntGauge) { func generateTestDoubleGauge() DoubleGauge { tv := NewDoubleGauge() - tv.InitEmpty() fillTestDoubleGauge(tv) return tv } @@ -2236,7 +2171,6 @@ func fillTestDoubleGauge(tv DoubleGauge) { func generateTestIntSum() IntSum { tv := NewIntSum() - tv.InitEmpty() fillTestIntSum(tv) return tv } @@ -2249,7 +2183,6 @@ func fillTestIntSum(tv IntSum) { func generateTestDoubleSum() DoubleSum { tv := NewDoubleSum() - tv.InitEmpty() fillTestDoubleSum(tv) return tv } @@ -2262,7 +2195,6 @@ func fillTestDoubleSum(tv DoubleSum) { func generateTestIntHistogram() IntHistogram { tv := NewIntHistogram() - tv.InitEmpty() fillTestIntHistogram(tv) return tv } @@ -2274,7 +2206,6 @@ func fillTestIntHistogram(tv IntHistogram) { func generateTestDoubleHistogram() DoubleHistogram { tv := NewDoubleHistogram() - tv.InitEmpty() fillTestDoubleHistogram(tv) return tv } @@ -2286,7 +2217,6 @@ func fillTestDoubleHistogram(tv DoubleHistogram) { func generateTestDoubleSummary() DoubleSummary { tv := NewDoubleSummary() - tv.InitEmpty() fillTestDoubleSummary(tv) return tv } diff --git a/consumer/pdata/metric.go b/consumer/pdata/metric.go index c54684c48ee..cfa33d3e1dc 100644 --- a/consumer/pdata/metric.go +++ b/consumer/pdata/metric.go @@ -147,34 +147,16 @@ func (md Metrics) MetricAndDataPointCount() (metricCount int, dataPointCount int } switch m.DataType() { case MetricDataTypeIntGauge: - if m.IntGauge().IsNil() { - continue - } dataPointCount += m.IntGauge().DataPoints().Len() case MetricDataTypeDoubleGauge: - if m.DoubleGauge().IsNil() { - continue - } dataPointCount += m.DoubleGauge().DataPoints().Len() case MetricDataTypeIntSum: - if m.IntSum().IsNil() { - continue - } dataPointCount += m.IntSum().DataPoints().Len() case MetricDataTypeDoubleSum: - if m.DoubleSum().IsNil() { - continue - } dataPointCount += m.DoubleSum().DataPoints().Len() case MetricDataTypeIntHistogram: - if m.IntHistogram().IsNil() { - continue - } dataPointCount += m.IntHistogram().DataPoints().Len() case MetricDataTypeDoubleHistogram: - if m.DoubleHistogram().IsNil() { - continue - } dataPointCount += m.DoubleHistogram().DataPoints().Len() case MetricDataTypeDoubleSummary: dataPointCount += m.DoubleSummary().DataPoints().Len() @@ -248,19 +230,19 @@ func (ms Metric) DataType() MetricDataType { func (ms Metric) SetDataType(ty MetricDataType) { switch ty { case MetricDataTypeIntGauge: - (*ms.orig).Data = &otlpmetrics.Metric_IntGauge{} + (*ms.orig).Data = &otlpmetrics.Metric_IntGauge{IntGauge: &otlpmetrics.IntGauge{}} case MetricDataTypeDoubleGauge: - (*ms.orig).Data = &otlpmetrics.Metric_DoubleGauge{} + (*ms.orig).Data = &otlpmetrics.Metric_DoubleGauge{DoubleGauge: &otlpmetrics.DoubleGauge{}} case MetricDataTypeIntSum: - (*ms.orig).Data = &otlpmetrics.Metric_IntSum{} + (*ms.orig).Data = &otlpmetrics.Metric_IntSum{IntSum: &otlpmetrics.IntSum{}} case MetricDataTypeDoubleSum: - (*ms.orig).Data = &otlpmetrics.Metric_DoubleSum{} + (*ms.orig).Data = &otlpmetrics.Metric_DoubleSum{DoubleSum: &otlpmetrics.DoubleSum{}} case MetricDataTypeIntHistogram: - (*ms.orig).Data = &otlpmetrics.Metric_IntHistogram{} + (*ms.orig).Data = &otlpmetrics.Metric_IntHistogram{IntHistogram: &otlpmetrics.IntHistogram{}} case MetricDataTypeDoubleHistogram: - (*ms.orig).Data = &otlpmetrics.Metric_DoubleHistogram{} + (*ms.orig).Data = &otlpmetrics.Metric_DoubleHistogram{DoubleHistogram: &otlpmetrics.DoubleHistogram{}} case MetricDataTypeDoubleSummary: - (*ms.orig).Data = &otlpmetrics.Metric_DoubleSummary{} + (*ms.orig).Data = &otlpmetrics.Metric_DoubleSummary{DoubleSummary: &otlpmetrics.DoubleSummary{}} } } @@ -268,80 +250,80 @@ func (ms Metric) SetDataType(ty MetricDataType) { // Calling this function when DataType() != MetricDataTypeIntGauge will cause a panic. // Calling this function on zero-initialized Metric will cause a panic. func (ms Metric) IntGauge() IntGauge { - return newIntGauge(&(*ms.orig).Data.(*otlpmetrics.Metric_IntGauge).IntGauge) + return newIntGauge((*ms.orig).Data.(*otlpmetrics.Metric_IntGauge).IntGauge) } // DoubleGauge returns the data as DoubleGauge. // Calling this function when DataType() != MetricDataTypeDoubleGauge will cause a panic. // Calling this function on zero-initialized Metric will cause a panic. func (ms Metric) DoubleGauge() DoubleGauge { - return newDoubleGauge(&(*ms.orig).Data.(*otlpmetrics.Metric_DoubleGauge).DoubleGauge) + return newDoubleGauge((*ms.orig).Data.(*otlpmetrics.Metric_DoubleGauge).DoubleGauge) } // IntSum returns the data as IntSum. // Calling this function when DataType() != MetricDataTypeIntSum will cause a panic. // Calling this function on zero-initialized Metric will cause a panic. func (ms Metric) IntSum() IntSum { - return newIntSum(&(*ms.orig).Data.(*otlpmetrics.Metric_IntSum).IntSum) + return newIntSum((*ms.orig).Data.(*otlpmetrics.Metric_IntSum).IntSum) } // DoubleSum returns the data as DoubleSum. // Calling this function when DataType() != MetricDataTypeDoubleSum will cause a panic. // Calling this function on zero-initialized Metric will cause a panic. func (ms Metric) DoubleSum() DoubleSum { - return newDoubleSum(&(*ms.orig).Data.(*otlpmetrics.Metric_DoubleSum).DoubleSum) + return newDoubleSum((*ms.orig).Data.(*otlpmetrics.Metric_DoubleSum).DoubleSum) } // IntHistogram returns the data as IntHistogram. // Calling this function when DataType() != MetricDataTypeIntHistogram will cause a panic. // Calling this function on zero-initialized Metric will cause a panic. func (ms Metric) IntHistogram() IntHistogram { - return newIntHistogram(&(*ms.orig).Data.(*otlpmetrics.Metric_IntHistogram).IntHistogram) + return newIntHistogram((*ms.orig).Data.(*otlpmetrics.Metric_IntHistogram).IntHistogram) } // DoubleHistogram returns the data as DoubleHistogram. // Calling this function when DataType() != MetricDataTypeDoubleHistogram will cause a panic. // Calling this function on zero-initialized Metric will cause a panic. func (ms Metric) DoubleHistogram() DoubleHistogram { - return newDoubleHistogram(&(*ms.orig).Data.(*otlpmetrics.Metric_DoubleHistogram).DoubleHistogram) + return newDoubleHistogram((*ms.orig).Data.(*otlpmetrics.Metric_DoubleHistogram).DoubleHistogram) } // DoubleSummary returns the data as DoubleSummary. // Calling this function when DataType() != MetricDataTypeDoubleSummary will cause a panic. // Calling this function on zero-initialized Metric will cause a panic. func (ms Metric) DoubleSummary() DoubleSummary { - return newDoubleSummary(&(*ms.orig).Data.(*otlpmetrics.Metric_DoubleSummary).DoubleSummary) + return newDoubleSummary((*ms.orig).Data.(*otlpmetrics.Metric_DoubleSummary).DoubleSummary) } func copyData(src, dest *otlpmetrics.Metric) { switch srcData := (src).Data.(type) { case *otlpmetrics.Metric_IntGauge: - data := &otlpmetrics.Metric_IntGauge{} - newIntGauge(&srcData.IntGauge).CopyTo(newIntGauge(&data.IntGauge)) + data := &otlpmetrics.Metric_IntGauge{IntGauge: &otlpmetrics.IntGauge{}} + newIntGauge(srcData.IntGauge).CopyTo(newIntGauge(data.IntGauge)) dest.Data = data case *otlpmetrics.Metric_DoubleGauge: - data := &otlpmetrics.Metric_DoubleGauge{} - newDoubleGauge(&srcData.DoubleGauge).CopyTo(newDoubleGauge(&data.DoubleGauge)) + data := &otlpmetrics.Metric_DoubleGauge{DoubleGauge: &otlpmetrics.DoubleGauge{}} + newDoubleGauge(srcData.DoubleGauge).CopyTo(newDoubleGauge(data.DoubleGauge)) dest.Data = data case *otlpmetrics.Metric_IntSum: - data := &otlpmetrics.Metric_IntSum{} - newIntSum(&srcData.IntSum).CopyTo(newIntSum(&data.IntSum)) + data := &otlpmetrics.Metric_IntSum{IntSum: &otlpmetrics.IntSum{}} + newIntSum(srcData.IntSum).CopyTo(newIntSum(data.IntSum)) dest.Data = data case *otlpmetrics.Metric_DoubleSum: - data := &otlpmetrics.Metric_DoubleSum{} - newDoubleSum(&srcData.DoubleSum).CopyTo(newDoubleSum(&data.DoubleSum)) + data := &otlpmetrics.Metric_DoubleSum{DoubleSum: &otlpmetrics.DoubleSum{}} + newDoubleSum(srcData.DoubleSum).CopyTo(newDoubleSum(data.DoubleSum)) dest.Data = data case *otlpmetrics.Metric_IntHistogram: - data := &otlpmetrics.Metric_IntHistogram{} - newIntHistogram(&srcData.IntHistogram).CopyTo(newIntHistogram(&data.IntHistogram)) + data := &otlpmetrics.Metric_IntHistogram{IntHistogram: &otlpmetrics.IntHistogram{}} + newIntHistogram(srcData.IntHistogram).CopyTo(newIntHistogram(data.IntHistogram)) dest.Data = data case *otlpmetrics.Metric_DoubleHistogram: - data := &otlpmetrics.Metric_DoubleHistogram{} - newDoubleHistogram(&srcData.DoubleHistogram).CopyTo(newDoubleHistogram(&data.DoubleHistogram)) + data := &otlpmetrics.Metric_DoubleHistogram{DoubleHistogram: &otlpmetrics.DoubleHistogram{}} + newDoubleHistogram(srcData.DoubleHistogram).CopyTo(newDoubleHistogram(data.DoubleHistogram)) dest.Data = data case *otlpmetrics.Metric_DoubleSummary: - data := &otlpmetrics.Metric_DoubleSummary{} - newDoubleSummary(&srcData.DoubleSummary).CopyTo(newDoubleSummary(&data.DoubleSummary)) + data := &otlpmetrics.Metric_DoubleSummary{DoubleSummary: &otlpmetrics.DoubleSummary{}} + newDoubleSummary(srcData.DoubleSummary).CopyTo(newDoubleSummary(data.DoubleSummary)) dest.Data = data } } diff --git a/consumer/pdata/metric_test.go b/consumer/pdata/metric_test.go index a84127863a7..8d93505c5aa 100644 --- a/consumer/pdata/metric_test.go +++ b/consumer/pdata/metric_test.go @@ -105,22 +105,16 @@ func TestDataType(t *testing.T) { assert.Equal(t, MetricDataTypeNone, m.DataType()) m.SetDataType(MetricDataTypeIntGauge) assert.Equal(t, MetricDataTypeIntGauge, m.DataType()) - assert.True(t, m.IntGauge().IsNil()) m.SetDataType(MetricDataTypeDoubleGauge) assert.Equal(t, MetricDataTypeDoubleGauge, m.DataType()) - assert.True(t, m.DoubleGauge().IsNil()) m.SetDataType(MetricDataTypeIntSum) assert.Equal(t, MetricDataTypeIntSum, m.DataType()) - assert.True(t, m.IntSum().IsNil()) m.SetDataType(MetricDataTypeDoubleSum) assert.Equal(t, MetricDataTypeDoubleSum, m.DataType()) - assert.True(t, m.DoubleSum().IsNil()) m.SetDataType(MetricDataTypeIntHistogram) assert.Equal(t, MetricDataTypeIntHistogram, m.DataType()) - assert.True(t, m.IntHistogram().IsNil()) m.SetDataType(MetricDataTypeDoubleHistogram) assert.Equal(t, MetricDataTypeDoubleHistogram, m.DataType()) - assert.True(t, m.DoubleHistogram().IsNil()) m.InitEmpty() assert.Equal(t, MetricDataTypeNone, m.DataType()) } diff --git a/consumer/simple/metrics.go b/consumer/simple/metrics.go index 1e195e0dfdd..14cc8cab03f 100644 --- a/consumer/simple/metrics.go +++ b/consumer/simple/metrics.go @@ -238,9 +238,6 @@ func (mb *Metrics) addDataPoint(name string, typ pdata.MetricDataType, val inter switch typ { case pdata.MetricDataTypeIntGauge: m := metric.IntGauge() - if m.IsNil() { - m.InitEmpty() - } dps := m.DataPoints() dp := pdata.NewIntDataPoint() dp.InitEmpty() @@ -251,9 +248,6 @@ func (mb *Metrics) addDataPoint(name string, typ pdata.MetricDataType, val inter case pdata.MetricDataTypeIntSum: m := metric.IntSum() - if m.IsNil() { - m.InitEmpty() - } dps := m.DataPoints() dp := pdata.NewIntDataPoint() dp.InitEmpty() @@ -264,9 +258,6 @@ func (mb *Metrics) addDataPoint(name string, typ pdata.MetricDataType, val inter case pdata.MetricDataTypeDoubleGauge: m := metric.DoubleGauge() - if m.IsNil() { - m.InitEmpty() - } dps := m.DataPoints() dp := pdata.NewDoubleDataPoint() dp.InitEmpty() @@ -277,9 +268,6 @@ func (mb *Metrics) addDataPoint(name string, typ pdata.MetricDataType, val inter case pdata.MetricDataTypeDoubleSum: m := metric.DoubleSum() - if m.IsNil() { - m.InitEmpty() - } dps := m.DataPoints() dp := pdata.NewDoubleDataPoint() dp.InitEmpty() @@ -290,9 +278,6 @@ func (mb *Metrics) addDataPoint(name string, typ pdata.MetricDataType, val inter case pdata.MetricDataTypeIntHistogram: m := metric.IntHistogram() - if m.IsNil() { - m.InitEmpty() - } dps := m.DataPoints() dp := pdata.NewIntHistogramDataPoint() dp.InitEmpty() @@ -303,9 +288,6 @@ func (mb *Metrics) addDataPoint(name string, typ pdata.MetricDataType, val inter case pdata.MetricDataTypeDoubleHistogram: m := metric.DoubleHistogram() - if m.IsNil() { - m.InitEmpty() - } dps := m.DataPoints() dp := pdata.NewDoubleHistogramDataPoint() dp.InitEmpty() diff --git a/consumer/simple/metrics_test.go b/consumer/simple/metrics_test.go index fa294300a11..70c3f6e1359 100644 --- a/consumer/simple/metrics_test.go +++ b/consumer/simple/metrics_test.go @@ -498,7 +498,6 @@ func BenchmarkPdataMetrics(b *testing.B) { metric.SetName("gauge" + strconv.Itoa(i)) metric.SetDataType(pdata.MetricDataTypeIntGauge) mAsType := metric.IntGauge() - mAsType.InitEmpty() dps := mAsType.DataPoints() dps.Resize(2) { diff --git a/internal/data/testdata/metric.go b/internal/data/testdata/metric.go index 0d4e66c4c91..1e2a4654497 100644 --- a/internal/data/testdata/metric.go +++ b/internal/data/testdata/metric.go @@ -656,31 +656,20 @@ func initMetric(m pdata.Metric, name string, ty pdata.MetricDataType) { m.SetUnit("1") m.SetDataType(ty) switch ty { - case pdata.MetricDataTypeIntGauge: - m.IntGauge().InitEmpty() - case pdata.MetricDataTypeDoubleGauge: - m.DoubleGauge().InitEmpty() case pdata.MetricDataTypeIntSum: sum := m.IntSum() - sum.InitEmpty() sum.SetIsMonotonic(true) sum.SetAggregationTemporality(pdata.AggregationTemporalityCumulative) case pdata.MetricDataTypeDoubleSum: sum := m.DoubleSum() - sum.InitEmpty() sum.SetIsMonotonic(true) sum.SetAggregationTemporality(pdata.AggregationTemporalityCumulative) case pdata.MetricDataTypeIntHistogram: histo := m.IntHistogram() - histo.InitEmpty() histo.SetAggregationTemporality(pdata.AggregationTemporalityCumulative) case pdata.MetricDataTypeDoubleHistogram: histo := m.DoubleHistogram() - histo.InitEmpty() histo.SetAggregationTemporality(pdata.AggregationTemporalityCumulative) - case pdata.MetricDataTypeDoubleSummary: - summary := m.DoubleSummary() - summary.InitEmpty() } } diff --git a/internal/goldendataset/metric_gen.go b/internal/goldendataset/metric_gen.go index 14983ed20f9..bfcb4466d39 100644 --- a/internal/goldendataset/metric_gen.go +++ b/internal/goldendataset/metric_gen.go @@ -123,36 +123,30 @@ func (g *metricGenerator) populateMetrics(cfg MetricCfg, ilm pdata.Instrumentati switch cfg.MetricDescriptorType { case pdata.MetricDataTypeIntGauge: metric.SetDataType(pdata.MetricDataTypeIntGauge) - metric.IntGauge().InitEmpty() populateIntPoints(cfg, metric.IntGauge().DataPoints()) case pdata.MetricDataTypeDoubleGauge: metric.SetDataType(pdata.MetricDataTypeDoubleGauge) - metric.DoubleGauge().InitEmpty() populateDoublePoints(cfg, metric.DoubleGauge().DataPoints()) case pdata.MetricDataTypeIntSum: metric.SetDataType(pdata.MetricDataTypeIntSum) sum := metric.IntSum() - sum.InitEmpty() sum.SetIsMonotonic(cfg.IsMonotonicSum) sum.SetAggregationTemporality(pdata.AggregationTemporalityCumulative) populateIntPoints(cfg, sum.DataPoints()) case pdata.MetricDataTypeDoubleSum: metric.SetDataType(pdata.MetricDataTypeDoubleSum) sum := metric.DoubleSum() - sum.InitEmpty() sum.SetIsMonotonic(cfg.IsMonotonicSum) sum.SetAggregationTemporality(pdata.AggregationTemporalityCumulative) populateDoublePoints(cfg, sum.DataPoints()) case pdata.MetricDataTypeIntHistogram: metric.SetDataType(pdata.MetricDataTypeIntHistogram) histo := metric.IntHistogram() - histo.InitEmpty() histo.SetAggregationTemporality(pdata.AggregationTemporalityCumulative) populateIntHistogram(cfg, histo) case pdata.MetricDataTypeDoubleHistogram: metric.SetDataType(pdata.MetricDataTypeDoubleHistogram) histo := metric.DoubleHistogram() - histo.InitEmpty() histo.SetAggregationTemporality(pdata.AggregationTemporalityCumulative) populateDoubleHistogram(cfg, histo) } diff --git a/internal/processor/filterexpr/matcher.go b/internal/processor/filterexpr/matcher.go index bc0a1b82c94..18c74b25995 100644 --- a/internal/processor/filterexpr/matcher.go +++ b/internal/processor/filterexpr/matcher.go @@ -62,9 +62,6 @@ func (m *Matcher) MatchMetric(metric pdata.Metric) (bool, error) { } func (m *Matcher) matchIntGauge(metricName string, gauge pdata.IntGauge) (bool, error) { - if gauge.IsNil() { - return false, nil - } pts := gauge.DataPoints() for i := 0; i < pts.Len(); i++ { pt := pts.At(i) @@ -83,9 +80,6 @@ func (m *Matcher) matchIntGauge(metricName string, gauge pdata.IntGauge) (bool, } func (m *Matcher) matchDoubleGauge(metricName string, gauge pdata.DoubleGauge) (bool, error) { - if gauge.IsNil() { - return false, nil - } pts := gauge.DataPoints() for i := 0; i < pts.Len(); i++ { pt := pts.At(i) @@ -104,9 +98,6 @@ func (m *Matcher) matchDoubleGauge(metricName string, gauge pdata.DoubleGauge) ( } func (m *Matcher) matchDoubleSum(metricName string, sum pdata.DoubleSum) (bool, error) { - if sum.IsNil() { - return false, nil - } pts := sum.DataPoints() for i := 0; i < pts.Len(); i++ { pt := pts.At(i) @@ -125,9 +116,6 @@ func (m *Matcher) matchDoubleSum(metricName string, sum pdata.DoubleSum) (bool, } func (m *Matcher) matchIntSum(metricName string, sum pdata.IntSum) (bool, error) { - if sum.IsNil() { - return false, nil - } pts := sum.DataPoints() for i := 0; i < pts.Len(); i++ { pt := pts.At(i) @@ -146,9 +134,6 @@ func (m *Matcher) matchIntSum(metricName string, sum pdata.IntSum) (bool, error) } func (m *Matcher) matchIntHistogram(metricName string, histogram pdata.IntHistogram) (bool, error) { - if histogram.IsNil() { - return false, nil - } pts := histogram.DataPoints() for i := 0; i < pts.Len(); i++ { pt := pts.At(i) @@ -167,9 +152,6 @@ func (m *Matcher) matchIntHistogram(metricName string, histogram pdata.IntHistog } func (m *Matcher) matchDoubleHistogram(metricName string, histogram pdata.DoubleHistogram) (bool, error) { - if histogram.IsNil() { - return false, nil - } pts := histogram.DataPoints() for i := 0; i < pts.Len(); i++ { pt := pts.At(i) diff --git a/internal/processor/filterexpr/matcher_test.go b/internal/processor/filterexpr/matcher_test.go index 1f8a0e76b8a..3d6b0208bdf 100644 --- a/internal/processor/filterexpr/matcher_test.go +++ b/internal/processor/filterexpr/matcher_test.go @@ -96,9 +96,7 @@ func TestIntGaugeNilDataPoint(t *testing.T) { m.InitEmpty() m.SetName("my.metric") m.SetDataType(pdata.MetricDataTypeIntGauge) - gauge := m.IntGauge() - gauge.InitEmpty() - dps := gauge.DataPoints() + dps := m.IntGauge().DataPoints() pt := pdata.NewIntDataPoint() dps.Append(pt) matched, err := matcher.MatchMetric(m) @@ -113,9 +111,7 @@ func TestDoubleGaugeNilDataPoint(t *testing.T) { m.InitEmpty() m.SetName("my.metric") m.SetDataType(pdata.MetricDataTypeDoubleGauge) - gauge := m.DoubleGauge() - gauge.InitEmpty() - dps := gauge.DataPoints() + dps := m.DoubleGauge().DataPoints() pt := pdata.NewDoubleDataPoint() dps.Append(pt) matched, err := matcher.MatchMetric(m) @@ -130,9 +126,7 @@ func TestDoubleSumNilDataPoint(t *testing.T) { m.InitEmpty() m.SetName("my.metric") m.SetDataType(pdata.MetricDataTypeDoubleSum) - sum := m.DoubleSum() - sum.InitEmpty() - dps := sum.DataPoints() + dps := m.DoubleSum().DataPoints() pt := pdata.NewDoubleDataPoint() dps.Append(pt) matched, err := matcher.MatchMetric(m) @@ -147,9 +141,7 @@ func TestIntSumNilDataPoint(t *testing.T) { m.InitEmpty() m.SetName("my.metric") m.SetDataType(pdata.MetricDataTypeIntSum) - sum := m.IntSum() - sum.InitEmpty() - dps := sum.DataPoints() + dps := m.IntSum().DataPoints() pt := pdata.NewIntDataPoint() dps.Append(pt) matched, err := matcher.MatchMetric(m) @@ -164,9 +156,7 @@ func TestIntHistogramNilDataPoint(t *testing.T) { m.InitEmpty() m.SetName("my.metric") m.SetDataType(pdata.MetricDataTypeIntHistogram) - h := m.IntHistogram() - h.InitEmpty() - dps := h.DataPoints() + dps := m.IntHistogram().DataPoints() pt := pdata.NewIntHistogramDataPoint() dps.Append(pt) matched, err := matcher.MatchMetric(m) @@ -181,9 +171,7 @@ func TestDoubleHistogramNilDataPoint(t *testing.T) { m.InitEmpty() m.SetName("my.metric") m.SetDataType(pdata.MetricDataTypeDoubleHistogram) - h := m.DoubleHistogram() - h.InitEmpty() - dps := h.DataPoints() + dps := m.DoubleHistogram().DataPoints() pt := pdata.NewDoubleHistogramDataPoint() dps.Append(pt) matched, err := matcher.MatchMetric(m) @@ -228,9 +216,7 @@ func testMatchIntGauge(t *testing.T, metricName, expression string, lbls map[str m.InitEmpty() m.SetName(metricName) m.SetDataType(pdata.MetricDataTypeIntGauge) - gauge := m.IntGauge() - gauge.InitEmpty() - dps := gauge.DataPoints() + dps := m.IntGauge().DataPoints() pt := pdata.NewIntDataPoint() pt.InitEmpty() if lbls != nil { @@ -251,9 +237,7 @@ func TestMatchIntGaugeDataPointByMetricAndSecondPointLabelValue(t *testing.T) { m.InitEmpty() m.SetName("my.metric") m.SetDataType(pdata.MetricDataTypeIntGauge) - gauge := m.IntGauge() - gauge.InitEmpty() - dps := gauge.DataPoints() + dps := m.IntGauge().DataPoints() pt1 := pdata.NewIntDataPoint() pt1.InitEmpty() @@ -285,9 +269,7 @@ func testMatchDoubleGauge(t *testing.T, metricName string) bool { m.InitEmpty() m.SetName(metricName) m.SetDataType(pdata.MetricDataTypeDoubleGauge) - gauge := m.DoubleGauge() - gauge.InitEmpty() - dps := gauge.DataPoints() + dps := m.DoubleGauge().DataPoints() pt := pdata.NewDoubleDataPoint() pt.InitEmpty() dps.Append(pt) @@ -311,9 +293,7 @@ func matchDoubleSum(t *testing.T, metricName string) bool { m.InitEmpty() m.SetName(metricName) m.SetDataType(pdata.MetricDataTypeDoubleSum) - sum := m.DoubleSum() - sum.InitEmpty() - dps := sum.DataPoints() + dps := m.DoubleSum().DataPoints() pt := pdata.NewDoubleDataPoint() pt.InitEmpty() dps.Append(pt) @@ -337,9 +317,7 @@ func matchIntSum(t *testing.T, metricName string) bool { m.InitEmpty() m.SetName(metricName) m.SetDataType(pdata.MetricDataTypeIntSum) - sum := m.IntSum() - sum.InitEmpty() - dps := sum.DataPoints() + dps := m.IntSum().DataPoints() pt := pdata.NewIntDataPoint() pt.InitEmpty() dps.Append(pt) @@ -363,9 +341,7 @@ func matchIntHistogram(t *testing.T, metricName string) bool { m.InitEmpty() m.SetName(metricName) m.SetDataType(pdata.MetricDataTypeIntHistogram) - sum := m.IntHistogram() - sum.InitEmpty() - dps := sum.DataPoints() + dps := m.IntHistogram().DataPoints() pt := pdata.NewIntHistogramDataPoint() pt.InitEmpty() dps.Append(pt) @@ -389,9 +365,7 @@ func matchDoubleHistogram(t *testing.T, metricName string) bool { m.InitEmpty() m.SetName(metricName) m.SetDataType(pdata.MetricDataTypeDoubleHistogram) - sum := m.DoubleHistogram() - sum.InitEmpty() - dps := sum.DataPoints() + dps := m.DoubleHistogram().DataPoints() pt := pdata.NewDoubleHistogramDataPoint() pt.InitEmpty() dps.Append(pt) diff --git a/receiver/hostmetricsreceiver/internal/metadata/generated_metrics.go b/receiver/hostmetricsreceiver/internal/metadata/generated_metrics.go index c15aa358ec6..871416e75c4 100644 --- a/receiver/hostmetricsreceiver/internal/metadata/generated_metrics.go +++ b/receiver/hostmetricsreceiver/internal/metadata/generated_metrics.go @@ -85,7 +85,6 @@ var Metrics = &metricStruct{ metric.SetUnit("s") metric.SetDataType(pdata.MetricDataTypeDoubleSum) data := metric.DoubleSum() - data.InitEmpty() data.SetIsMonotonic(true) data.SetAggregationTemporality(pdata.AggregationTemporalityCumulative) @@ -102,7 +101,6 @@ var Metrics = &metricStruct{ metric.SetUnit("By") metric.SetDataType(pdata.MetricDataTypeIntSum) data := metric.IntSum() - data.InitEmpty() data.SetIsMonotonic(false) data.SetAggregationTemporality(pdata.AggregationTemporalityCumulative) diff --git a/receiver/hostmetricsreceiver/internal/scraper/diskscraper/disk_metadata.go b/receiver/hostmetricsreceiver/internal/scraper/diskscraper/disk_metadata.go index 2eec56716ff..8fdcda49895 100644 --- a/receiver/hostmetricsreceiver/internal/scraper/diskscraper/disk_metadata.go +++ b/receiver/hostmetricsreceiver/internal/scraper/diskscraper/disk_metadata.go @@ -42,7 +42,6 @@ var diskIODescriptor = func() pdata.Metric { metric.SetUnit("bytes") metric.SetDataType(pdata.MetricDataTypeIntSum) sum := metric.IntSum() - sum.InitEmpty() sum.SetIsMonotonic(true) sum.SetAggregationTemporality(pdata.AggregationTemporalityCumulative) return metric @@ -56,7 +55,6 @@ var diskOpsDescriptor = func() pdata.Metric { metric.SetUnit("1") metric.SetDataType(pdata.MetricDataTypeIntSum) sum := metric.IntSum() - sum.InitEmpty() sum.SetIsMonotonic(true) sum.SetAggregationTemporality(pdata.AggregationTemporalityCumulative) return metric @@ -70,7 +68,6 @@ var diskIOTimeDescriptor = func() pdata.Metric { metric.SetUnit("s") metric.SetDataType(pdata.MetricDataTypeDoubleSum) sum := metric.DoubleSum() - sum.InitEmpty() sum.SetIsMonotonic(true) sum.SetAggregationTemporality(pdata.AggregationTemporalityCumulative) return metric @@ -84,7 +81,6 @@ var diskOperationTimeDescriptor = func() pdata.Metric { metric.SetUnit("s") metric.SetDataType(pdata.MetricDataTypeDoubleSum) sum := metric.DoubleSum() - sum.InitEmpty() sum.SetIsMonotonic(true) sum.SetAggregationTemporality(pdata.AggregationTemporalityCumulative) return metric @@ -98,7 +94,6 @@ var diskPendingOperationsDescriptor = func() pdata.Metric { metric.SetUnit("1") metric.SetDataType(pdata.MetricDataTypeIntSum) sum := metric.IntSum() - sum.InitEmpty() sum.SetIsMonotonic(false) sum.SetAggregationTemporality(pdata.AggregationTemporalityCumulative) return metric @@ -112,7 +107,6 @@ var diskMergedDescriptor = func() pdata.Metric { metric.SetUnit("1") metric.SetDataType(pdata.MetricDataTypeIntSum) sum := metric.IntSum() - sum.InitEmpty() sum.SetIsMonotonic(true) sum.SetAggregationTemporality(pdata.AggregationTemporalityCumulative) return metric diff --git a/receiver/hostmetricsreceiver/internal/scraper/filesystemscraper/filesystem_metadata.go b/receiver/hostmetricsreceiver/internal/scraper/filesystemscraper/filesystem_metadata.go index fc3810edb01..a3e9747384c 100644 --- a/receiver/hostmetricsreceiver/internal/scraper/filesystemscraper/filesystem_metadata.go +++ b/receiver/hostmetricsreceiver/internal/scraper/filesystemscraper/filesystem_metadata.go @@ -46,7 +46,6 @@ var fileSystemUsageDescriptor = func() pdata.Metric { metric.SetUnit("bytes") metric.SetDataType(pdata.MetricDataTypeIntSum) sum := metric.IntSum() - sum.InitEmpty() sum.SetIsMonotonic(false) sum.SetAggregationTemporality(pdata.AggregationTemporalityCumulative) return metric @@ -60,7 +59,6 @@ var fileSystemINodesUsageDescriptor = func() pdata.Metric { metric.SetUnit("1") metric.SetDataType(pdata.MetricDataTypeIntSum) sum := metric.IntSum() - sum.InitEmpty() sum.SetIsMonotonic(false) sum.SetAggregationTemporality(pdata.AggregationTemporalityCumulative) return metric diff --git a/receiver/hostmetricsreceiver/internal/scraper/loadscraper/load_metadata.go b/receiver/hostmetricsreceiver/internal/scraper/loadscraper/load_metadata.go index 6e1b182609b..c807cab5c15 100644 --- a/receiver/hostmetricsreceiver/internal/scraper/loadscraper/load_metadata.go +++ b/receiver/hostmetricsreceiver/internal/scraper/loadscraper/load_metadata.go @@ -27,7 +27,6 @@ var loadAvg1MDescriptor = func() pdata.Metric { metric.SetDescription("Average CPU Load over 1 minute.") metric.SetUnit("1") metric.SetDataType(pdata.MetricDataTypeDoubleGauge) - metric.DoubleGauge().InitEmpty() return metric }() @@ -38,7 +37,6 @@ var loadAvg5mDescriptor = func() pdata.Metric { metric.SetDescription("Average CPU Load over 5 minutes.") metric.SetUnit("1") metric.SetDataType(pdata.MetricDataTypeDoubleGauge) - metric.DoubleGauge().InitEmpty() return metric }() @@ -49,6 +47,5 @@ var loadAvg15mDescriptor = func() pdata.Metric { metric.SetDescription("Average CPU Load over 15 minutes.") metric.SetUnit("1") metric.SetDataType(pdata.MetricDataTypeDoubleGauge) - metric.DoubleGauge().InitEmpty() return metric }() diff --git a/receiver/hostmetricsreceiver/internal/scraper/networkscraper/network_metadata.go b/receiver/hostmetricsreceiver/internal/scraper/networkscraper/network_metadata.go index 352a1a90c97..eebcdaed676 100644 --- a/receiver/hostmetricsreceiver/internal/scraper/networkscraper/network_metadata.go +++ b/receiver/hostmetricsreceiver/internal/scraper/networkscraper/network_metadata.go @@ -43,7 +43,6 @@ var networkPacketsDescriptor = func() pdata.Metric { metric.SetUnit("1") metric.SetDataType(pdata.MetricDataTypeIntSum) sum := metric.IntSum() - sum.InitEmpty() sum.SetIsMonotonic(true) sum.SetAggregationTemporality(pdata.AggregationTemporalityCumulative) return metric @@ -57,7 +56,6 @@ var networkDroppedPacketsDescriptor = func() pdata.Metric { metric.SetUnit("1") metric.SetDataType(pdata.MetricDataTypeIntSum) sum := metric.IntSum() - sum.InitEmpty() sum.SetIsMonotonic(true) sum.SetAggregationTemporality(pdata.AggregationTemporalityCumulative) return metric @@ -71,7 +69,6 @@ var networkErrorsDescriptor = func() pdata.Metric { metric.SetUnit("1") metric.SetDataType(pdata.MetricDataTypeIntSum) sum := metric.IntSum() - sum.InitEmpty() sum.SetIsMonotonic(true) sum.SetAggregationTemporality(pdata.AggregationTemporalityCumulative) return metric @@ -85,7 +82,6 @@ var networkIODescriptor = func() pdata.Metric { metric.SetUnit("bytes") metric.SetDataType(pdata.MetricDataTypeIntSum) sum := metric.IntSum() - sum.InitEmpty() sum.SetIsMonotonic(true) sum.SetAggregationTemporality(pdata.AggregationTemporalityCumulative) return metric @@ -99,7 +95,6 @@ var networkTCPConnectionsDescriptor = func() pdata.Metric { metric.SetUnit("bytes") metric.SetDataType(pdata.MetricDataTypeIntSum) sum := metric.IntSum() - sum.InitEmpty() sum.SetIsMonotonic(false) sum.SetAggregationTemporality(pdata.AggregationTemporalityCumulative) return metric diff --git a/receiver/hostmetricsreceiver/internal/scraper/processesscraper/processes_metadata.go b/receiver/hostmetricsreceiver/internal/scraper/processesscraper/processes_metadata.go index faaef4899bb..483f6376299 100644 --- a/receiver/hostmetricsreceiver/internal/scraper/processesscraper/processes_metadata.go +++ b/receiver/hostmetricsreceiver/internal/scraper/processesscraper/processes_metadata.go @@ -28,7 +28,6 @@ var processesRunningDescriptor = func() pdata.Metric { metric.SetUnit("1") metric.SetDataType(pdata.MetricDataTypeIntSum) sum := metric.IntSum() - sum.InitEmpty() sum.SetIsMonotonic(false) sum.SetAggregationTemporality(pdata.AggregationTemporalityCumulative) return metric @@ -42,7 +41,6 @@ var processesBlockedDescriptor = func() pdata.Metric { metric.SetUnit("1") metric.SetDataType(pdata.MetricDataTypeIntSum) sum := metric.IntSum() - sum.InitEmpty() sum.SetIsMonotonic(false) sum.SetAggregationTemporality(pdata.AggregationTemporalityCumulative) return metric diff --git a/receiver/hostmetricsreceiver/internal/scraper/processscraper/process_metadata.go b/receiver/hostmetricsreceiver/internal/scraper/processscraper/process_metadata.go index fc02c106de4..8d055f26a13 100644 --- a/receiver/hostmetricsreceiver/internal/scraper/processscraper/process_metadata.go +++ b/receiver/hostmetricsreceiver/internal/scraper/processscraper/process_metadata.go @@ -50,7 +50,6 @@ var cpuTimeDescriptor = func() pdata.Metric { metric.SetUnit("s") metric.SetDataType(pdata.MetricDataTypeDoubleSum) sum := metric.DoubleSum() - sum.InitEmpty() sum.SetIsMonotonic(true) sum.SetAggregationTemporality(pdata.AggregationTemporalityCumulative) return metric @@ -64,7 +63,6 @@ var physicalMemoryUsageDescriptor = func() pdata.Metric { metric.SetUnit("bytes") metric.SetDataType(pdata.MetricDataTypeIntSum) sum := metric.IntSum() - sum.InitEmpty() sum.SetIsMonotonic(false) sum.SetAggregationTemporality(pdata.AggregationTemporalityCumulative) return metric @@ -78,7 +76,6 @@ var virtualMemoryUsageDescriptor = func() pdata.Metric { metric.SetUnit("bytes") metric.SetDataType(pdata.MetricDataTypeIntSum) sum := metric.IntSum() - sum.InitEmpty() sum.SetIsMonotonic(false) sum.SetAggregationTemporality(pdata.AggregationTemporalityCumulative) return metric @@ -92,7 +89,6 @@ var diskIODescriptor = func() pdata.Metric { metric.SetUnit("bytes") metric.SetDataType(pdata.MetricDataTypeIntSum) sum := metric.IntSum() - sum.InitEmpty() sum.SetIsMonotonic(true) sum.SetAggregationTemporality(pdata.AggregationTemporalityCumulative) return metric diff --git a/receiver/hostmetricsreceiver/internal/scraper/swapscraper/swap_metadata.go b/receiver/hostmetricsreceiver/internal/scraper/swapscraper/swap_metadata.go index 5437e1ff9f4..f491b2bbdbc 100644 --- a/receiver/hostmetricsreceiver/internal/scraper/swapscraper/swap_metadata.go +++ b/receiver/hostmetricsreceiver/internal/scraper/swapscraper/swap_metadata.go @@ -57,7 +57,6 @@ var swapUsageDescriptor = func() pdata.Metric { metric.SetUnit("bytes") metric.SetDataType(pdata.MetricDataTypeIntSum) sum := metric.IntSum() - sum.InitEmpty() sum.SetIsMonotonic(false) sum.SetAggregationTemporality(pdata.AggregationTemporalityCumulative) return metric @@ -71,7 +70,6 @@ var swapPagingDescriptor = func() pdata.Metric { metric.SetUnit("1") metric.SetDataType(pdata.MetricDataTypeIntSum) sum := metric.IntSum() - sum.InitEmpty() sum.SetIsMonotonic(true) sum.SetAggregationTemporality(pdata.AggregationTemporalityCumulative) return metric @@ -85,7 +83,6 @@ var swapPageFaultsDescriptor = func() pdata.Metric { metric.SetUnit("1") metric.SetDataType(pdata.MetricDataTypeIntSum) sum := metric.IntSum() - sum.InitEmpty() sum.SetIsMonotonic(true) sum.SetAggregationTemporality(pdata.AggregationTemporalityCumulative) return metric diff --git a/receiver/scraperhelper/scrapercontroller_test.go b/receiver/scraperhelper/scrapercontroller_test.go index ca629bb6e2a..6218e1f6c4c 100644 --- a/receiver/scraperhelper/scrapercontroller_test.go +++ b/receiver/scraperhelper/scrapercontroller_test.go @@ -403,7 +403,6 @@ func singleMetric() pdata.MetricSlice { metrics := pdata.NewMetricSlice() metrics.Resize(1) metrics.At(0).SetDataType(pdata.MetricDataTypeIntGauge) - metrics.At(0).IntGauge().InitEmpty() metrics.At(0).IntGauge().DataPoints().Resize(1) return metrics } diff --git a/testbed/testbed/data_providers.go b/testbed/testbed/data_providers.go index b6cae106458..dc3902bc51f 100644 --- a/testbed/testbed/data_providers.go +++ b/testbed/testbed/data_providers.go @@ -139,15 +139,14 @@ func (dp *PerfTestDataProvider) GenerateMetrics() (pdata.Metrics, bool) { metric.SetDescription("Load Generator Counter #" + strconv.Itoa(i)) metric.SetUnit("1") metric.SetDataType(pdata.MetricDataTypeIntGauge) - gauge := metric.IntGauge() - gauge.InitEmpty() batchIndex := dp.batchesGenerated.Inc() + dps := metric.IntGauge().DataPoints() // Generate data points for the metric. - gauge.DataPoints().Resize(dataPointsPerMetric) + dps.Resize(dataPointsPerMetric) for j := 0; j < dataPointsPerMetric; j++ { - dataPoint := gauge.DataPoints().At(j) + dataPoint := dps.At(j) dataPoint.SetStartTime(pdata.TimestampUnixNano(uint64(time.Now().UnixNano()))) value := dp.dataItemsGenerated.Inc() dataPoint.SetValue(int64(value)) diff --git a/translator/internaldata/oc_to_metrics.go b/translator/internaldata/oc_to_metrics.go index 33af8143d22..5318c5ac57d 100644 --- a/translator/internaldata/oc_to_metrics.go +++ b/translator/internaldata/oc_to_metrics.go @@ -193,18 +193,15 @@ func descriptorTypeToMetrics(t ocmetrics.MetricDescriptor_Type, metric pdata.Met case ocmetrics.MetricDescriptor_GAUGE_INT64: metric.InitEmpty() metric.SetDataType(pdata.MetricDataTypeIntGauge) - metric.IntGauge().InitEmpty() return pdata.MetricDataTypeIntGauge case ocmetrics.MetricDescriptor_GAUGE_DOUBLE: metric.InitEmpty() metric.SetDataType(pdata.MetricDataTypeDoubleGauge) - metric.DoubleGauge().InitEmpty() return pdata.MetricDataTypeDoubleGauge case ocmetrics.MetricDescriptor_CUMULATIVE_INT64: metric.InitEmpty() metric.SetDataType(pdata.MetricDataTypeIntSum) sum := metric.IntSum() - sum.InitEmpty() sum.SetIsMonotonic(true) sum.SetAggregationTemporality(pdata.AggregationTemporalityCumulative) return pdata.MetricDataTypeIntSum @@ -212,7 +209,6 @@ func descriptorTypeToMetrics(t ocmetrics.MetricDescriptor_Type, metric pdata.Met metric.InitEmpty() metric.SetDataType(pdata.MetricDataTypeDoubleSum) sum := metric.DoubleSum() - sum.InitEmpty() sum.SetIsMonotonic(true) sum.SetAggregationTemporality(pdata.AggregationTemporalityCumulative) return pdata.MetricDataTypeDoubleSum @@ -220,14 +216,11 @@ func descriptorTypeToMetrics(t ocmetrics.MetricDescriptor_Type, metric pdata.Met metric.InitEmpty() metric.SetDataType(pdata.MetricDataTypeDoubleHistogram) histo := metric.DoubleHistogram() - histo.InitEmpty() histo.SetAggregationTemporality(pdata.AggregationTemporalityCumulative) return pdata.MetricDataTypeDoubleHistogram case ocmetrics.MetricDescriptor_SUMMARY: metric.InitEmpty() metric.SetDataType(pdata.MetricDataTypeDoubleSummary) - summary := metric.DoubleSummary() - summary.InitEmpty() // no temporality specified for summary metric return pdata.MetricDataTypeDoubleSummary }