diff --git a/cmd/mdatagen/metrics.tmpl b/cmd/mdatagen/metrics.tmpl index cf6cd748d8a..6f953b64c5d 100644 --- a/cmd/mdatagen/metrics.tmpl +++ b/cmd/mdatagen/metrics.tmpl @@ -86,7 +86,6 @@ var Metrics = &metricStruct{ "{{ $name }}", func() pdata.Metric { metric := pdata.NewMetric() - metric.InitEmpty() metric.SetName("{{ $name }}") metric.SetDescription("{{ $metric.Description }}") metric.SetUnit("{{ $metric.Unit }}") diff --git a/cmd/pdatagen/internal/base_fields.go b/cmd/pdatagen/internal/base_fields.go index 3a487491d33..0e867a767a0 100644 --- a/cmd/pdatagen/internal/base_fields.go +++ b/cmd/pdatagen/internal/base_fields.go @@ -414,7 +414,7 @@ func (one oneofField) generateSetWithTestValue(sb *strings.Builder) { } func (one oneofField) generateCopyToValue(sb *strings.Builder) { - sb.WriteString("\t" + one.copyFuncName + "((*ms.orig), (*dest.orig))") + sb.WriteString("\t" + one.copyFuncName + "(ms.orig, dest.orig)") } var _ baseField = (*oneofField)(nil) diff --git a/cmd/pdatagen/internal/base_slices.go b/cmd/pdatagen/internal/base_slices.go index a5d0249cbf4..5a0e8bdf144 100644 --- a/cmd/pdatagen/internal/base_slices.go +++ b/cmd/pdatagen/internal/base_slices.go @@ -58,7 +58,7 @@ func (es ${structName}) Len() int { // ... // Do something with the element // } func (es ${structName}) At(ix int) ${elementName} { - return new${elementName}(&(*es.orig)[ix]) + return new${elementName}((*es.orig)[ix]) } // MoveAndAppendTo moves all elements from the current slice and appends them to the dest. @@ -80,7 +80,7 @@ func (es ${structName}) CopyTo(dest ${structName}) { if srcLen <= destCap { (*dest.orig) = (*dest.orig)[:srcLen:destCap] for i := range *es.orig { - new${elementName}(&(*es.orig)[i]).CopyTo(new${elementName}(&(*dest.orig)[i])) + new${elementName}((*es.orig)[i]).CopyTo(new${elementName}((*dest.orig)[i])) } return } @@ -88,7 +88,7 @@ func (es ${structName}) CopyTo(dest ${structName}) { wrappers := make([]*${originName}, srcLen) for i := range *es.orig { wrappers[i] = &origs[i] - new${elementName}(&(*es.orig)[i]).CopyTo(new${elementName}(&wrappers[i])) + new${elementName}((*es.orig)[i]).CopyTo(new${elementName}(wrappers[i])) } *dest.orig = wrappers } @@ -130,7 +130,7 @@ func (es ${structName}) Resize(newLen int) { // could still be referenced so do not reuse it after passing it to this // method. func (es ${structName}) Append(e ${elementName}) { - *es.orig = append(*es.orig, *e.orig) + *es.orig = append(*es.orig, e.orig) }` const slicePtrTestTemplate = `func Test${structName}(t *testing.T) { @@ -141,7 +141,6 @@ const slicePtrTestTemplate = `func Test${structName}(t *testing.T) { es.Resize(7) emptyVal := New${elementName}() - emptyVal.InitEmpty() testVal := generateTest${elementName}() assert.EqualValues(t, 7, es.Len()) for i := 0; i < es.Len(); i++ { @@ -194,19 +193,18 @@ func Test${structName}_CopyTo(t *testing.T) { func Test${structName}_Resize(t *testing.T) { es := generateTest${structName}() emptyVal := New${elementName}() - emptyVal.InitEmpty() // Test Resize less elements. const resizeSmallLen = 4 expectedEs := make(map[*${originName}]bool, resizeSmallLen) for i := 0; i < resizeSmallLen; i++ { - expectedEs[*(es.At(i).orig)] = true + expectedEs[es.At(i).orig] = true } assert.Equal(t, resizeSmallLen, len(expectedEs)) es.Resize(resizeSmallLen) assert.Equal(t, resizeSmallLen, es.Len()) foundEs := make(map[*${originName}]bool, resizeSmallLen) for i := 0; i < es.Len(); i++ { - foundEs[*(es.At(i).orig)] = true + foundEs[es.At(i).orig] = true } assert.EqualValues(t, expectedEs, foundEs) @@ -215,14 +213,14 @@ func Test${structName}_Resize(t *testing.T) { oldLen := es.Len() expectedEs = make(map[*${originName}]bool, oldLen) for i := 0; i < oldLen; i++ { - expectedEs[*(es.At(i).orig)] = true + expectedEs[es.At(i).orig] = true } assert.Equal(t, oldLen, len(expectedEs)) es.Resize(resizeLargeLen) assert.Equal(t, resizeLargeLen, es.Len()) foundEs = make(map[*${originName}]bool, oldLen) for i := 0; i < oldLen; i++ { - foundEs[*(es.At(i).orig)] = true + foundEs[es.At(i).orig] = true } assert.EqualValues(t, expectedEs, foundEs) for i := oldLen; i < resizeLargeLen; i++ { @@ -236,17 +234,14 @@ func Test${structName}_Resize(t *testing.T) { func Test${structName}_Append(t *testing.T) { es := generateTest${structName}() - emptyVal := New${elementName}() - emptyVal.InitEmpty() + emptyVal := New${elementName}() es.Append(emptyVal) - assert.EqualValues(t, *(es.At(7)).orig, *emptyVal.orig) + assert.EqualValues(t, es.At(7).orig, emptyVal.orig) emptyVal2 := New${elementName}() - emptyVal2.InitEmpty() - es.Append(emptyVal2) - assert.EqualValues(t, *(es.At(8)).orig, *emptyVal2.orig) + assert.EqualValues(t, es.At(8).orig, emptyVal2.orig) assert.Equal(t, 9, es.Len()) }` @@ -474,13 +469,12 @@ func Test${structName}_Resize(t *testing.T) { func Test${structName}_Append(t *testing.T) { es := generateTest${structName}() - emptyVal := New${elementName}() + emptyVal := New${elementName}() es.Append(emptyVal) assert.EqualValues(t, *(es.At(7)).orig, *emptyVal.orig) emptyVal2 := New${elementName}() - es.Append(emptyVal2) assert.EqualValues(t, *(es.At(8)).orig, *emptyVal2.orig) @@ -507,7 +501,7 @@ type baseSlice interface { // Will generate code only for a slice of pointer fields. type sliceOfPtrs struct { structName string - element *messagePtrStruct + element *messageValueStruct } func (ss *sliceOfPtrs) getName() string { diff --git a/cmd/pdatagen/internal/common_structs.go b/cmd/pdatagen/internal/common_structs.go index 8f88d23f4ad..1c3868acd35 100644 --- a/cmd/pdatagen/internal/common_structs.go +++ b/cmd/pdatagen/internal/common_structs.go @@ -55,7 +55,7 @@ var stringMap = &sliceOfPtrs{ element: stringKeyValue, } -var stringKeyValue = &messagePtrStruct{} +var stringKeyValue = &messageValueStruct{} // This will not be generated by this class. // Defined here just to be available as returned message for the fields. @@ -64,7 +64,7 @@ var attributeMap = &sliceOfPtrs{ element: attributeKeyValue, } -var attributeKeyValue = &messagePtrStruct{} +var attributeKeyValue = &messageValueStruct{} var instrumentationLibraryField = &messageValueField{ fieldName: "InstrumentationLibrary", diff --git a/cmd/pdatagen/internal/log_structs.go b/cmd/pdatagen/internal/log_structs.go index 7f3acded7fa..35b6a7522cb 100644 --- a/cmd/pdatagen/internal/log_structs.go +++ b/cmd/pdatagen/internal/log_structs.go @@ -42,7 +42,7 @@ var resourceLogsSlice = &sliceOfPtrs{ element: resourceLogs, } -var resourceLogs = &messagePtrStruct{ +var resourceLogs = &messageValueStruct{ structName: "ResourceLogs", description: "// ResourceLogs is a collection of logs from a Resource.", originFullName: "otlplogs.ResourceLogs", @@ -61,7 +61,7 @@ var instrumentationLibraryLogsSlice = &sliceOfPtrs{ element: instrumentationLibraryLogs, } -var instrumentationLibraryLogs = &messagePtrStruct{ +var instrumentationLibraryLogs = &messageValueStruct{ structName: "InstrumentationLibraryLogs", description: "// InstrumentationLibraryLogs is a collection of logs from a LibraryInstrumentation.", originFullName: "otlplogs.InstrumentationLibraryLogs", @@ -80,7 +80,7 @@ var logSlice = &sliceOfPtrs{ element: logRecord, } -var logRecord = &messagePtrStruct{ +var logRecord = &messageValueStruct{ structName: "LogRecord", description: "// LogRecord are experimental implementation of OpenTelemetry Log Data Model.\n", originFullName: "otlplogs.LogRecord", diff --git a/cmd/pdatagen/internal/metrics_structs.go b/cmd/pdatagen/internal/metrics_structs.go index b44f71ce0f3..d38a3182add 100644 --- a/cmd/pdatagen/internal/metrics_structs.go +++ b/cmd/pdatagen/internal/metrics_structs.go @@ -64,7 +64,7 @@ var resourceMetricsSlice = &sliceOfPtrs{ element: resourceMetrics, } -var resourceMetrics = &messagePtrStruct{ +var resourceMetrics = &messageValueStruct{ structName: "ResourceMetrics", description: "// InstrumentationLibraryMetrics is a collection of metrics from a LibraryInstrumentation.", originFullName: "otlpmetrics.ResourceMetrics", @@ -83,7 +83,7 @@ var instrumentationLibraryMetricsSlice = &sliceOfPtrs{ element: instrumentationLibraryMetrics, } -var instrumentationLibraryMetrics = &messagePtrStruct{ +var instrumentationLibraryMetrics = &messageValueStruct{ structName: "InstrumentationLibraryMetrics", description: "// InstrumentationLibraryMetrics is a collection of metrics from a LibraryInstrumentation.", originFullName: "otlpmetrics.InstrumentationLibraryMetrics", @@ -102,7 +102,7 @@ var metricSlice = &sliceOfPtrs{ element: metric, } -var metric = &messagePtrStruct{ +var metric = &messageValueStruct{ structName: "Metric", description: "// Metric represents one metric as a collection of datapoints.\n" + "// See Metric definition in OTLP: https://github.com/open-telemetry/opentelemetry-proto/blob/master/opentelemetry/proto/metrics/v1/metrics.proto", @@ -229,7 +229,7 @@ var intDataPointSlice = &sliceOfPtrs{ element: intDataPoint, } -var intDataPoint = &messagePtrStruct{ +var intDataPoint = &messageValueStruct{ structName: "IntDataPoint", description: "// IntDataPoint is a single data point in a timeseries that describes the time-varying values of a scalar int metric.", originFullName: "otlpmetrics.IntDataPoint", @@ -247,7 +247,7 @@ var doubleDataPointSlice = &sliceOfPtrs{ element: doubleDataPoint, } -var doubleDataPoint = &messagePtrStruct{ +var doubleDataPoint = &messageValueStruct{ structName: "DoubleDataPoint", description: "// DoubleDataPoint is a single data point in a timeseries that describes the time-varying value of a double metric.", originFullName: "otlpmetrics.DoubleDataPoint", @@ -265,7 +265,7 @@ var intHistogramDataPointSlice = &sliceOfPtrs{ element: intHistogramDataPoint, } -var intHistogramDataPoint = &messagePtrStruct{ +var intHistogramDataPoint = &messageValueStruct{ structName: "IntHistogramDataPoint", description: "// IntHistogramDataPoint is a single data point in a timeseries that describes the time-varying values of a Histogram of int values.", originFullName: "otlpmetrics.IntHistogramDataPoint", @@ -286,7 +286,7 @@ var doubleHistogramDataPointSlice = &sliceOfPtrs{ element: doubleHistogramDataPoint, } -var doubleHistogramDataPoint = &messagePtrStruct{ +var doubleHistogramDataPoint = &messageValueStruct{ structName: "DoubleHistogramDataPoint", description: "// DoubleHistogramDataPoint is a single data point in a timeseries that describes the time-varying values of a Histogram of double values.", originFullName: "otlpmetrics.DoubleHistogramDataPoint", @@ -307,7 +307,7 @@ var doubleSummaryDataPointSlice = &sliceOfPtrs{ element: doubleSummaryDataPoint, } -var doubleSummaryDataPoint = &messagePtrStruct{ +var doubleSummaryDataPoint = &messageValueStruct{ structName: "DoubleSummaryDataPoint", description: "// DoubleSummaryDataPoint is a single data point in a timeseries that describes the time-varying values of a Summary of double values.", originFullName: "otlpmetrics.DoubleSummaryDataPoint", @@ -330,7 +330,7 @@ var quantileValuesSlice = &sliceOfPtrs{ element: quantileValues, } -var quantileValues = &messagePtrStruct{ +var quantileValues = &messageValueStruct{ structName: "ValueAtQuantile", description: "// ValueAtQuantile is a quantile value within a Summary data point", originFullName: "otlpmetrics.DoubleSummaryDataPoint_ValueAtQuantile", @@ -345,7 +345,7 @@ var intExemplarSlice = &sliceOfPtrs{ element: intExemplar, } -var intExemplar = &messagePtrStruct{ +var intExemplar = &messageValueStruct{ structName: "IntExemplar", description: "// IntExemplar is a sample input int measurement.\n//\n" + "// Exemplars also hold information about the environment when the measurement was recorded,\n" + @@ -368,7 +368,7 @@ var doubleExemplarSlice = &sliceOfPtrs{ element: doubleExemplar, } -var doubleExemplar = &messagePtrStruct{ +var doubleExemplar = &messageValueStruct{ structName: "DoubleExemplar", description: "// DoubleExemplar is a sample input double measurement.\n//\n" + "// Exemplars also hold information about the environment when the measurement was recorded,\n" + diff --git a/cmd/pdatagen/internal/trace_structs.go b/cmd/pdatagen/internal/trace_structs.go index 36ada96c408..7f7807ae57b 100644 --- a/cmd/pdatagen/internal/trace_structs.go +++ b/cmd/pdatagen/internal/trace_structs.go @@ -48,7 +48,7 @@ var resourceSpansSlice = &sliceOfPtrs{ element: resourceSpans, } -var resourceSpans = &messagePtrStruct{ +var resourceSpans = &messageValueStruct{ structName: "ResourceSpans", description: "// InstrumentationLibrarySpans is a collection of spans from a LibraryInstrumentation.", originFullName: "otlptrace.ResourceSpans", @@ -67,7 +67,7 @@ var instrumentationLibrarySpansSlice = &sliceOfPtrs{ element: instrumentationLibrarySpans, } -var instrumentationLibrarySpans = &messagePtrStruct{ +var instrumentationLibrarySpans = &messageValueStruct{ structName: "InstrumentationLibrarySpans", description: "// InstrumentationLibrarySpans is a collection of spans from a LibraryInstrumentation.", originFullName: "otlptrace.InstrumentationLibrarySpans", @@ -86,7 +86,7 @@ var spanSlice = &sliceOfPtrs{ element: span, } -var span = &messagePtrStruct{ +var span = &messageValueStruct{ structName: "Span", description: "// Span represents a single operation within a trace.\n" + "// See Span definition in OTLP: https://github.com/open-telemetry/opentelemetry-proto/blob/master/opentelemetry/proto/trace/v1/trace.proto#L37", @@ -146,7 +146,7 @@ var spanEventSlice = &sliceOfPtrs{ element: spanEvent, } -var spanEvent = &messagePtrStruct{ +var spanEvent = &messageValueStruct{ structName: "SpanEvent", description: "// SpanEvent is a time-stamped annotation of the span, consisting of user-supplied\n" + "// text description and key-value pairs. See OTLP for event definition.", @@ -164,7 +164,7 @@ var spanLinkSlice = &sliceOfPtrs{ element: spanLink, } -var spanLink = &messagePtrStruct{ +var spanLink = &messageValueStruct{ structName: "SpanLink", description: "// SpanLink is a pointer from the current span to another span in the same trace or in a\n" + "// different trace. See OTLP for link definition.", diff --git a/consumer/pdata/generated_common_test.go b/consumer/pdata/generated_common_test.go index 4f4fcecb3a4..3a720aca7d1 100644 --- a/consumer/pdata/generated_common_test.go +++ b/consumer/pdata/generated_common_test.go @@ -150,13 +150,12 @@ func TestAnyValueArray_Resize(t *testing.T) { func TestAnyValueArray_Append(t *testing.T) { es := generateTestAnyValueArray() - emptyVal := NewAttributeValue() + emptyVal := NewAttributeValue() es.Append(emptyVal) assert.EqualValues(t, *(es.At(7)).orig, *emptyVal.orig) emptyVal2 := NewAttributeValue() - es.Append(emptyVal2) assert.EqualValues(t, *(es.At(8)).orig, *emptyVal2.orig) diff --git a/consumer/pdata/generated_log.go b/consumer/pdata/generated_log.go index 8b558459565..5898f28ec5b 100644 --- a/consumer/pdata/generated_log.go +++ b/consumer/pdata/generated_log.go @@ -61,7 +61,7 @@ func (es ResourceLogsSlice) Len() int { // ... // Do something with the element // } func (es ResourceLogsSlice) At(ix int) ResourceLogs { - return newResourceLogs(&(*es.orig)[ix]) + return newResourceLogs((*es.orig)[ix]) } // MoveAndAppendTo moves all elements from the current slice and appends them to the dest. @@ -83,7 +83,7 @@ func (es ResourceLogsSlice) CopyTo(dest ResourceLogsSlice) { if srcLen <= destCap { (*dest.orig) = (*dest.orig)[:srcLen:destCap] for i := range *es.orig { - newResourceLogs(&(*es.orig)[i]).CopyTo(newResourceLogs(&(*dest.orig)[i])) + newResourceLogs((*es.orig)[i]).CopyTo(newResourceLogs((*dest.orig)[i])) } return } @@ -91,7 +91,7 @@ func (es ResourceLogsSlice) CopyTo(dest ResourceLogsSlice) { wrappers := make([]*otlplogs.ResourceLogs, srcLen) for i := range *es.orig { wrappers[i] = &origs[i] - newResourceLogs(&(*es.orig)[i]).CopyTo(newResourceLogs(&wrappers[i])) + newResourceLogs((*es.orig)[i]).CopyTo(newResourceLogs(wrappers[i])) } *dest.orig = wrappers } @@ -133,7 +133,7 @@ func (es ResourceLogsSlice) Resize(newLen int) { // could still be referenced so do not reuse it after passing it to this // method. func (es ResourceLogsSlice) Append(e ResourceLogs) { - *es.orig = append(*es.orig, *e.orig) + *es.orig = append(*es.orig, e.orig) } // ResourceLogs is a collection of logs from a Resource. @@ -145,33 +145,23 @@ func (es ResourceLogsSlice) Append(e ResourceLogs) { // Important: zero-initialized instance is not valid for use. type ResourceLogs struct { // orig points to the pointer otlplogs.ResourceLogs field contained somewhere else. - // We use pointer-to-pointer to be able to modify it in InitEmpty func. - orig **otlplogs.ResourceLogs + orig *otlplogs.ResourceLogs } -func newResourceLogs(orig **otlplogs.ResourceLogs) ResourceLogs { - return ResourceLogs{orig} +func newResourceLogs(orig *otlplogs.ResourceLogs) ResourceLogs { + return ResourceLogs{orig: orig} } -// NewResourceLogs creates a new "nil" ResourceLogs. -// To initialize the struct call "InitEmpty". +// NewResourceLogs creates a new empty ResourceLogs. // // This must be used only in testing code since no "Set" method available. func NewResourceLogs() ResourceLogs { - orig := (*otlplogs.ResourceLogs)(nil) - return newResourceLogs(&orig) + return newResourceLogs(&otlplogs.ResourceLogs{}) } -// InitEmpty overwrites the current value with empty. +// Deprecated: This function will be removed soon. func (ms ResourceLogs) InitEmpty() { - *ms.orig = &otlplogs.ResourceLogs{} -} - -// IsNil returns true if the underlying data are nil. -// -// Important: All other functions will cause a runtime error if this returns "true". -func (ms ResourceLogs) IsNil() bool { - return *ms.orig == nil + *ms.orig = otlplogs.ResourceLogs{} } // Resource returns the resource associated with this ResourceLogs. @@ -190,13 +180,6 @@ func (ms ResourceLogs) InstrumentationLibraryLogs() InstrumentationLibraryLogsSl // CopyTo copies all properties from the current struct to the dest. func (ms ResourceLogs) CopyTo(dest ResourceLogs) { - if ms.IsNil() { - *dest.orig = nil - return - } - if dest.IsNil() { - dest.InitEmpty() - } ms.Resource().CopyTo(dest.Resource()) ms.InstrumentationLibraryLogs().CopyTo(dest.InstrumentationLibraryLogs()) } @@ -240,7 +223,7 @@ func (es InstrumentationLibraryLogsSlice) Len() int { // ... // Do something with the element // } func (es InstrumentationLibraryLogsSlice) At(ix int) InstrumentationLibraryLogs { - return newInstrumentationLibraryLogs(&(*es.orig)[ix]) + return newInstrumentationLibraryLogs((*es.orig)[ix]) } // MoveAndAppendTo moves all elements from the current slice and appends them to the dest. @@ -262,7 +245,7 @@ func (es InstrumentationLibraryLogsSlice) CopyTo(dest InstrumentationLibraryLogs if srcLen <= destCap { (*dest.orig) = (*dest.orig)[:srcLen:destCap] for i := range *es.orig { - newInstrumentationLibraryLogs(&(*es.orig)[i]).CopyTo(newInstrumentationLibraryLogs(&(*dest.orig)[i])) + newInstrumentationLibraryLogs((*es.orig)[i]).CopyTo(newInstrumentationLibraryLogs((*dest.orig)[i])) } return } @@ -270,7 +253,7 @@ func (es InstrumentationLibraryLogsSlice) CopyTo(dest InstrumentationLibraryLogs wrappers := make([]*otlplogs.InstrumentationLibraryLogs, srcLen) for i := range *es.orig { wrappers[i] = &origs[i] - newInstrumentationLibraryLogs(&(*es.orig)[i]).CopyTo(newInstrumentationLibraryLogs(&wrappers[i])) + newInstrumentationLibraryLogs((*es.orig)[i]).CopyTo(newInstrumentationLibraryLogs(wrappers[i])) } *dest.orig = wrappers } @@ -312,7 +295,7 @@ func (es InstrumentationLibraryLogsSlice) Resize(newLen int) { // could still be referenced so do not reuse it after passing it to this // method. func (es InstrumentationLibraryLogsSlice) Append(e InstrumentationLibraryLogs) { - *es.orig = append(*es.orig, *e.orig) + *es.orig = append(*es.orig, e.orig) } // InstrumentationLibraryLogs is a collection of logs from a LibraryInstrumentation. @@ -324,33 +307,23 @@ func (es InstrumentationLibraryLogsSlice) Append(e InstrumentationLibraryLogs) { // Important: zero-initialized instance is not valid for use. type InstrumentationLibraryLogs struct { // orig points to the pointer otlplogs.InstrumentationLibraryLogs field contained somewhere else. - // We use pointer-to-pointer to be able to modify it in InitEmpty func. - orig **otlplogs.InstrumentationLibraryLogs + orig *otlplogs.InstrumentationLibraryLogs } -func newInstrumentationLibraryLogs(orig **otlplogs.InstrumentationLibraryLogs) InstrumentationLibraryLogs { - return InstrumentationLibraryLogs{orig} +func newInstrumentationLibraryLogs(orig *otlplogs.InstrumentationLibraryLogs) InstrumentationLibraryLogs { + return InstrumentationLibraryLogs{orig: orig} } -// NewInstrumentationLibraryLogs creates a new "nil" InstrumentationLibraryLogs. -// To initialize the struct call "InitEmpty". +// NewInstrumentationLibraryLogs creates a new empty InstrumentationLibraryLogs. // // This must be used only in testing code since no "Set" method available. func NewInstrumentationLibraryLogs() InstrumentationLibraryLogs { - orig := (*otlplogs.InstrumentationLibraryLogs)(nil) - return newInstrumentationLibraryLogs(&orig) + return newInstrumentationLibraryLogs(&otlplogs.InstrumentationLibraryLogs{}) } -// InitEmpty overwrites the current value with empty. +// Deprecated: This function will be removed soon. func (ms InstrumentationLibraryLogs) InitEmpty() { - *ms.orig = &otlplogs.InstrumentationLibraryLogs{} -} - -// IsNil returns true if the underlying data are nil. -// -// Important: All other functions will cause a runtime error if this returns "true". -func (ms InstrumentationLibraryLogs) IsNil() bool { - return *ms.orig == nil + *ms.orig = otlplogs.InstrumentationLibraryLogs{} } // InstrumentationLibrary returns the instrumentationlibrary associated with this InstrumentationLibraryLogs. @@ -369,13 +342,6 @@ func (ms InstrumentationLibraryLogs) Logs() LogSlice { // CopyTo copies all properties from the current struct to the dest. func (ms InstrumentationLibraryLogs) CopyTo(dest InstrumentationLibraryLogs) { - if ms.IsNil() { - *dest.orig = nil - return - } - if dest.IsNil() { - dest.InitEmpty() - } ms.InstrumentationLibrary().CopyTo(dest.InstrumentationLibrary()) ms.Logs().CopyTo(dest.Logs()) } @@ -419,7 +385,7 @@ func (es LogSlice) Len() int { // ... // Do something with the element // } func (es LogSlice) At(ix int) LogRecord { - return newLogRecord(&(*es.orig)[ix]) + return newLogRecord((*es.orig)[ix]) } // MoveAndAppendTo moves all elements from the current slice and appends them to the dest. @@ -441,7 +407,7 @@ func (es LogSlice) CopyTo(dest LogSlice) { if srcLen <= destCap { (*dest.orig) = (*dest.orig)[:srcLen:destCap] for i := range *es.orig { - newLogRecord(&(*es.orig)[i]).CopyTo(newLogRecord(&(*dest.orig)[i])) + newLogRecord((*es.orig)[i]).CopyTo(newLogRecord((*dest.orig)[i])) } return } @@ -449,7 +415,7 @@ func (es LogSlice) CopyTo(dest LogSlice) { wrappers := make([]*otlplogs.LogRecord, srcLen) for i := range *es.orig { wrappers[i] = &origs[i] - newLogRecord(&(*es.orig)[i]).CopyTo(newLogRecord(&wrappers[i])) + newLogRecord((*es.orig)[i]).CopyTo(newLogRecord(wrappers[i])) } *dest.orig = wrappers } @@ -491,7 +457,7 @@ func (es LogSlice) Resize(newLen int) { // could still be referenced so do not reuse it after passing it to this // method. func (es LogSlice) Append(e LogRecord) { - *es.orig = append(*es.orig, *e.orig) + *es.orig = append(*es.orig, e.orig) } // LogRecord are experimental implementation of OpenTelemetry Log Data Model. @@ -504,33 +470,23 @@ func (es LogSlice) Append(e LogRecord) { // Important: zero-initialized instance is not valid for use. type LogRecord struct { // orig points to the pointer otlplogs.LogRecord field contained somewhere else. - // We use pointer-to-pointer to be able to modify it in InitEmpty func. - orig **otlplogs.LogRecord + orig *otlplogs.LogRecord } -func newLogRecord(orig **otlplogs.LogRecord) LogRecord { - return LogRecord{orig} +func newLogRecord(orig *otlplogs.LogRecord) LogRecord { + return LogRecord{orig: orig} } -// NewLogRecord creates a new "nil" LogRecord. -// To initialize the struct call "InitEmpty". +// NewLogRecord creates a new empty LogRecord. // // This must be used only in testing code since no "Set" method available. func NewLogRecord() LogRecord { - orig := (*otlplogs.LogRecord)(nil) - return newLogRecord(&orig) + return newLogRecord(&otlplogs.LogRecord{}) } -// InitEmpty overwrites the current value with empty. +// Deprecated: This function will be removed soon. func (ms LogRecord) InitEmpty() { - *ms.orig = &otlplogs.LogRecord{} -} - -// IsNil returns true if the underlying data are nil. -// -// Important: All other functions will cause a runtime error if this returns "true". -func (ms LogRecord) IsNil() bool { - return *ms.orig == nil + *ms.orig = otlplogs.LogRecord{} } // Timestamp returns the timestamp associated with this LogRecord. @@ -661,13 +617,6 @@ func (ms LogRecord) SetDroppedAttributesCount(v uint32) { // CopyTo copies all properties from the current struct to the dest. func (ms LogRecord) CopyTo(dest LogRecord) { - if ms.IsNil() { - *dest.orig = nil - return - } - if dest.IsNil() { - dest.InitEmpty() - } dest.SetTimestamp(ms.Timestamp()) dest.SetTraceID(ms.TraceID()) dest.SetSpanID(ms.SpanID()) diff --git a/consumer/pdata/generated_log_test.go b/consumer/pdata/generated_log_test.go index 5f6f55d3de4..0991f5a2e2a 100644 --- a/consumer/pdata/generated_log_test.go +++ b/consumer/pdata/generated_log_test.go @@ -33,7 +33,6 @@ func TestResourceLogsSlice(t *testing.T) { es.Resize(7) emptyVal := NewResourceLogs() - emptyVal.InitEmpty() testVal := generateTestResourceLogs() assert.EqualValues(t, 7, es.Len()) for i := 0; i < es.Len(); i++ { @@ -86,19 +85,18 @@ func TestResourceLogsSlice_CopyTo(t *testing.T) { func TestResourceLogsSlice_Resize(t *testing.T) { es := generateTestResourceLogsSlice() emptyVal := NewResourceLogs() - emptyVal.InitEmpty() // Test Resize less elements. const resizeSmallLen = 4 expectedEs := make(map[*otlplogs.ResourceLogs]bool, resizeSmallLen) for i := 0; i < resizeSmallLen; i++ { - expectedEs[*(es.At(i).orig)] = true + expectedEs[es.At(i).orig] = true } assert.Equal(t, resizeSmallLen, len(expectedEs)) es.Resize(resizeSmallLen) assert.Equal(t, resizeSmallLen, es.Len()) foundEs := make(map[*otlplogs.ResourceLogs]bool, resizeSmallLen) for i := 0; i < es.Len(); i++ { - foundEs[*(es.At(i).orig)] = true + foundEs[es.At(i).orig] = true } assert.EqualValues(t, expectedEs, foundEs) @@ -107,14 +105,14 @@ func TestResourceLogsSlice_Resize(t *testing.T) { oldLen := es.Len() expectedEs = make(map[*otlplogs.ResourceLogs]bool, oldLen) for i := 0; i < oldLen; i++ { - expectedEs[*(es.At(i).orig)] = true + expectedEs[es.At(i).orig] = true } assert.Equal(t, oldLen, len(expectedEs)) es.Resize(resizeLargeLen) assert.Equal(t, resizeLargeLen, es.Len()) foundEs = make(map[*otlplogs.ResourceLogs]bool, oldLen) for i := 0; i < oldLen; i++ { - foundEs[*(es.At(i).orig)] = true + foundEs[es.At(i).orig] = true } assert.EqualValues(t, expectedEs, foundEs) for i := oldLen; i < resizeLargeLen; i++ { @@ -128,32 +126,20 @@ func TestResourceLogsSlice_Resize(t *testing.T) { func TestResourceLogsSlice_Append(t *testing.T) { es := generateTestResourceLogsSlice() - emptyVal := NewResourceLogs() - emptyVal.InitEmpty() + emptyVal := NewResourceLogs() es.Append(emptyVal) - assert.EqualValues(t, *(es.At(7)).orig, *emptyVal.orig) + assert.EqualValues(t, es.At(7).orig, emptyVal.orig) emptyVal2 := NewResourceLogs() - emptyVal2.InitEmpty() - es.Append(emptyVal2) - assert.EqualValues(t, *(es.At(8)).orig, *emptyVal2.orig) + assert.EqualValues(t, es.At(8).orig, emptyVal2.orig) assert.Equal(t, 9, es.Len()) } -func TestResourceLogs_InitEmpty(t *testing.T) { - ms := NewResourceLogs() - assert.True(t, ms.IsNil()) - ms.InitEmpty() - assert.False(t, ms.IsNil()) -} - func TestResourceLogs_CopyTo(t *testing.T) { ms := NewResourceLogs() - NewResourceLogs().CopyTo(ms) - assert.True(t, ms.IsNil()) generateTestResourceLogs().CopyTo(ms) assert.EqualValues(t, generateTestResourceLogs(), ms) } @@ -182,7 +168,6 @@ func TestInstrumentationLibraryLogsSlice(t *testing.T) { es.Resize(7) emptyVal := NewInstrumentationLibraryLogs() - emptyVal.InitEmpty() testVal := generateTestInstrumentationLibraryLogs() assert.EqualValues(t, 7, es.Len()) for i := 0; i < es.Len(); i++ { @@ -235,19 +220,18 @@ func TestInstrumentationLibraryLogsSlice_CopyTo(t *testing.T) { func TestInstrumentationLibraryLogsSlice_Resize(t *testing.T) { es := generateTestInstrumentationLibraryLogsSlice() emptyVal := NewInstrumentationLibraryLogs() - emptyVal.InitEmpty() // Test Resize less elements. const resizeSmallLen = 4 expectedEs := make(map[*otlplogs.InstrumentationLibraryLogs]bool, resizeSmallLen) for i := 0; i < resizeSmallLen; i++ { - expectedEs[*(es.At(i).orig)] = true + expectedEs[es.At(i).orig] = true } assert.Equal(t, resizeSmallLen, len(expectedEs)) es.Resize(resizeSmallLen) assert.Equal(t, resizeSmallLen, es.Len()) foundEs := make(map[*otlplogs.InstrumentationLibraryLogs]bool, resizeSmallLen) for i := 0; i < es.Len(); i++ { - foundEs[*(es.At(i).orig)] = true + foundEs[es.At(i).orig] = true } assert.EqualValues(t, expectedEs, foundEs) @@ -256,14 +240,14 @@ func TestInstrumentationLibraryLogsSlice_Resize(t *testing.T) { oldLen := es.Len() expectedEs = make(map[*otlplogs.InstrumentationLibraryLogs]bool, oldLen) for i := 0; i < oldLen; i++ { - expectedEs[*(es.At(i).orig)] = true + expectedEs[es.At(i).orig] = true } assert.Equal(t, oldLen, len(expectedEs)) es.Resize(resizeLargeLen) assert.Equal(t, resizeLargeLen, es.Len()) foundEs = make(map[*otlplogs.InstrumentationLibraryLogs]bool, oldLen) for i := 0; i < oldLen; i++ { - foundEs[*(es.At(i).orig)] = true + foundEs[es.At(i).orig] = true } assert.EqualValues(t, expectedEs, foundEs) for i := oldLen; i < resizeLargeLen; i++ { @@ -277,32 +261,20 @@ func TestInstrumentationLibraryLogsSlice_Resize(t *testing.T) { func TestInstrumentationLibraryLogsSlice_Append(t *testing.T) { es := generateTestInstrumentationLibraryLogsSlice() - emptyVal := NewInstrumentationLibraryLogs() - emptyVal.InitEmpty() + emptyVal := NewInstrumentationLibraryLogs() es.Append(emptyVal) - assert.EqualValues(t, *(es.At(7)).orig, *emptyVal.orig) + assert.EqualValues(t, es.At(7).orig, emptyVal.orig) emptyVal2 := NewInstrumentationLibraryLogs() - emptyVal2.InitEmpty() - es.Append(emptyVal2) - assert.EqualValues(t, *(es.At(8)).orig, *emptyVal2.orig) + assert.EqualValues(t, es.At(8).orig, emptyVal2.orig) assert.Equal(t, 9, es.Len()) } -func TestInstrumentationLibraryLogs_InitEmpty(t *testing.T) { - ms := NewInstrumentationLibraryLogs() - assert.True(t, ms.IsNil()) - ms.InitEmpty() - assert.False(t, ms.IsNil()) -} - func TestInstrumentationLibraryLogs_CopyTo(t *testing.T) { ms := NewInstrumentationLibraryLogs() - NewInstrumentationLibraryLogs().CopyTo(ms) - assert.True(t, ms.IsNil()) generateTestInstrumentationLibraryLogs().CopyTo(ms) assert.EqualValues(t, generateTestInstrumentationLibraryLogs(), ms) } @@ -331,7 +303,6 @@ func TestLogSlice(t *testing.T) { es.Resize(7) emptyVal := NewLogRecord() - emptyVal.InitEmpty() testVal := generateTestLogRecord() assert.EqualValues(t, 7, es.Len()) for i := 0; i < es.Len(); i++ { @@ -384,19 +355,18 @@ func TestLogSlice_CopyTo(t *testing.T) { func TestLogSlice_Resize(t *testing.T) { es := generateTestLogSlice() emptyVal := NewLogRecord() - emptyVal.InitEmpty() // Test Resize less elements. const resizeSmallLen = 4 expectedEs := make(map[*otlplogs.LogRecord]bool, resizeSmallLen) for i := 0; i < resizeSmallLen; i++ { - expectedEs[*(es.At(i).orig)] = true + expectedEs[es.At(i).orig] = true } assert.Equal(t, resizeSmallLen, len(expectedEs)) es.Resize(resizeSmallLen) assert.Equal(t, resizeSmallLen, es.Len()) foundEs := make(map[*otlplogs.LogRecord]bool, resizeSmallLen) for i := 0; i < es.Len(); i++ { - foundEs[*(es.At(i).orig)] = true + foundEs[es.At(i).orig] = true } assert.EqualValues(t, expectedEs, foundEs) @@ -405,14 +375,14 @@ func TestLogSlice_Resize(t *testing.T) { oldLen := es.Len() expectedEs = make(map[*otlplogs.LogRecord]bool, oldLen) for i := 0; i < oldLen; i++ { - expectedEs[*(es.At(i).orig)] = true + expectedEs[es.At(i).orig] = true } assert.Equal(t, oldLen, len(expectedEs)) es.Resize(resizeLargeLen) assert.Equal(t, resizeLargeLen, es.Len()) foundEs = make(map[*otlplogs.LogRecord]bool, oldLen) for i := 0; i < oldLen; i++ { - foundEs[*(es.At(i).orig)] = true + foundEs[es.At(i).orig] = true } assert.EqualValues(t, expectedEs, foundEs) for i := oldLen; i < resizeLargeLen; i++ { @@ -426,32 +396,20 @@ func TestLogSlice_Resize(t *testing.T) { func TestLogSlice_Append(t *testing.T) { es := generateTestLogSlice() - emptyVal := NewLogRecord() - emptyVal.InitEmpty() + emptyVal := NewLogRecord() es.Append(emptyVal) - assert.EqualValues(t, *(es.At(7)).orig, *emptyVal.orig) + assert.EqualValues(t, es.At(7).orig, emptyVal.orig) emptyVal2 := NewLogRecord() - emptyVal2.InitEmpty() - es.Append(emptyVal2) - assert.EqualValues(t, *(es.At(8)).orig, *emptyVal2.orig) + assert.EqualValues(t, es.At(8).orig, emptyVal2.orig) assert.Equal(t, 9, es.Len()) } -func TestLogRecord_InitEmpty(t *testing.T) { - ms := NewLogRecord() - assert.True(t, ms.IsNil()) - ms.InitEmpty() - assert.False(t, ms.IsNil()) -} - func TestLogRecord_CopyTo(t *testing.T) { ms := NewLogRecord() - NewLogRecord().CopyTo(ms) - assert.True(t, ms.IsNil()) generateTestLogRecord().CopyTo(ms) assert.EqualValues(t, generateTestLogRecord(), ms) } @@ -559,7 +517,6 @@ func fillTestResourceLogsSlice(tv ResourceLogsSlice) { func generateTestResourceLogs() ResourceLogs { tv := NewResourceLogs() - tv.InitEmpty() fillTestResourceLogs(tv) return tv } @@ -584,7 +541,6 @@ func fillTestInstrumentationLibraryLogsSlice(tv InstrumentationLibraryLogsSlice) func generateTestInstrumentationLibraryLogs() InstrumentationLibraryLogs { tv := NewInstrumentationLibraryLogs() - tv.InitEmpty() fillTestInstrumentationLibraryLogs(tv) return tv } @@ -609,7 +565,6 @@ func fillTestLogSlice(tv LogSlice) { func generateTestLogRecord() LogRecord { tv := NewLogRecord() - tv.InitEmpty() fillTestLogRecord(tv) return tv } diff --git a/consumer/pdata/generated_metrics.go b/consumer/pdata/generated_metrics.go index 183f93965d3..baac4ba351f 100644 --- a/consumer/pdata/generated_metrics.go +++ b/consumer/pdata/generated_metrics.go @@ -60,7 +60,7 @@ func (es ResourceMetricsSlice) Len() int { // ... // Do something with the element // } func (es ResourceMetricsSlice) At(ix int) ResourceMetrics { - return newResourceMetrics(&(*es.orig)[ix]) + return newResourceMetrics((*es.orig)[ix]) } // MoveAndAppendTo moves all elements from the current slice and appends them to the dest. @@ -82,7 +82,7 @@ func (es ResourceMetricsSlice) CopyTo(dest ResourceMetricsSlice) { if srcLen <= destCap { (*dest.orig) = (*dest.orig)[:srcLen:destCap] for i := range *es.orig { - newResourceMetrics(&(*es.orig)[i]).CopyTo(newResourceMetrics(&(*dest.orig)[i])) + newResourceMetrics((*es.orig)[i]).CopyTo(newResourceMetrics((*dest.orig)[i])) } return } @@ -90,7 +90,7 @@ func (es ResourceMetricsSlice) CopyTo(dest ResourceMetricsSlice) { wrappers := make([]*otlpmetrics.ResourceMetrics, srcLen) for i := range *es.orig { wrappers[i] = &origs[i] - newResourceMetrics(&(*es.orig)[i]).CopyTo(newResourceMetrics(&wrappers[i])) + newResourceMetrics((*es.orig)[i]).CopyTo(newResourceMetrics(wrappers[i])) } *dest.orig = wrappers } @@ -132,7 +132,7 @@ func (es ResourceMetricsSlice) Resize(newLen int) { // could still be referenced so do not reuse it after passing it to this // method. func (es ResourceMetricsSlice) Append(e ResourceMetrics) { - *es.orig = append(*es.orig, *e.orig) + *es.orig = append(*es.orig, e.orig) } // InstrumentationLibraryMetrics is a collection of metrics from a LibraryInstrumentation. @@ -144,33 +144,23 @@ func (es ResourceMetricsSlice) Append(e ResourceMetrics) { // Important: zero-initialized instance is not valid for use. type ResourceMetrics struct { // orig points to the pointer otlpmetrics.ResourceMetrics field contained somewhere else. - // We use pointer-to-pointer to be able to modify it in InitEmpty func. - orig **otlpmetrics.ResourceMetrics + orig *otlpmetrics.ResourceMetrics } -func newResourceMetrics(orig **otlpmetrics.ResourceMetrics) ResourceMetrics { - return ResourceMetrics{orig} +func newResourceMetrics(orig *otlpmetrics.ResourceMetrics) ResourceMetrics { + return ResourceMetrics{orig: orig} } -// NewResourceMetrics creates a new "nil" ResourceMetrics. -// To initialize the struct call "InitEmpty". +// NewResourceMetrics creates a new empty ResourceMetrics. // // This must be used only in testing code since no "Set" method available. func NewResourceMetrics() ResourceMetrics { - orig := (*otlpmetrics.ResourceMetrics)(nil) - return newResourceMetrics(&orig) + return newResourceMetrics(&otlpmetrics.ResourceMetrics{}) } -// InitEmpty overwrites the current value with empty. +// Deprecated: This function will be removed soon. func (ms ResourceMetrics) InitEmpty() { - *ms.orig = &otlpmetrics.ResourceMetrics{} -} - -// IsNil returns true if the underlying data are nil. -// -// Important: All other functions will cause a runtime error if this returns "true". -func (ms ResourceMetrics) IsNil() bool { - return *ms.orig == nil + *ms.orig = otlpmetrics.ResourceMetrics{} } // Resource returns the resource associated with this ResourceMetrics. @@ -189,13 +179,6 @@ func (ms ResourceMetrics) InstrumentationLibraryMetrics() InstrumentationLibrary // CopyTo copies all properties from the current struct to the dest. func (ms ResourceMetrics) CopyTo(dest ResourceMetrics) { - if ms.IsNil() { - *dest.orig = nil - return - } - if dest.IsNil() { - dest.InitEmpty() - } ms.Resource().CopyTo(dest.Resource()) ms.InstrumentationLibraryMetrics().CopyTo(dest.InstrumentationLibraryMetrics()) } @@ -239,7 +222,7 @@ func (es InstrumentationLibraryMetricsSlice) Len() int { // ... // Do something with the element // } func (es InstrumentationLibraryMetricsSlice) At(ix int) InstrumentationLibraryMetrics { - return newInstrumentationLibraryMetrics(&(*es.orig)[ix]) + return newInstrumentationLibraryMetrics((*es.orig)[ix]) } // MoveAndAppendTo moves all elements from the current slice and appends them to the dest. @@ -261,7 +244,7 @@ func (es InstrumentationLibraryMetricsSlice) CopyTo(dest InstrumentationLibraryM if srcLen <= destCap { (*dest.orig) = (*dest.orig)[:srcLen:destCap] for i := range *es.orig { - newInstrumentationLibraryMetrics(&(*es.orig)[i]).CopyTo(newInstrumentationLibraryMetrics(&(*dest.orig)[i])) + newInstrumentationLibraryMetrics((*es.orig)[i]).CopyTo(newInstrumentationLibraryMetrics((*dest.orig)[i])) } return } @@ -269,7 +252,7 @@ func (es InstrumentationLibraryMetricsSlice) CopyTo(dest InstrumentationLibraryM wrappers := make([]*otlpmetrics.InstrumentationLibraryMetrics, srcLen) for i := range *es.orig { wrappers[i] = &origs[i] - newInstrumentationLibraryMetrics(&(*es.orig)[i]).CopyTo(newInstrumentationLibraryMetrics(&wrappers[i])) + newInstrumentationLibraryMetrics((*es.orig)[i]).CopyTo(newInstrumentationLibraryMetrics(wrappers[i])) } *dest.orig = wrappers } @@ -311,7 +294,7 @@ func (es InstrumentationLibraryMetricsSlice) Resize(newLen int) { // could still be referenced so do not reuse it after passing it to this // method. func (es InstrumentationLibraryMetricsSlice) Append(e InstrumentationLibraryMetrics) { - *es.orig = append(*es.orig, *e.orig) + *es.orig = append(*es.orig, e.orig) } // InstrumentationLibraryMetrics is a collection of metrics from a LibraryInstrumentation. @@ -323,33 +306,23 @@ func (es InstrumentationLibraryMetricsSlice) Append(e InstrumentationLibraryMetr // Important: zero-initialized instance is not valid for use. type InstrumentationLibraryMetrics struct { // orig points to the pointer otlpmetrics.InstrumentationLibraryMetrics field contained somewhere else. - // We use pointer-to-pointer to be able to modify it in InitEmpty func. - orig **otlpmetrics.InstrumentationLibraryMetrics + orig *otlpmetrics.InstrumentationLibraryMetrics } -func newInstrumentationLibraryMetrics(orig **otlpmetrics.InstrumentationLibraryMetrics) InstrumentationLibraryMetrics { - return InstrumentationLibraryMetrics{orig} +func newInstrumentationLibraryMetrics(orig *otlpmetrics.InstrumentationLibraryMetrics) InstrumentationLibraryMetrics { + return InstrumentationLibraryMetrics{orig: orig} } -// NewInstrumentationLibraryMetrics creates a new "nil" InstrumentationLibraryMetrics. -// To initialize the struct call "InitEmpty". +// NewInstrumentationLibraryMetrics creates a new empty InstrumentationLibraryMetrics. // // This must be used only in testing code since no "Set" method available. func NewInstrumentationLibraryMetrics() InstrumentationLibraryMetrics { - orig := (*otlpmetrics.InstrumentationLibraryMetrics)(nil) - return newInstrumentationLibraryMetrics(&orig) + return newInstrumentationLibraryMetrics(&otlpmetrics.InstrumentationLibraryMetrics{}) } -// InitEmpty overwrites the current value with empty. +// Deprecated: This function will be removed soon. func (ms InstrumentationLibraryMetrics) InitEmpty() { - *ms.orig = &otlpmetrics.InstrumentationLibraryMetrics{} -} - -// IsNil returns true if the underlying data are nil. -// -// Important: All other functions will cause a runtime error if this returns "true". -func (ms InstrumentationLibraryMetrics) IsNil() bool { - return *ms.orig == nil + *ms.orig = otlpmetrics.InstrumentationLibraryMetrics{} } // InstrumentationLibrary returns the instrumentationlibrary associated with this InstrumentationLibraryMetrics. @@ -368,13 +341,6 @@ func (ms InstrumentationLibraryMetrics) Metrics() MetricSlice { // CopyTo copies all properties from the current struct to the dest. func (ms InstrumentationLibraryMetrics) CopyTo(dest InstrumentationLibraryMetrics) { - if ms.IsNil() { - *dest.orig = nil - return - } - if dest.IsNil() { - dest.InitEmpty() - } ms.InstrumentationLibrary().CopyTo(dest.InstrumentationLibrary()) ms.Metrics().CopyTo(dest.Metrics()) } @@ -418,7 +384,7 @@ func (es MetricSlice) Len() int { // ... // Do something with the element // } func (es MetricSlice) At(ix int) Metric { - return newMetric(&(*es.orig)[ix]) + return newMetric((*es.orig)[ix]) } // MoveAndAppendTo moves all elements from the current slice and appends them to the dest. @@ -440,7 +406,7 @@ func (es MetricSlice) CopyTo(dest MetricSlice) { if srcLen <= destCap { (*dest.orig) = (*dest.orig)[:srcLen:destCap] for i := range *es.orig { - newMetric(&(*es.orig)[i]).CopyTo(newMetric(&(*dest.orig)[i])) + newMetric((*es.orig)[i]).CopyTo(newMetric((*dest.orig)[i])) } return } @@ -448,7 +414,7 @@ func (es MetricSlice) CopyTo(dest MetricSlice) { wrappers := make([]*otlpmetrics.Metric, srcLen) for i := range *es.orig { wrappers[i] = &origs[i] - newMetric(&(*es.orig)[i]).CopyTo(newMetric(&wrappers[i])) + newMetric((*es.orig)[i]).CopyTo(newMetric(wrappers[i])) } *dest.orig = wrappers } @@ -490,7 +456,7 @@ func (es MetricSlice) Resize(newLen int) { // could still be referenced so do not reuse it after passing it to this // method. func (es MetricSlice) Append(e Metric) { - *es.orig = append(*es.orig, *e.orig) + *es.orig = append(*es.orig, e.orig) } // Metric represents one metric as a collection of datapoints. @@ -503,33 +469,23 @@ func (es MetricSlice) Append(e Metric) { // Important: zero-initialized instance is not valid for use. type Metric struct { // orig points to the pointer otlpmetrics.Metric field contained somewhere else. - // We use pointer-to-pointer to be able to modify it in InitEmpty func. - orig **otlpmetrics.Metric + orig *otlpmetrics.Metric } -func newMetric(orig **otlpmetrics.Metric) Metric { - return Metric{orig} +func newMetric(orig *otlpmetrics.Metric) Metric { + return Metric{orig: orig} } -// NewMetric creates a new "nil" Metric. -// To initialize the struct call "InitEmpty". +// NewMetric creates a new empty Metric. // // This must be used only in testing code since no "Set" method available. func NewMetric() Metric { - orig := (*otlpmetrics.Metric)(nil) - return newMetric(&orig) + return newMetric(&otlpmetrics.Metric{}) } -// InitEmpty overwrites the current value with empty. +// Deprecated: This function will be removed soon. func (ms Metric) InitEmpty() { - *ms.orig = &otlpmetrics.Metric{} -} - -// IsNil returns true if the underlying data are nil. -// -// Important: All other functions will cause a runtime error if this returns "true". -func (ms Metric) IsNil() bool { - return *ms.orig == nil + *ms.orig = otlpmetrics.Metric{} } // Name returns the name associated with this Metric. @@ -576,17 +532,10 @@ func (ms Metric) SetUnit(v string) { // CopyTo copies all properties from the current struct to the dest. func (ms Metric) CopyTo(dest Metric) { - if ms.IsNil() { - *dest.orig = nil - return - } - if dest.IsNil() { - dest.InitEmpty() - } dest.SetName(ms.Name()) dest.SetDescription(ms.Description()) dest.SetUnit(ms.Unit()) - copyData((*ms.orig), (*dest.orig)) + copyData(ms.orig, dest.orig) } // IntGauge represents the type of a int scalar metric that always exports the "current value" for every data point. @@ -998,7 +947,7 @@ func (es IntDataPointSlice) Len() int { // ... // Do something with the element // } func (es IntDataPointSlice) At(ix int) IntDataPoint { - return newIntDataPoint(&(*es.orig)[ix]) + return newIntDataPoint((*es.orig)[ix]) } // MoveAndAppendTo moves all elements from the current slice and appends them to the dest. @@ -1020,7 +969,7 @@ func (es IntDataPointSlice) CopyTo(dest IntDataPointSlice) { if srcLen <= destCap { (*dest.orig) = (*dest.orig)[:srcLen:destCap] for i := range *es.orig { - newIntDataPoint(&(*es.orig)[i]).CopyTo(newIntDataPoint(&(*dest.orig)[i])) + newIntDataPoint((*es.orig)[i]).CopyTo(newIntDataPoint((*dest.orig)[i])) } return } @@ -1028,7 +977,7 @@ func (es IntDataPointSlice) CopyTo(dest IntDataPointSlice) { wrappers := make([]*otlpmetrics.IntDataPoint, srcLen) for i := range *es.orig { wrappers[i] = &origs[i] - newIntDataPoint(&(*es.orig)[i]).CopyTo(newIntDataPoint(&wrappers[i])) + newIntDataPoint((*es.orig)[i]).CopyTo(newIntDataPoint(wrappers[i])) } *dest.orig = wrappers } @@ -1070,7 +1019,7 @@ func (es IntDataPointSlice) Resize(newLen int) { // could still be referenced so do not reuse it after passing it to this // method. func (es IntDataPointSlice) Append(e IntDataPoint) { - *es.orig = append(*es.orig, *e.orig) + *es.orig = append(*es.orig, e.orig) } // IntDataPoint is a single data point in a timeseries that describes the time-varying values of a scalar int metric. @@ -1082,33 +1031,23 @@ func (es IntDataPointSlice) Append(e IntDataPoint) { // Important: zero-initialized instance is not valid for use. type IntDataPoint struct { // orig points to the pointer otlpmetrics.IntDataPoint field contained somewhere else. - // We use pointer-to-pointer to be able to modify it in InitEmpty func. - orig **otlpmetrics.IntDataPoint + orig *otlpmetrics.IntDataPoint } -func newIntDataPoint(orig **otlpmetrics.IntDataPoint) IntDataPoint { - return IntDataPoint{orig} +func newIntDataPoint(orig *otlpmetrics.IntDataPoint) IntDataPoint { + return IntDataPoint{orig: orig} } -// NewIntDataPoint creates a new "nil" IntDataPoint. -// To initialize the struct call "InitEmpty". +// NewIntDataPoint creates a new empty IntDataPoint. // // This must be used only in testing code since no "Set" method available. func NewIntDataPoint() IntDataPoint { - orig := (*otlpmetrics.IntDataPoint)(nil) - return newIntDataPoint(&orig) + return newIntDataPoint(&otlpmetrics.IntDataPoint{}) } -// InitEmpty overwrites the current value with empty. +// Deprecated: This function will be removed soon. func (ms IntDataPoint) InitEmpty() { - *ms.orig = &otlpmetrics.IntDataPoint{} -} - -// IsNil returns true if the underlying data are nil. -// -// Important: All other functions will cause a runtime error if this returns "true". -func (ms IntDataPoint) IsNil() bool { - return *ms.orig == nil + *ms.orig = otlpmetrics.IntDataPoint{} } // LabelsMap returns the Labels associated with this IntDataPoint. @@ -1169,13 +1108,6 @@ func (ms IntDataPoint) Exemplars() IntExemplarSlice { // CopyTo copies all properties from the current struct to the dest. func (ms IntDataPoint) CopyTo(dest IntDataPoint) { - if ms.IsNil() { - *dest.orig = nil - return - } - if dest.IsNil() { - dest.InitEmpty() - } ms.LabelsMap().CopyTo(dest.LabelsMap()) dest.SetStartTime(ms.StartTime()) dest.SetTimestamp(ms.Timestamp()) @@ -1222,7 +1154,7 @@ func (es DoubleDataPointSlice) Len() int { // ... // Do something with the element // } func (es DoubleDataPointSlice) At(ix int) DoubleDataPoint { - return newDoubleDataPoint(&(*es.orig)[ix]) + return newDoubleDataPoint((*es.orig)[ix]) } // MoveAndAppendTo moves all elements from the current slice and appends them to the dest. @@ -1244,7 +1176,7 @@ func (es DoubleDataPointSlice) CopyTo(dest DoubleDataPointSlice) { if srcLen <= destCap { (*dest.orig) = (*dest.orig)[:srcLen:destCap] for i := range *es.orig { - newDoubleDataPoint(&(*es.orig)[i]).CopyTo(newDoubleDataPoint(&(*dest.orig)[i])) + newDoubleDataPoint((*es.orig)[i]).CopyTo(newDoubleDataPoint((*dest.orig)[i])) } return } @@ -1252,7 +1184,7 @@ func (es DoubleDataPointSlice) CopyTo(dest DoubleDataPointSlice) { wrappers := make([]*otlpmetrics.DoubleDataPoint, srcLen) for i := range *es.orig { wrappers[i] = &origs[i] - newDoubleDataPoint(&(*es.orig)[i]).CopyTo(newDoubleDataPoint(&wrappers[i])) + newDoubleDataPoint((*es.orig)[i]).CopyTo(newDoubleDataPoint(wrappers[i])) } *dest.orig = wrappers } @@ -1294,7 +1226,7 @@ func (es DoubleDataPointSlice) Resize(newLen int) { // could still be referenced so do not reuse it after passing it to this // method. func (es DoubleDataPointSlice) Append(e DoubleDataPoint) { - *es.orig = append(*es.orig, *e.orig) + *es.orig = append(*es.orig, e.orig) } // DoubleDataPoint is a single data point in a timeseries that describes the time-varying value of a double metric. @@ -1306,33 +1238,23 @@ func (es DoubleDataPointSlice) Append(e DoubleDataPoint) { // Important: zero-initialized instance is not valid for use. type DoubleDataPoint struct { // orig points to the pointer otlpmetrics.DoubleDataPoint field contained somewhere else. - // We use pointer-to-pointer to be able to modify it in InitEmpty func. - orig **otlpmetrics.DoubleDataPoint + orig *otlpmetrics.DoubleDataPoint } -func newDoubleDataPoint(orig **otlpmetrics.DoubleDataPoint) DoubleDataPoint { - return DoubleDataPoint{orig} +func newDoubleDataPoint(orig *otlpmetrics.DoubleDataPoint) DoubleDataPoint { + return DoubleDataPoint{orig: orig} } -// NewDoubleDataPoint creates a new "nil" DoubleDataPoint. -// To initialize the struct call "InitEmpty". +// NewDoubleDataPoint creates a new empty DoubleDataPoint. // // This must be used only in testing code since no "Set" method available. func NewDoubleDataPoint() DoubleDataPoint { - orig := (*otlpmetrics.DoubleDataPoint)(nil) - return newDoubleDataPoint(&orig) + return newDoubleDataPoint(&otlpmetrics.DoubleDataPoint{}) } -// InitEmpty overwrites the current value with empty. +// Deprecated: This function will be removed soon. func (ms DoubleDataPoint) InitEmpty() { - *ms.orig = &otlpmetrics.DoubleDataPoint{} -} - -// IsNil returns true if the underlying data are nil. -// -// Important: All other functions will cause a runtime error if this returns "true". -func (ms DoubleDataPoint) IsNil() bool { - return *ms.orig == nil + *ms.orig = otlpmetrics.DoubleDataPoint{} } // LabelsMap returns the Labels associated with this DoubleDataPoint. @@ -1393,13 +1315,6 @@ func (ms DoubleDataPoint) Exemplars() DoubleExemplarSlice { // CopyTo copies all properties from the current struct to the dest. func (ms DoubleDataPoint) CopyTo(dest DoubleDataPoint) { - if ms.IsNil() { - *dest.orig = nil - return - } - if dest.IsNil() { - dest.InitEmpty() - } ms.LabelsMap().CopyTo(dest.LabelsMap()) dest.SetStartTime(ms.StartTime()) dest.SetTimestamp(ms.Timestamp()) @@ -1446,7 +1361,7 @@ func (es IntHistogramDataPointSlice) Len() int { // ... // Do something with the element // } func (es IntHistogramDataPointSlice) At(ix int) IntHistogramDataPoint { - return newIntHistogramDataPoint(&(*es.orig)[ix]) + return newIntHistogramDataPoint((*es.orig)[ix]) } // MoveAndAppendTo moves all elements from the current slice and appends them to the dest. @@ -1468,7 +1383,7 @@ func (es IntHistogramDataPointSlice) CopyTo(dest IntHistogramDataPointSlice) { if srcLen <= destCap { (*dest.orig) = (*dest.orig)[:srcLen:destCap] for i := range *es.orig { - newIntHistogramDataPoint(&(*es.orig)[i]).CopyTo(newIntHistogramDataPoint(&(*dest.orig)[i])) + newIntHistogramDataPoint((*es.orig)[i]).CopyTo(newIntHistogramDataPoint((*dest.orig)[i])) } return } @@ -1476,7 +1391,7 @@ func (es IntHistogramDataPointSlice) CopyTo(dest IntHistogramDataPointSlice) { wrappers := make([]*otlpmetrics.IntHistogramDataPoint, srcLen) for i := range *es.orig { wrappers[i] = &origs[i] - newIntHistogramDataPoint(&(*es.orig)[i]).CopyTo(newIntHistogramDataPoint(&wrappers[i])) + newIntHistogramDataPoint((*es.orig)[i]).CopyTo(newIntHistogramDataPoint(wrappers[i])) } *dest.orig = wrappers } @@ -1518,7 +1433,7 @@ func (es IntHistogramDataPointSlice) Resize(newLen int) { // could still be referenced so do not reuse it after passing it to this // method. func (es IntHistogramDataPointSlice) Append(e IntHistogramDataPoint) { - *es.orig = append(*es.orig, *e.orig) + *es.orig = append(*es.orig, e.orig) } // IntHistogramDataPoint is a single data point in a timeseries that describes the time-varying values of a Histogram of int values. @@ -1530,33 +1445,23 @@ func (es IntHistogramDataPointSlice) Append(e IntHistogramDataPoint) { // Important: zero-initialized instance is not valid for use. type IntHistogramDataPoint struct { // orig points to the pointer otlpmetrics.IntHistogramDataPoint field contained somewhere else. - // We use pointer-to-pointer to be able to modify it in InitEmpty func. - orig **otlpmetrics.IntHistogramDataPoint + orig *otlpmetrics.IntHistogramDataPoint } -func newIntHistogramDataPoint(orig **otlpmetrics.IntHistogramDataPoint) IntHistogramDataPoint { - return IntHistogramDataPoint{orig} +func newIntHistogramDataPoint(orig *otlpmetrics.IntHistogramDataPoint) IntHistogramDataPoint { + return IntHistogramDataPoint{orig: orig} } -// NewIntHistogramDataPoint creates a new "nil" IntHistogramDataPoint. -// To initialize the struct call "InitEmpty". +// NewIntHistogramDataPoint creates a new empty IntHistogramDataPoint. // // This must be used only in testing code since no "Set" method available. func NewIntHistogramDataPoint() IntHistogramDataPoint { - orig := (*otlpmetrics.IntHistogramDataPoint)(nil) - return newIntHistogramDataPoint(&orig) + return newIntHistogramDataPoint(&otlpmetrics.IntHistogramDataPoint{}) } -// InitEmpty overwrites the current value with empty. +// Deprecated: This function will be removed soon. func (ms IntHistogramDataPoint) InitEmpty() { - *ms.orig = &otlpmetrics.IntHistogramDataPoint{} -} - -// IsNil returns true if the underlying data are nil. -// -// Important: All other functions will cause a runtime error if this returns "true". -func (ms IntHistogramDataPoint) IsNil() bool { - return *ms.orig == nil + *ms.orig = otlpmetrics.IntHistogramDataPoint{} } // LabelsMap returns the Labels associated with this IntHistogramDataPoint. @@ -1659,13 +1564,6 @@ func (ms IntHistogramDataPoint) Exemplars() IntExemplarSlice { // CopyTo copies all properties from the current struct to the dest. func (ms IntHistogramDataPoint) CopyTo(dest IntHistogramDataPoint) { - if ms.IsNil() { - *dest.orig = nil - return - } - if dest.IsNil() { - dest.InitEmpty() - } ms.LabelsMap().CopyTo(dest.LabelsMap()) dest.SetStartTime(ms.StartTime()) dest.SetTimestamp(ms.Timestamp()) @@ -1715,7 +1613,7 @@ func (es DoubleHistogramDataPointSlice) Len() int { // ... // Do something with the element // } func (es DoubleHistogramDataPointSlice) At(ix int) DoubleHistogramDataPoint { - return newDoubleHistogramDataPoint(&(*es.orig)[ix]) + return newDoubleHistogramDataPoint((*es.orig)[ix]) } // MoveAndAppendTo moves all elements from the current slice and appends them to the dest. @@ -1737,7 +1635,7 @@ func (es DoubleHistogramDataPointSlice) CopyTo(dest DoubleHistogramDataPointSlic if srcLen <= destCap { (*dest.orig) = (*dest.orig)[:srcLen:destCap] for i := range *es.orig { - newDoubleHistogramDataPoint(&(*es.orig)[i]).CopyTo(newDoubleHistogramDataPoint(&(*dest.orig)[i])) + newDoubleHistogramDataPoint((*es.orig)[i]).CopyTo(newDoubleHistogramDataPoint((*dest.orig)[i])) } return } @@ -1745,7 +1643,7 @@ func (es DoubleHistogramDataPointSlice) CopyTo(dest DoubleHistogramDataPointSlic wrappers := make([]*otlpmetrics.DoubleHistogramDataPoint, srcLen) for i := range *es.orig { wrappers[i] = &origs[i] - newDoubleHistogramDataPoint(&(*es.orig)[i]).CopyTo(newDoubleHistogramDataPoint(&wrappers[i])) + newDoubleHistogramDataPoint((*es.orig)[i]).CopyTo(newDoubleHistogramDataPoint(wrappers[i])) } *dest.orig = wrappers } @@ -1787,7 +1685,7 @@ func (es DoubleHistogramDataPointSlice) Resize(newLen int) { // could still be referenced so do not reuse it after passing it to this // method. func (es DoubleHistogramDataPointSlice) Append(e DoubleHistogramDataPoint) { - *es.orig = append(*es.orig, *e.orig) + *es.orig = append(*es.orig, e.orig) } // DoubleHistogramDataPoint is a single data point in a timeseries that describes the time-varying values of a Histogram of double values. @@ -1799,33 +1697,23 @@ func (es DoubleHistogramDataPointSlice) Append(e DoubleHistogramDataPoint) { // Important: zero-initialized instance is not valid for use. type DoubleHistogramDataPoint struct { // orig points to the pointer otlpmetrics.DoubleHistogramDataPoint field contained somewhere else. - // We use pointer-to-pointer to be able to modify it in InitEmpty func. - orig **otlpmetrics.DoubleHistogramDataPoint + orig *otlpmetrics.DoubleHistogramDataPoint } -func newDoubleHistogramDataPoint(orig **otlpmetrics.DoubleHistogramDataPoint) DoubleHistogramDataPoint { - return DoubleHistogramDataPoint{orig} +func newDoubleHistogramDataPoint(orig *otlpmetrics.DoubleHistogramDataPoint) DoubleHistogramDataPoint { + return DoubleHistogramDataPoint{orig: orig} } -// NewDoubleHistogramDataPoint creates a new "nil" DoubleHistogramDataPoint. -// To initialize the struct call "InitEmpty". +// NewDoubleHistogramDataPoint creates a new empty DoubleHistogramDataPoint. // // This must be used only in testing code since no "Set" method available. func NewDoubleHistogramDataPoint() DoubleHistogramDataPoint { - orig := (*otlpmetrics.DoubleHistogramDataPoint)(nil) - return newDoubleHistogramDataPoint(&orig) + return newDoubleHistogramDataPoint(&otlpmetrics.DoubleHistogramDataPoint{}) } -// InitEmpty overwrites the current value with empty. +// Deprecated: This function will be removed soon. func (ms DoubleHistogramDataPoint) InitEmpty() { - *ms.orig = &otlpmetrics.DoubleHistogramDataPoint{} -} - -// IsNil returns true if the underlying data are nil. -// -// Important: All other functions will cause a runtime error if this returns "true". -func (ms DoubleHistogramDataPoint) IsNil() bool { - return *ms.orig == nil + *ms.orig = otlpmetrics.DoubleHistogramDataPoint{} } // LabelsMap returns the Labels associated with this DoubleHistogramDataPoint. @@ -1928,13 +1816,6 @@ func (ms DoubleHistogramDataPoint) Exemplars() DoubleExemplarSlice { // CopyTo copies all properties from the current struct to the dest. func (ms DoubleHistogramDataPoint) CopyTo(dest DoubleHistogramDataPoint) { - if ms.IsNil() { - *dest.orig = nil - return - } - if dest.IsNil() { - dest.InitEmpty() - } ms.LabelsMap().CopyTo(dest.LabelsMap()) dest.SetStartTime(ms.StartTime()) dest.SetTimestamp(ms.Timestamp()) @@ -1984,7 +1865,7 @@ func (es DoubleSummaryDataPointSlice) Len() int { // ... // Do something with the element // } func (es DoubleSummaryDataPointSlice) At(ix int) DoubleSummaryDataPoint { - return newDoubleSummaryDataPoint(&(*es.orig)[ix]) + return newDoubleSummaryDataPoint((*es.orig)[ix]) } // MoveAndAppendTo moves all elements from the current slice and appends them to the dest. @@ -2006,7 +1887,7 @@ func (es DoubleSummaryDataPointSlice) CopyTo(dest DoubleSummaryDataPointSlice) { if srcLen <= destCap { (*dest.orig) = (*dest.orig)[:srcLen:destCap] for i := range *es.orig { - newDoubleSummaryDataPoint(&(*es.orig)[i]).CopyTo(newDoubleSummaryDataPoint(&(*dest.orig)[i])) + newDoubleSummaryDataPoint((*es.orig)[i]).CopyTo(newDoubleSummaryDataPoint((*dest.orig)[i])) } return } @@ -2014,7 +1895,7 @@ func (es DoubleSummaryDataPointSlice) CopyTo(dest DoubleSummaryDataPointSlice) { wrappers := make([]*otlpmetrics.DoubleSummaryDataPoint, srcLen) for i := range *es.orig { wrappers[i] = &origs[i] - newDoubleSummaryDataPoint(&(*es.orig)[i]).CopyTo(newDoubleSummaryDataPoint(&wrappers[i])) + newDoubleSummaryDataPoint((*es.orig)[i]).CopyTo(newDoubleSummaryDataPoint(wrappers[i])) } *dest.orig = wrappers } @@ -2056,7 +1937,7 @@ func (es DoubleSummaryDataPointSlice) Resize(newLen int) { // could still be referenced so do not reuse it after passing it to this // method. func (es DoubleSummaryDataPointSlice) Append(e DoubleSummaryDataPoint) { - *es.orig = append(*es.orig, *e.orig) + *es.orig = append(*es.orig, e.orig) } // DoubleSummaryDataPoint is a single data point in a timeseries that describes the time-varying values of a Summary of double values. @@ -2068,33 +1949,23 @@ func (es DoubleSummaryDataPointSlice) Append(e DoubleSummaryDataPoint) { // Important: zero-initialized instance is not valid for use. type DoubleSummaryDataPoint struct { // orig points to the pointer otlpmetrics.DoubleSummaryDataPoint field contained somewhere else. - // We use pointer-to-pointer to be able to modify it in InitEmpty func. - orig **otlpmetrics.DoubleSummaryDataPoint + orig *otlpmetrics.DoubleSummaryDataPoint } -func newDoubleSummaryDataPoint(orig **otlpmetrics.DoubleSummaryDataPoint) DoubleSummaryDataPoint { - return DoubleSummaryDataPoint{orig} +func newDoubleSummaryDataPoint(orig *otlpmetrics.DoubleSummaryDataPoint) DoubleSummaryDataPoint { + return DoubleSummaryDataPoint{orig: orig} } -// NewDoubleSummaryDataPoint creates a new "nil" DoubleSummaryDataPoint. -// To initialize the struct call "InitEmpty". +// NewDoubleSummaryDataPoint creates a new empty DoubleSummaryDataPoint. // // This must be used only in testing code since no "Set" method available. func NewDoubleSummaryDataPoint() DoubleSummaryDataPoint { - orig := (*otlpmetrics.DoubleSummaryDataPoint)(nil) - return newDoubleSummaryDataPoint(&orig) + return newDoubleSummaryDataPoint(&otlpmetrics.DoubleSummaryDataPoint{}) } -// InitEmpty overwrites the current value with empty. +// Deprecated: This function will be removed soon. func (ms DoubleSummaryDataPoint) InitEmpty() { - *ms.orig = &otlpmetrics.DoubleSummaryDataPoint{} -} - -// IsNil returns true if the underlying data are nil. -// -// Important: All other functions will cause a runtime error if this returns "true". -func (ms DoubleSummaryDataPoint) IsNil() bool { - return *ms.orig == nil + *ms.orig = otlpmetrics.DoubleSummaryDataPoint{} } // LabelsMap returns the Labels associated with this DoubleSummaryDataPoint. @@ -2169,13 +2040,6 @@ func (ms DoubleSummaryDataPoint) QuantileValues() ValueAtQuantileSlice { // CopyTo copies all properties from the current struct to the dest. func (ms DoubleSummaryDataPoint) CopyTo(dest DoubleSummaryDataPoint) { - if ms.IsNil() { - *dest.orig = nil - return - } - if dest.IsNil() { - dest.InitEmpty() - } ms.LabelsMap().CopyTo(dest.LabelsMap()) dest.SetStartTime(ms.StartTime()) dest.SetTimestamp(ms.Timestamp()) @@ -2223,7 +2087,7 @@ func (es ValueAtQuantileSlice) Len() int { // ... // Do something with the element // } func (es ValueAtQuantileSlice) At(ix int) ValueAtQuantile { - return newValueAtQuantile(&(*es.orig)[ix]) + return newValueAtQuantile((*es.orig)[ix]) } // MoveAndAppendTo moves all elements from the current slice and appends them to the dest. @@ -2245,7 +2109,7 @@ func (es ValueAtQuantileSlice) CopyTo(dest ValueAtQuantileSlice) { if srcLen <= destCap { (*dest.orig) = (*dest.orig)[:srcLen:destCap] for i := range *es.orig { - newValueAtQuantile(&(*es.orig)[i]).CopyTo(newValueAtQuantile(&(*dest.orig)[i])) + newValueAtQuantile((*es.orig)[i]).CopyTo(newValueAtQuantile((*dest.orig)[i])) } return } @@ -2253,7 +2117,7 @@ func (es ValueAtQuantileSlice) CopyTo(dest ValueAtQuantileSlice) { wrappers := make([]*otlpmetrics.DoubleSummaryDataPoint_ValueAtQuantile, srcLen) for i := range *es.orig { wrappers[i] = &origs[i] - newValueAtQuantile(&(*es.orig)[i]).CopyTo(newValueAtQuantile(&wrappers[i])) + newValueAtQuantile((*es.orig)[i]).CopyTo(newValueAtQuantile(wrappers[i])) } *dest.orig = wrappers } @@ -2295,7 +2159,7 @@ func (es ValueAtQuantileSlice) Resize(newLen int) { // could still be referenced so do not reuse it after passing it to this // method. func (es ValueAtQuantileSlice) Append(e ValueAtQuantile) { - *es.orig = append(*es.orig, *e.orig) + *es.orig = append(*es.orig, e.orig) } // ValueAtQuantile is a quantile value within a Summary data point @@ -2307,33 +2171,23 @@ func (es ValueAtQuantileSlice) Append(e ValueAtQuantile) { // Important: zero-initialized instance is not valid for use. type ValueAtQuantile struct { // orig points to the pointer otlpmetrics.DoubleSummaryDataPoint_ValueAtQuantile field contained somewhere else. - // We use pointer-to-pointer to be able to modify it in InitEmpty func. - orig **otlpmetrics.DoubleSummaryDataPoint_ValueAtQuantile + orig *otlpmetrics.DoubleSummaryDataPoint_ValueAtQuantile } -func newValueAtQuantile(orig **otlpmetrics.DoubleSummaryDataPoint_ValueAtQuantile) ValueAtQuantile { - return ValueAtQuantile{orig} +func newValueAtQuantile(orig *otlpmetrics.DoubleSummaryDataPoint_ValueAtQuantile) ValueAtQuantile { + return ValueAtQuantile{orig: orig} } -// NewValueAtQuantile creates a new "nil" ValueAtQuantile. -// To initialize the struct call "InitEmpty". +// NewValueAtQuantile creates a new empty ValueAtQuantile. // // This must be used only in testing code since no "Set" method available. func NewValueAtQuantile() ValueAtQuantile { - orig := (*otlpmetrics.DoubleSummaryDataPoint_ValueAtQuantile)(nil) - return newValueAtQuantile(&orig) + return newValueAtQuantile(&otlpmetrics.DoubleSummaryDataPoint_ValueAtQuantile{}) } -// InitEmpty overwrites the current value with empty. +// Deprecated: This function will be removed soon. func (ms ValueAtQuantile) InitEmpty() { - *ms.orig = &otlpmetrics.DoubleSummaryDataPoint_ValueAtQuantile{} -} - -// IsNil returns true if the underlying data are nil. -// -// Important: All other functions will cause a runtime error if this returns "true". -func (ms ValueAtQuantile) IsNil() bool { - return *ms.orig == nil + *ms.orig = otlpmetrics.DoubleSummaryDataPoint_ValueAtQuantile{} } // Quantile returns the quantile associated with this ValueAtQuantile. @@ -2366,13 +2220,6 @@ func (ms ValueAtQuantile) SetValue(v float64) { // CopyTo copies all properties from the current struct to the dest. func (ms ValueAtQuantile) CopyTo(dest ValueAtQuantile) { - if ms.IsNil() { - *dest.orig = nil - return - } - if dest.IsNil() { - dest.InitEmpty() - } dest.SetQuantile(ms.Quantile()) dest.SetValue(ms.Value()) } @@ -2416,7 +2263,7 @@ func (es IntExemplarSlice) Len() int { // ... // Do something with the element // } func (es IntExemplarSlice) At(ix int) IntExemplar { - return newIntExemplar(&(*es.orig)[ix]) + return newIntExemplar((*es.orig)[ix]) } // MoveAndAppendTo moves all elements from the current slice and appends them to the dest. @@ -2438,7 +2285,7 @@ func (es IntExemplarSlice) CopyTo(dest IntExemplarSlice) { if srcLen <= destCap { (*dest.orig) = (*dest.orig)[:srcLen:destCap] for i := range *es.orig { - newIntExemplar(&(*es.orig)[i]).CopyTo(newIntExemplar(&(*dest.orig)[i])) + newIntExemplar((*es.orig)[i]).CopyTo(newIntExemplar((*dest.orig)[i])) } return } @@ -2446,7 +2293,7 @@ func (es IntExemplarSlice) CopyTo(dest IntExemplarSlice) { wrappers := make([]*otlpmetrics.IntExemplar, srcLen) for i := range *es.orig { wrappers[i] = &origs[i] - newIntExemplar(&(*es.orig)[i]).CopyTo(newIntExemplar(&wrappers[i])) + newIntExemplar((*es.orig)[i]).CopyTo(newIntExemplar(wrappers[i])) } *dest.orig = wrappers } @@ -2488,7 +2335,7 @@ func (es IntExemplarSlice) Resize(newLen int) { // could still be referenced so do not reuse it after passing it to this // method. func (es IntExemplarSlice) Append(e IntExemplar) { - *es.orig = append(*es.orig, *e.orig) + *es.orig = append(*es.orig, e.orig) } // IntExemplar is a sample input int measurement. @@ -2503,33 +2350,23 @@ func (es IntExemplarSlice) Append(e IntExemplar) { // Important: zero-initialized instance is not valid for use. type IntExemplar struct { // orig points to the pointer otlpmetrics.IntExemplar field contained somewhere else. - // We use pointer-to-pointer to be able to modify it in InitEmpty func. - orig **otlpmetrics.IntExemplar + orig *otlpmetrics.IntExemplar } -func newIntExemplar(orig **otlpmetrics.IntExemplar) IntExemplar { - return IntExemplar{orig} +func newIntExemplar(orig *otlpmetrics.IntExemplar) IntExemplar { + return IntExemplar{orig: orig} } -// NewIntExemplar creates a new "nil" IntExemplar. -// To initialize the struct call "InitEmpty". +// NewIntExemplar creates a new empty IntExemplar. // // This must be used only in testing code since no "Set" method available. func NewIntExemplar() IntExemplar { - orig := (*otlpmetrics.IntExemplar)(nil) - return newIntExemplar(&orig) + return newIntExemplar(&otlpmetrics.IntExemplar{}) } -// InitEmpty overwrites the current value with empty. +// Deprecated: This function will be removed soon. func (ms IntExemplar) InitEmpty() { - *ms.orig = &otlpmetrics.IntExemplar{} -} - -// IsNil returns true if the underlying data are nil. -// -// Important: All other functions will cause a runtime error if this returns "true". -func (ms IntExemplar) IsNil() bool { - return *ms.orig == nil + *ms.orig = otlpmetrics.IntExemplar{} } // Timestamp returns the timestamp associated with this IntExemplar. @@ -2569,13 +2406,6 @@ func (ms IntExemplar) FilteredLabels() StringMap { // CopyTo copies all properties from the current struct to the dest. func (ms IntExemplar) CopyTo(dest IntExemplar) { - if ms.IsNil() { - *dest.orig = nil - return - } - if dest.IsNil() { - dest.InitEmpty() - } dest.SetTimestamp(ms.Timestamp()) dest.SetValue(ms.Value()) ms.FilteredLabels().CopyTo(dest.FilteredLabels()) @@ -2620,7 +2450,7 @@ func (es DoubleExemplarSlice) Len() int { // ... // Do something with the element // } func (es DoubleExemplarSlice) At(ix int) DoubleExemplar { - return newDoubleExemplar(&(*es.orig)[ix]) + return newDoubleExemplar((*es.orig)[ix]) } // MoveAndAppendTo moves all elements from the current slice and appends them to the dest. @@ -2642,7 +2472,7 @@ func (es DoubleExemplarSlice) CopyTo(dest DoubleExemplarSlice) { if srcLen <= destCap { (*dest.orig) = (*dest.orig)[:srcLen:destCap] for i := range *es.orig { - newDoubleExemplar(&(*es.orig)[i]).CopyTo(newDoubleExemplar(&(*dest.orig)[i])) + newDoubleExemplar((*es.orig)[i]).CopyTo(newDoubleExemplar((*dest.orig)[i])) } return } @@ -2650,7 +2480,7 @@ func (es DoubleExemplarSlice) CopyTo(dest DoubleExemplarSlice) { wrappers := make([]*otlpmetrics.DoubleExemplar, srcLen) for i := range *es.orig { wrappers[i] = &origs[i] - newDoubleExemplar(&(*es.orig)[i]).CopyTo(newDoubleExemplar(&wrappers[i])) + newDoubleExemplar((*es.orig)[i]).CopyTo(newDoubleExemplar(wrappers[i])) } *dest.orig = wrappers } @@ -2692,7 +2522,7 @@ func (es DoubleExemplarSlice) Resize(newLen int) { // could still be referenced so do not reuse it after passing it to this // method. func (es DoubleExemplarSlice) Append(e DoubleExemplar) { - *es.orig = append(*es.orig, *e.orig) + *es.orig = append(*es.orig, e.orig) } // DoubleExemplar is a sample input double measurement. @@ -2707,33 +2537,23 @@ func (es DoubleExemplarSlice) Append(e DoubleExemplar) { // Important: zero-initialized instance is not valid for use. type DoubleExemplar struct { // orig points to the pointer otlpmetrics.DoubleExemplar field contained somewhere else. - // We use pointer-to-pointer to be able to modify it in InitEmpty func. - orig **otlpmetrics.DoubleExemplar + orig *otlpmetrics.DoubleExemplar } -func newDoubleExemplar(orig **otlpmetrics.DoubleExemplar) DoubleExemplar { - return DoubleExemplar{orig} +func newDoubleExemplar(orig *otlpmetrics.DoubleExemplar) DoubleExemplar { + return DoubleExemplar{orig: orig} } -// NewDoubleExemplar creates a new "nil" DoubleExemplar. -// To initialize the struct call "InitEmpty". +// NewDoubleExemplar creates a new empty DoubleExemplar. // // This must be used only in testing code since no "Set" method available. func NewDoubleExemplar() DoubleExemplar { - orig := (*otlpmetrics.DoubleExemplar)(nil) - return newDoubleExemplar(&orig) + return newDoubleExemplar(&otlpmetrics.DoubleExemplar{}) } -// InitEmpty overwrites the current value with empty. +// Deprecated: This function will be removed soon. func (ms DoubleExemplar) InitEmpty() { - *ms.orig = &otlpmetrics.DoubleExemplar{} -} - -// IsNil returns true if the underlying data are nil. -// -// Important: All other functions will cause a runtime error if this returns "true". -func (ms DoubleExemplar) IsNil() bool { - return *ms.orig == nil + *ms.orig = otlpmetrics.DoubleExemplar{} } // Timestamp returns the timestamp associated with this DoubleExemplar. @@ -2773,13 +2593,6 @@ func (ms DoubleExemplar) FilteredLabels() StringMap { // CopyTo copies all properties from the current struct to the dest. func (ms DoubleExemplar) CopyTo(dest DoubleExemplar) { - if ms.IsNil() { - *dest.orig = nil - return - } - if dest.IsNil() { - dest.InitEmpty() - } dest.SetTimestamp(ms.Timestamp()) dest.SetValue(ms.Value()) ms.FilteredLabels().CopyTo(dest.FilteredLabels()) diff --git a/consumer/pdata/generated_metrics_test.go b/consumer/pdata/generated_metrics_test.go index 3b80f1b0e94..e504d250543 100644 --- a/consumer/pdata/generated_metrics_test.go +++ b/consumer/pdata/generated_metrics_test.go @@ -33,7 +33,6 @@ func TestResourceMetricsSlice(t *testing.T) { es.Resize(7) emptyVal := NewResourceMetrics() - emptyVal.InitEmpty() testVal := generateTestResourceMetrics() assert.EqualValues(t, 7, es.Len()) for i := 0; i < es.Len(); i++ { @@ -86,19 +85,18 @@ func TestResourceMetricsSlice_CopyTo(t *testing.T) { func TestResourceMetricsSlice_Resize(t *testing.T) { es := generateTestResourceMetricsSlice() emptyVal := NewResourceMetrics() - emptyVal.InitEmpty() // Test Resize less elements. const resizeSmallLen = 4 expectedEs := make(map[*otlpmetrics.ResourceMetrics]bool, resizeSmallLen) for i := 0; i < resizeSmallLen; i++ { - expectedEs[*(es.At(i).orig)] = true + expectedEs[es.At(i).orig] = true } assert.Equal(t, resizeSmallLen, len(expectedEs)) es.Resize(resizeSmallLen) assert.Equal(t, resizeSmallLen, es.Len()) foundEs := make(map[*otlpmetrics.ResourceMetrics]bool, resizeSmallLen) for i := 0; i < es.Len(); i++ { - foundEs[*(es.At(i).orig)] = true + foundEs[es.At(i).orig] = true } assert.EqualValues(t, expectedEs, foundEs) @@ -107,14 +105,14 @@ func TestResourceMetricsSlice_Resize(t *testing.T) { oldLen := es.Len() expectedEs = make(map[*otlpmetrics.ResourceMetrics]bool, oldLen) for i := 0; i < oldLen; i++ { - expectedEs[*(es.At(i).orig)] = true + expectedEs[es.At(i).orig] = true } assert.Equal(t, oldLen, len(expectedEs)) es.Resize(resizeLargeLen) assert.Equal(t, resizeLargeLen, es.Len()) foundEs = make(map[*otlpmetrics.ResourceMetrics]bool, oldLen) for i := 0; i < oldLen; i++ { - foundEs[*(es.At(i).orig)] = true + foundEs[es.At(i).orig] = true } assert.EqualValues(t, expectedEs, foundEs) for i := oldLen; i < resizeLargeLen; i++ { @@ -128,32 +126,20 @@ func TestResourceMetricsSlice_Resize(t *testing.T) { func TestResourceMetricsSlice_Append(t *testing.T) { es := generateTestResourceMetricsSlice() - emptyVal := NewResourceMetrics() - emptyVal.InitEmpty() + emptyVal := NewResourceMetrics() es.Append(emptyVal) - assert.EqualValues(t, *(es.At(7)).orig, *emptyVal.orig) + assert.EqualValues(t, es.At(7).orig, emptyVal.orig) emptyVal2 := NewResourceMetrics() - emptyVal2.InitEmpty() - es.Append(emptyVal2) - assert.EqualValues(t, *(es.At(8)).orig, *emptyVal2.orig) + assert.EqualValues(t, es.At(8).orig, emptyVal2.orig) assert.Equal(t, 9, es.Len()) } -func TestResourceMetrics_InitEmpty(t *testing.T) { - ms := NewResourceMetrics() - assert.True(t, ms.IsNil()) - ms.InitEmpty() - assert.False(t, ms.IsNil()) -} - func TestResourceMetrics_CopyTo(t *testing.T) { ms := NewResourceMetrics() - NewResourceMetrics().CopyTo(ms) - assert.True(t, ms.IsNil()) generateTestResourceMetrics().CopyTo(ms) assert.EqualValues(t, generateTestResourceMetrics(), ms) } @@ -182,7 +168,6 @@ func TestInstrumentationLibraryMetricsSlice(t *testing.T) { es.Resize(7) emptyVal := NewInstrumentationLibraryMetrics() - emptyVal.InitEmpty() testVal := generateTestInstrumentationLibraryMetrics() assert.EqualValues(t, 7, es.Len()) for i := 0; i < es.Len(); i++ { @@ -235,19 +220,18 @@ func TestInstrumentationLibraryMetricsSlice_CopyTo(t *testing.T) { func TestInstrumentationLibraryMetricsSlice_Resize(t *testing.T) { es := generateTestInstrumentationLibraryMetricsSlice() emptyVal := NewInstrumentationLibraryMetrics() - emptyVal.InitEmpty() // Test Resize less elements. const resizeSmallLen = 4 expectedEs := make(map[*otlpmetrics.InstrumentationLibraryMetrics]bool, resizeSmallLen) for i := 0; i < resizeSmallLen; i++ { - expectedEs[*(es.At(i).orig)] = true + expectedEs[es.At(i).orig] = true } assert.Equal(t, resizeSmallLen, len(expectedEs)) es.Resize(resizeSmallLen) assert.Equal(t, resizeSmallLen, es.Len()) foundEs := make(map[*otlpmetrics.InstrumentationLibraryMetrics]bool, resizeSmallLen) for i := 0; i < es.Len(); i++ { - foundEs[*(es.At(i).orig)] = true + foundEs[es.At(i).orig] = true } assert.EqualValues(t, expectedEs, foundEs) @@ -256,14 +240,14 @@ func TestInstrumentationLibraryMetricsSlice_Resize(t *testing.T) { oldLen := es.Len() expectedEs = make(map[*otlpmetrics.InstrumentationLibraryMetrics]bool, oldLen) for i := 0; i < oldLen; i++ { - expectedEs[*(es.At(i).orig)] = true + expectedEs[es.At(i).orig] = true } assert.Equal(t, oldLen, len(expectedEs)) es.Resize(resizeLargeLen) assert.Equal(t, resizeLargeLen, es.Len()) foundEs = make(map[*otlpmetrics.InstrumentationLibraryMetrics]bool, oldLen) for i := 0; i < oldLen; i++ { - foundEs[*(es.At(i).orig)] = true + foundEs[es.At(i).orig] = true } assert.EqualValues(t, expectedEs, foundEs) for i := oldLen; i < resizeLargeLen; i++ { @@ -277,32 +261,20 @@ func TestInstrumentationLibraryMetricsSlice_Resize(t *testing.T) { func TestInstrumentationLibraryMetricsSlice_Append(t *testing.T) { es := generateTestInstrumentationLibraryMetricsSlice() - emptyVal := NewInstrumentationLibraryMetrics() - emptyVal.InitEmpty() + emptyVal := NewInstrumentationLibraryMetrics() es.Append(emptyVal) - assert.EqualValues(t, *(es.At(7)).orig, *emptyVal.orig) + assert.EqualValues(t, es.At(7).orig, emptyVal.orig) emptyVal2 := NewInstrumentationLibraryMetrics() - emptyVal2.InitEmpty() - es.Append(emptyVal2) - assert.EqualValues(t, *(es.At(8)).orig, *emptyVal2.orig) + assert.EqualValues(t, es.At(8).orig, emptyVal2.orig) assert.Equal(t, 9, es.Len()) } -func TestInstrumentationLibraryMetrics_InitEmpty(t *testing.T) { - ms := NewInstrumentationLibraryMetrics() - assert.True(t, ms.IsNil()) - ms.InitEmpty() - assert.False(t, ms.IsNil()) -} - func TestInstrumentationLibraryMetrics_CopyTo(t *testing.T) { ms := NewInstrumentationLibraryMetrics() - NewInstrumentationLibraryMetrics().CopyTo(ms) - assert.True(t, ms.IsNil()) generateTestInstrumentationLibraryMetrics().CopyTo(ms) assert.EqualValues(t, generateTestInstrumentationLibraryMetrics(), ms) } @@ -331,7 +303,6 @@ func TestMetricSlice(t *testing.T) { es.Resize(7) emptyVal := NewMetric() - emptyVal.InitEmpty() testVal := generateTestMetric() assert.EqualValues(t, 7, es.Len()) for i := 0; i < es.Len(); i++ { @@ -384,19 +355,18 @@ func TestMetricSlice_CopyTo(t *testing.T) { func TestMetricSlice_Resize(t *testing.T) { es := generateTestMetricSlice() emptyVal := NewMetric() - emptyVal.InitEmpty() // Test Resize less elements. const resizeSmallLen = 4 expectedEs := make(map[*otlpmetrics.Metric]bool, resizeSmallLen) for i := 0; i < resizeSmallLen; i++ { - expectedEs[*(es.At(i).orig)] = true + expectedEs[es.At(i).orig] = true } assert.Equal(t, resizeSmallLen, len(expectedEs)) es.Resize(resizeSmallLen) assert.Equal(t, resizeSmallLen, es.Len()) foundEs := make(map[*otlpmetrics.Metric]bool, resizeSmallLen) for i := 0; i < es.Len(); i++ { - foundEs[*(es.At(i).orig)] = true + foundEs[es.At(i).orig] = true } assert.EqualValues(t, expectedEs, foundEs) @@ -405,14 +375,14 @@ func TestMetricSlice_Resize(t *testing.T) { oldLen := es.Len() expectedEs = make(map[*otlpmetrics.Metric]bool, oldLen) for i := 0; i < oldLen; i++ { - expectedEs[*(es.At(i).orig)] = true + expectedEs[es.At(i).orig] = true } assert.Equal(t, oldLen, len(expectedEs)) es.Resize(resizeLargeLen) assert.Equal(t, resizeLargeLen, es.Len()) foundEs = make(map[*otlpmetrics.Metric]bool, oldLen) for i := 0; i < oldLen; i++ { - foundEs[*(es.At(i).orig)] = true + foundEs[es.At(i).orig] = true } assert.EqualValues(t, expectedEs, foundEs) for i := oldLen; i < resizeLargeLen; i++ { @@ -426,32 +396,20 @@ func TestMetricSlice_Resize(t *testing.T) { func TestMetricSlice_Append(t *testing.T) { es := generateTestMetricSlice() - emptyVal := NewMetric() - emptyVal.InitEmpty() + emptyVal := NewMetric() es.Append(emptyVal) - assert.EqualValues(t, *(es.At(7)).orig, *emptyVal.orig) + assert.EqualValues(t, es.At(7).orig, emptyVal.orig) emptyVal2 := NewMetric() - emptyVal2.InitEmpty() - es.Append(emptyVal2) - assert.EqualValues(t, *(es.At(8)).orig, *emptyVal2.orig) + assert.EqualValues(t, es.At(8).orig, emptyVal2.orig) assert.Equal(t, 9, es.Len()) } -func TestMetric_InitEmpty(t *testing.T) { - ms := NewMetric() - assert.True(t, ms.IsNil()) - ms.InitEmpty() - assert.False(t, ms.IsNil()) -} - func TestMetric_CopyTo(t *testing.T) { ms := NewMetric() - NewMetric().CopyTo(ms) - assert.True(t, ms.IsNil()) generateTestMetric().CopyTo(ms) assert.EqualValues(t, generateTestMetric(), ms) } @@ -650,7 +608,6 @@ func TestIntDataPointSlice(t *testing.T) { es.Resize(7) emptyVal := NewIntDataPoint() - emptyVal.InitEmpty() testVal := generateTestIntDataPoint() assert.EqualValues(t, 7, es.Len()) for i := 0; i < es.Len(); i++ { @@ -703,19 +660,18 @@ func TestIntDataPointSlice_CopyTo(t *testing.T) { func TestIntDataPointSlice_Resize(t *testing.T) { es := generateTestIntDataPointSlice() emptyVal := NewIntDataPoint() - emptyVal.InitEmpty() // Test Resize less elements. const resizeSmallLen = 4 expectedEs := make(map[*otlpmetrics.IntDataPoint]bool, resizeSmallLen) for i := 0; i < resizeSmallLen; i++ { - expectedEs[*(es.At(i).orig)] = true + expectedEs[es.At(i).orig] = true } assert.Equal(t, resizeSmallLen, len(expectedEs)) es.Resize(resizeSmallLen) assert.Equal(t, resizeSmallLen, es.Len()) foundEs := make(map[*otlpmetrics.IntDataPoint]bool, resizeSmallLen) for i := 0; i < es.Len(); i++ { - foundEs[*(es.At(i).orig)] = true + foundEs[es.At(i).orig] = true } assert.EqualValues(t, expectedEs, foundEs) @@ -724,14 +680,14 @@ func TestIntDataPointSlice_Resize(t *testing.T) { oldLen := es.Len() expectedEs = make(map[*otlpmetrics.IntDataPoint]bool, oldLen) for i := 0; i < oldLen; i++ { - expectedEs[*(es.At(i).orig)] = true + expectedEs[es.At(i).orig] = true } assert.Equal(t, oldLen, len(expectedEs)) es.Resize(resizeLargeLen) assert.Equal(t, resizeLargeLen, es.Len()) foundEs = make(map[*otlpmetrics.IntDataPoint]bool, oldLen) for i := 0; i < oldLen; i++ { - foundEs[*(es.At(i).orig)] = true + foundEs[es.At(i).orig] = true } assert.EqualValues(t, expectedEs, foundEs) for i := oldLen; i < resizeLargeLen; i++ { @@ -745,32 +701,20 @@ func TestIntDataPointSlice_Resize(t *testing.T) { func TestIntDataPointSlice_Append(t *testing.T) { es := generateTestIntDataPointSlice() - emptyVal := NewIntDataPoint() - emptyVal.InitEmpty() + emptyVal := NewIntDataPoint() es.Append(emptyVal) - assert.EqualValues(t, *(es.At(7)).orig, *emptyVal.orig) + assert.EqualValues(t, es.At(7).orig, emptyVal.orig) emptyVal2 := NewIntDataPoint() - emptyVal2.InitEmpty() - es.Append(emptyVal2) - assert.EqualValues(t, *(es.At(8)).orig, *emptyVal2.orig) + assert.EqualValues(t, es.At(8).orig, emptyVal2.orig) assert.Equal(t, 9, es.Len()) } -func TestIntDataPoint_InitEmpty(t *testing.T) { - ms := NewIntDataPoint() - assert.True(t, ms.IsNil()) - ms.InitEmpty() - assert.False(t, ms.IsNil()) -} - func TestIntDataPoint_CopyTo(t *testing.T) { ms := NewIntDataPoint() - NewIntDataPoint().CopyTo(ms) - assert.True(t, ms.IsNil()) generateTestIntDataPoint().CopyTo(ms) assert.EqualValues(t, generateTestIntDataPoint(), ms) } @@ -828,7 +772,6 @@ func TestDoubleDataPointSlice(t *testing.T) { es.Resize(7) emptyVal := NewDoubleDataPoint() - emptyVal.InitEmpty() testVal := generateTestDoubleDataPoint() assert.EqualValues(t, 7, es.Len()) for i := 0; i < es.Len(); i++ { @@ -881,19 +824,18 @@ func TestDoubleDataPointSlice_CopyTo(t *testing.T) { func TestDoubleDataPointSlice_Resize(t *testing.T) { es := generateTestDoubleDataPointSlice() emptyVal := NewDoubleDataPoint() - emptyVal.InitEmpty() // Test Resize less elements. const resizeSmallLen = 4 expectedEs := make(map[*otlpmetrics.DoubleDataPoint]bool, resizeSmallLen) for i := 0; i < resizeSmallLen; i++ { - expectedEs[*(es.At(i).orig)] = true + expectedEs[es.At(i).orig] = true } assert.Equal(t, resizeSmallLen, len(expectedEs)) es.Resize(resizeSmallLen) assert.Equal(t, resizeSmallLen, es.Len()) foundEs := make(map[*otlpmetrics.DoubleDataPoint]bool, resizeSmallLen) for i := 0; i < es.Len(); i++ { - foundEs[*(es.At(i).orig)] = true + foundEs[es.At(i).orig] = true } assert.EqualValues(t, expectedEs, foundEs) @@ -902,14 +844,14 @@ func TestDoubleDataPointSlice_Resize(t *testing.T) { oldLen := es.Len() expectedEs = make(map[*otlpmetrics.DoubleDataPoint]bool, oldLen) for i := 0; i < oldLen; i++ { - expectedEs[*(es.At(i).orig)] = true + expectedEs[es.At(i).orig] = true } assert.Equal(t, oldLen, len(expectedEs)) es.Resize(resizeLargeLen) assert.Equal(t, resizeLargeLen, es.Len()) foundEs = make(map[*otlpmetrics.DoubleDataPoint]bool, oldLen) for i := 0; i < oldLen; i++ { - foundEs[*(es.At(i).orig)] = true + foundEs[es.At(i).orig] = true } assert.EqualValues(t, expectedEs, foundEs) for i := oldLen; i < resizeLargeLen; i++ { @@ -923,32 +865,20 @@ func TestDoubleDataPointSlice_Resize(t *testing.T) { func TestDoubleDataPointSlice_Append(t *testing.T) { es := generateTestDoubleDataPointSlice() - emptyVal := NewDoubleDataPoint() - emptyVal.InitEmpty() + emptyVal := NewDoubleDataPoint() es.Append(emptyVal) - assert.EqualValues(t, *(es.At(7)).orig, *emptyVal.orig) + assert.EqualValues(t, es.At(7).orig, emptyVal.orig) emptyVal2 := NewDoubleDataPoint() - emptyVal2.InitEmpty() - es.Append(emptyVal2) - assert.EqualValues(t, *(es.At(8)).orig, *emptyVal2.orig) + assert.EqualValues(t, es.At(8).orig, emptyVal2.orig) assert.Equal(t, 9, es.Len()) } -func TestDoubleDataPoint_InitEmpty(t *testing.T) { - ms := NewDoubleDataPoint() - assert.True(t, ms.IsNil()) - ms.InitEmpty() - assert.False(t, ms.IsNil()) -} - func TestDoubleDataPoint_CopyTo(t *testing.T) { ms := NewDoubleDataPoint() - NewDoubleDataPoint().CopyTo(ms) - assert.True(t, ms.IsNil()) generateTestDoubleDataPoint().CopyTo(ms) assert.EqualValues(t, generateTestDoubleDataPoint(), ms) } @@ -1006,7 +936,6 @@ func TestIntHistogramDataPointSlice(t *testing.T) { es.Resize(7) emptyVal := NewIntHistogramDataPoint() - emptyVal.InitEmpty() testVal := generateTestIntHistogramDataPoint() assert.EqualValues(t, 7, es.Len()) for i := 0; i < es.Len(); i++ { @@ -1059,19 +988,18 @@ func TestIntHistogramDataPointSlice_CopyTo(t *testing.T) { func TestIntHistogramDataPointSlice_Resize(t *testing.T) { es := generateTestIntHistogramDataPointSlice() emptyVal := NewIntHistogramDataPoint() - emptyVal.InitEmpty() // Test Resize less elements. const resizeSmallLen = 4 expectedEs := make(map[*otlpmetrics.IntHistogramDataPoint]bool, resizeSmallLen) for i := 0; i < resizeSmallLen; i++ { - expectedEs[*(es.At(i).orig)] = true + expectedEs[es.At(i).orig] = true } assert.Equal(t, resizeSmallLen, len(expectedEs)) es.Resize(resizeSmallLen) assert.Equal(t, resizeSmallLen, es.Len()) foundEs := make(map[*otlpmetrics.IntHistogramDataPoint]bool, resizeSmallLen) for i := 0; i < es.Len(); i++ { - foundEs[*(es.At(i).orig)] = true + foundEs[es.At(i).orig] = true } assert.EqualValues(t, expectedEs, foundEs) @@ -1080,14 +1008,14 @@ func TestIntHistogramDataPointSlice_Resize(t *testing.T) { oldLen := es.Len() expectedEs = make(map[*otlpmetrics.IntHistogramDataPoint]bool, oldLen) for i := 0; i < oldLen; i++ { - expectedEs[*(es.At(i).orig)] = true + expectedEs[es.At(i).orig] = true } assert.Equal(t, oldLen, len(expectedEs)) es.Resize(resizeLargeLen) assert.Equal(t, resizeLargeLen, es.Len()) foundEs = make(map[*otlpmetrics.IntHistogramDataPoint]bool, oldLen) for i := 0; i < oldLen; i++ { - foundEs[*(es.At(i).orig)] = true + foundEs[es.At(i).orig] = true } assert.EqualValues(t, expectedEs, foundEs) for i := oldLen; i < resizeLargeLen; i++ { @@ -1101,32 +1029,20 @@ func TestIntHistogramDataPointSlice_Resize(t *testing.T) { func TestIntHistogramDataPointSlice_Append(t *testing.T) { es := generateTestIntHistogramDataPointSlice() - emptyVal := NewIntHistogramDataPoint() - emptyVal.InitEmpty() + emptyVal := NewIntHistogramDataPoint() es.Append(emptyVal) - assert.EqualValues(t, *(es.At(7)).orig, *emptyVal.orig) + assert.EqualValues(t, es.At(7).orig, emptyVal.orig) emptyVal2 := NewIntHistogramDataPoint() - emptyVal2.InitEmpty() - es.Append(emptyVal2) - assert.EqualValues(t, *(es.At(8)).orig, *emptyVal2.orig) + assert.EqualValues(t, es.At(8).orig, emptyVal2.orig) assert.Equal(t, 9, es.Len()) } -func TestIntHistogramDataPoint_InitEmpty(t *testing.T) { - ms := NewIntHistogramDataPoint() - assert.True(t, ms.IsNil()) - ms.InitEmpty() - assert.False(t, ms.IsNil()) -} - func TestIntHistogramDataPoint_CopyTo(t *testing.T) { ms := NewIntHistogramDataPoint() - NewIntHistogramDataPoint().CopyTo(ms) - assert.True(t, ms.IsNil()) generateTestIntHistogramDataPoint().CopyTo(ms) assert.EqualValues(t, generateTestIntHistogramDataPoint(), ms) } @@ -1211,7 +1127,6 @@ func TestDoubleHistogramDataPointSlice(t *testing.T) { es.Resize(7) emptyVal := NewDoubleHistogramDataPoint() - emptyVal.InitEmpty() testVal := generateTestDoubleHistogramDataPoint() assert.EqualValues(t, 7, es.Len()) for i := 0; i < es.Len(); i++ { @@ -1264,19 +1179,18 @@ func TestDoubleHistogramDataPointSlice_CopyTo(t *testing.T) { func TestDoubleHistogramDataPointSlice_Resize(t *testing.T) { es := generateTestDoubleHistogramDataPointSlice() emptyVal := NewDoubleHistogramDataPoint() - emptyVal.InitEmpty() // Test Resize less elements. const resizeSmallLen = 4 expectedEs := make(map[*otlpmetrics.DoubleHistogramDataPoint]bool, resizeSmallLen) for i := 0; i < resizeSmallLen; i++ { - expectedEs[*(es.At(i).orig)] = true + expectedEs[es.At(i).orig] = true } assert.Equal(t, resizeSmallLen, len(expectedEs)) es.Resize(resizeSmallLen) assert.Equal(t, resizeSmallLen, es.Len()) foundEs := make(map[*otlpmetrics.DoubleHistogramDataPoint]bool, resizeSmallLen) for i := 0; i < es.Len(); i++ { - foundEs[*(es.At(i).orig)] = true + foundEs[es.At(i).orig] = true } assert.EqualValues(t, expectedEs, foundEs) @@ -1285,14 +1199,14 @@ func TestDoubleHistogramDataPointSlice_Resize(t *testing.T) { oldLen := es.Len() expectedEs = make(map[*otlpmetrics.DoubleHistogramDataPoint]bool, oldLen) for i := 0; i < oldLen; i++ { - expectedEs[*(es.At(i).orig)] = true + expectedEs[es.At(i).orig] = true } assert.Equal(t, oldLen, len(expectedEs)) es.Resize(resizeLargeLen) assert.Equal(t, resizeLargeLen, es.Len()) foundEs = make(map[*otlpmetrics.DoubleHistogramDataPoint]bool, oldLen) for i := 0; i < oldLen; i++ { - foundEs[*(es.At(i).orig)] = true + foundEs[es.At(i).orig] = true } assert.EqualValues(t, expectedEs, foundEs) for i := oldLen; i < resizeLargeLen; i++ { @@ -1306,32 +1220,20 @@ func TestDoubleHistogramDataPointSlice_Resize(t *testing.T) { func TestDoubleHistogramDataPointSlice_Append(t *testing.T) { es := generateTestDoubleHistogramDataPointSlice() - emptyVal := NewDoubleHistogramDataPoint() - emptyVal.InitEmpty() + emptyVal := NewDoubleHistogramDataPoint() es.Append(emptyVal) - assert.EqualValues(t, *(es.At(7)).orig, *emptyVal.orig) + assert.EqualValues(t, es.At(7).orig, emptyVal.orig) emptyVal2 := NewDoubleHistogramDataPoint() - emptyVal2.InitEmpty() - es.Append(emptyVal2) - assert.EqualValues(t, *(es.At(8)).orig, *emptyVal2.orig) + assert.EqualValues(t, es.At(8).orig, emptyVal2.orig) assert.Equal(t, 9, es.Len()) } -func TestDoubleHistogramDataPoint_InitEmpty(t *testing.T) { - ms := NewDoubleHistogramDataPoint() - assert.True(t, ms.IsNil()) - ms.InitEmpty() - assert.False(t, ms.IsNil()) -} - func TestDoubleHistogramDataPoint_CopyTo(t *testing.T) { ms := NewDoubleHistogramDataPoint() - NewDoubleHistogramDataPoint().CopyTo(ms) - assert.True(t, ms.IsNil()) generateTestDoubleHistogramDataPoint().CopyTo(ms) assert.EqualValues(t, generateTestDoubleHistogramDataPoint(), ms) } @@ -1416,7 +1318,6 @@ func TestDoubleSummaryDataPointSlice(t *testing.T) { es.Resize(7) emptyVal := NewDoubleSummaryDataPoint() - emptyVal.InitEmpty() testVal := generateTestDoubleSummaryDataPoint() assert.EqualValues(t, 7, es.Len()) for i := 0; i < es.Len(); i++ { @@ -1469,19 +1370,18 @@ func TestDoubleSummaryDataPointSlice_CopyTo(t *testing.T) { func TestDoubleSummaryDataPointSlice_Resize(t *testing.T) { es := generateTestDoubleSummaryDataPointSlice() emptyVal := NewDoubleSummaryDataPoint() - emptyVal.InitEmpty() // Test Resize less elements. const resizeSmallLen = 4 expectedEs := make(map[*otlpmetrics.DoubleSummaryDataPoint]bool, resizeSmallLen) for i := 0; i < resizeSmallLen; i++ { - expectedEs[*(es.At(i).orig)] = true + expectedEs[es.At(i).orig] = true } assert.Equal(t, resizeSmallLen, len(expectedEs)) es.Resize(resizeSmallLen) assert.Equal(t, resizeSmallLen, es.Len()) foundEs := make(map[*otlpmetrics.DoubleSummaryDataPoint]bool, resizeSmallLen) for i := 0; i < es.Len(); i++ { - foundEs[*(es.At(i).orig)] = true + foundEs[es.At(i).orig] = true } assert.EqualValues(t, expectedEs, foundEs) @@ -1490,14 +1390,14 @@ func TestDoubleSummaryDataPointSlice_Resize(t *testing.T) { oldLen := es.Len() expectedEs = make(map[*otlpmetrics.DoubleSummaryDataPoint]bool, oldLen) for i := 0; i < oldLen; i++ { - expectedEs[*(es.At(i).orig)] = true + expectedEs[es.At(i).orig] = true } assert.Equal(t, oldLen, len(expectedEs)) es.Resize(resizeLargeLen) assert.Equal(t, resizeLargeLen, es.Len()) foundEs = make(map[*otlpmetrics.DoubleSummaryDataPoint]bool, oldLen) for i := 0; i < oldLen; i++ { - foundEs[*(es.At(i).orig)] = true + foundEs[es.At(i).orig] = true } assert.EqualValues(t, expectedEs, foundEs) for i := oldLen; i < resizeLargeLen; i++ { @@ -1511,32 +1411,20 @@ func TestDoubleSummaryDataPointSlice_Resize(t *testing.T) { func TestDoubleSummaryDataPointSlice_Append(t *testing.T) { es := generateTestDoubleSummaryDataPointSlice() - emptyVal := NewDoubleSummaryDataPoint() - emptyVal.InitEmpty() + emptyVal := NewDoubleSummaryDataPoint() es.Append(emptyVal) - assert.EqualValues(t, *(es.At(7)).orig, *emptyVal.orig) + assert.EqualValues(t, es.At(7).orig, emptyVal.orig) emptyVal2 := NewDoubleSummaryDataPoint() - emptyVal2.InitEmpty() - es.Append(emptyVal2) - assert.EqualValues(t, *(es.At(8)).orig, *emptyVal2.orig) + assert.EqualValues(t, es.At(8).orig, emptyVal2.orig) assert.Equal(t, 9, es.Len()) } -func TestDoubleSummaryDataPoint_InitEmpty(t *testing.T) { - ms := NewDoubleSummaryDataPoint() - assert.True(t, ms.IsNil()) - ms.InitEmpty() - assert.False(t, ms.IsNil()) -} - func TestDoubleSummaryDataPoint_CopyTo(t *testing.T) { ms := NewDoubleSummaryDataPoint() - NewDoubleSummaryDataPoint().CopyTo(ms) - assert.True(t, ms.IsNil()) generateTestDoubleSummaryDataPoint().CopyTo(ms) assert.EqualValues(t, generateTestDoubleSummaryDataPoint(), ms) } @@ -1603,7 +1491,6 @@ func TestValueAtQuantileSlice(t *testing.T) { es.Resize(7) emptyVal := NewValueAtQuantile() - emptyVal.InitEmpty() testVal := generateTestValueAtQuantile() assert.EqualValues(t, 7, es.Len()) for i := 0; i < es.Len(); i++ { @@ -1656,19 +1543,18 @@ func TestValueAtQuantileSlice_CopyTo(t *testing.T) { func TestValueAtQuantileSlice_Resize(t *testing.T) { es := generateTestValueAtQuantileSlice() emptyVal := NewValueAtQuantile() - emptyVal.InitEmpty() // Test Resize less elements. const resizeSmallLen = 4 expectedEs := make(map[*otlpmetrics.DoubleSummaryDataPoint_ValueAtQuantile]bool, resizeSmallLen) for i := 0; i < resizeSmallLen; i++ { - expectedEs[*(es.At(i).orig)] = true + expectedEs[es.At(i).orig] = true } assert.Equal(t, resizeSmallLen, len(expectedEs)) es.Resize(resizeSmallLen) assert.Equal(t, resizeSmallLen, es.Len()) foundEs := make(map[*otlpmetrics.DoubleSummaryDataPoint_ValueAtQuantile]bool, resizeSmallLen) for i := 0; i < es.Len(); i++ { - foundEs[*(es.At(i).orig)] = true + foundEs[es.At(i).orig] = true } assert.EqualValues(t, expectedEs, foundEs) @@ -1677,14 +1563,14 @@ func TestValueAtQuantileSlice_Resize(t *testing.T) { oldLen := es.Len() expectedEs = make(map[*otlpmetrics.DoubleSummaryDataPoint_ValueAtQuantile]bool, oldLen) for i := 0; i < oldLen; i++ { - expectedEs[*(es.At(i).orig)] = true + expectedEs[es.At(i).orig] = true } assert.Equal(t, oldLen, len(expectedEs)) es.Resize(resizeLargeLen) assert.Equal(t, resizeLargeLen, es.Len()) foundEs = make(map[*otlpmetrics.DoubleSummaryDataPoint_ValueAtQuantile]bool, oldLen) for i := 0; i < oldLen; i++ { - foundEs[*(es.At(i).orig)] = true + foundEs[es.At(i).orig] = true } assert.EqualValues(t, expectedEs, foundEs) for i := oldLen; i < resizeLargeLen; i++ { @@ -1698,32 +1584,20 @@ func TestValueAtQuantileSlice_Resize(t *testing.T) { func TestValueAtQuantileSlice_Append(t *testing.T) { es := generateTestValueAtQuantileSlice() - emptyVal := NewValueAtQuantile() - emptyVal.InitEmpty() + emptyVal := NewValueAtQuantile() es.Append(emptyVal) - assert.EqualValues(t, *(es.At(7)).orig, *emptyVal.orig) + assert.EqualValues(t, es.At(7).orig, emptyVal.orig) emptyVal2 := NewValueAtQuantile() - emptyVal2.InitEmpty() - es.Append(emptyVal2) - assert.EqualValues(t, *(es.At(8)).orig, *emptyVal2.orig) + assert.EqualValues(t, es.At(8).orig, emptyVal2.orig) assert.Equal(t, 9, es.Len()) } -func TestValueAtQuantile_InitEmpty(t *testing.T) { - ms := NewValueAtQuantile() - assert.True(t, ms.IsNil()) - ms.InitEmpty() - assert.False(t, ms.IsNil()) -} - func TestValueAtQuantile_CopyTo(t *testing.T) { ms := NewValueAtQuantile() - NewValueAtQuantile().CopyTo(ms) - assert.True(t, ms.IsNil()) generateTestValueAtQuantile().CopyTo(ms) assert.EqualValues(t, generateTestValueAtQuantile(), ms) } @@ -1754,7 +1628,6 @@ func TestIntExemplarSlice(t *testing.T) { es.Resize(7) emptyVal := NewIntExemplar() - emptyVal.InitEmpty() testVal := generateTestIntExemplar() assert.EqualValues(t, 7, es.Len()) for i := 0; i < es.Len(); i++ { @@ -1807,19 +1680,18 @@ func TestIntExemplarSlice_CopyTo(t *testing.T) { func TestIntExemplarSlice_Resize(t *testing.T) { es := generateTestIntExemplarSlice() emptyVal := NewIntExemplar() - emptyVal.InitEmpty() // Test Resize less elements. const resizeSmallLen = 4 expectedEs := make(map[*otlpmetrics.IntExemplar]bool, resizeSmallLen) for i := 0; i < resizeSmallLen; i++ { - expectedEs[*(es.At(i).orig)] = true + expectedEs[es.At(i).orig] = true } assert.Equal(t, resizeSmallLen, len(expectedEs)) es.Resize(resizeSmallLen) assert.Equal(t, resizeSmallLen, es.Len()) foundEs := make(map[*otlpmetrics.IntExemplar]bool, resizeSmallLen) for i := 0; i < es.Len(); i++ { - foundEs[*(es.At(i).orig)] = true + foundEs[es.At(i).orig] = true } assert.EqualValues(t, expectedEs, foundEs) @@ -1828,14 +1700,14 @@ func TestIntExemplarSlice_Resize(t *testing.T) { oldLen := es.Len() expectedEs = make(map[*otlpmetrics.IntExemplar]bool, oldLen) for i := 0; i < oldLen; i++ { - expectedEs[*(es.At(i).orig)] = true + expectedEs[es.At(i).orig] = true } assert.Equal(t, oldLen, len(expectedEs)) es.Resize(resizeLargeLen) assert.Equal(t, resizeLargeLen, es.Len()) foundEs = make(map[*otlpmetrics.IntExemplar]bool, oldLen) for i := 0; i < oldLen; i++ { - foundEs[*(es.At(i).orig)] = true + foundEs[es.At(i).orig] = true } assert.EqualValues(t, expectedEs, foundEs) for i := oldLen; i < resizeLargeLen; i++ { @@ -1849,32 +1721,20 @@ func TestIntExemplarSlice_Resize(t *testing.T) { func TestIntExemplarSlice_Append(t *testing.T) { es := generateTestIntExemplarSlice() - emptyVal := NewIntExemplar() - emptyVal.InitEmpty() + emptyVal := NewIntExemplar() es.Append(emptyVal) - assert.EqualValues(t, *(es.At(7)).orig, *emptyVal.orig) + assert.EqualValues(t, es.At(7).orig, emptyVal.orig) emptyVal2 := NewIntExemplar() - emptyVal2.InitEmpty() - es.Append(emptyVal2) - assert.EqualValues(t, *(es.At(8)).orig, *emptyVal2.orig) + assert.EqualValues(t, es.At(8).orig, emptyVal2.orig) assert.Equal(t, 9, es.Len()) } -func TestIntExemplar_InitEmpty(t *testing.T) { - ms := NewIntExemplar() - assert.True(t, ms.IsNil()) - ms.InitEmpty() - assert.False(t, ms.IsNil()) -} - func TestIntExemplar_CopyTo(t *testing.T) { ms := NewIntExemplar() - NewIntExemplar().CopyTo(ms) - assert.True(t, ms.IsNil()) generateTestIntExemplar().CopyTo(ms) assert.EqualValues(t, generateTestIntExemplar(), ms) } @@ -1914,7 +1774,6 @@ func TestDoubleExemplarSlice(t *testing.T) { es.Resize(7) emptyVal := NewDoubleExemplar() - emptyVal.InitEmpty() testVal := generateTestDoubleExemplar() assert.EqualValues(t, 7, es.Len()) for i := 0; i < es.Len(); i++ { @@ -1967,19 +1826,18 @@ func TestDoubleExemplarSlice_CopyTo(t *testing.T) { func TestDoubleExemplarSlice_Resize(t *testing.T) { es := generateTestDoubleExemplarSlice() emptyVal := NewDoubleExemplar() - emptyVal.InitEmpty() // Test Resize less elements. const resizeSmallLen = 4 expectedEs := make(map[*otlpmetrics.DoubleExemplar]bool, resizeSmallLen) for i := 0; i < resizeSmallLen; i++ { - expectedEs[*(es.At(i).orig)] = true + expectedEs[es.At(i).orig] = true } assert.Equal(t, resizeSmallLen, len(expectedEs)) es.Resize(resizeSmallLen) assert.Equal(t, resizeSmallLen, es.Len()) foundEs := make(map[*otlpmetrics.DoubleExemplar]bool, resizeSmallLen) for i := 0; i < es.Len(); i++ { - foundEs[*(es.At(i).orig)] = true + foundEs[es.At(i).orig] = true } assert.EqualValues(t, expectedEs, foundEs) @@ -1988,14 +1846,14 @@ func TestDoubleExemplarSlice_Resize(t *testing.T) { oldLen := es.Len() expectedEs = make(map[*otlpmetrics.DoubleExemplar]bool, oldLen) for i := 0; i < oldLen; i++ { - expectedEs[*(es.At(i).orig)] = true + expectedEs[es.At(i).orig] = true } assert.Equal(t, oldLen, len(expectedEs)) es.Resize(resizeLargeLen) assert.Equal(t, resizeLargeLen, es.Len()) foundEs = make(map[*otlpmetrics.DoubleExemplar]bool, oldLen) for i := 0; i < oldLen; i++ { - foundEs[*(es.At(i).orig)] = true + foundEs[es.At(i).orig] = true } assert.EqualValues(t, expectedEs, foundEs) for i := oldLen; i < resizeLargeLen; i++ { @@ -2009,32 +1867,20 @@ func TestDoubleExemplarSlice_Resize(t *testing.T) { func TestDoubleExemplarSlice_Append(t *testing.T) { es := generateTestDoubleExemplarSlice() - emptyVal := NewDoubleExemplar() - emptyVal.InitEmpty() + emptyVal := NewDoubleExemplar() es.Append(emptyVal) - assert.EqualValues(t, *(es.At(7)).orig, *emptyVal.orig) + assert.EqualValues(t, es.At(7).orig, emptyVal.orig) emptyVal2 := NewDoubleExemplar() - emptyVal2.InitEmpty() - es.Append(emptyVal2) - assert.EqualValues(t, *(es.At(8)).orig, *emptyVal2.orig) + assert.EqualValues(t, es.At(8).orig, emptyVal2.orig) assert.Equal(t, 9, es.Len()) } -func TestDoubleExemplar_InitEmpty(t *testing.T) { - ms := NewDoubleExemplar() - assert.True(t, ms.IsNil()) - ms.InitEmpty() - assert.False(t, ms.IsNil()) -} - func TestDoubleExemplar_CopyTo(t *testing.T) { ms := NewDoubleExemplar() - NewDoubleExemplar().CopyTo(ms) - assert.True(t, ms.IsNil()) generateTestDoubleExemplar().CopyTo(ms) assert.EqualValues(t, generateTestDoubleExemplar(), ms) } @@ -2081,7 +1927,6 @@ func fillTestResourceMetricsSlice(tv ResourceMetricsSlice) { func generateTestResourceMetrics() ResourceMetrics { tv := NewResourceMetrics() - tv.InitEmpty() fillTestResourceMetrics(tv) return tv } @@ -2106,7 +1951,6 @@ func fillTestInstrumentationLibraryMetricsSlice(tv InstrumentationLibraryMetrics func generateTestInstrumentationLibraryMetrics() InstrumentationLibraryMetrics { tv := NewInstrumentationLibraryMetrics() - tv.InitEmpty() fillTestInstrumentationLibraryMetrics(tv) return tv } @@ -2131,7 +1975,6 @@ func fillTestMetricSlice(tv MetricSlice) { func generateTestMetric() Metric { tv := NewMetric() - tv.InitEmpty() fillTestMetric(tv) return tv } @@ -2236,7 +2079,6 @@ func fillTestIntDataPointSlice(tv IntDataPointSlice) { func generateTestIntDataPoint() IntDataPoint { tv := NewIntDataPoint() - tv.InitEmpty() fillTestIntDataPoint(tv) return tv } @@ -2264,7 +2106,6 @@ func fillTestDoubleDataPointSlice(tv DoubleDataPointSlice) { func generateTestDoubleDataPoint() DoubleDataPoint { tv := NewDoubleDataPoint() - tv.InitEmpty() fillTestDoubleDataPoint(tv) return tv } @@ -2292,7 +2133,6 @@ func fillTestIntHistogramDataPointSlice(tv IntHistogramDataPointSlice) { func generateTestIntHistogramDataPoint() IntHistogramDataPoint { tv := NewIntHistogramDataPoint() - tv.InitEmpty() fillTestIntHistogramDataPoint(tv) return tv } @@ -2323,7 +2163,6 @@ func fillTestDoubleHistogramDataPointSlice(tv DoubleHistogramDataPointSlice) { func generateTestDoubleHistogramDataPoint() DoubleHistogramDataPoint { tv := NewDoubleHistogramDataPoint() - tv.InitEmpty() fillTestDoubleHistogramDataPoint(tv) return tv } @@ -2354,7 +2193,6 @@ func fillTestDoubleSummaryDataPointSlice(tv DoubleSummaryDataPointSlice) { func generateTestDoubleSummaryDataPoint() DoubleSummaryDataPoint { tv := NewDoubleSummaryDataPoint() - tv.InitEmpty() fillTestDoubleSummaryDataPoint(tv) return tv } @@ -2383,7 +2221,6 @@ func fillTestValueAtQuantileSlice(tv ValueAtQuantileSlice) { func generateTestValueAtQuantile() ValueAtQuantile { tv := NewValueAtQuantile() - tv.InitEmpty() fillTestValueAtQuantile(tv) return tv } @@ -2408,7 +2245,6 @@ func fillTestIntExemplarSlice(tv IntExemplarSlice) { func generateTestIntExemplar() IntExemplar { tv := NewIntExemplar() - tv.InitEmpty() fillTestIntExemplar(tv) return tv } @@ -2434,7 +2270,6 @@ func fillTestDoubleExemplarSlice(tv DoubleExemplarSlice) { func generateTestDoubleExemplar() DoubleExemplar { tv := NewDoubleExemplar() - tv.InitEmpty() fillTestDoubleExemplar(tv) return tv } diff --git a/consumer/pdata/generated_trace.go b/consumer/pdata/generated_trace.go index 56723a26fe3..ba7c028a3f5 100644 --- a/consumer/pdata/generated_trace.go +++ b/consumer/pdata/generated_trace.go @@ -61,7 +61,7 @@ func (es ResourceSpansSlice) Len() int { // ... // Do something with the element // } func (es ResourceSpansSlice) At(ix int) ResourceSpans { - return newResourceSpans(&(*es.orig)[ix]) + return newResourceSpans((*es.orig)[ix]) } // MoveAndAppendTo moves all elements from the current slice and appends them to the dest. @@ -83,7 +83,7 @@ func (es ResourceSpansSlice) CopyTo(dest ResourceSpansSlice) { if srcLen <= destCap { (*dest.orig) = (*dest.orig)[:srcLen:destCap] for i := range *es.orig { - newResourceSpans(&(*es.orig)[i]).CopyTo(newResourceSpans(&(*dest.orig)[i])) + newResourceSpans((*es.orig)[i]).CopyTo(newResourceSpans((*dest.orig)[i])) } return } @@ -91,7 +91,7 @@ func (es ResourceSpansSlice) CopyTo(dest ResourceSpansSlice) { wrappers := make([]*otlptrace.ResourceSpans, srcLen) for i := range *es.orig { wrappers[i] = &origs[i] - newResourceSpans(&(*es.orig)[i]).CopyTo(newResourceSpans(&wrappers[i])) + newResourceSpans((*es.orig)[i]).CopyTo(newResourceSpans(wrappers[i])) } *dest.orig = wrappers } @@ -133,7 +133,7 @@ func (es ResourceSpansSlice) Resize(newLen int) { // could still be referenced so do not reuse it after passing it to this // method. func (es ResourceSpansSlice) Append(e ResourceSpans) { - *es.orig = append(*es.orig, *e.orig) + *es.orig = append(*es.orig, e.orig) } // InstrumentationLibrarySpans is a collection of spans from a LibraryInstrumentation. @@ -145,33 +145,23 @@ func (es ResourceSpansSlice) Append(e ResourceSpans) { // Important: zero-initialized instance is not valid for use. type ResourceSpans struct { // orig points to the pointer otlptrace.ResourceSpans field contained somewhere else. - // We use pointer-to-pointer to be able to modify it in InitEmpty func. - orig **otlptrace.ResourceSpans + orig *otlptrace.ResourceSpans } -func newResourceSpans(orig **otlptrace.ResourceSpans) ResourceSpans { - return ResourceSpans{orig} +func newResourceSpans(orig *otlptrace.ResourceSpans) ResourceSpans { + return ResourceSpans{orig: orig} } -// NewResourceSpans creates a new "nil" ResourceSpans. -// To initialize the struct call "InitEmpty". +// NewResourceSpans creates a new empty ResourceSpans. // // This must be used only in testing code since no "Set" method available. func NewResourceSpans() ResourceSpans { - orig := (*otlptrace.ResourceSpans)(nil) - return newResourceSpans(&orig) + return newResourceSpans(&otlptrace.ResourceSpans{}) } -// InitEmpty overwrites the current value with empty. +// Deprecated: This function will be removed soon. func (ms ResourceSpans) InitEmpty() { - *ms.orig = &otlptrace.ResourceSpans{} -} - -// IsNil returns true if the underlying data are nil. -// -// Important: All other functions will cause a runtime error if this returns "true". -func (ms ResourceSpans) IsNil() bool { - return *ms.orig == nil + *ms.orig = otlptrace.ResourceSpans{} } // Resource returns the resource associated with this ResourceSpans. @@ -190,13 +180,6 @@ func (ms ResourceSpans) InstrumentationLibrarySpans() InstrumentationLibrarySpan // CopyTo copies all properties from the current struct to the dest. func (ms ResourceSpans) CopyTo(dest ResourceSpans) { - if ms.IsNil() { - *dest.orig = nil - return - } - if dest.IsNil() { - dest.InitEmpty() - } ms.Resource().CopyTo(dest.Resource()) ms.InstrumentationLibrarySpans().CopyTo(dest.InstrumentationLibrarySpans()) } @@ -240,7 +223,7 @@ func (es InstrumentationLibrarySpansSlice) Len() int { // ... // Do something with the element // } func (es InstrumentationLibrarySpansSlice) At(ix int) InstrumentationLibrarySpans { - return newInstrumentationLibrarySpans(&(*es.orig)[ix]) + return newInstrumentationLibrarySpans((*es.orig)[ix]) } // MoveAndAppendTo moves all elements from the current slice and appends them to the dest. @@ -262,7 +245,7 @@ func (es InstrumentationLibrarySpansSlice) CopyTo(dest InstrumentationLibrarySpa if srcLen <= destCap { (*dest.orig) = (*dest.orig)[:srcLen:destCap] for i := range *es.orig { - newInstrumentationLibrarySpans(&(*es.orig)[i]).CopyTo(newInstrumentationLibrarySpans(&(*dest.orig)[i])) + newInstrumentationLibrarySpans((*es.orig)[i]).CopyTo(newInstrumentationLibrarySpans((*dest.orig)[i])) } return } @@ -270,7 +253,7 @@ func (es InstrumentationLibrarySpansSlice) CopyTo(dest InstrumentationLibrarySpa wrappers := make([]*otlptrace.InstrumentationLibrarySpans, srcLen) for i := range *es.orig { wrappers[i] = &origs[i] - newInstrumentationLibrarySpans(&(*es.orig)[i]).CopyTo(newInstrumentationLibrarySpans(&wrappers[i])) + newInstrumentationLibrarySpans((*es.orig)[i]).CopyTo(newInstrumentationLibrarySpans(wrappers[i])) } *dest.orig = wrappers } @@ -312,7 +295,7 @@ func (es InstrumentationLibrarySpansSlice) Resize(newLen int) { // could still be referenced so do not reuse it after passing it to this // method. func (es InstrumentationLibrarySpansSlice) Append(e InstrumentationLibrarySpans) { - *es.orig = append(*es.orig, *e.orig) + *es.orig = append(*es.orig, e.orig) } // InstrumentationLibrarySpans is a collection of spans from a LibraryInstrumentation. @@ -324,33 +307,23 @@ func (es InstrumentationLibrarySpansSlice) Append(e InstrumentationLibrarySpans) // Important: zero-initialized instance is not valid for use. type InstrumentationLibrarySpans struct { // orig points to the pointer otlptrace.InstrumentationLibrarySpans field contained somewhere else. - // We use pointer-to-pointer to be able to modify it in InitEmpty func. - orig **otlptrace.InstrumentationLibrarySpans + orig *otlptrace.InstrumentationLibrarySpans } -func newInstrumentationLibrarySpans(orig **otlptrace.InstrumentationLibrarySpans) InstrumentationLibrarySpans { - return InstrumentationLibrarySpans{orig} +func newInstrumentationLibrarySpans(orig *otlptrace.InstrumentationLibrarySpans) InstrumentationLibrarySpans { + return InstrumentationLibrarySpans{orig: orig} } -// NewInstrumentationLibrarySpans creates a new "nil" InstrumentationLibrarySpans. -// To initialize the struct call "InitEmpty". +// NewInstrumentationLibrarySpans creates a new empty InstrumentationLibrarySpans. // // This must be used only in testing code since no "Set" method available. func NewInstrumentationLibrarySpans() InstrumentationLibrarySpans { - orig := (*otlptrace.InstrumentationLibrarySpans)(nil) - return newInstrumentationLibrarySpans(&orig) + return newInstrumentationLibrarySpans(&otlptrace.InstrumentationLibrarySpans{}) } -// InitEmpty overwrites the current value with empty. +// Deprecated: This function will be removed soon. func (ms InstrumentationLibrarySpans) InitEmpty() { - *ms.orig = &otlptrace.InstrumentationLibrarySpans{} -} - -// IsNil returns true if the underlying data are nil. -// -// Important: All other functions will cause a runtime error if this returns "true". -func (ms InstrumentationLibrarySpans) IsNil() bool { - return *ms.orig == nil + *ms.orig = otlptrace.InstrumentationLibrarySpans{} } // InstrumentationLibrary returns the instrumentationlibrary associated with this InstrumentationLibrarySpans. @@ -369,13 +342,6 @@ func (ms InstrumentationLibrarySpans) Spans() SpanSlice { // CopyTo copies all properties from the current struct to the dest. func (ms InstrumentationLibrarySpans) CopyTo(dest InstrumentationLibrarySpans) { - if ms.IsNil() { - *dest.orig = nil - return - } - if dest.IsNil() { - dest.InitEmpty() - } ms.InstrumentationLibrary().CopyTo(dest.InstrumentationLibrary()) ms.Spans().CopyTo(dest.Spans()) } @@ -419,7 +385,7 @@ func (es SpanSlice) Len() int { // ... // Do something with the element // } func (es SpanSlice) At(ix int) Span { - return newSpan(&(*es.orig)[ix]) + return newSpan((*es.orig)[ix]) } // MoveAndAppendTo moves all elements from the current slice and appends them to the dest. @@ -441,7 +407,7 @@ func (es SpanSlice) CopyTo(dest SpanSlice) { if srcLen <= destCap { (*dest.orig) = (*dest.orig)[:srcLen:destCap] for i := range *es.orig { - newSpan(&(*es.orig)[i]).CopyTo(newSpan(&(*dest.orig)[i])) + newSpan((*es.orig)[i]).CopyTo(newSpan((*dest.orig)[i])) } return } @@ -449,7 +415,7 @@ func (es SpanSlice) CopyTo(dest SpanSlice) { wrappers := make([]*otlptrace.Span, srcLen) for i := range *es.orig { wrappers[i] = &origs[i] - newSpan(&(*es.orig)[i]).CopyTo(newSpan(&wrappers[i])) + newSpan((*es.orig)[i]).CopyTo(newSpan(wrappers[i])) } *dest.orig = wrappers } @@ -491,7 +457,7 @@ func (es SpanSlice) Resize(newLen int) { // could still be referenced so do not reuse it after passing it to this // method. func (es SpanSlice) Append(e Span) { - *es.orig = append(*es.orig, *e.orig) + *es.orig = append(*es.orig, e.orig) } // Span represents a single operation within a trace. @@ -504,33 +470,23 @@ func (es SpanSlice) Append(e Span) { // Important: zero-initialized instance is not valid for use. type Span struct { // orig points to the pointer otlptrace.Span field contained somewhere else. - // We use pointer-to-pointer to be able to modify it in InitEmpty func. - orig **otlptrace.Span + orig *otlptrace.Span } -func newSpan(orig **otlptrace.Span) Span { - return Span{orig} +func newSpan(orig *otlptrace.Span) Span { + return Span{orig: orig} } -// NewSpan creates a new "nil" Span. -// To initialize the struct call "InitEmpty". +// NewSpan creates a new empty Span. // // This must be used only in testing code since no "Set" method available. func NewSpan() Span { - orig := (*otlptrace.Span)(nil) - return newSpan(&orig) + return newSpan(&otlptrace.Span{}) } -// InitEmpty overwrites the current value with empty. +// Deprecated: This function will be removed soon. func (ms Span) InitEmpty() { - *ms.orig = &otlptrace.Span{} -} - -// IsNil returns true if the underlying data are nil. -// -// Important: All other functions will cause a runtime error if this returns "true". -func (ms Span) IsNil() bool { - return *ms.orig == nil + *ms.orig = otlptrace.Span{} } // TraceID returns the traceid associated with this Span. @@ -720,13 +676,6 @@ func (ms Span) Status() SpanStatus { // CopyTo copies all properties from the current struct to the dest. func (ms Span) CopyTo(dest Span) { - if ms.IsNil() { - *dest.orig = nil - return - } - if dest.IsNil() { - dest.InitEmpty() - } dest.SetTraceID(ms.TraceID()) dest.SetSpanID(ms.SpanID()) dest.SetTraceState(ms.TraceState()) @@ -783,7 +732,7 @@ func (es SpanEventSlice) Len() int { // ... // Do something with the element // } func (es SpanEventSlice) At(ix int) SpanEvent { - return newSpanEvent(&(*es.orig)[ix]) + return newSpanEvent((*es.orig)[ix]) } // MoveAndAppendTo moves all elements from the current slice and appends them to the dest. @@ -805,7 +754,7 @@ func (es SpanEventSlice) CopyTo(dest SpanEventSlice) { if srcLen <= destCap { (*dest.orig) = (*dest.orig)[:srcLen:destCap] for i := range *es.orig { - newSpanEvent(&(*es.orig)[i]).CopyTo(newSpanEvent(&(*dest.orig)[i])) + newSpanEvent((*es.orig)[i]).CopyTo(newSpanEvent((*dest.orig)[i])) } return } @@ -813,7 +762,7 @@ func (es SpanEventSlice) CopyTo(dest SpanEventSlice) { wrappers := make([]*otlptrace.Span_Event, srcLen) for i := range *es.orig { wrappers[i] = &origs[i] - newSpanEvent(&(*es.orig)[i]).CopyTo(newSpanEvent(&wrappers[i])) + newSpanEvent((*es.orig)[i]).CopyTo(newSpanEvent(wrappers[i])) } *dest.orig = wrappers } @@ -855,7 +804,7 @@ func (es SpanEventSlice) Resize(newLen int) { // could still be referenced so do not reuse it after passing it to this // method. func (es SpanEventSlice) Append(e SpanEvent) { - *es.orig = append(*es.orig, *e.orig) + *es.orig = append(*es.orig, e.orig) } // SpanEvent is a time-stamped annotation of the span, consisting of user-supplied @@ -868,33 +817,23 @@ func (es SpanEventSlice) Append(e SpanEvent) { // Important: zero-initialized instance is not valid for use. type SpanEvent struct { // orig points to the pointer otlptrace.Span_Event field contained somewhere else. - // We use pointer-to-pointer to be able to modify it in InitEmpty func. - orig **otlptrace.Span_Event + orig *otlptrace.Span_Event } -func newSpanEvent(orig **otlptrace.Span_Event) SpanEvent { - return SpanEvent{orig} +func newSpanEvent(orig *otlptrace.Span_Event) SpanEvent { + return SpanEvent{orig: orig} } -// NewSpanEvent creates a new "nil" SpanEvent. -// To initialize the struct call "InitEmpty". +// NewSpanEvent creates a new empty SpanEvent. // // This must be used only in testing code since no "Set" method available. func NewSpanEvent() SpanEvent { - orig := (*otlptrace.Span_Event)(nil) - return newSpanEvent(&orig) + return newSpanEvent(&otlptrace.Span_Event{}) } -// InitEmpty overwrites the current value with empty. +// Deprecated: This function will be removed soon. func (ms SpanEvent) InitEmpty() { - *ms.orig = &otlptrace.Span_Event{} -} - -// IsNil returns true if the underlying data are nil. -// -// Important: All other functions will cause a runtime error if this returns "true". -func (ms SpanEvent) IsNil() bool { - return *ms.orig == nil + *ms.orig = otlptrace.Span_Event{} } // Timestamp returns the timestamp associated with this SpanEvent. @@ -948,13 +887,6 @@ func (ms SpanEvent) SetDroppedAttributesCount(v uint32) { // CopyTo copies all properties from the current struct to the dest. func (ms SpanEvent) CopyTo(dest SpanEvent) { - if ms.IsNil() { - *dest.orig = nil - return - } - if dest.IsNil() { - dest.InitEmpty() - } dest.SetTimestamp(ms.Timestamp()) dest.SetName(ms.Name()) ms.Attributes().CopyTo(dest.Attributes()) @@ -1000,7 +932,7 @@ func (es SpanLinkSlice) Len() int { // ... // Do something with the element // } func (es SpanLinkSlice) At(ix int) SpanLink { - return newSpanLink(&(*es.orig)[ix]) + return newSpanLink((*es.orig)[ix]) } // MoveAndAppendTo moves all elements from the current slice and appends them to the dest. @@ -1022,7 +954,7 @@ func (es SpanLinkSlice) CopyTo(dest SpanLinkSlice) { if srcLen <= destCap { (*dest.orig) = (*dest.orig)[:srcLen:destCap] for i := range *es.orig { - newSpanLink(&(*es.orig)[i]).CopyTo(newSpanLink(&(*dest.orig)[i])) + newSpanLink((*es.orig)[i]).CopyTo(newSpanLink((*dest.orig)[i])) } return } @@ -1030,7 +962,7 @@ func (es SpanLinkSlice) CopyTo(dest SpanLinkSlice) { wrappers := make([]*otlptrace.Span_Link, srcLen) for i := range *es.orig { wrappers[i] = &origs[i] - newSpanLink(&(*es.orig)[i]).CopyTo(newSpanLink(&wrappers[i])) + newSpanLink((*es.orig)[i]).CopyTo(newSpanLink(wrappers[i])) } *dest.orig = wrappers } @@ -1072,7 +1004,7 @@ func (es SpanLinkSlice) Resize(newLen int) { // could still be referenced so do not reuse it after passing it to this // method. func (es SpanLinkSlice) Append(e SpanLink) { - *es.orig = append(*es.orig, *e.orig) + *es.orig = append(*es.orig, e.orig) } // SpanLink is a pointer from the current span to another span in the same trace or in a @@ -1085,33 +1017,23 @@ func (es SpanLinkSlice) Append(e SpanLink) { // Important: zero-initialized instance is not valid for use. type SpanLink struct { // orig points to the pointer otlptrace.Span_Link field contained somewhere else. - // We use pointer-to-pointer to be able to modify it in InitEmpty func. - orig **otlptrace.Span_Link + orig *otlptrace.Span_Link } -func newSpanLink(orig **otlptrace.Span_Link) SpanLink { - return SpanLink{orig} +func newSpanLink(orig *otlptrace.Span_Link) SpanLink { + return SpanLink{orig: orig} } -// NewSpanLink creates a new "nil" SpanLink. -// To initialize the struct call "InitEmpty". +// NewSpanLink creates a new empty SpanLink. // // This must be used only in testing code since no "Set" method available. func NewSpanLink() SpanLink { - orig := (*otlptrace.Span_Link)(nil) - return newSpanLink(&orig) + return newSpanLink(&otlptrace.Span_Link{}) } -// InitEmpty overwrites the current value with empty. +// Deprecated: This function will be removed soon. func (ms SpanLink) InitEmpty() { - *ms.orig = &otlptrace.Span_Link{} -} - -// IsNil returns true if the underlying data are nil. -// -// Important: All other functions will cause a runtime error if this returns "true". -func (ms SpanLink) IsNil() bool { - return *ms.orig == nil + *ms.orig = otlptrace.Span_Link{} } // TraceID returns the traceid associated with this SpanLink. @@ -1179,13 +1101,6 @@ func (ms SpanLink) SetDroppedAttributesCount(v uint32) { // CopyTo copies all properties from the current struct to the dest. func (ms SpanLink) CopyTo(dest SpanLink) { - if ms.IsNil() { - *dest.orig = nil - return - } - if dest.IsNil() { - dest.InitEmpty() - } dest.SetTraceID(ms.TraceID()) dest.SetSpanID(ms.SpanID()) dest.SetTraceState(ms.TraceState()) diff --git a/consumer/pdata/generated_trace_test.go b/consumer/pdata/generated_trace_test.go index 862bac61461..9845cd61c97 100644 --- a/consumer/pdata/generated_trace_test.go +++ b/consumer/pdata/generated_trace_test.go @@ -33,7 +33,6 @@ func TestResourceSpansSlice(t *testing.T) { es.Resize(7) emptyVal := NewResourceSpans() - emptyVal.InitEmpty() testVal := generateTestResourceSpans() assert.EqualValues(t, 7, es.Len()) for i := 0; i < es.Len(); i++ { @@ -86,19 +85,18 @@ func TestResourceSpansSlice_CopyTo(t *testing.T) { func TestResourceSpansSlice_Resize(t *testing.T) { es := generateTestResourceSpansSlice() emptyVal := NewResourceSpans() - emptyVal.InitEmpty() // Test Resize less elements. const resizeSmallLen = 4 expectedEs := make(map[*otlptrace.ResourceSpans]bool, resizeSmallLen) for i := 0; i < resizeSmallLen; i++ { - expectedEs[*(es.At(i).orig)] = true + expectedEs[es.At(i).orig] = true } assert.Equal(t, resizeSmallLen, len(expectedEs)) es.Resize(resizeSmallLen) assert.Equal(t, resizeSmallLen, es.Len()) foundEs := make(map[*otlptrace.ResourceSpans]bool, resizeSmallLen) for i := 0; i < es.Len(); i++ { - foundEs[*(es.At(i).orig)] = true + foundEs[es.At(i).orig] = true } assert.EqualValues(t, expectedEs, foundEs) @@ -107,14 +105,14 @@ func TestResourceSpansSlice_Resize(t *testing.T) { oldLen := es.Len() expectedEs = make(map[*otlptrace.ResourceSpans]bool, oldLen) for i := 0; i < oldLen; i++ { - expectedEs[*(es.At(i).orig)] = true + expectedEs[es.At(i).orig] = true } assert.Equal(t, oldLen, len(expectedEs)) es.Resize(resizeLargeLen) assert.Equal(t, resizeLargeLen, es.Len()) foundEs = make(map[*otlptrace.ResourceSpans]bool, oldLen) for i := 0; i < oldLen; i++ { - foundEs[*(es.At(i).orig)] = true + foundEs[es.At(i).orig] = true } assert.EqualValues(t, expectedEs, foundEs) for i := oldLen; i < resizeLargeLen; i++ { @@ -128,32 +126,20 @@ func TestResourceSpansSlice_Resize(t *testing.T) { func TestResourceSpansSlice_Append(t *testing.T) { es := generateTestResourceSpansSlice() - emptyVal := NewResourceSpans() - emptyVal.InitEmpty() + emptyVal := NewResourceSpans() es.Append(emptyVal) - assert.EqualValues(t, *(es.At(7)).orig, *emptyVal.orig) + assert.EqualValues(t, es.At(7).orig, emptyVal.orig) emptyVal2 := NewResourceSpans() - emptyVal2.InitEmpty() - es.Append(emptyVal2) - assert.EqualValues(t, *(es.At(8)).orig, *emptyVal2.orig) + assert.EqualValues(t, es.At(8).orig, emptyVal2.orig) assert.Equal(t, 9, es.Len()) } -func TestResourceSpans_InitEmpty(t *testing.T) { - ms := NewResourceSpans() - assert.True(t, ms.IsNil()) - ms.InitEmpty() - assert.False(t, ms.IsNil()) -} - func TestResourceSpans_CopyTo(t *testing.T) { ms := NewResourceSpans() - NewResourceSpans().CopyTo(ms) - assert.True(t, ms.IsNil()) generateTestResourceSpans().CopyTo(ms) assert.EqualValues(t, generateTestResourceSpans(), ms) } @@ -182,7 +168,6 @@ func TestInstrumentationLibrarySpansSlice(t *testing.T) { es.Resize(7) emptyVal := NewInstrumentationLibrarySpans() - emptyVal.InitEmpty() testVal := generateTestInstrumentationLibrarySpans() assert.EqualValues(t, 7, es.Len()) for i := 0; i < es.Len(); i++ { @@ -235,19 +220,18 @@ func TestInstrumentationLibrarySpansSlice_CopyTo(t *testing.T) { func TestInstrumentationLibrarySpansSlice_Resize(t *testing.T) { es := generateTestInstrumentationLibrarySpansSlice() emptyVal := NewInstrumentationLibrarySpans() - emptyVal.InitEmpty() // Test Resize less elements. const resizeSmallLen = 4 expectedEs := make(map[*otlptrace.InstrumentationLibrarySpans]bool, resizeSmallLen) for i := 0; i < resizeSmallLen; i++ { - expectedEs[*(es.At(i).orig)] = true + expectedEs[es.At(i).orig] = true } assert.Equal(t, resizeSmallLen, len(expectedEs)) es.Resize(resizeSmallLen) assert.Equal(t, resizeSmallLen, es.Len()) foundEs := make(map[*otlptrace.InstrumentationLibrarySpans]bool, resizeSmallLen) for i := 0; i < es.Len(); i++ { - foundEs[*(es.At(i).orig)] = true + foundEs[es.At(i).orig] = true } assert.EqualValues(t, expectedEs, foundEs) @@ -256,14 +240,14 @@ func TestInstrumentationLibrarySpansSlice_Resize(t *testing.T) { oldLen := es.Len() expectedEs = make(map[*otlptrace.InstrumentationLibrarySpans]bool, oldLen) for i := 0; i < oldLen; i++ { - expectedEs[*(es.At(i).orig)] = true + expectedEs[es.At(i).orig] = true } assert.Equal(t, oldLen, len(expectedEs)) es.Resize(resizeLargeLen) assert.Equal(t, resizeLargeLen, es.Len()) foundEs = make(map[*otlptrace.InstrumentationLibrarySpans]bool, oldLen) for i := 0; i < oldLen; i++ { - foundEs[*(es.At(i).orig)] = true + foundEs[es.At(i).orig] = true } assert.EqualValues(t, expectedEs, foundEs) for i := oldLen; i < resizeLargeLen; i++ { @@ -277,32 +261,20 @@ func TestInstrumentationLibrarySpansSlice_Resize(t *testing.T) { func TestInstrumentationLibrarySpansSlice_Append(t *testing.T) { es := generateTestInstrumentationLibrarySpansSlice() - emptyVal := NewInstrumentationLibrarySpans() - emptyVal.InitEmpty() + emptyVal := NewInstrumentationLibrarySpans() es.Append(emptyVal) - assert.EqualValues(t, *(es.At(7)).orig, *emptyVal.orig) + assert.EqualValues(t, es.At(7).orig, emptyVal.orig) emptyVal2 := NewInstrumentationLibrarySpans() - emptyVal2.InitEmpty() - es.Append(emptyVal2) - assert.EqualValues(t, *(es.At(8)).orig, *emptyVal2.orig) + assert.EqualValues(t, es.At(8).orig, emptyVal2.orig) assert.Equal(t, 9, es.Len()) } -func TestInstrumentationLibrarySpans_InitEmpty(t *testing.T) { - ms := NewInstrumentationLibrarySpans() - assert.True(t, ms.IsNil()) - ms.InitEmpty() - assert.False(t, ms.IsNil()) -} - func TestInstrumentationLibrarySpans_CopyTo(t *testing.T) { ms := NewInstrumentationLibrarySpans() - NewInstrumentationLibrarySpans().CopyTo(ms) - assert.True(t, ms.IsNil()) generateTestInstrumentationLibrarySpans().CopyTo(ms) assert.EqualValues(t, generateTestInstrumentationLibrarySpans(), ms) } @@ -331,7 +303,6 @@ func TestSpanSlice(t *testing.T) { es.Resize(7) emptyVal := NewSpan() - emptyVal.InitEmpty() testVal := generateTestSpan() assert.EqualValues(t, 7, es.Len()) for i := 0; i < es.Len(); i++ { @@ -384,19 +355,18 @@ func TestSpanSlice_CopyTo(t *testing.T) { func TestSpanSlice_Resize(t *testing.T) { es := generateTestSpanSlice() emptyVal := NewSpan() - emptyVal.InitEmpty() // Test Resize less elements. const resizeSmallLen = 4 expectedEs := make(map[*otlptrace.Span]bool, resizeSmallLen) for i := 0; i < resizeSmallLen; i++ { - expectedEs[*(es.At(i).orig)] = true + expectedEs[es.At(i).orig] = true } assert.Equal(t, resizeSmallLen, len(expectedEs)) es.Resize(resizeSmallLen) assert.Equal(t, resizeSmallLen, es.Len()) foundEs := make(map[*otlptrace.Span]bool, resizeSmallLen) for i := 0; i < es.Len(); i++ { - foundEs[*(es.At(i).orig)] = true + foundEs[es.At(i).orig] = true } assert.EqualValues(t, expectedEs, foundEs) @@ -405,14 +375,14 @@ func TestSpanSlice_Resize(t *testing.T) { oldLen := es.Len() expectedEs = make(map[*otlptrace.Span]bool, oldLen) for i := 0; i < oldLen; i++ { - expectedEs[*(es.At(i).orig)] = true + expectedEs[es.At(i).orig] = true } assert.Equal(t, oldLen, len(expectedEs)) es.Resize(resizeLargeLen) assert.Equal(t, resizeLargeLen, es.Len()) foundEs = make(map[*otlptrace.Span]bool, oldLen) for i := 0; i < oldLen; i++ { - foundEs[*(es.At(i).orig)] = true + foundEs[es.At(i).orig] = true } assert.EqualValues(t, expectedEs, foundEs) for i := oldLen; i < resizeLargeLen; i++ { @@ -426,32 +396,20 @@ func TestSpanSlice_Resize(t *testing.T) { func TestSpanSlice_Append(t *testing.T) { es := generateTestSpanSlice() - emptyVal := NewSpan() - emptyVal.InitEmpty() + emptyVal := NewSpan() es.Append(emptyVal) - assert.EqualValues(t, *(es.At(7)).orig, *emptyVal.orig) + assert.EqualValues(t, es.At(7).orig, emptyVal.orig) emptyVal2 := NewSpan() - emptyVal2.InitEmpty() - es.Append(emptyVal2) - assert.EqualValues(t, *(es.At(8)).orig, *emptyVal2.orig) + assert.EqualValues(t, es.At(8).orig, emptyVal2.orig) assert.Equal(t, 9, es.Len()) } -func TestSpan_InitEmpty(t *testing.T) { - ms := NewSpan() - assert.True(t, ms.IsNil()) - ms.InitEmpty() - assert.False(t, ms.IsNil()) -} - func TestSpan_CopyTo(t *testing.T) { ms := NewSpan() - NewSpan().CopyTo(ms) - assert.True(t, ms.IsNil()) generateTestSpan().CopyTo(ms) assert.EqualValues(t, generateTestSpan(), ms) } @@ -600,7 +558,6 @@ func TestSpanEventSlice(t *testing.T) { es.Resize(7) emptyVal := NewSpanEvent() - emptyVal.InitEmpty() testVal := generateTestSpanEvent() assert.EqualValues(t, 7, es.Len()) for i := 0; i < es.Len(); i++ { @@ -653,19 +610,18 @@ func TestSpanEventSlice_CopyTo(t *testing.T) { func TestSpanEventSlice_Resize(t *testing.T) { es := generateTestSpanEventSlice() emptyVal := NewSpanEvent() - emptyVal.InitEmpty() // Test Resize less elements. const resizeSmallLen = 4 expectedEs := make(map[*otlptrace.Span_Event]bool, resizeSmallLen) for i := 0; i < resizeSmallLen; i++ { - expectedEs[*(es.At(i).orig)] = true + expectedEs[es.At(i).orig] = true } assert.Equal(t, resizeSmallLen, len(expectedEs)) es.Resize(resizeSmallLen) assert.Equal(t, resizeSmallLen, es.Len()) foundEs := make(map[*otlptrace.Span_Event]bool, resizeSmallLen) for i := 0; i < es.Len(); i++ { - foundEs[*(es.At(i).orig)] = true + foundEs[es.At(i).orig] = true } assert.EqualValues(t, expectedEs, foundEs) @@ -674,14 +630,14 @@ func TestSpanEventSlice_Resize(t *testing.T) { oldLen := es.Len() expectedEs = make(map[*otlptrace.Span_Event]bool, oldLen) for i := 0; i < oldLen; i++ { - expectedEs[*(es.At(i).orig)] = true + expectedEs[es.At(i).orig] = true } assert.Equal(t, oldLen, len(expectedEs)) es.Resize(resizeLargeLen) assert.Equal(t, resizeLargeLen, es.Len()) foundEs = make(map[*otlptrace.Span_Event]bool, oldLen) for i := 0; i < oldLen; i++ { - foundEs[*(es.At(i).orig)] = true + foundEs[es.At(i).orig] = true } assert.EqualValues(t, expectedEs, foundEs) for i := oldLen; i < resizeLargeLen; i++ { @@ -695,32 +651,20 @@ func TestSpanEventSlice_Resize(t *testing.T) { func TestSpanEventSlice_Append(t *testing.T) { es := generateTestSpanEventSlice() - emptyVal := NewSpanEvent() - emptyVal.InitEmpty() + emptyVal := NewSpanEvent() es.Append(emptyVal) - assert.EqualValues(t, *(es.At(7)).orig, *emptyVal.orig) + assert.EqualValues(t, es.At(7).orig, emptyVal.orig) emptyVal2 := NewSpanEvent() - emptyVal2.InitEmpty() - es.Append(emptyVal2) - assert.EqualValues(t, *(es.At(8)).orig, *emptyVal2.orig) + assert.EqualValues(t, es.At(8).orig, emptyVal2.orig) assert.Equal(t, 9, es.Len()) } -func TestSpanEvent_InitEmpty(t *testing.T) { - ms := NewSpanEvent() - assert.True(t, ms.IsNil()) - ms.InitEmpty() - assert.False(t, ms.IsNil()) -} - func TestSpanEvent_CopyTo(t *testing.T) { ms := NewSpanEvent() - NewSpanEvent().CopyTo(ms) - assert.True(t, ms.IsNil()) generateTestSpanEvent().CopyTo(ms) assert.EqualValues(t, generateTestSpanEvent(), ms) } @@ -769,7 +713,6 @@ func TestSpanLinkSlice(t *testing.T) { es.Resize(7) emptyVal := NewSpanLink() - emptyVal.InitEmpty() testVal := generateTestSpanLink() assert.EqualValues(t, 7, es.Len()) for i := 0; i < es.Len(); i++ { @@ -822,19 +765,18 @@ func TestSpanLinkSlice_CopyTo(t *testing.T) { func TestSpanLinkSlice_Resize(t *testing.T) { es := generateTestSpanLinkSlice() emptyVal := NewSpanLink() - emptyVal.InitEmpty() // Test Resize less elements. const resizeSmallLen = 4 expectedEs := make(map[*otlptrace.Span_Link]bool, resizeSmallLen) for i := 0; i < resizeSmallLen; i++ { - expectedEs[*(es.At(i).orig)] = true + expectedEs[es.At(i).orig] = true } assert.Equal(t, resizeSmallLen, len(expectedEs)) es.Resize(resizeSmallLen) assert.Equal(t, resizeSmallLen, es.Len()) foundEs := make(map[*otlptrace.Span_Link]bool, resizeSmallLen) for i := 0; i < es.Len(); i++ { - foundEs[*(es.At(i).orig)] = true + foundEs[es.At(i).orig] = true } assert.EqualValues(t, expectedEs, foundEs) @@ -843,14 +785,14 @@ func TestSpanLinkSlice_Resize(t *testing.T) { oldLen := es.Len() expectedEs = make(map[*otlptrace.Span_Link]bool, oldLen) for i := 0; i < oldLen; i++ { - expectedEs[*(es.At(i).orig)] = true + expectedEs[es.At(i).orig] = true } assert.Equal(t, oldLen, len(expectedEs)) es.Resize(resizeLargeLen) assert.Equal(t, resizeLargeLen, es.Len()) foundEs = make(map[*otlptrace.Span_Link]bool, oldLen) for i := 0; i < oldLen; i++ { - foundEs[*(es.At(i).orig)] = true + foundEs[es.At(i).orig] = true } assert.EqualValues(t, expectedEs, foundEs) for i := oldLen; i < resizeLargeLen; i++ { @@ -864,32 +806,20 @@ func TestSpanLinkSlice_Resize(t *testing.T) { func TestSpanLinkSlice_Append(t *testing.T) { es := generateTestSpanLinkSlice() - emptyVal := NewSpanLink() - emptyVal.InitEmpty() + emptyVal := NewSpanLink() es.Append(emptyVal) - assert.EqualValues(t, *(es.At(7)).orig, *emptyVal.orig) + assert.EqualValues(t, es.At(7).orig, emptyVal.orig) emptyVal2 := NewSpanLink() - emptyVal2.InitEmpty() - es.Append(emptyVal2) - assert.EqualValues(t, *(es.At(8)).orig, *emptyVal2.orig) + assert.EqualValues(t, es.At(8).orig, emptyVal2.orig) assert.Equal(t, 9, es.Len()) } -func TestSpanLink_InitEmpty(t *testing.T) { - ms := NewSpanLink() - assert.True(t, ms.IsNil()) - ms.InitEmpty() - assert.False(t, ms.IsNil()) -} - func TestSpanLink_CopyTo(t *testing.T) { ms := NewSpanLink() - NewSpanLink().CopyTo(ms) - assert.True(t, ms.IsNil()) generateTestSpanLink().CopyTo(ms) assert.EqualValues(t, generateTestSpanLink(), ms) } @@ -996,7 +926,6 @@ func fillTestResourceSpansSlice(tv ResourceSpansSlice) { func generateTestResourceSpans() ResourceSpans { tv := NewResourceSpans() - tv.InitEmpty() fillTestResourceSpans(tv) return tv } @@ -1021,7 +950,6 @@ func fillTestInstrumentationLibrarySpansSlice(tv InstrumentationLibrarySpansSlic func generateTestInstrumentationLibrarySpans() InstrumentationLibrarySpans { tv := NewInstrumentationLibrarySpans() - tv.InitEmpty() fillTestInstrumentationLibrarySpans(tv) return tv } @@ -1046,7 +974,6 @@ func fillTestSpanSlice(tv SpanSlice) { func generateTestSpan() Span { tv := NewSpan() - tv.InitEmpty() fillTestSpan(tv) return tv } @@ -1085,7 +1012,6 @@ func fillTestSpanEventSlice(tv SpanEventSlice) { func generateTestSpanEvent() SpanEvent { tv := NewSpanEvent() - tv.InitEmpty() fillTestSpanEvent(tv) return tv } @@ -1112,7 +1038,6 @@ func fillTestSpanLinkSlice(tv SpanLinkSlice) { func generateTestSpanLink() SpanLink { tv := NewSpanLink() - tv.InitEmpty() fillTestSpanLink(tv) return tv } diff --git a/consumer/pdata/log.go b/consumer/pdata/log.go index 9d2e8996476..fef6a4f2aa0 100644 --- a/consumer/pdata/log.go +++ b/consumer/pdata/log.go @@ -87,16 +87,9 @@ func (ld Logs) LogRecordCount() int { rss := ld.ResourceLogs() for i := 0; i < rss.Len(); i++ { rs := rss.At(i) - if rs.IsNil() { - continue - } - ill := rs.InstrumentationLibraryLogs() for i := 0; i < ill.Len(); i++ { logs := ill.At(i) - if logs.IsNil() { - continue - } logCount += logs.Logs().Len() } } diff --git a/consumer/pdata/log_test.go b/consumer/pdata/log_test.go index 78a8579d630..c0f35c34ab4 100644 --- a/consumer/pdata/log_test.go +++ b/consumer/pdata/log_test.go @@ -47,18 +47,18 @@ func TestLogRecordCount(t *testing.T) { assert.EqualValues(t, 6, md.LogRecordCount()) } -func TestLogRecordCountWithNils(t *testing.T) { - assert.EqualValues(t, 0, LogsFromInternalRep(internal.LogsFromOtlp([]*otlplogs.ResourceLogs{nil, {}})).LogRecordCount()) +func TestLogRecordCountWithEmpty(t *testing.T) { + assert.EqualValues(t, 0, LogsFromInternalRep(internal.LogsFromOtlp([]*otlplogs.ResourceLogs{{}})).LogRecordCount()) assert.EqualValues(t, 0, LogsFromInternalRep(internal.LogsFromOtlp([]*otlplogs.ResourceLogs{ { - InstrumentationLibraryLogs: []*otlplogs.InstrumentationLibraryLogs{nil, {}}, + InstrumentationLibraryLogs: []*otlplogs.InstrumentationLibraryLogs{{}}, }, })).LogRecordCount()) - assert.EqualValues(t, 2, LogsFromInternalRep(internal.LogsFromOtlp([]*otlplogs.ResourceLogs{ + assert.EqualValues(t, 1, LogsFromInternalRep(internal.LogsFromOtlp([]*otlplogs.ResourceLogs{ { InstrumentationLibraryLogs: []*otlplogs.InstrumentationLibraryLogs{ { - Logs: []*otlplogs.LogRecord{nil, {}}, + Logs: []*otlplogs.LogRecord{{}}, }, }, }, diff --git a/consumer/pdata/metric.go b/consumer/pdata/metric.go index cfa33d3e1dc..d415c9f2001 100644 --- a/consumer/pdata/metric.go +++ b/consumer/pdata/metric.go @@ -96,15 +96,9 @@ func (md Metrics) MetricCount() int { rms := md.ResourceMetrics() for i := 0; i < rms.Len(); i++ { rm := rms.At(i) - if rm.IsNil() { - continue - } ilms := rm.InstrumentationLibraryMetrics() for j := 0; j < ilms.Len(); j++ { ilm := ilms.At(j) - if ilm.IsNil() { - continue - } metricCount += ilm.Metrics().Len() } } @@ -128,23 +122,14 @@ func (md Metrics) MetricAndDataPointCount() (metricCount int, dataPointCount int rms := md.ResourceMetrics() for i := 0; i < rms.Len(); i++ { rm := rms.At(i) - if rm.IsNil() { - continue - } ilms := rm.InstrumentationLibraryMetrics() for j := 0; j < ilms.Len(); j++ { ilm := ilms.At(j) - if ilm.IsNil() { - continue - } metrics := ilm.Metrics() metricCount += metrics.Len() ms := ilm.Metrics() for k := 0; k < ms.Len(); k++ { m := ms.At(k) - if m.IsNil() { - continue - } switch m.DataType() { case MetricDataTypeIntGauge: dataPointCount += m.IntGauge().DataPoints().Len() @@ -206,7 +191,7 @@ func (mdt MetricDataType) String() string { // DataType returns the type of the data for this Metric. // Calling this function on zero-initialized Metric will cause a panic. func (ms Metric) DataType() MetricDataType { - switch (*ms.orig).Data.(type) { + switch ms.orig.Data.(type) { case *otlpmetrics.Metric_IntGauge: return MetricDataTypeIntGauge case *otlpmetrics.Metric_DoubleGauge: @@ -230,19 +215,19 @@ func (ms Metric) DataType() MetricDataType { func (ms Metric) SetDataType(ty MetricDataType) { switch ty { case MetricDataTypeIntGauge: - (*ms.orig).Data = &otlpmetrics.Metric_IntGauge{IntGauge: &otlpmetrics.IntGauge{}} + ms.orig.Data = &otlpmetrics.Metric_IntGauge{IntGauge: &otlpmetrics.IntGauge{}} case MetricDataTypeDoubleGauge: - (*ms.orig).Data = &otlpmetrics.Metric_DoubleGauge{DoubleGauge: &otlpmetrics.DoubleGauge{}} + ms.orig.Data = &otlpmetrics.Metric_DoubleGauge{DoubleGauge: &otlpmetrics.DoubleGauge{}} case MetricDataTypeIntSum: - (*ms.orig).Data = &otlpmetrics.Metric_IntSum{IntSum: &otlpmetrics.IntSum{}} + ms.orig.Data = &otlpmetrics.Metric_IntSum{IntSum: &otlpmetrics.IntSum{}} case MetricDataTypeDoubleSum: - (*ms.orig).Data = &otlpmetrics.Metric_DoubleSum{DoubleSum: &otlpmetrics.DoubleSum{}} + ms.orig.Data = &otlpmetrics.Metric_DoubleSum{DoubleSum: &otlpmetrics.DoubleSum{}} case MetricDataTypeIntHistogram: - (*ms.orig).Data = &otlpmetrics.Metric_IntHistogram{IntHistogram: &otlpmetrics.IntHistogram{}} + ms.orig.Data = &otlpmetrics.Metric_IntHistogram{IntHistogram: &otlpmetrics.IntHistogram{}} case MetricDataTypeDoubleHistogram: - (*ms.orig).Data = &otlpmetrics.Metric_DoubleHistogram{DoubleHistogram: &otlpmetrics.DoubleHistogram{}} + ms.orig.Data = &otlpmetrics.Metric_DoubleHistogram{DoubleHistogram: &otlpmetrics.DoubleHistogram{}} case MetricDataTypeDoubleSummary: - (*ms.orig).Data = &otlpmetrics.Metric_DoubleSummary{DoubleSummary: &otlpmetrics.DoubleSummary{}} + ms.orig.Data = &otlpmetrics.Metric_DoubleSummary{DoubleSummary: &otlpmetrics.DoubleSummary{}} } } @@ -250,49 +235,49 @@ 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) { diff --git a/consumer/pdata/metric_test.go b/consumer/pdata/metric_test.go index d302abad2f2..4c9aad9cfdb 100644 --- a/consumer/pdata/metric_test.go +++ b/consumer/pdata/metric_test.go @@ -101,7 +101,6 @@ func TestCopyData(t *testing.T) { func TestDataType(t *testing.T) { m := NewMetric() - m.InitEmpty() assert.Equal(t, MetricDataTypeNone, m.DataType()) m.SetDataType(MetricDataTypeIntGauge) assert.Equal(t, MetricDataTypeIntGauge, m.DataType()) @@ -115,8 +114,8 @@ func TestDataType(t *testing.T) { assert.Equal(t, MetricDataTypeIntHistogram, m.DataType()) m.SetDataType(MetricDataTypeDoubleHistogram) assert.Equal(t, MetricDataTypeDoubleHistogram, m.DataType()) - m.InitEmpty() - assert.Equal(t, MetricDataTypeNone, m.DataType()) + m.SetDataType(MetricDataTypeDoubleSummary) + assert.Equal(t, MetricDataTypeDoubleSummary, m.DataType()) } func TestResourceMetricsWireCompatibility(t *testing.T) { @@ -128,7 +127,7 @@ func TestResourceMetricsWireCompatibility(t *testing.T) { pdataRM := generateTestResourceMetrics() // Marshal its underlying ProtoBuf to wire. - wire1, err := gogoproto.Marshal(*pdataRM.orig) + wire1, err := gogoproto.Marshal(pdataRM.orig) assert.NoError(t, err) assert.NotNil(t, wire1) @@ -149,7 +148,7 @@ func TestResourceMetricsWireCompatibility(t *testing.T) { // Now compare that the original and final ProtoBuf messages are the same. // This proves that goproto and gogoproto marshaling/unmarshaling are wire compatible. - assert.True(t, assert.EqualValues(t, *pdataRM.orig, &gogoprotoRM)) + assert.True(t, assert.EqualValues(t, pdataRM.orig, &gogoprotoRM)) } func TestMetricCount(t *testing.T) { @@ -185,7 +184,6 @@ func TestMetricSize(t *testing.T) { metric := rms.At(0).InstrumentationLibraryMetrics().At(0).Metrics().At(0) metric.SetDataType(MetricDataTypeDoubleHistogram) doubleHistogram := metric.DoubleHistogram() - doubleHistogram.InitEmpty() doubleHistogram.DataPoints().Resize(1) doubleHistogram.DataPoints().At(0).SetCount(123) doubleHistogram.DataPoints().At(0).SetSum(123) @@ -206,18 +204,18 @@ func TestMetricsSizeWithNil(t *testing.T) { assert.Equal(t, 0, MetricsFromOtlp([]*otlpmetrics.ResourceMetrics{nil}).Size()) } -func TestMetricCountWithNils(t *testing.T) { - assert.EqualValues(t, 0, MetricsFromOtlp([]*otlpmetrics.ResourceMetrics{nil, {}}).MetricCount()) +func TestMetricCountWithEmpty(t *testing.T) { + assert.EqualValues(t, 0, MetricsFromOtlp([]*otlpmetrics.ResourceMetrics{{}}).MetricCount()) assert.EqualValues(t, 0, MetricsFromOtlp([]*otlpmetrics.ResourceMetrics{ { - InstrumentationLibraryMetrics: []*otlpmetrics.InstrumentationLibraryMetrics{nil, {}}, + InstrumentationLibraryMetrics: []*otlpmetrics.InstrumentationLibraryMetrics{{}}, }, }).MetricCount()) - assert.EqualValues(t, 2, MetricsFromOtlp([]*otlpmetrics.ResourceMetrics{ + assert.EqualValues(t, 1, MetricsFromOtlp([]*otlpmetrics.ResourceMetrics{ { InstrumentationLibraryMetrics: []*otlpmetrics.InstrumentationLibraryMetrics{ { - Metrics: []*otlpmetrics.Metric{nil, {}}, + Metrics: []*otlpmetrics.Metric{{}}, }, }, }, @@ -248,7 +246,6 @@ func TestMetricAndDataPointCount(t *testing.T) { assert.EqualValues(t, 0, dps) ilms.At(0).Metrics().At(0).SetDataType(MetricDataTypeIntSum) intSum := ilms.At(0).Metrics().At(0).IntSum() - intSum.InitEmpty() intSum.DataPoints().Resize(3) _, dps = md.MetricAndDataPointCount() assert.EqualValues(t, 3, dps) @@ -268,25 +265,23 @@ func TestMetricAndDataPointCount(t *testing.T) { assert.EqualValues(t, 0, dps) ilms.At(0).Metrics().At(1).SetDataType(MetricDataTypeDoubleGauge) doubleGauge := ilms.At(0).Metrics().At(1).DoubleGauge() - doubleGauge.InitEmpty() doubleGauge.DataPoints().Resize(1) ilms.At(0).Metrics().At(3).SetDataType(MetricDataTypeIntHistogram) intHistogram := ilms.At(0).Metrics().At(3).IntHistogram() - intHistogram.InitEmpty() intHistogram.DataPoints().Resize(3) ms, dps = md.MetricAndDataPointCount() assert.EqualValues(t, 6, ms) assert.EqualValues(t, 4, dps) } -func TestMetricAndDataPointCountWithNil(t *testing.T) { - ms, dps := MetricsFromOtlp([]*otlpmetrics.ResourceMetrics{nil, {}}).MetricAndDataPointCount() +func TestMetricAndDataPointCountWithEmpty(t *testing.T) { + ms, dps := MetricsFromOtlp([]*otlpmetrics.ResourceMetrics{{}}).MetricAndDataPointCount() assert.EqualValues(t, 0, ms) assert.EqualValues(t, 0, dps) ms, dps = MetricsFromOtlp([]*otlpmetrics.ResourceMetrics{ { - InstrumentationLibraryMetrics: []*otlpmetrics.InstrumentationLibraryMetrics{nil, {}}, + InstrumentationLibraryMetrics: []*otlpmetrics.InstrumentationLibraryMetrics{{}}, }, }).MetricAndDataPointCount() assert.EqualValues(t, 0, ms) @@ -296,12 +291,12 @@ func TestMetricAndDataPointCountWithNil(t *testing.T) { { InstrumentationLibraryMetrics: []*otlpmetrics.InstrumentationLibraryMetrics{ { - Metrics: []*otlpmetrics.Metric{nil, {}}, + Metrics: []*otlpmetrics.Metric{{}}, }, }, }, }).MetricAndDataPointCount() - assert.EqualValues(t, 2, ms) + assert.EqualValues(t, 1, ms) assert.EqualValues(t, 0, dps) ms, dps = MetricsFromOtlp([]*otlpmetrics.ResourceMetrics{ @@ -312,7 +307,7 @@ func TestMetricAndDataPointCountWithNil(t *testing.T) { Data: &otlpmetrics.Metric_DoubleGauge{ DoubleGauge: &otlpmetrics.DoubleGauge{ DataPoints: []*otlpmetrics.DoubleDataPoint{ - nil, {}, + {}, }, }, }, @@ -322,40 +317,32 @@ func TestMetricAndDataPointCountWithNil(t *testing.T) { }, }).MetricAndDataPointCount() assert.EqualValues(t, 1, ms) - assert.EqualValues(t, 2, dps) + assert.EqualValues(t, 1, dps) } func TestMetricAndDataPointCountWithNilDataPoints(t *testing.T) { metrics := NewMetrics() rm := NewResourceMetrics() - rm.InitEmpty() metrics.ResourceMetrics().Append(rm) ilm := NewInstrumentationLibraryMetrics() - ilm.InitEmpty() rm.InstrumentationLibraryMetrics().Append(ilm) intGauge := NewMetric() - intGauge.InitEmpty() ilm.Metrics().Append(intGauge) intGauge.SetDataType(MetricDataTypeIntGauge) doubleGauge := NewMetric() - doubleGauge.InitEmpty() ilm.Metrics().Append(doubleGauge) doubleGauge.SetDataType(MetricDataTypeDoubleGauge) intHistogram := NewMetric() - intHistogram.InitEmpty() ilm.Metrics().Append(intHistogram) intHistogram.SetDataType(MetricDataTypeIntHistogram) doubleHistogram := NewMetric() - doubleHistogram.InitEmpty() ilm.Metrics().Append(doubleHistogram) doubleHistogram.SetDataType(MetricDataTypeDoubleHistogram) intSum := NewMetric() - intSum.InitEmpty() ilm.Metrics().Append(intSum) intSum.SetDataType(MetricDataTypeIntSum) doubleSum := NewMetric() - doubleSum.InitEmpty() ilm.Metrics().Append(doubleSum) doubleSum.SetDataType(MetricDataTypeDoubleSum) diff --git a/consumer/pdata/trace.go b/consumer/pdata/trace.go index 60848e12a15..a6c8edef734 100644 --- a/consumer/pdata/trace.go +++ b/consumer/pdata/trace.go @@ -79,15 +79,8 @@ func (td Traces) SpanCount() int { rss := td.ResourceSpans() for i := 0; i < rss.Len(); i++ { rs := rss.At(i) - if rs.IsNil() { - continue - } ilss := rs.InstrumentationLibrarySpans() for j := 0; j < ilss.Len(); j++ { - ils := ilss.At(j) - if ils.IsNil() { - continue - } spanCount += ilss.At(j).Spans().Len() } } diff --git a/consumer/pdata/trace_test.go b/consumer/pdata/trace_test.go index ea2c1007a06..2b554b45b97 100644 --- a/consumer/pdata/trace_test.go +++ b/consumer/pdata/trace_test.go @@ -74,18 +74,18 @@ func TestTracesSizeWithNil(t *testing.T) { assert.Equal(t, 0, TracesFromOtlp([]*otlptrace.ResourceSpans{nil}).Size()) } -func TestSpanCountWithNils(t *testing.T) { - assert.EqualValues(t, 0, TracesFromOtlp([]*otlptrace.ResourceSpans{nil, {}}).SpanCount()) +func TestSpanCountWithEmpty(t *testing.T) { + assert.EqualValues(t, 0, TracesFromOtlp([]*otlptrace.ResourceSpans{{}}).SpanCount()) assert.EqualValues(t, 0, TracesFromOtlp([]*otlptrace.ResourceSpans{ { - InstrumentationLibrarySpans: []*otlptrace.InstrumentationLibrarySpans{nil, {}}, + InstrumentationLibrarySpans: []*otlptrace.InstrumentationLibrarySpans{{}}, }, }).SpanCount()) - assert.EqualValues(t, 2, TracesFromOtlp([]*otlptrace.ResourceSpans{ + assert.EqualValues(t, 1, TracesFromOtlp([]*otlptrace.ResourceSpans{ { InstrumentationLibrarySpans: []*otlptrace.InstrumentationLibrarySpans{ { - Spans: []*otlptrace.Span{nil, {}}, + Spans: []*otlptrace.Span{{}}, }, }, }, @@ -163,7 +163,7 @@ func TestResourceSpansWireCompatibility(t *testing.T) { pdataRS := generateTestResourceSpans() // Marshal its underlying ProtoBuf to wire. - wire1, err := gogoproto.Marshal(*pdataRS.orig) + wire1, err := gogoproto.Marshal(pdataRS.orig) assert.NoError(t, err) assert.NotNil(t, wire1) @@ -184,7 +184,7 @@ func TestResourceSpansWireCompatibility(t *testing.T) { // Now compare that the original and final ProtoBuf messages are the same. // This proves that goproto and gogoproto marshaling/unmarshaling are wire compatible. - assert.EqualValues(t, *pdataRS.orig, &gogoprotoRS2) + assert.EqualValues(t, pdataRS.orig, &gogoprotoRS2) } func TestTracesToFromOtlpProtoBytes(t *testing.T) { diff --git a/consumer/simple/metrics.go b/consumer/simple/metrics.go index dff11e54a03..cd9e5a60df8 100644 --- a/consumer/simple/metrics.go +++ b/consumer/simple/metrics.go @@ -176,7 +176,6 @@ func (mb *Metrics) getMetricsSlice() pdata.MetricSlice { rmsLen := rms.Len() rms.Resize(rmsLen + 1) rm := rms.At(rmsLen) - rm.InitEmpty() res := rm.Resource() for k, v := range mb.ResourceAttributes { @@ -186,7 +185,6 @@ func (mb *Metrics) getMetricsSlice() pdata.MetricSlice { ilms := rm.InstrumentationLibraryMetrics() ilms.Resize(1) ilm := ilms.At(0) - ilm.InitEmpty() il := ilm.InstrumentationLibrary() il.SetName(mb.InstrumentationLibraryName) @@ -212,7 +210,6 @@ func (mb *Metrics) getOrCreateMetric(name string, typ pdata.MetricDataType) pdat metric = fac() } else { metric = pdata.NewMetric() - metric.InitEmpty() metric.SetName(name) metric.SetDataType(typ) @@ -239,7 +236,6 @@ func (mb *Metrics) addDataPoint(name string, typ pdata.MetricDataType, val inter m := metric.IntGauge() dps := m.DataPoints() dp := pdata.NewIntDataPoint() - dp.InitEmpty() dp.LabelsMap().InitFromMap(mb.Labels) dp.SetValue(val.(int64)) dp.SetTimestamp(tsNano) @@ -249,7 +245,6 @@ func (mb *Metrics) addDataPoint(name string, typ pdata.MetricDataType, val inter m := metric.IntSum() dps := m.DataPoints() dp := pdata.NewIntDataPoint() - dp.InitEmpty() dp.LabelsMap().InitFromMap(mb.Labels) dp.SetValue(val.(int64)) dp.SetTimestamp(tsNano) @@ -259,7 +254,6 @@ func (mb *Metrics) addDataPoint(name string, typ pdata.MetricDataType, val inter m := metric.DoubleGauge() dps := m.DataPoints() dp := pdata.NewDoubleDataPoint() - dp.InitEmpty() dp.LabelsMap().InitFromMap(mb.Labels) dp.SetValue(val.(float64)) dp.SetTimestamp(tsNano) @@ -269,7 +263,6 @@ func (mb *Metrics) addDataPoint(name string, typ pdata.MetricDataType, val inter m := metric.DoubleSum() dps := m.DataPoints() dp := pdata.NewDoubleDataPoint() - dp.InitEmpty() dp.LabelsMap().InitFromMap(mb.Labels) dp.SetValue(val.(float64)) dp.SetTimestamp(tsNano) @@ -279,7 +272,6 @@ func (mb *Metrics) addDataPoint(name string, typ pdata.MetricDataType, val inter m := metric.IntHistogram() dps := m.DataPoints() dp := pdata.NewIntHistogramDataPoint() - dp.InitEmpty() dp.LabelsMap().InitFromMap(mb.Labels) val.(pdata.IntHistogramDataPoint).CopyTo(dp) dp.SetTimestamp(tsNano) @@ -289,7 +281,6 @@ func (mb *Metrics) addDataPoint(name string, typ pdata.MetricDataType, val inter m := metric.DoubleHistogram() dps := m.DataPoints() dp := pdata.NewDoubleHistogramDataPoint() - dp.InitEmpty() dp.LabelsMap().InitFromMap(mb.Labels) val.(pdata.DoubleHistogramDataPoint).CopyTo(dp) dp.SetTimestamp(tsNano) diff --git a/consumer/simple/metrics_test.go b/consumer/simple/metrics_test.go index 282df32dbf0..412face9c90 100644 --- a/consumer/simple/metrics_test.go +++ b/consumer/simple/metrics_test.go @@ -262,9 +262,7 @@ func TestMetrics(t *testing.T) { AddDSumDataPoint("disk.time_awake", 100.6) intHisto := pdata.NewIntHistogramDataPoint() - intHisto.InitEmpty() doubleHisto := pdata.NewDoubleHistogramDataPoint() - doubleHisto.InitEmpty() mb.WithLabels(map[string]string{ "partition": "1", @@ -287,7 +285,6 @@ func TestMetricFactories(t *testing.T) { MetricFactoriesByName: map[string]func() pdata.Metric{ "disk.ops": func() pdata.Metric { m := pdata.NewMetric() - m.InitEmpty() m.SetName("disk.ops") m.SetDescription("This counts disk operations") m.SetDataType(pdata.MetricDataTypeIntSum) @@ -411,9 +408,7 @@ func TestSafeMetrics(t *testing.T) { AddDSumDataPoint("disk.time_awake"+idx, 100.6) intHisto := pdata.NewIntHistogramDataPoint() - intHisto.InitEmpty() doubleHisto := pdata.NewDoubleHistogramDataPoint() - doubleHisto.InitEmpty() for j := 0; j < 5; j++ { mb.WithLabels(map[string]string{ @@ -473,7 +468,6 @@ func BenchmarkPdataMetrics(b *testing.B) { rmsLen := rms.Len() rms.Resize(rmsLen + 1) rm := rms.At(rmsLen) - rm.InitEmpty() res := rm.Resource() resAttrs := res.Attributes() @@ -483,7 +477,6 @@ func BenchmarkPdataMetrics(b *testing.B) { ilms := rm.InstrumentationLibraryMetrics() ilms.Resize(1) ilm := ilms.At(0) - ilm.InitEmpty() metrics := ilm.Metrics() metrics.Resize(6) @@ -493,7 +486,6 @@ func BenchmarkPdataMetrics(b *testing.B) { for i := 0; i < 50; i++ { metric := metrics.At(0) - metric.InitEmpty() metric.SetName("gauge" + strconv.Itoa(i)) metric.SetDataType(pdata.MetricDataTypeIntGauge) mAsType := metric.IntGauge() diff --git a/exporter/exporterhelper/resource_to_label.go b/exporter/exporterhelper/resource_to_label.go index 71f46fca9fb..b2c046756c7 100644 --- a/exporter/exporterhelper/resource_to_label.go +++ b/exporter/exporterhelper/resource_to_label.go @@ -44,15 +44,9 @@ func convertResourceToLabels(md pdata.Metrics) pdata.Metrics { ilms := rms.At(i).InstrumentationLibraryMetrics() for j := 0; j < ilms.Len(); j++ { ilm := ilms.At(j) - if ilm.IsNil() { - continue - } metricSlice := ilm.Metrics() for k := 0; k < metricSlice.Len(); k++ { metric := metricSlice.At(k) - if metric.IsNil() { - continue - } addLabelsToMetric(&metric, labelMap) } } @@ -93,41 +87,25 @@ func addLabelsToMetric(metric *pdata.Metric, labelMap pdata.StringMap) { func addLabelsToIntDataPoints(ps pdata.IntDataPointSlice, newLabelMap pdata.StringMap) { for i := 0; i < ps.Len(); i++ { - dataPoint := ps.At(i) - if dataPoint.IsNil() { - continue - } - joinStringMaps(newLabelMap, dataPoint.LabelsMap()) + joinStringMaps(newLabelMap, ps.At(i).LabelsMap()) } } func addLabelsToDoubleDataPoints(ps pdata.DoubleDataPointSlice, newLabelMap pdata.StringMap) { for i := 0; i < ps.Len(); i++ { - dataPoint := ps.At(i) - if dataPoint.IsNil() { - continue - } - joinStringMaps(newLabelMap, dataPoint.LabelsMap()) + joinStringMaps(newLabelMap, ps.At(i).LabelsMap()) } } func addLabelsToIntHistogramDataPoints(ps pdata.IntHistogramDataPointSlice, newLabelMap pdata.StringMap) { for i := 0; i < ps.Len(); i++ { - dataPoint := ps.At(i) - if dataPoint.IsNil() { - continue - } - joinStringMaps(newLabelMap, dataPoint.LabelsMap()) + joinStringMaps(newLabelMap, ps.At(i).LabelsMap()) } } func addLabelsToDoubleHistogramDataPoints(ps pdata.DoubleHistogramDataPointSlice, newLabelMap pdata.StringMap) { for i := 0; i < ps.Len(); i++ { - dataPoint := ps.At(i) - if dataPoint.IsNil() { - continue - } - joinStringMaps(newLabelMap, dataPoint.LabelsMap()) + joinStringMaps(newLabelMap, ps.At(i).LabelsMap()) } } diff --git a/exporter/exporterhelper/resource_to_label_test.go b/exporter/exporterhelper/resource_to_label_test.go index 1b445b97bc1..232673f84a3 100644 --- a/exporter/exporterhelper/resource_to_label_test.go +++ b/exporter/exporterhelper/resource_to_label_test.go @@ -88,33 +88,3 @@ func TestConvertResourceToLabelsAllDataTypesNilDataPoint(t *testing.T) { assert.Equal(t, 1, md.ResourceMetrics().At(0).Resource().Attributes().Len()) } - -func TestConvertResourceToLabelsOneMetricOneNil(t *testing.T) { - md := testdata.GenerateMetricsOneMetricOneNil() - assert.NotNil(t, md) - - // Before converting resource to labels - assert.Equal(t, 1, md.ResourceMetrics().At(0).Resource().Attributes().Len()) - - cloneMd := convertResourceToLabels(md) - - // After converting resource to labels - assert.Equal(t, 1, cloneMd.ResourceMetrics().At(0).Resource().Attributes().Len()) - - assert.Equal(t, 1, md.ResourceMetrics().At(0).Resource().Attributes().Len()) -} - -func TestConvertResourceToLabelsOneEmptyOneNilIlm(t *testing.T) { - md := testdata.GenerateMetricsOneEmptyOneNilInstrumentationLibrary() - assert.NotNil(t, md) - - // Before converting resource to labels - assert.Equal(t, 1, md.ResourceMetrics().At(0).Resource().Attributes().Len()) - - cloneMd := convertResourceToLabels(md) - - // After converting resource to labels - assert.Equal(t, 1, cloneMd.ResourceMetrics().At(0).Resource().Attributes().Len()) - - assert.Equal(t, 1, md.ResourceMetrics().At(0).Resource().Attributes().Len()) -} diff --git a/exporter/loggingexporter/logging_exporter.go b/exporter/loggingexporter/logging_exporter.go index 8afaa4460ff..581f1fedaf5 100644 --- a/exporter/loggingexporter/logging_exporter.go +++ b/exporter/loggingexporter/logging_exporter.go @@ -115,10 +115,6 @@ func (b *logDataBuffer) logMetricDataPoints(m pdata.Metric) { func (b *logDataBuffer) logIntDataPoints(ps pdata.IntDataPointSlice) { for i := 0; i < ps.Len(); i++ { p := ps.At(i) - if p.IsNil() { - continue - } - b.logEntry("IntDataPoints #%d", i) b.logDataPointLabels(p.LabelsMap()) @@ -131,10 +127,6 @@ func (b *logDataBuffer) logIntDataPoints(ps pdata.IntDataPointSlice) { func (b *logDataBuffer) logDoubleDataPoints(ps pdata.DoubleDataPointSlice) { for i := 0; i < ps.Len(); i++ { p := ps.At(i) - if p.IsNil() { - continue - } - b.logEntry("DoubleDataPoints #%d", i) b.logDataPointLabels(p.LabelsMap()) @@ -147,10 +139,6 @@ func (b *logDataBuffer) logDoubleDataPoints(ps pdata.DoubleDataPointSlice) { func (b *logDataBuffer) logDoubleHistogramDataPoints(ps pdata.DoubleHistogramDataPointSlice) { for i := 0; i < ps.Len(); i++ { p := ps.At(i) - if p.IsNil() { - continue - } - b.logEntry("HistogramDataPoints #%d", i) b.logDataPointLabels(p.LabelsMap()) @@ -178,10 +166,6 @@ func (b *logDataBuffer) logDoubleHistogramDataPoints(ps pdata.DoubleHistogramDat func (b *logDataBuffer) logIntHistogramDataPoints(ps pdata.IntHistogramDataPointSlice) { for i := 0; i < ps.Len(); i++ { p := ps.At(i) - if p.IsNil() { - continue - } - b.logEntry("HistogramDataPoints #%d", i) b.logDataPointLabels(p.LabelsMap()) @@ -209,10 +193,6 @@ func (b *logDataBuffer) logIntHistogramDataPoints(ps pdata.IntHistogramDataPoint func (b *logDataBuffer) logDoubleSummaryDataPoints(ps pdata.DoubleSummaryDataPointSlice) { for i := 0; i < ps.Len(); i++ { p := ps.At(i) - if p.IsNil() { - continue - } - b.logEntry("SummaryDataPoints #%d", i) b.logDataPointLabels(p.LabelsMap()) @@ -249,9 +229,6 @@ func (b *logDataBuffer) logEvents(description string, se pdata.SpanEventSlice) { b.logEntry("%s:", description) for i := 0; i < se.Len(); i++ { e := se.At(i) - if e.IsNil() { - continue - } b.logEntry("SpanEvent #%d", i) b.logEntry(" -> Name: %s", e.Name()) b.logEntry(" -> Timestamp: %d", e.Timestamp()) @@ -276,9 +253,6 @@ func (b *logDataBuffer) logLinks(description string, sl pdata.SpanLinkSlice) { for i := 0; i < sl.Len(); i++ { l := sl.At(i) - if l.IsNil() { - continue - } b.logEntry("SpanLink #%d", i) b.logEntry(" -> Trace ID: %s", l.TraceID().HexString()) b.logEntry(" -> ID: %s", l.SpanID().HexString()) @@ -347,30 +321,17 @@ func (s *loggingExporter) pushTraceData( for i := 0; i < rss.Len(); i++ { buf.logEntry("ResourceSpans #%d", i) rs := rss.At(i) - if rs.IsNil() { - buf.logEntry("* Nil ResourceSpans") - continue - } buf.logAttributeMap("Resource labels", rs.Resource().Attributes()) ilss := rs.InstrumentationLibrarySpans() for j := 0; j < ilss.Len(); j++ { buf.logEntry("InstrumentationLibrarySpans #%d", j) ils := ilss.At(j) - if ils.IsNil() { - buf.logEntry("* Nil InstrumentationLibrarySpans") - continue - } buf.logInstrumentationLibrary(ils.InstrumentationLibrary()) spans := ils.Spans() for k := 0; k < spans.Len(); k++ { buf.logEntry("Span #%d", k) span := spans.At(k) - if span.IsNil() { - buf.logEntry("* Nil Span") - continue - } - buf.logAttr("Trace ID", span.TraceID().HexString()) buf.logAttr("Parent ID", span.ParentSpanID().HexString()) buf.logAttr("ID", span.SpanID().HexString()) @@ -409,29 +370,16 @@ func (s *loggingExporter) pushMetricsData( for i := 0; i < rms.Len(); i++ { buf.logEntry("ResourceMetrics #%d", i) rm := rms.At(i) - if rm.IsNil() { - buf.logEntry("* Nil ResourceMetrics") - continue - } buf.logAttributeMap("Resource labels", rm.Resource().Attributes()) ilms := rm.InstrumentationLibraryMetrics() for j := 0; j < ilms.Len(); j++ { buf.logEntry("InstrumentationLibraryMetrics #%d", j) ilm := ilms.At(j) - if ilm.IsNil() { - buf.logEntry("* Nil InstrumentationLibraryMetrics") - continue - } buf.logInstrumentationLibrary(ilm.InstrumentationLibrary()) metrics := ilm.Metrics() for k := 0; k < metrics.Len(); k++ { buf.logEntry("Metric #%d", k) metric := metrics.At(k) - if metric.IsNil() { - buf.logEntry("* Nil Metric") - continue - } - buf.logMetricDescriptor(metric) buf.logMetricDataPoints(metric) } @@ -518,29 +466,17 @@ func (s *loggingExporter) pushLogData( for i := 0; i < rls.Len(); i++ { buf.logEntry("ResourceLog #%d", i) rl := rls.At(i) - if rl.IsNil() { - buf.logEntry("* Nil ResourceLog") - continue - } buf.logAttributeMap("Resource labels", rl.Resource().Attributes()) ills := rl.InstrumentationLibraryLogs() for j := 0; j < ills.Len(); j++ { buf.logEntry("InstrumentationLibraryLogs #%d", j) ils := ills.At(j) - if ils.IsNil() { - buf.logEntry("* Nil InstrumentationLibraryLogs") - continue - } buf.logInstrumentationLibrary(ils.InstrumentationLibrary()) logs := ils.Logs() - for j := 0; j < logs.Len(); j++ { - buf.logEntry("LogRecord #%d", j) - lr := logs.At(j) - if lr.IsNil() { - buf.logEntry("* Nil LogRecord") - continue - } + for k := 0; k < logs.Len(); k++ { + buf.logEntry("LogRecord #%d", k) + lr := logs.At(k) buf.logLogRecord(lr) } } diff --git a/exporter/loggingexporter/logging_exporter_test.go b/exporter/loggingexporter/logging_exporter_test.go index 17a73d9865e..db2bca219f9 100644 --- a/exporter/loggingexporter/logging_exporter_test.go +++ b/exporter/loggingexporter/logging_exporter_test.go @@ -32,9 +32,6 @@ func TestLoggingTraceExporterNoErrors(t *testing.T) { assert.NoError(t, err) assert.NoError(t, lte.ConsumeTraces(context.Background(), testdata.GenerateTraceDataEmpty())) - assert.NoError(t, lte.ConsumeTraces(context.Background(), testdata.GenerateTraceDataOneEmptyOneNilResourceSpans())) - assert.NoError(t, lte.ConsumeTraces(context.Background(), testdata.GenerateTraceDataOneEmptyOneNilInstrumentationLibrary())) - assert.NoError(t, lte.ConsumeTraces(context.Background(), testdata.GenerateTraceDataOneSpanOneNil())) assert.NoError(t, lte.ConsumeTraces(context.Background(), testdata.GenerateTraceDataTwoSpansSameResourceOneDifferent())) assert.NoError(t, lte.Shutdown(context.Background())) @@ -46,9 +43,6 @@ func TestLoggingMetricsExporterNoErrors(t *testing.T) { assert.NoError(t, err) assert.NoError(t, lme.ConsumeMetrics(context.Background(), testdata.GenerateMetricsEmpty())) - assert.NoError(t, lme.ConsumeMetrics(context.Background(), testdata.GenerateMetricsOneEmptyOneNilResourceMetrics())) - assert.NoError(t, lme.ConsumeMetrics(context.Background(), testdata.GenerateMetricsOneEmptyOneNilInstrumentationLibrary())) - assert.NoError(t, lme.ConsumeMetrics(context.Background(), testdata.GenerateMetricsOneMetricOneNil())) assert.NoError(t, lme.ConsumeMetrics(context.Background(), testdata.GeneratMetricsAllTypesWithSampleDatapoints())) assert.NoError(t, lme.ConsumeMetrics(context.Background(), testdata.GenerateMetricsAllTypesNilDataPoint())) assert.NoError(t, lme.ConsumeMetrics(context.Background(), testdata.GenerateMetricsAllTypesEmptyDataPoint())) @@ -64,7 +58,6 @@ func TestLoggingLogsExporterNoErrors(t *testing.T) { assert.NoError(t, lle.ConsumeLogs(context.Background(), testdata.GenerateLogDataEmpty())) assert.NoError(t, lle.ConsumeLogs(context.Background(), testdata.GenerateLogDataOneEmptyResourceLogs())) - assert.NoError(t, lle.ConsumeLogs(context.Background(), testdata.GenerateLogDataOneEmptyOneNilResourceLogs())) assert.NoError(t, lle.ConsumeLogs(context.Background(), testdata.GenerateLogDataNoLogRecords())) assert.NoError(t, lle.ConsumeLogs(context.Background(), testdata.GenerateLogDataOneEmptyLogs())) diff --git a/exporter/prometheusremotewriteexporter/exporter_test.go b/exporter/prometheusremotewriteexporter/exporter_test.go index ebd16b7637e..c0e31d496b3 100644 --- a/exporter/prometheusremotewriteexporter/exporter_test.go +++ b/exporter/prometheusremotewriteexporter/exporter_test.go @@ -258,22 +258,6 @@ func Test_PushMetrics(t *testing.T) { invalidTypeBatch := testdata.GenerateMetricsMetricTypeInvalid() - nilBatch1 := testdata.GenerateMetricsOneEmptyResourceMetrics() - nilBatch2 := testdata.GenerateMetricsOneEmptyInstrumentationLibrary() - nilBatch3 := testdata.GenerateMetricsOneMetric() - - nilResource := pdata.MetricsToOtlp(nilBatch1) - nilResource[0] = nil - nilResourceBatch := pdata.MetricsFromOtlp(nilResource) - - nilInstrumentation := pdata.MetricsToOtlp(nilBatch2) - nilInstrumentation[0].InstrumentationLibraryMetrics[0] = nil - nilInstrumentationBatch := pdata.MetricsFromOtlp(nilInstrumentation) - - nilMetric := pdata.MetricsToOtlp(nilBatch3) - nilMetric[0].InstrumentationLibraryMetrics[0].Metrics[0] = nil - nilMetricBatch := pdata.MetricsFromOtlp(nilMetric) - // success cases intSumBatch := testdata.GenerateMetricsManyMetricsSameResource(10) @@ -517,33 +501,6 @@ func Test_PushMetrics(t *testing.T) { invalidTypeBatch.MetricCount(), true, }, - { - "nil_resourece_case", - &nilResourceBatch, - nil, - 0, - http.StatusAccepted, - nilResourceBatch.MetricCount(), - false, - }, - { - "nil_instrumentation_case", - &nilInstrumentationBatch, - nil, - 0, - http.StatusAccepted, - nilInstrumentationBatch.MetricCount(), - false, - }, - { - "nil_metric_case", - &nilMetricBatch, - nil, - 0, - http.StatusAccepted, - nilMetricBatch.MetricCount(), - true, - }, { "intSum_case", &intSumBatch, diff --git a/internal/goldendataset/metric_gen.go b/internal/goldendataset/metric_gen.go index bfcb4466d39..76e376647f6 100644 --- a/internal/goldendataset/metric_gen.go +++ b/internal/goldendataset/metric_gen.go @@ -154,7 +154,6 @@ func (g *metricGenerator) populateMetrics(cfg MetricCfg, ilm pdata.Instrumentati } func (g *metricGenerator) populateMetricDesc(cfg MetricCfg, metric pdata.Metric) { - metric.InitEmpty() metric.SetName(fmt.Sprintf("%smetric_%d", cfg.MetricNamePrefix, g.metricID)) g.metricID++ metric.SetDescription("my-md-description") diff --git a/internal/goldendataset/metric_gen_test.go b/internal/goldendataset/metric_gen_test.go index 59813ebea7d..360f9e50a08 100644 --- a/internal/goldendataset/metric_gen_test.go +++ b/internal/goldendataset/metric_gen_test.go @@ -60,7 +60,6 @@ func TestGenDefault(t *testing.T) { func TestDoubleHistogramFunctions(t *testing.T) { pt := pdata.NewDoubleHistogramDataPoint() - pt.InitEmpty() setDoubleHistogramBounds(pt, 1, 2, 3, 4, 5) require.Equal(t, 5, len(pt.ExplicitBounds())) require.Equal(t, 5, len(pt.BucketCounts())) @@ -83,7 +82,6 @@ func TestDoubleHistogramFunctions(t *testing.T) { func TestIntHistogramFunctions(t *testing.T) { pt := pdata.NewIntHistogramDataPoint() - pt.InitEmpty() setIntHistogramBounds(pt, 1, 2, 3, 4, 5) require.Equal(t, 5, len(pt.ExplicitBounds())) require.Equal(t, 5, len(pt.BucketCounts())) diff --git a/internal/processor/filterexpr/matcher.go b/internal/processor/filterexpr/matcher.go index 18c74b25995..8f92c59af3c 100644 --- a/internal/processor/filterexpr/matcher.go +++ b/internal/processor/filterexpr/matcher.go @@ -64,11 +64,7 @@ func (m *Matcher) MatchMetric(metric pdata.Metric) (bool, error) { func (m *Matcher) matchIntGauge(metricName string, gauge pdata.IntGauge) (bool, error) { pts := gauge.DataPoints() for i := 0; i < pts.Len(); i++ { - pt := pts.At(i) - if pt.IsNil() { - continue - } - matched, err := m.matchEnv(metricName, pt.LabelsMap()) + matched, err := m.matchEnv(metricName, pts.At(i).LabelsMap()) if err != nil { return false, err } @@ -82,11 +78,7 @@ func (m *Matcher) matchIntGauge(metricName string, gauge pdata.IntGauge) (bool, func (m *Matcher) matchDoubleGauge(metricName string, gauge pdata.DoubleGauge) (bool, error) { pts := gauge.DataPoints() for i := 0; i < pts.Len(); i++ { - pt := pts.At(i) - if pt.IsNil() { - continue - } - matched, err := m.matchEnv(metricName, pt.LabelsMap()) + matched, err := m.matchEnv(metricName, pts.At(i).LabelsMap()) if err != nil { return false, err } @@ -100,11 +92,7 @@ func (m *Matcher) matchDoubleGauge(metricName string, gauge pdata.DoubleGauge) ( func (m *Matcher) matchDoubleSum(metricName string, sum pdata.DoubleSum) (bool, error) { pts := sum.DataPoints() for i := 0; i < pts.Len(); i++ { - pt := pts.At(i) - if pt.IsNil() { - continue - } - matched, err := m.matchEnv(metricName, pt.LabelsMap()) + matched, err := m.matchEnv(metricName, pts.At(i).LabelsMap()) if err != nil { return false, err } @@ -118,11 +106,7 @@ func (m *Matcher) matchDoubleSum(metricName string, sum pdata.DoubleSum) (bool, func (m *Matcher) matchIntSum(metricName string, sum pdata.IntSum) (bool, error) { pts := sum.DataPoints() for i := 0; i < pts.Len(); i++ { - pt := pts.At(i) - if pt.IsNil() { - continue - } - matched, err := m.matchEnv(metricName, pt.LabelsMap()) + matched, err := m.matchEnv(metricName, pts.At(i).LabelsMap()) if err != nil { return false, err } @@ -136,11 +120,7 @@ func (m *Matcher) matchIntSum(metricName string, sum pdata.IntSum) (bool, error) func (m *Matcher) matchIntHistogram(metricName string, histogram pdata.IntHistogram) (bool, error) { pts := histogram.DataPoints() for i := 0; i < pts.Len(); i++ { - pt := pts.At(i) - if pt.IsNil() { - continue - } - matched, err := m.matchEnv(metricName, pt.LabelsMap()) + matched, err := m.matchEnv(metricName, pts.At(i).LabelsMap()) if err != nil { return false, err } @@ -154,11 +134,7 @@ func (m *Matcher) matchIntHistogram(metricName string, histogram pdata.IntHistog func (m *Matcher) matchDoubleHistogram(metricName string, histogram pdata.DoubleHistogram) (bool, error) { pts := histogram.DataPoints() for i := 0; i < pts.Len(); i++ { - pt := pts.At(i) - if pt.IsNil() { - continue - } - matched, err := m.matchEnv(metricName, pt.LabelsMap()) + matched, err := m.matchEnv(metricName, pts.At(i).LabelsMap()) if err != nil { return false, err } diff --git a/internal/processor/filterexpr/matcher_test.go b/internal/processor/filterexpr/matcher_test.go index 3d6b0208bdf..3aa49adc13b 100644 --- a/internal/processor/filterexpr/matcher_test.go +++ b/internal/processor/filterexpr/matcher_test.go @@ -39,7 +39,6 @@ func TestUnknownDataType(t *testing.T) { matcher, err := NewMatcher(`MetricName == 'my.metric'`) require.NoError(t, err) m := pdata.NewMetric() - m.InitEmpty() m.SetName("my.metric") m.SetDataType(-1) matched, err := matcher.MatchMetric(m) @@ -81,7 +80,6 @@ func testNilValue(t *testing.T, dataType pdata.MetricDataType) { matcher, err := NewMatcher(`MetricName == 'my.metric'`) require.NoError(t, err) m := pdata.NewMetric() - m.InitEmpty() m.SetName("my.metric") m.SetDataType(dataType) matched, err := matcher.MatchMetric(m) @@ -89,94 +87,82 @@ func testNilValue(t *testing.T, dataType pdata.MetricDataType) { assert.False(t, matched) } -func TestIntGaugeNilDataPoint(t *testing.T) { +func TestIntGaugeEmptyDataPoint(t *testing.T) { matcher, err := NewMatcher(`MetricName == 'my.metric'`) require.NoError(t, err) m := pdata.NewMetric() - m.InitEmpty() m.SetName("my.metric") m.SetDataType(pdata.MetricDataTypeIntGauge) dps := m.IntGauge().DataPoints() - pt := pdata.NewIntDataPoint() - dps.Append(pt) + dps.Append(pdata.NewIntDataPoint()) matched, err := matcher.MatchMetric(m) assert.NoError(t, err) - assert.False(t, matched) + assert.True(t, matched) } -func TestDoubleGaugeNilDataPoint(t *testing.T) { +func TestDoubleGaugeEmptyDataPoint(t *testing.T) { matcher, err := NewMatcher(`MetricName == 'my.metric'`) require.NoError(t, err) m := pdata.NewMetric() - m.InitEmpty() m.SetName("my.metric") m.SetDataType(pdata.MetricDataTypeDoubleGauge) dps := m.DoubleGauge().DataPoints() - pt := pdata.NewDoubleDataPoint() - dps.Append(pt) + dps.Append(pdata.NewDoubleDataPoint()) matched, err := matcher.MatchMetric(m) assert.NoError(t, err) - assert.False(t, matched) + assert.True(t, matched) } -func TestDoubleSumNilDataPoint(t *testing.T) { +func TestDoubleSumEmptyDataPoint(t *testing.T) { matcher, err := NewMatcher(`MetricName == 'my.metric'`) require.NoError(t, err) m := pdata.NewMetric() - m.InitEmpty() m.SetName("my.metric") m.SetDataType(pdata.MetricDataTypeDoubleSum) dps := m.DoubleSum().DataPoints() - pt := pdata.NewDoubleDataPoint() - dps.Append(pt) + dps.Append(pdata.NewDoubleDataPoint()) matched, err := matcher.MatchMetric(m) assert.NoError(t, err) - assert.False(t, matched) + assert.True(t, matched) } -func TestIntSumNilDataPoint(t *testing.T) { +func TestIntSumEmptyDataPoint(t *testing.T) { matcher, err := NewMatcher(`MetricName == 'my.metric'`) require.NoError(t, err) m := pdata.NewMetric() - m.InitEmpty() m.SetName("my.metric") m.SetDataType(pdata.MetricDataTypeIntSum) dps := m.IntSum().DataPoints() - pt := pdata.NewIntDataPoint() - dps.Append(pt) + dps.Append(pdata.NewIntDataPoint()) matched, err := matcher.MatchMetric(m) assert.NoError(t, err) - assert.False(t, matched) + assert.True(t, matched) } -func TestIntHistogramNilDataPoint(t *testing.T) { +func TestIntHistogramEmptyDataPoint(t *testing.T) { matcher, err := NewMatcher(`MetricName == 'my.metric'`) require.NoError(t, err) m := pdata.NewMetric() - m.InitEmpty() m.SetName("my.metric") m.SetDataType(pdata.MetricDataTypeIntHistogram) dps := m.IntHistogram().DataPoints() - pt := pdata.NewIntHistogramDataPoint() - dps.Append(pt) + dps.Append(pdata.NewIntHistogramDataPoint()) matched, err := matcher.MatchMetric(m) assert.NoError(t, err) - assert.False(t, matched) + assert.True(t, matched) } -func TestDoubleHistogramNilDataPoint(t *testing.T) { +func TestDoubleHistogramEmptyDataPoint(t *testing.T) { matcher, err := NewMatcher(`MetricName == 'my.metric'`) require.NoError(t, err) m := pdata.NewMetric() - m.InitEmpty() m.SetName("my.metric") m.SetDataType(pdata.MetricDataTypeDoubleHistogram) dps := m.DoubleHistogram().DataPoints() - pt := pdata.NewDoubleHistogramDataPoint() - dps.Append(pt) + dps.Append(pdata.NewDoubleHistogramDataPoint()) matched, err := matcher.MatchMetric(m) assert.NoError(t, err) - assert.False(t, matched) + assert.True(t, matched) } func TestMatchIntGaugeByMetricName(t *testing.T) { @@ -213,12 +199,10 @@ func testMatchIntGauge(t *testing.T, metricName, expression string, lbls map[str matcher, err := NewMatcher(expression) require.NoError(t, err) m := pdata.NewMetric() - m.InitEmpty() m.SetName(metricName) m.SetDataType(pdata.MetricDataTypeIntGauge) dps := m.IntGauge().DataPoints() pt := pdata.NewIntDataPoint() - pt.InitEmpty() if lbls != nil { pt.LabelsMap().InitFromMap(lbls) } @@ -234,18 +218,15 @@ func TestMatchIntGaugeDataPointByMetricAndSecondPointLabelValue(t *testing.T) { ) require.NoError(t, err) m := pdata.NewMetric() - m.InitEmpty() m.SetName("my.metric") m.SetDataType(pdata.MetricDataTypeIntGauge) dps := m.IntGauge().DataPoints() pt1 := pdata.NewIntDataPoint() - pt1.InitEmpty() pt1.LabelsMap().Insert("foo", "bar") dps.Append(pt1) pt2 := pdata.NewIntDataPoint() - pt2.InitEmpty() pt2.LabelsMap().Insert("baz", "glarch") dps.Append(pt2) @@ -266,12 +247,10 @@ func testMatchDoubleGauge(t *testing.T, metricName string) bool { matcher, err := NewMatcher(`MetricName == 'my.metric'`) require.NoError(t, err) m := pdata.NewMetric() - m.InitEmpty() m.SetName(metricName) m.SetDataType(pdata.MetricDataTypeDoubleGauge) dps := m.DoubleGauge().DataPoints() pt := pdata.NewDoubleDataPoint() - pt.InitEmpty() dps.Append(pt) match, err := matcher.MatchMetric(m) assert.NoError(t, err) @@ -290,12 +269,10 @@ func matchDoubleSum(t *testing.T, metricName string) bool { matcher, err := NewMatcher(`MetricName == 'my.metric'`) require.NoError(t, err) m := pdata.NewMetric() - m.InitEmpty() m.SetName(metricName) m.SetDataType(pdata.MetricDataTypeDoubleSum) dps := m.DoubleSum().DataPoints() pt := pdata.NewDoubleDataPoint() - pt.InitEmpty() dps.Append(pt) matched, err := matcher.MatchMetric(m) assert.NoError(t, err) @@ -314,12 +291,10 @@ func matchIntSum(t *testing.T, metricName string) bool { matcher, err := NewMatcher(`MetricName == 'my.metric'`) require.NoError(t, err) m := pdata.NewMetric() - m.InitEmpty() m.SetName(metricName) m.SetDataType(pdata.MetricDataTypeIntSum) dps := m.IntSum().DataPoints() pt := pdata.NewIntDataPoint() - pt.InitEmpty() dps.Append(pt) matched, err := matcher.MatchMetric(m) assert.NoError(t, err) @@ -338,12 +313,10 @@ func matchIntHistogram(t *testing.T, metricName string) bool { matcher, err := NewMatcher(`MetricName == 'my.metric'`) require.NoError(t, err) m := pdata.NewMetric() - m.InitEmpty() m.SetName(metricName) m.SetDataType(pdata.MetricDataTypeIntHistogram) dps := m.IntHistogram().DataPoints() pt := pdata.NewIntHistogramDataPoint() - pt.InitEmpty() dps.Append(pt) matched, err := matcher.MatchMetric(m) assert.NoError(t, err) @@ -362,12 +335,10 @@ func matchDoubleHistogram(t *testing.T, metricName string) bool { matcher, err := NewMatcher(`MetricName == 'my.metric'`) require.NoError(t, err) m := pdata.NewMetric() - m.InitEmpty() m.SetName(metricName) m.SetDataType(pdata.MetricDataTypeDoubleHistogram) dps := m.DoubleHistogram().DataPoints() pt := pdata.NewDoubleHistogramDataPoint() - pt.InitEmpty() dps.Append(pt) matched, err := matcher.MatchMetric(m) assert.NoError(t, err) diff --git a/internal/processor/filterlog/filterlog_test.go b/internal/processor/filterlog/filterlog_test.go index d41ff94843a..ef14afed163 100644 --- a/internal/processor/filterlog/filterlog_test.go +++ b/internal/processor/filterlog/filterlog_test.go @@ -127,7 +127,6 @@ func TestLogRecord_Matching_False(t *testing.T) { } lr := pdata.NewLogRecord() - lr.InitEmpty() lr.SetName("logName") for _, tc := range testcases { t.Run(tc.name, func(t *testing.T) { @@ -169,7 +168,6 @@ func TestLogRecord_Matching_True(t *testing.T) { } lr := pdata.NewLogRecord() - lr.InitEmpty() lr.SetName("logName") for _, tc := range testcases { diff --git a/internal/processor/filtermetric/filtermetric_test.go b/internal/processor/filtermetric/filtermetric_test.go index 768956037fc..cdc82af1765 100644 --- a/internal/processor/filtermetric/filtermetric_test.go +++ b/internal/processor/filtermetric/filtermetric_test.go @@ -44,7 +44,6 @@ var ( func createMetric(name string) pdata.Metric { metric := pdata.NewMetric() - metric.InitEmpty() metric.SetName(name) return metric } diff --git a/internal/processor/filterspan/filterspan_test.go b/internal/processor/filterspan/filterspan_test.go index 3bfbf2491a3..5c4cd68fd7a 100644 --- a/internal/processor/filterspan/filterspan_test.go +++ b/internal/processor/filterspan/filterspan_test.go @@ -146,7 +146,6 @@ func TestSpan_Matching_False(t *testing.T) { } span := pdata.NewSpan() - span.InitEmpty() span.SetName("spanName") library := pdata.NewInstrumentationLibrary() resource := pdata.NewResource() @@ -173,7 +172,6 @@ func TestSpan_MissingServiceName(t *testing.T) { assert.NotNil(t, mp) emptySpan := pdata.NewSpan() - emptySpan.InitEmpty() assert.False(t, mp.MatchSpan(emptySpan, pdata.NewResource(), pdata.NewInstrumentationLibrary())) } @@ -222,7 +220,6 @@ func TestSpan_Matching_True(t *testing.T) { } span := pdata.NewSpan() - span.InitEmpty() span.SetName("spanName") span.Attributes().InitFromMap(map[string]pdata.AttributeValue{ "keyString": pdata.NewAttributeValueString("arithmetic"), diff --git a/internal/testdata/log.go b/internal/testdata/log.go index 4c437724448..232ef728ee4 100644 --- a/internal/testdata/log.go +++ b/internal/testdata/log.go @@ -17,13 +17,10 @@ package testdata import ( "time" - "go.opentelemetry.io/collector/internal/data" - otlplogs "go.opentelemetry.io/collector/internal/data/opentelemetry-proto-gen/logs/v1" - otlpresource "go.opentelemetry.io/collector/internal/data/opentelemetry-proto-gen/resource/v1" - "go.opentelemetry.io/collector/consumer/pdata" - "go.opentelemetry.io/collector/internal" + "go.opentelemetry.io/collector/internal/data" otlpcommon "go.opentelemetry.io/collector/internal/data/opentelemetry-proto-gen/common/v1" + otlplogs "go.opentelemetry.io/collector/internal/data/opentelemetry-proto-gen/logs/v1" ) var ( @@ -31,10 +28,6 @@ var ( TestLogTimestamp = pdata.TimestampUnixNano(TestLogTime.UnixNano()) ) -const ( - NumLogTests = 11 -) - func GenerateLogDataEmpty() pdata.Logs { ld := pdata.NewLogs() return ld @@ -56,30 +49,6 @@ func generateLogOtlpOneEmptyResourceLogs() []*otlplogs.ResourceLogs { } } -func GenerateLogDataOneEmptyOneNilResourceLogs() pdata.Logs { - return pdata.LogsFromInternalRep(internal.LogsFromOtlp(generateLogOtlpOneEmptyOneNilResourceLogs())) - -} - -func generateLogOtlpOneEmptyOneNilResourceLogs() []*otlplogs.ResourceLogs { - return []*otlplogs.ResourceLogs{ - {}, - nil, - } -} - -func GenerateLogDataOneEmptyOneNilInstrumentationLibrary() pdata.Logs { - return pdata.LogsFromInternalRep(internal.LogsFromOtlp(generateLogOtlpOneEmptyOneNilInstrumentationLibrary())) - -} - -func generateLogOtlpOneEmptyOneNilInstrumentationLibrary() []*otlplogs.ResourceLogs { - return []*otlplogs.ResourceLogs{ - {}, - {otlpresource.Resource{}, []*otlplogs.InstrumentationLibraryLogs{nil}}, - } -} - func GenerateLogDataNoLogRecords() pdata.Logs { ld := GenerateLogDataOneEmptyResourceLogs() rs0 := ld.ResourceLogs().At(0) @@ -118,26 +87,6 @@ func generateLogOtlpOneEmptyLogs() []*otlplogs.ResourceLogs { } } -func GenerateLogDataOneEmptyOneNilLogRecord() pdata.Logs { - return pdata.LogsFromInternalRep(internal.LogsFromOtlp(generateLogOtlpOneEmptyOneNilLogRecord())) -} - -func generateLogOtlpOneEmptyOneNilLogRecord() []*otlplogs.ResourceLogs { - return []*otlplogs.ResourceLogs{ - { - Resource: generateOtlpResource1(), - InstrumentationLibraryLogs: []*otlplogs.InstrumentationLibraryLogs{ - { - Logs: []*otlplogs.LogRecord{ - {}, - nil, - }, - }, - }, - }, - } -} - func GenerateLogDataOneLogNoResource() pdata.Logs { ld := GenerateLogDataOneEmptyResourceLogs() rs0 := ld.ResourceLogs().At(0) @@ -187,26 +136,6 @@ func generateLogOtlpOneLog() []*otlplogs.ResourceLogs { } } -func GenerateLogDataOneLogOneNil() pdata.Logs { - return pdata.LogsFromInternalRep(internal.LogsFromOtlp(generateLogOtlpOneLogOneNil())) -} - -func generateLogOtlpOneLogOneNil() []*otlplogs.ResourceLogs { - return []*otlplogs.ResourceLogs{ - { - Resource: generateOtlpResource1(), - InstrumentationLibraryLogs: []*otlplogs.InstrumentationLibraryLogs{ - { - Logs: []*otlplogs.LogRecord{ - generateOtlpLogOne(), - nil, - }, - }, - }, - }, - } -} - func GenerateLogDataTwoLogsSameResource() pdata.Logs { ld := GenerateLogDataOneEmptyLogs() rs0 := ld.ResourceLogs().At(0) diff --git a/internal/testdata/log_test.go b/internal/testdata/log_test.go index 5b2e0db3bcb..2ceb87ede33 100644 --- a/internal/testdata/log_test.go +++ b/internal/testdata/log_test.go @@ -42,11 +42,6 @@ func generateAllLogTestCases() []logTestCase { ld: GenerateLogDataOneEmptyResourceLogs(), otlp: generateLogOtlpOneEmptyResourceLogs(), }, - { - name: "one-empty-one-nil-resource-logs", - ld: GenerateLogDataOneEmptyOneNilResourceLogs(), - otlp: generateLogOtlpOneEmptyOneNilResourceLogs(), - }, { name: "no-log-records", ld: GenerateLogDataNoLogRecords(), @@ -57,11 +52,6 @@ func generateAllLogTestCases() []logTestCase { ld: GenerateLogDataOneEmptyLogs(), otlp: generateLogOtlpOneEmptyLogs(), }, - { - name: "one-empty-one-nil-log-record", - ld: GenerateLogDataOneEmptyOneNilLogRecord(), - otlp: generateLogOtlpOneEmptyOneNilLogRecord(), - }, { name: "one-log-record-no-resource", ld: GenerateLogDataOneLogNoResource(), @@ -72,11 +62,6 @@ func generateAllLogTestCases() []logTestCase { ld: GenerateLogDataOneLog(), otlp: generateLogOtlpOneLog(), }, - { - name: "one-log-record-one-nil", - ld: GenerateLogDataOneLogOneNil(), - otlp: generateLogOtlpOneLogOneNil(), - }, { name: "two-records-same-resource", ld: GenerateLogDataTwoLogsSameResource(), @@ -93,7 +78,6 @@ func generateAllLogTestCases() []logTestCase { func TestToFromOtlpLog(t *testing.T) { allTestCases := generateAllLogTestCases() // Ensure NumLogTests gets updated. - assert.EqualValues(t, NumLogTests, len(allTestCases)) for i := range allTestCases { test := allTestCases[i] t.Run(test.name, func(t *testing.T) { @@ -104,22 +88,3 @@ func TestToFromOtlpLog(t *testing.T) { }) } } - -func TestToFromOtlpLogWithNils(t *testing.T) { - md := GenerateLogDataOneEmptyOneNilResourceLogs() - assert.EqualValues(t, 2, md.ResourceLogs().Len()) - assert.False(t, md.ResourceLogs().At(0).IsNil()) - assert.True(t, md.ResourceLogs().At(1).IsNil()) - - md = GenerateLogDataOneEmptyOneNilLogRecord() - rs := md.ResourceLogs().At(0) - assert.EqualValues(t, 2, rs.InstrumentationLibraryLogs().At(0).Logs().Len()) - assert.False(t, rs.InstrumentationLibraryLogs().At(0).Logs().At(0).IsNil()) - assert.True(t, rs.InstrumentationLibraryLogs().At(0).Logs().At(1).IsNil()) - - md = GenerateLogDataOneLogOneNil() - rl0 := md.ResourceLogs().At(0) - assert.EqualValues(t, 2, rl0.InstrumentationLibraryLogs().At(0).Logs().Len()) - assert.False(t, rl0.InstrumentationLibraryLogs().At(0).Logs().At(0).IsNil()) - assert.True(t, rl0.InstrumentationLibraryLogs().At(0).Logs().At(1).IsNil()) -} diff --git a/internal/testdata/metric.go b/internal/testdata/metric.go index 1e2a4654497..0047be01bf9 100644 --- a/internal/testdata/metric.go +++ b/internal/testdata/metric.go @@ -40,7 +40,6 @@ const ( TestDoubleHistogramMetricName = "double-histogram" TestIntHistogramMetricName = "int-histogram" TestDoubleSummaryMetricName = "double-summary" - NumMetricTests = 14 ) func GenerateMetricsEmpty() pdata.Metrics { @@ -64,17 +63,6 @@ func generateMetricsOtlpOneEmptyResourceMetrics() []*otlpmetrics.ResourceMetrics } } -func GenerateMetricsOneEmptyOneNilResourceMetrics() pdata.Metrics { - return pdata.MetricsFromOtlp(generateMetricsOtlpOneEmptyOneNilResourceMetrics()) -} - -func generateMetricsOtlpOneEmptyOneNilResourceMetrics() []*otlpmetrics.ResourceMetrics { - return []*otlpmetrics.ResourceMetrics{ - {}, - nil, - } -} - func GenerateMetricsNoLibraries() pdata.Metrics { md := GenerateMetricsOneEmptyResourceMetrics() ms0 := md.ResourceMetrics().At(0) @@ -108,22 +96,6 @@ func generateMetricsOtlpOneEmptyInstrumentationLibrary() []*otlpmetrics.Resource } } -func GenerateMetricsOneEmptyOneNilInstrumentationLibrary() pdata.Metrics { - return pdata.MetricsFromOtlp(generateMetricsOtlpOneEmptyOneNilInstrumentationLibrary()) -} - -func generateMetricsOtlpOneEmptyOneNilInstrumentationLibrary() []*otlpmetrics.ResourceMetrics { - return []*otlpmetrics.ResourceMetrics{ - { - Resource: generateOtlpResource1(), - InstrumentationLibraryMetrics: []*otlpmetrics.InstrumentationLibraryMetrics{ - {}, - nil, - }, - }, - } -} - func GenerateMetricsOneMetricNoResource() pdata.Metrics { md := GenerateMetricsOneEmptyResourceMetrics() rm0 := md.ResourceMetrics().At(0) @@ -213,26 +185,6 @@ func GenerateMetricsOtlpTwoMetrics() []*otlpmetrics.ResourceMetrics { } } -func GenerateMetricsOneMetricOneNil() pdata.Metrics { - return pdata.MetricsFromOtlp(generateMetricsOtlpOneMetricOneNil()) -} - -func generateMetricsOtlpOneMetricOneNil() []*otlpmetrics.ResourceMetrics { - return []*otlpmetrics.ResourceMetrics{ - { - Resource: generateOtlpResource1(), - InstrumentationLibraryMetrics: []*otlpmetrics.InstrumentationLibraryMetrics{ - { - Metrics: []*otlpmetrics.Metric{ - generateOtlpCounterIntMetric(), - nil, - }, - }, - }, - }, - } -} - func GenerateMetricsOneMetricNoLabels() pdata.Metrics { md := GenerateMetricsOneMetric() dps := md.ResourceMetrics().At(0).InstrumentationLibraryMetrics().At(0).Metrics().At(0).IntSum().DataPoints() @@ -249,17 +201,6 @@ func generateMetricsOtlpOneMetricNoLabels() []*otlpmetrics.ResourceMetrics { return md } -func GenerateMetricsOneMetricOneNilPoint() pdata.Metrics { - return pdata.MetricsFromOtlp(generateMetricsOtlpOneMetricOneNilPoint()) -} - -func generateMetricsOtlpOneMetricOneNilPoint() []*otlpmetrics.ResourceMetrics { - md := generateMetricsOtlpOneMetric() - mis := md[0].InstrumentationLibraryMetrics[0].Metrics[0].Data.(*otlpmetrics.Metric_IntSum).IntSum - mis.DataPoints = append(mis.DataPoints, nil) - return md -} - func GenerateMetricsAllTypesNoDataPoints() pdata.Metrics { md := GenerateMetricsOneEmptyInstrumentationLibrary() ilm0 := md.ResourceMetrics().At(0).InstrumentationLibraryMetrics().At(0) @@ -650,7 +591,6 @@ func generateOTLPDoubleSummaryMetric() *otlpmetrics.Metric { } func initMetric(m pdata.Metric, name string, ty pdata.MetricDataType) { - m.InitEmpty() m.SetName(name) m.SetDescription("") m.SetUnit("1") diff --git a/internal/testdata/metric_test.go b/internal/testdata/metric_test.go index 0d6e7614eb4..b686cb9f98e 100644 --- a/internal/testdata/metric_test.go +++ b/internal/testdata/metric_test.go @@ -41,11 +41,6 @@ func generateAllMetricsTestCases() []traceMetricsCase { td: GenerateMetricsOneEmptyResourceMetrics(), otlp: generateMetricsOtlpOneEmptyResourceMetrics(), }, - { - name: "one-empty-one-nil-resource-metrics", - td: GenerateMetricsOneEmptyOneNilResourceMetrics(), - otlp: generateMetricsOtlpOneEmptyOneNilResourceMetrics(), - }, { name: "no-libraries", td: GenerateMetricsNoLibraries(), @@ -56,11 +51,6 @@ func generateAllMetricsTestCases() []traceMetricsCase { td: GenerateMetricsOneEmptyInstrumentationLibrary(), otlp: generateMetricsOtlpOneEmptyInstrumentationLibrary(), }, - { - name: "one-empty-one-nil-instrumentation-library", - td: GenerateMetricsOneEmptyOneNilInstrumentationLibrary(), - otlp: generateMetricsOtlpOneEmptyOneNilInstrumentationLibrary(), - }, { name: "one-metric-no-resource", td: GenerateMetricsOneMetricNoResource(), @@ -76,21 +66,11 @@ func generateAllMetricsTestCases() []traceMetricsCase { td: GenerateMetricsTwoMetrics(), otlp: GenerateMetricsOtlpTwoMetrics(), }, - { - name: "one-metric-one-nil", - td: GenerateMetricsOneMetricOneNil(), - otlp: generateMetricsOtlpOneMetricOneNil(), - }, { name: "one-metric-no-labels", td: GenerateMetricsOneMetricNoLabels(), otlp: generateMetricsOtlpOneMetricNoLabels(), }, - { - name: "one-metric-one-nil-point", - td: GenerateMetricsOneMetricOneNilPoint(), - otlp: generateMetricsOtlpOneMetricOneNilPoint(), - }, { name: "all-types-no-data-points", td: GenerateMetricsAllTypesNoDataPoints(), @@ -107,7 +87,6 @@ func generateAllMetricsTestCases() []traceMetricsCase { func TestToFromOtlpMetrics(t *testing.T) { allTestCases := generateAllMetricsTestCases() // Ensure NumMetricTests gets updated. - assert.EqualValues(t, NumMetricTests, len(allTestCases)) for i := range allTestCases { test := allTestCases[i] t.Run(test.name, func(t *testing.T) { @@ -119,25 +98,6 @@ func TestToFromOtlpMetrics(t *testing.T) { } } -func TestToFromOtlpMetricsWithNils(t *testing.T) { - md := GenerateMetricsOneEmptyOneNilResourceMetrics() - assert.EqualValues(t, 2, md.ResourceMetrics().Len()) - assert.False(t, md.ResourceMetrics().At(0).IsNil()) - assert.True(t, md.ResourceMetrics().At(1).IsNil()) - - md = GenerateMetricsOneEmptyOneNilInstrumentationLibrary() - rs := md.ResourceMetrics().At(0) - assert.EqualValues(t, 2, rs.InstrumentationLibraryMetrics().Len()) - assert.False(t, rs.InstrumentationLibraryMetrics().At(0).IsNil()) - assert.True(t, rs.InstrumentationLibraryMetrics().At(1).IsNil()) - - md = GenerateMetricsOneMetricOneNil() - ilss := md.ResourceMetrics().At(0).InstrumentationLibraryMetrics().At(0) - assert.EqualValues(t, 2, ilss.Metrics().Len()) - assert.False(t, ilss.Metrics().At(0).IsNil()) - assert.True(t, ilss.Metrics().At(1).IsNil()) -} - func TestGenerateMetricsManyMetricsSameResource(t *testing.T) { md := GenerateMetricsManyMetricsSameResource(100) assert.EqualValues(t, 1, md.ResourceMetrics().Len()) diff --git a/internal/testdata/trace.go b/internal/testdata/trace.go index b8be8f90412..efd74cf374a 100644 --- a/internal/testdata/trace.go +++ b/internal/testdata/trace.go @@ -33,10 +33,6 @@ var ( TestSpanEndTimestamp = pdata.TimestampUnixNano(TestSpanEndTime.UnixNano()) ) -const ( - NumTraceTests = 11 -) - func GenerateTraceDataEmpty() pdata.Traces { td := pdata.NewTraces() return td @@ -58,18 +54,6 @@ func generateTraceOtlpOneEmptyResourceSpans() []*otlptrace.ResourceSpans { } } -func GenerateTraceDataOneEmptyOneNilResourceSpans() pdata.Traces { - return pdata.TracesFromOtlp(generateTraceOtlpOneEmptyOneNilResourceSpans()) - -} - -func generateTraceOtlpOneEmptyOneNilResourceSpans() []*otlptrace.ResourceSpans { - return []*otlptrace.ResourceSpans{ - {}, - nil, - } -} - func GenerateTraceDataNoLibraries() pdata.Traces { td := GenerateTraceDataOneEmptyResourceSpans() rs0 := td.ResourceSpans().At(0) @@ -103,22 +87,6 @@ func generateTraceOtlpOneEmptyInstrumentationLibrary() []*otlptrace.ResourceSpan } } -func GenerateTraceDataOneEmptyOneNilInstrumentationLibrary() pdata.Traces { - return pdata.TracesFromOtlp(generateTraceOtlpOneEmptyOneNilInstrumentationLibrary()) -} - -func generateTraceOtlpOneEmptyOneNilInstrumentationLibrary() []*otlptrace.ResourceSpans { - return []*otlptrace.ResourceSpans{ - { - Resource: generateOtlpResource1(), - InstrumentationLibrarySpans: []*otlptrace.InstrumentationLibrarySpans{ - {}, - nil, - }, - }, - } -} - func GenerateTraceDataOneSpanNoResource() pdata.Traces { td := GenerateTraceDataOneEmptyResourceSpans() rs0 := td.ResourceSpans().At(0) @@ -166,26 +134,6 @@ func generateTraceOtlpOneSpan() []*otlptrace.ResourceSpans { } } -func GenerateTraceDataOneSpanOneNil() pdata.Traces { - return pdata.TracesFromOtlp(generateTraceOtlpOneSpanOneNil()) -} - -func generateTraceOtlpOneSpanOneNil() []*otlptrace.ResourceSpans { - return []*otlptrace.ResourceSpans{ - { - Resource: generateOtlpResource1(), - InstrumentationLibrarySpans: []*otlptrace.InstrumentationLibrarySpans{ - { - Spans: []*otlptrace.Span{ - generateOtlpSpanOne(), - nil, - }, - }, - }, - }, - } -} - func GenerateTraceDataTwoSpansSameResource() pdata.Traces { td := GenerateTraceDataOneEmptyInstrumentationLibrary() rs0ils0 := td.ResourceSpans().At(0).InstrumentationLibrarySpans().At(0) diff --git a/internal/testdata/trace_test.go b/internal/testdata/trace_test.go index 3c45681699e..aebddf6d0dd 100644 --- a/internal/testdata/trace_test.go +++ b/internal/testdata/trace_test.go @@ -42,11 +42,6 @@ func generateAllTraceTestCases() []traceTestCase { td: GenerateTraceDataOneEmptyResourceSpans(), otlp: generateTraceOtlpOneEmptyResourceSpans(), }, - { - name: "one-empty-one-nil-resource-spans", - td: GenerateTraceDataOneEmptyOneNilResourceSpans(), - otlp: generateTraceOtlpOneEmptyOneNilResourceSpans(), - }, { name: "no-libraries", td: GenerateTraceDataNoLibraries(), @@ -57,11 +52,6 @@ func generateAllTraceTestCases() []traceTestCase { td: GenerateTraceDataOneEmptyInstrumentationLibrary(), otlp: generateTraceOtlpOneEmptyInstrumentationLibrary(), }, - { - name: "one-empty-one-nil-instrumentation-library", - td: GenerateTraceDataOneEmptyOneNilInstrumentationLibrary(), - otlp: generateTraceOtlpOneEmptyOneNilInstrumentationLibrary(), - }, { name: "one-span-no-resource", td: GenerateTraceDataOneSpanNoResource(), @@ -72,11 +62,6 @@ func generateAllTraceTestCases() []traceTestCase { td: GenerateTraceDataOneSpan(), otlp: generateTraceOtlpOneSpan(), }, - { - name: "one-span-one-nil", - td: GenerateTraceDataOneSpanOneNil(), - otlp: generateTraceOtlpOneSpanOneNil(), - }, { name: "two-spans-same-resource", td: GenerateTraceDataTwoSpansSameResource(), @@ -93,7 +78,6 @@ func generateAllTraceTestCases() []traceTestCase { func TestToFromOtlpTrace(t *testing.T) { allTestCases := generateAllTraceTestCases() // Ensure NumTraceTests gets updated. - assert.EqualValues(t, NumTraceTests, len(allTestCases)) for i := range allTestCases { test := allTestCases[i] t.Run(test.name, func(t *testing.T) { @@ -104,22 +88,3 @@ func TestToFromOtlpTrace(t *testing.T) { }) } } - -func TestToFromOtlpTraceWithNils(t *testing.T) { - md := GenerateTraceDataOneEmptyOneNilResourceSpans() - assert.EqualValues(t, 2, md.ResourceSpans().Len()) - assert.False(t, md.ResourceSpans().At(0).IsNil()) - assert.True(t, md.ResourceSpans().At(1).IsNil()) - - md = GenerateTraceDataOneEmptyOneNilInstrumentationLibrary() - rs := md.ResourceSpans().At(0) - assert.EqualValues(t, 2, rs.InstrumentationLibrarySpans().Len()) - assert.False(t, rs.InstrumentationLibrarySpans().At(0).IsNil()) - assert.True(t, rs.InstrumentationLibrarySpans().At(1).IsNil()) - - md = GenerateTraceDataOneSpanOneNil() - ilss := md.ResourceSpans().At(0).InstrumentationLibrarySpans().At(0) - assert.EqualValues(t, 2, ilss.Spans().Len()) - assert.False(t, ilss.Spans().At(0).IsNil()) - assert.True(t, ilss.Spans().At(1).IsNil()) -} diff --git a/processor/attributesprocessor/attributes_log.go b/processor/attributesprocessor/attributes_log.go index f6b964969a8..83b5174ab0d 100644 --- a/processor/attributesprocessor/attributes_log.go +++ b/processor/attributesprocessor/attributes_log.go @@ -44,25 +44,14 @@ func (a *logAttributesProcessor) ProcessLogs(_ context.Context, ld pdata.Logs) ( rls := ld.ResourceLogs() for i := 0; i < rls.Len(); i++ { rs := rls.At(i) - if rs.IsNil() { - continue - } ilss := rs.InstrumentationLibraryLogs() resource := rs.Resource() for j := 0; j < ilss.Len(); j++ { ils := ilss.At(j) - if ils.IsNil() { - continue - } logs := ils.Logs() library := ils.InstrumentationLibrary() for k := 0; k < logs.Len(); k++ { lr := logs.At(k) - if lr.IsNil() { - // Do not create empty log records just to add attributes - continue - } - if a.skipLog(lr, resource, library) { continue } diff --git a/processor/attributesprocessor/attributes_log_test.go b/processor/attributesprocessor/attributes_log_test.go index f941a3fa695..2bf0afe50a7 100644 --- a/processor/attributesprocessor/attributes_log_test.go +++ b/processor/attributesprocessor/attributes_log_test.go @@ -66,22 +66,13 @@ func sortLogAttributes(ld pdata.Logs) { rss := ld.ResourceLogs() for i := 0; i < rss.Len(); i++ { rs := rss.At(i) - if rs.IsNil() { - continue - } rs.Resource().Attributes().Sort() - ilss := rss.At(i).InstrumentationLibraryLogs() + ilss := rs.InstrumentationLibraryLogs() for j := 0; j < ilss.Len(); j++ { - ils := ilss.At(j) - if ils.IsNil() { - continue - } - logs := ils.Logs() + logs := ilss.At(j).Logs() for k := 0; k < logs.Len(); k++ { s := logs.At(k) - if !s.IsNil() { - s.Attributes().Sort() - } + s.Attributes().Sort() } } } @@ -105,25 +96,6 @@ func TestLogProcessor_NilEmptyData(t *testing.T) { input: testdata.GenerateLogDataOneEmptyResourceLogs(), output: testdata.GenerateLogDataOneEmptyResourceLogs(), }, - { - name: "one-empty-one-nil-resource-logs", - input: testdata.GenerateLogDataOneEmptyOneNilResourceLogs(), - output: testdata.GenerateLogDataOneEmptyOneNilResourceLogs(), - }, - { - name: "one-empty-one-nil-instrumentation-library", - input: testdata.GenerateLogDataOneEmptyOneNilInstrumentationLibrary(), - output: testdata.GenerateLogDataOneEmptyOneNilInstrumentationLibrary(), - }, - { - name: "one-empty-one-nil-log-record", - input: testdata.GenerateLogDataOneEmptyOneNilLogRecord(), - output: func() pdata.Logs { - lr := testdata.GenerateLogDataOneEmptyOneNilLogRecord() - lr.ResourceLogs().At(0).InstrumentationLibraryLogs().At(0).Logs().At(0).Attributes().InitEmptyWithCapacity(1) - return lr - }(), - }, { name: "no-libraries", input: testdata.GenerateLogDataOneEmptyResourceLogs(), diff --git a/processor/attributesprocessor/attributes_trace.go b/processor/attributesprocessor/attributes_trace.go index 63e83c711cc..0e708fe55be 100644 --- a/processor/attributesprocessor/attributes_trace.go +++ b/processor/attributesprocessor/attributes_trace.go @@ -44,25 +44,14 @@ func (a *spanAttributesProcessor) ProcessTraces(_ context.Context, td pdata.Trac rss := td.ResourceSpans() for i := 0; i < rss.Len(); i++ { rs := rss.At(i) - if rs.IsNil() { - continue - } resource := rs.Resource() ilss := rs.InstrumentationLibrarySpans() for j := 0; j < ilss.Len(); j++ { ils := ilss.At(j) - if ils.IsNil() { - continue - } spans := ils.Spans() library := ils.InstrumentationLibrary() for k := 0; k < spans.Len(); k++ { span := spans.At(k) - if span.IsNil() { - // Do not create empty spans just to add attributes - continue - } - if filterspan.SkipSpan(a.include, a.exclude, span, resource, library) { continue } diff --git a/processor/attributesprocessor/attributes_trace_test.go b/processor/attributesprocessor/attributes_trace_test.go index 302ed3a61b4..a6eaf7f7506 100644 --- a/processor/attributesprocessor/attributes_trace_test.go +++ b/processor/attributesprocessor/attributes_trace_test.go @@ -71,22 +71,12 @@ func sortAttributes(td pdata.Traces) { rss := td.ResourceSpans() for i := 0; i < rss.Len(); i++ { rs := rss.At(i) - if rs.IsNil() { - continue - } rs.Resource().Attributes().Sort() - ilss := rss.At(i).InstrumentationLibrarySpans() + ilss := rs.InstrumentationLibrarySpans() for j := 0; j < ilss.Len(); j++ { - ils := ilss.At(j) - if ils.IsNil() { - continue - } - spans := ils.Spans() + spans := ilss.At(j).Spans() for k := 0; k < spans.Len(); k++ { - s := spans.At(k) - if !s.IsNil() { - s.Attributes().Sort() - } + spans.At(k).Attributes().Sort() } } } @@ -111,11 +101,6 @@ func TestSpanProcessor_NilEmptyData(t *testing.T) { input: testdata.GenerateTraceDataOneEmptyResourceSpans(), output: testdata.GenerateTraceDataOneEmptyResourceSpans(), }, - { - name: "one-empty-one-nil-resource-spans", - input: testdata.GenerateTraceDataOneEmptyOneNilResourceSpans(), - output: testdata.GenerateTraceDataOneEmptyOneNilResourceSpans(), - }, { name: "no-libraries", input: testdata.GenerateTraceDataNoLibraries(), @@ -126,11 +111,6 @@ func TestSpanProcessor_NilEmptyData(t *testing.T) { input: testdata.GenerateTraceDataOneEmptyInstrumentationLibrary(), output: testdata.GenerateTraceDataOneEmptyInstrumentationLibrary(), }, - { - name: "one-empty-one-nil-instrumentation-library", - input: testdata.GenerateTraceDataOneEmptyOneNilInstrumentationLibrary(), - output: testdata.GenerateTraceDataOneEmptyOneNilInstrumentationLibrary(), - }, } factory := NewFactory() cfg := factory.CreateDefaultConfig() diff --git a/processor/batchprocessor/batch_processor_test.go b/processor/batchprocessor/batch_processor_test.go index 58a6bc7440a..b21bbe3dff8 100644 --- a/processor/batchprocessor/batch_processor_test.go +++ b/processor/batchprocessor/batch_processor_test.go @@ -438,19 +438,9 @@ func spansReceivedByName(tds []pdata.Traces) map[string]pdata.Span { for i := range tds { rss := tds[i].ResourceSpans() for i := 0; i < rss.Len(); i++ { - rs := rss.At(i) - if rs.IsNil() { - continue - } - - ilss := rs.InstrumentationLibrarySpans() + ilss := rss.At(i).InstrumentationLibrarySpans() for j := 0; j < ilss.Len(); j++ { - ils := ilss.At(j) - if ils.IsNil() { - continue - } - - spans := ils.Spans() + spans := ilss.At(j).Spans() for k := 0; k < spans.Len(); k++ { span := spans.At(k) spansReceivedByName[spans.At(k).Name()] = span @@ -466,17 +456,9 @@ func metricsReceivedByName(mds []pdata.Metrics) map[string]pdata.Metric { for _, md := range mds { rms := md.ResourceMetrics() for i := 0; i < rms.Len(); i++ { - rm := rms.At(i) - if rm.IsNil() { - continue - } - ilms := rm.InstrumentationLibraryMetrics() + ilms := rms.At(i).InstrumentationLibraryMetrics() for j := 0; j < ilms.Len(); j++ { - ilm := ilms.At(j) - if ilm.IsNil() { - continue - } - metrics := ilm.Metrics() + metrics := ilms.At(j).Metrics() for k := 0; k < metrics.Len(); k++ { metric := metrics.At(k) metricsReceivedByName[metric.Name()] = metric @@ -695,17 +677,9 @@ func logsReceivedByName(lds []pdata.Logs) map[string]pdata.LogRecord { ld := lds[i] rms := ld.ResourceLogs() for i := 0; i < rms.Len(); i++ { - rm := rms.At(i) - if rm.IsNil() { - continue - } - ilms := rm.InstrumentationLibraryLogs() + ilms := rms.At(i).InstrumentationLibraryLogs() for j := 0; j < ilms.Len(); j++ { - ilm := ilms.At(j) - if ilm.IsNil() { - continue - } - logs := ilm.Logs() + logs := ilms.At(j).Logs() for k := 0; k < logs.Len(); k++ { log := logs.At(k) logsReceivedByName[log.Name()] = log diff --git a/processor/batchprocessor/splittraces.go b/processor/batchprocessor/splittraces.go index 0bd30f7936e..34c0c179f0d 100644 --- a/processor/batchprocessor/splittraces.go +++ b/processor/batchprocessor/splittraces.go @@ -29,14 +29,12 @@ func splitTrace(size int, toSplit pdata.Traces) pdata.Traces { for i := rss.Len() - 1; i >= 0; i-- { rs := rss.At(i) destRs := pdata.NewResourceSpans() - destRs.InitEmpty() rs.Resource().CopyTo(destRs.Resource()) result.ResourceSpans().Append(destRs) for j := rs.InstrumentationLibrarySpans().Len() - 1; j >= 0; j-- { instSpans := rs.InstrumentationLibrarySpans().At(j) destInstSpans := pdata.NewInstrumentationLibrarySpans() - destInstSpans.InitEmpty() destRs.InstrumentationLibrarySpans().Append(destInstSpans) instSpans.InstrumentationLibrary().CopyTo(destInstSpans.InstrumentationLibrary()) diff --git a/processor/filterprocessor/filter_processor.go b/processor/filterprocessor/filter_processor.go index 774f6ad2ef9..fe544165393 100644 --- a/processor/filterprocessor/filter_processor.go +++ b/processor/filterprocessor/filter_processor.go @@ -91,23 +91,11 @@ func (fmp *filterMetricProcessor) ProcessMetrics(_ context.Context, pdm pdata.Me rms := pdm.ResourceMetrics() idx := newMetricIndex() for i := 0; i < rms.Len(); i++ { - rm := rms.At(i) - if rm.IsNil() { - continue - } - ilms := rm.InstrumentationLibraryMetrics() + ilms := rms.At(i).InstrumentationLibraryMetrics() for j := 0; j < ilms.Len(); j++ { - ilm := ilms.At(j) - if ilm.IsNil() { - continue - } - ms := ilm.Metrics() + ms := ilms.At(j).Metrics() for k := 0; k < ms.Len(); k++ { - metric := ms.At(k) - if metric.IsNil() { - continue - } - keep, err := fmp.shouldKeepMetric(metric) + keep, err := fmp.shouldKeepMetric(ms.At(k)) if err != nil { fmp.logger.Error("shouldKeepMetric failed", zap.Error(err)) // don't `continue`, keep the metric if there's an error diff --git a/processor/filterprocessor/filter_processor_test.go b/processor/filterprocessor/filter_processor_test.go index b01b17e75de..a922a18b838 100644 --- a/processor/filterprocessor/filter_processor_test.go +++ b/processor/filterprocessor/filter_processor_test.go @@ -369,7 +369,6 @@ func TestNilILM(t *testing.T) { metrics := pdata.NewMetrics() rms := metrics.ResourceMetrics() rm := pdata.NewResourceMetrics() - rm.InitEmpty() rms.Append(rm) ilms := rm.InstrumentationLibraryMetrics() ilms.Append(pdata.NewInstrumentationLibraryMetrics()) @@ -380,12 +379,10 @@ func TestNilMetric(t *testing.T) { metrics := pdata.NewMetrics() rms := metrics.ResourceMetrics() rm := pdata.NewResourceMetrics() - rm.InitEmpty() rms.Append(rm) ilms := rm.InstrumentationLibraryMetrics() ilm := pdata.NewInstrumentationLibraryMetrics() ilms.Append(ilm) - ilm.InitEmpty() ms := ilm.Metrics() ms.Append(pdata.NewMetric()) requireNotPanics(t, metrics) diff --git a/processor/filterprocessor/metric_index.go b/processor/filterprocessor/metric_index.go index ca55b83a2ca..8c92599a925 100644 --- a/processor/filterprocessor/metric_index.go +++ b/processor/filterprocessor/metric_index.go @@ -58,7 +58,6 @@ func (idx metricIndex) extract(pdm pdata.Metrics) pdata.Metrics { ilmSliceIn := rmIn.InstrumentationLibraryMetrics() rmOut := pdata.NewResourceMetrics() - rmOut.InitEmpty() rmSliceOut.Append(rmOut) resourceOut := rmOut.Resource() rmIn.Resource().CopyTo(resourceOut) @@ -69,7 +68,6 @@ func (idx metricIndex) extract(pdm pdata.Metrics) pdata.Metrics { mSliceIn := ilmIn.Metrics() ilmOut := pdata.NewInstrumentationLibraryMetrics() - ilmOut.InitEmpty() ilmSliceOut.Append(ilmOut) ilOut := ilmOut.InstrumentationLibrary() ilmIn.InstrumentationLibrary().CopyTo(ilOut) diff --git a/processor/metrics.go b/processor/metrics.go index 81dc54cf00d..faf78477544 100644 --- a/processor/metrics.go +++ b/processor/metrics.go @@ -146,20 +146,12 @@ func spanCountByResourceStringAttribute(td pdata.Traces, attrKey string) map[str rss := td.ResourceSpans() for i := 0; i < rss.Len(); i++ { rs := rss.At(i) - if rs.IsNil() { - continue - } - var attrStringVal string if attrVal, ok := rs.Resource().Attributes().Get(attrKey); ok { attrStringVal = attrVal.StringVal() } ilss := rs.InstrumentationLibrarySpans() for j := 0; j < ilss.Len(); j++ { - ils := ilss.At(j) - if ils.IsNil() { - continue - } spanCounts[attrStringVal] += ilss.At(j).Spans().Len() } } diff --git a/processor/samplingprocessor/probabilisticsamplerprocessor/probabilisticsampler.go b/processor/samplingprocessor/probabilisticsamplerprocessor/probabilisticsampler.go index 9dd551b85b7..2f97912fe77 100644 --- a/processor/samplingprocessor/probabilisticsamplerprocessor/probabilisticsampler.go +++ b/processor/samplingprocessor/probabilisticsamplerprocessor/probabilisticsampler.go @@ -73,11 +73,7 @@ func (tsp *tracesamplerprocessor) ConsumeTraces(ctx context.Context, td pdata.Tr rspans := td.ResourceSpans() sampledTraceData := pdata.NewTraces() for i := 0; i < rspans.Len(); i++ { - rspan := rspans.At(i) - if rspan.IsNil() { - continue - } - tsp.processTraces(rspan, sampledTraceData) + tsp.processTraces(rspans.At(i), sampledTraceData) } return tsp.nextConsumer.ConsumeTraces(ctx, sampledTraceData) } @@ -94,9 +90,6 @@ func (tsp *tracesamplerprocessor) processTraces(resourceSpans pdata.ResourceSpan ilss := resourceSpans.InstrumentationLibrarySpans() for j := 0; j < ilss.Len(); j++ { ils := ilss.At(j) - if ils.IsNil() { - continue - } for k := 0; k < ils.Spans().Len(); k++ { span := ils.Spans().At(k) sp := parseSpanSamplingPriority(span) @@ -140,9 +133,6 @@ func (tsp *tracesamplerprocessor) Shutdown(context.Context) error { // OpenTracing semantic tags: // https://github.com/opentracing/specification/blob/master/semantic_conventions.md#span-tags-table func parseSpanSamplingPriority(span pdata.Span) samplingPriority { - if span.IsNil() { - return deferDecision - } attribMap := span.Attributes() if attribMap.Len() <= 0 { return deferDecision diff --git a/processor/samplingprocessor/probabilisticsamplerprocessor/probabilisticsampler_test.go b/processor/samplingprocessor/probabilisticsamplerprocessor/probabilisticsampler_test.go index a898f1c5566..e84ac94249d 100644 --- a/processor/samplingprocessor/probabilisticsamplerprocessor/probabilisticsampler_test.go +++ b/processor/samplingprocessor/probabilisticsamplerprocessor/probabilisticsampler_test.go @@ -418,7 +418,6 @@ func Test_parseSpanSamplingPriority(t *testing.T) { func getSpanWithAttributes(key string, value pdata.AttributeValue) pdata.Span { span := pdata.NewSpan() - span.InitEmpty() span.SetName("spanName") span.Attributes().InitFromMap(map[string]pdata.AttributeValue{key: value}) return span @@ -484,16 +483,9 @@ func assertSampledData(t *testing.T, sampled []pdata.Traces, serviceName string) rspans := td.ResourceSpans() for i := 0; i < rspans.Len(); i++ { rspan := rspans.At(i) - if rspan.IsNil() { - continue - } - ilss := rspans.At(i).InstrumentationLibrarySpans() + ilss := rspan.InstrumentationLibrarySpans() for j := 0; j < ilss.Len(); j++ { ils := ilss.At(j) - if ils.IsNil() { - continue - } - if svcNameAttr, _ := rspan.Resource().Attributes().Get("service.name"); svcNameAttr.StringVal() != serviceName { continue } diff --git a/processor/spanprocessor/span.go b/processor/spanprocessor/span.go index 386e47999d8..340b4211934 100644 --- a/processor/spanprocessor/span.go +++ b/processor/spanprocessor/span.go @@ -83,24 +83,14 @@ func (sp *spanProcessor) ProcessTraces(_ context.Context, td pdata.Traces) (pdat rss := td.ResourceSpans() for i := 0; i < rss.Len(); i++ { rs := rss.At(i) - if rs.IsNil() { - continue - } ilss := rs.InstrumentationLibrarySpans() resource := rs.Resource() for j := 0; j < ilss.Len(); j++ { ils := ilss.At(j) - if ils.IsNil() { - continue - } spans := ils.Spans() library := ils.InstrumentationLibrary() for k := 0; k < spans.Len(); k++ { s := spans.At(k) - if s.IsNil() { - continue - } - if filterspan.SkipSpan(sp.include, sp.exclude, s, resource, library) { continue } diff --git a/processor/spanprocessor/span_test.go b/processor/spanprocessor/span_test.go index 2d3f50a6e53..df4fe1b5b27 100644 --- a/processor/spanprocessor/span_test.go +++ b/processor/spanprocessor/span_test.go @@ -65,22 +65,12 @@ func runIndividualTestCase(t *testing.T, tt testCase, tp component.TracesProcess rss := td.ResourceSpans() for i := 0; i < rss.Len(); i++ { rs := rss.At(i) - if rs.IsNil() { - continue - } rs.Resource().Attributes().Sort() - ilss := rss.At(i).InstrumentationLibrarySpans() + ilss := rs.InstrumentationLibrarySpans() for j := 0; j < ilss.Len(); j++ { - ils := ilss.At(j) - if ils.IsNil() { - continue - } - spans := ils.Spans() + spans := ilss.At(j).Spans() for k := 0; k < spans.Len(); k++ { - s := spans.At(k) - if !s.IsNil() { - s.Attributes().Sort() - } + spans.At(k).Attributes().Sort() } } } @@ -123,11 +113,6 @@ func TestSpanProcessor_NilEmptyData(t *testing.T) { input: testdata.GenerateTraceDataOneEmptyResourceSpans(), output: testdata.GenerateTraceDataOneEmptyResourceSpans(), }, - { - name: "one-empty-one-nil-resource-spans", - input: testdata.GenerateTraceDataOneEmptyOneNilResourceSpans(), - output: testdata.GenerateTraceDataOneEmptyOneNilResourceSpans(), - }, { name: "no-libraries", input: testdata.GenerateTraceDataNoLibraries(), @@ -138,11 +123,6 @@ func TestSpanProcessor_NilEmptyData(t *testing.T) { input: testdata.GenerateTraceDataOneEmptyInstrumentationLibrary(), output: testdata.GenerateTraceDataOneEmptyInstrumentationLibrary(), }, - { - name: "one-empty-one-nil-instrumentation-library", - input: testdata.GenerateTraceDataOneEmptyOneNilInstrumentationLibrary(), - output: testdata.GenerateTraceDataOneEmptyOneNilInstrumentationLibrary(), - }, } factory := NewFactory() cfg := factory.CreateDefaultConfig() diff --git a/proto_patch.sed b/proto_patch.sed index 2c07d098406..b97fc073438 100644 --- a/proto_patch.sed +++ b/proto_patch.sed @@ -24,15 +24,8 @@ s+repeated opentelemetry.proto.common.v1.KeyValue \(.*\);+repeated opentelemetry s+repeated KeyValue \(.*\);+repeated KeyValue \1\ [ (gogoproto.nullable) = false ];+g -s+repeated opentelemetry.proto.common.v1.AnyValue \(.*\);+repeated opentelemetry.proto.common.v1.AnyValue \1\ - [\ - (gogoproto.nullable) = false\ - ];+g - s+AnyValue \(.*\);+AnyValue \1\ - [\ - (gogoproto.nullable) = false\ - ];+g + [ (gogoproto.nullable) = false ];+g s+repeated opentelemetry.proto.common.v1.StringKeyValue \(.*\);+repeated opentelemetry.proto.common.v1.StringKeyValue \1\ [ (gogoproto.nullable) = false ];+g diff --git a/receiver/fluentforwardreceiver/conversion.go b/receiver/fluentforwardreceiver/conversion.go index da3c727fda6..74e3b0febe2 100644 --- a/receiver/fluentforwardreceiver/conversion.go +++ b/receiver/fluentforwardreceiver/conversion.go @@ -397,8 +397,6 @@ func (pfe *PackedForwardEventLogRecords) parseEntries(entriesRaw []byte, isGzipp msgpReader := msgp.NewReader(reader) for { lr := pdata.NewLogRecord() - lr.InitEmpty() - err := parseEntryToLogRecord(msgpReader, lr) if err != nil { if msgp.Cause(err) == io.EOF { diff --git a/receiver/hostmetricsreceiver/internal/metadata/generated_metrics.go b/receiver/hostmetricsreceiver/internal/metadata/generated_metrics.go index 7ddbcd3b226..0462614b1a8 100644 --- a/receiver/hostmetricsreceiver/internal/metadata/generated_metrics.go +++ b/receiver/hostmetricsreceiver/internal/metadata/generated_metrics.go @@ -79,7 +79,6 @@ var Metrics = &metricStruct{ "system.cpu.time", func() pdata.Metric { metric := pdata.NewMetric() - metric.InitEmpty() metric.SetName("system.cpu.time") metric.SetDescription("Total CPU seconds broken down by different states.") metric.SetUnit("s") @@ -94,7 +93,6 @@ var Metrics = &metricStruct{ "system.memory.usage", func() pdata.Metric { metric := pdata.NewMetric() - metric.InitEmpty() metric.SetName("system.memory.usage") metric.SetDescription("Bytes of memory in use.") metric.SetUnit("By") diff --git a/receiver/hostmetricsreceiver/internal/scraper/diskscraper/disk_metadata.go b/receiver/hostmetricsreceiver/internal/scraper/diskscraper/disk_metadata.go index 8fdcda49895..8ffd1129135 100644 --- a/receiver/hostmetricsreceiver/internal/scraper/diskscraper/disk_metadata.go +++ b/receiver/hostmetricsreceiver/internal/scraper/diskscraper/disk_metadata.go @@ -36,7 +36,6 @@ const ( var diskIODescriptor = func() pdata.Metric { metric := pdata.NewMetric() - metric.InitEmpty() metric.SetName("system.disk.io") metric.SetDescription("Disk bytes transferred.") metric.SetUnit("bytes") @@ -49,7 +48,6 @@ var diskIODescriptor = func() pdata.Metric { var diskOpsDescriptor = func() pdata.Metric { metric := pdata.NewMetric() - metric.InitEmpty() metric.SetName("system.disk.ops") metric.SetDescription("Disk operations count.") metric.SetUnit("1") @@ -62,7 +60,6 @@ var diskOpsDescriptor = func() pdata.Metric { var diskIOTimeDescriptor = func() pdata.Metric { metric := pdata.NewMetric() - metric.InitEmpty() metric.SetName("system.disk.io_time") metric.SetDescription("Time disk spent activated. On Windows, this is calculated as the inverse of disk idle time.") metric.SetUnit("s") @@ -75,7 +72,6 @@ var diskIOTimeDescriptor = func() pdata.Metric { var diskOperationTimeDescriptor = func() pdata.Metric { metric := pdata.NewMetric() - metric.InitEmpty() metric.SetName("system.disk.operation_time") metric.SetDescription("Time spent in disk operations.") metric.SetUnit("s") @@ -88,7 +84,6 @@ var diskOperationTimeDescriptor = func() pdata.Metric { var diskPendingOperationsDescriptor = func() pdata.Metric { metric := pdata.NewMetric() - metric.InitEmpty() metric.SetName("system.disk.pending_operations") metric.SetDescription("The queue size of pending I/O operations.") metric.SetUnit("1") @@ -101,7 +96,6 @@ var diskPendingOperationsDescriptor = func() pdata.Metric { var diskMergedDescriptor = func() pdata.Metric { metric := pdata.NewMetric() - metric.InitEmpty() metric.SetName("system.disk.merged") metric.SetDescription("The number of disk reads merged into single physical disk access operations.") metric.SetUnit("1") diff --git a/receiver/hostmetricsreceiver/internal/scraper/filesystemscraper/filesystem_metadata.go b/receiver/hostmetricsreceiver/internal/scraper/filesystemscraper/filesystem_metadata.go index a3e9747384c..b13a2211685 100644 --- a/receiver/hostmetricsreceiver/internal/scraper/filesystemscraper/filesystem_metadata.go +++ b/receiver/hostmetricsreceiver/internal/scraper/filesystemscraper/filesystem_metadata.go @@ -40,7 +40,6 @@ const ( var fileSystemUsageDescriptor = func() pdata.Metric { metric := pdata.NewMetric() - metric.InitEmpty() metric.SetName("system.filesystem.usage") metric.SetDescription("Filesystem bytes used.") metric.SetUnit("bytes") @@ -53,7 +52,6 @@ var fileSystemUsageDescriptor = func() pdata.Metric { var fileSystemINodesUsageDescriptor = func() pdata.Metric { metric := pdata.NewMetric() - metric.InitEmpty() metric.SetName("system.filesystem.inodes.usage") metric.SetDescription("FileSystem iNodes used.") metric.SetUnit("1") diff --git a/receiver/hostmetricsreceiver/internal/scraper/loadscraper/load_metadata.go b/receiver/hostmetricsreceiver/internal/scraper/loadscraper/load_metadata.go index c807cab5c15..f52437a1611 100644 --- a/receiver/hostmetricsreceiver/internal/scraper/loadscraper/load_metadata.go +++ b/receiver/hostmetricsreceiver/internal/scraper/loadscraper/load_metadata.go @@ -22,7 +22,6 @@ import ( var loadAvg1MDescriptor = func() pdata.Metric { metric := pdata.NewMetric() - metric.InitEmpty() metric.SetName("system.cpu.load_average.1m") metric.SetDescription("Average CPU Load over 1 minute.") metric.SetUnit("1") @@ -32,7 +31,6 @@ var loadAvg1MDescriptor = func() pdata.Metric { var loadAvg5mDescriptor = func() pdata.Metric { metric := pdata.NewMetric() - metric.InitEmpty() metric.SetName("system.cpu.load_average.5m") metric.SetDescription("Average CPU Load over 5 minutes.") metric.SetUnit("1") @@ -42,7 +40,6 @@ var loadAvg5mDescriptor = func() pdata.Metric { var loadAvg15mDescriptor = func() pdata.Metric { metric := pdata.NewMetric() - metric.InitEmpty() metric.SetName("system.cpu.load_average.15m") metric.SetDescription("Average CPU Load over 15 minutes.") metric.SetUnit("1") diff --git a/receiver/hostmetricsreceiver/internal/scraper/networkscraper/network_metadata.go b/receiver/hostmetricsreceiver/internal/scraper/networkscraper/network_metadata.go index eebcdaed676..62e51130563 100644 --- a/receiver/hostmetricsreceiver/internal/scraper/networkscraper/network_metadata.go +++ b/receiver/hostmetricsreceiver/internal/scraper/networkscraper/network_metadata.go @@ -37,7 +37,6 @@ const ( var networkPacketsDescriptor = func() pdata.Metric { metric := pdata.NewMetric() - metric.InitEmpty() metric.SetName("system.network.packets") metric.SetDescription("The number of packets transferred.") metric.SetUnit("1") @@ -50,7 +49,6 @@ var networkPacketsDescriptor = func() pdata.Metric { var networkDroppedPacketsDescriptor = func() pdata.Metric { metric := pdata.NewMetric() - metric.InitEmpty() metric.SetName("system.network.dropped_packets") metric.SetDescription("The number of packets dropped.") metric.SetUnit("1") @@ -63,7 +61,6 @@ var networkDroppedPacketsDescriptor = func() pdata.Metric { var networkErrorsDescriptor = func() pdata.Metric { metric := pdata.NewMetric() - metric.InitEmpty() metric.SetName("system.network.errors") metric.SetDescription("The number of errors encountered") metric.SetUnit("1") @@ -76,7 +73,6 @@ var networkErrorsDescriptor = func() pdata.Metric { var networkIODescriptor = func() pdata.Metric { metric := pdata.NewMetric() - metric.InitEmpty() metric.SetName("system.network.io") metric.SetDescription("The number of bytes transmitted and received") metric.SetUnit("bytes") @@ -89,7 +85,6 @@ var networkIODescriptor = func() pdata.Metric { var networkTCPConnectionsDescriptor = func() pdata.Metric { metric := pdata.NewMetric() - metric.InitEmpty() metric.SetName("system.network.tcp_connections") metric.SetDescription("The number of tcp connections") metric.SetUnit("bytes") diff --git a/receiver/hostmetricsreceiver/internal/scraper/processesscraper/processes_metadata.go b/receiver/hostmetricsreceiver/internal/scraper/processesscraper/processes_metadata.go index 483f6376299..813bd2749b9 100644 --- a/receiver/hostmetricsreceiver/internal/scraper/processesscraper/processes_metadata.go +++ b/receiver/hostmetricsreceiver/internal/scraper/processesscraper/processes_metadata.go @@ -22,7 +22,6 @@ import ( var processesRunningDescriptor = func() pdata.Metric { metric := pdata.NewMetric() - metric.InitEmpty() metric.SetName("system.processes.running") metric.SetDescription("Total number of running processes.") metric.SetUnit("1") @@ -35,7 +34,6 @@ var processesRunningDescriptor = func() pdata.Metric { var processesBlockedDescriptor = func() pdata.Metric { metric := pdata.NewMetric() - metric.InitEmpty() metric.SetName("system.processes.blocked") metric.SetDescription("Total number of blocked processes.") metric.SetUnit("1") diff --git a/receiver/hostmetricsreceiver/internal/scraper/processscraper/process_metadata.go b/receiver/hostmetricsreceiver/internal/scraper/processscraper/process_metadata.go index 8d055f26a13..449f05e2a56 100644 --- a/receiver/hostmetricsreceiver/internal/scraper/processscraper/process_metadata.go +++ b/receiver/hostmetricsreceiver/internal/scraper/processscraper/process_metadata.go @@ -44,7 +44,6 @@ const ( var cpuTimeDescriptor = func() pdata.Metric { metric := pdata.NewMetric() - metric.InitEmpty() metric.SetName("process.cpu.time") metric.SetDescription("Total CPU seconds broken down by different states.") metric.SetUnit("s") @@ -57,7 +56,6 @@ var cpuTimeDescriptor = func() pdata.Metric { var physicalMemoryUsageDescriptor = func() pdata.Metric { metric := pdata.NewMetric() - metric.InitEmpty() metric.SetName("process.memory.physical_usage") metric.SetDescription("The amount of physical memory in use.") metric.SetUnit("bytes") @@ -70,7 +68,6 @@ var physicalMemoryUsageDescriptor = func() pdata.Metric { var virtualMemoryUsageDescriptor = func() pdata.Metric { metric := pdata.NewMetric() - metric.InitEmpty() metric.SetName("process.memory.virtual_usage") metric.SetDescription("Virtual memory size.") metric.SetUnit("bytes") @@ -83,7 +80,6 @@ var virtualMemoryUsageDescriptor = func() pdata.Metric { var diskIODescriptor = func() pdata.Metric { metric := pdata.NewMetric() - metric.InitEmpty() metric.SetName("process.disk.io") metric.SetDescription("Disk bytes transferred.") metric.SetUnit("bytes") diff --git a/receiver/hostmetricsreceiver/internal/scraper/swapscraper/swap_metadata.go b/receiver/hostmetricsreceiver/internal/scraper/swapscraper/swap_metadata.go index f491b2bbdbc..649b14c1042 100644 --- a/receiver/hostmetricsreceiver/internal/scraper/swapscraper/swap_metadata.go +++ b/receiver/hostmetricsreceiver/internal/scraper/swapscraper/swap_metadata.go @@ -51,7 +51,6 @@ const ( var swapUsageDescriptor = func() pdata.Metric { metric := pdata.NewMetric() - metric.InitEmpty() metric.SetName("system.swap.usage") metric.SetDescription("Swap (unix) or pagefile (windows) usage.") metric.SetUnit("bytes") @@ -64,7 +63,6 @@ var swapUsageDescriptor = func() pdata.Metric { var swapPagingDescriptor = func() pdata.Metric { metric := pdata.NewMetric() - metric.InitEmpty() metric.SetName("system.swap.paging_ops") metric.SetDescription("The number of paging operations.") metric.SetUnit("1") @@ -77,7 +75,6 @@ var swapPagingDescriptor = func() pdata.Metric { var swapPageFaultsDescriptor = func() pdata.Metric { metric := pdata.NewMetric() - metric.InitEmpty() metric.SetName("system.swap.page_faults") metric.SetDescription("The number of page faults.") metric.SetUnit("1") diff --git a/receiver/kafkareceiver/kafka_receiver_test.go b/receiver/kafkareceiver/kafka_receiver_test.go index f70f9c84604..f865970186e 100644 --- a/receiver/kafkareceiver/kafka_receiver_test.go +++ b/receiver/kafkareceiver/kafka_receiver_test.go @@ -223,7 +223,6 @@ func TestConsumerGroupHandler_error_nextConsumer(t *testing.T) { td := pdata.NewTraces() td.ResourceSpans().Resize(1) - td.ResourceSpans().At(0).InitEmpty() request := &otlptrace.ExportTraceServiceRequest{ ResourceSpans: pdata.TracesToOtlp(td), } diff --git a/testbed/correctness/metrics/metric_diff.go b/testbed/correctness/metrics/metric_diff.go index aa3a0f310ae..edb2a33a644 100644 --- a/testbed/correctness/metrics/metric_diff.go +++ b/testbed/correctness/metrics/metric_diff.go @@ -213,10 +213,6 @@ func diffDoubleExemplars( return diffs } for i := 0; i < expected.Len(); i++ { - diffs, mismatch = diffValues(diffs, expected.At(i).IsNil(), actual.At(i).IsNil(), "DoubleExemplar IsNil") - if mismatch { - continue - } diffs = diff(diffs, expected.At(i).Value(), actual.At(i).Value(), "DoubleExemplar Value") } return diffs @@ -262,10 +258,6 @@ func diffIntExemplars( return diffs } for i := 0; i < expected.Len(); i++ { - diffs, mismatch = diffValues(diffs, expected.At(i).IsNil(), actual.At(i).IsNil(), "DoubleExemplar IsNil") - if mismatch { - continue - } diffs = diff(diffs, expected.At(i).Value(), actual.At(i).Value(), "DoubleExemplar Value") } return diffs diff --git a/testbed/testbed/data_providers.go b/testbed/testbed/data_providers.go index dc3902bc51f..0767135a9dd 100644 --- a/testbed/testbed/data_providers.go +++ b/testbed/testbed/data_providers.go @@ -185,7 +185,6 @@ func (dp *PerfTestDataProvider) GenerateLogs() (pdata.Logs, bool) { for i := 0; i < dp.options.ItemsPerBatch; i++ { itemIndex := dp.dataItemsGenerated.Inc() record := logRecords.At(i) - record.InitEmpty() record.SetSeverityNumber(pdata.SeverityNumberINFO3) record.SetSeverityText("INFO3") record.SetName("load_generator_" + strconv.Itoa(i)) diff --git a/translator/internaldata/metrics_to_oc.go b/translator/internaldata/metrics_to_oc.go index 05916b14272..612d5de048b 100644 --- a/translator/internaldata/metrics_to_oc.go +++ b/translator/internaldata/metrics_to_oc.go @@ -43,11 +43,7 @@ func MetricsToOC(md pdata.Metrics) []consumerdata.MetricsData { ocResourceMetricsList := make([]consumerdata.MetricsData, 0, resourceMetrics.Len()) for i := 0; i < resourceMetrics.Len(); i++ { - rs := resourceMetrics.At(i) - if rs.IsNil() { - continue - } - ocResourceMetricsList = append(ocResourceMetricsList, resourceMetricsToOC(rs)) + ocResourceMetricsList = append(ocResourceMetricsList, resourceMetricsToOC(resourceMetrics.At(i))) } return ocResourceMetricsList @@ -65,17 +61,10 @@ func resourceMetricsToOC(rm pdata.ResourceMetrics) consumerdata.MetricsData { ocMetrics := make([]*ocmetrics.Metric, 0, ilms.At(0).Metrics().Len()) for i := 0; i < ilms.Len(); i++ { ilm := ilms.At(i) - if ilm.IsNil() { - continue - } // TODO: Handle instrumentation library name and version. metrics := ilm.Metrics() for j := 0; j < metrics.Len(); j++ { - m := metrics.At(j) - if m.IsNil() { - continue - } - ocMetrics = append(ocMetrics, metricToOC(m)) + ocMetrics = append(ocMetrics, metricToOC(metrics.At(j))) } } if len(ocMetrics) != 0 { @@ -161,51 +150,31 @@ func collectLabelKeys(metric pdata.Metric) *labelKeys { func collectLabelKeysIntDataPoints(ips pdata.IntDataPointSlice, keySet map[string]struct{}) { for i := 0; i < ips.Len(); i++ { - ip := ips.At(i) - if ip.IsNil() { - continue - } - addLabelKeys(keySet, ip.LabelsMap()) + addLabelKeys(keySet, ips.At(i).LabelsMap()) } } func collectLabelKeysDoubleDataPoints(dps pdata.DoubleDataPointSlice, keySet map[string]struct{}) { for i := 0; i < dps.Len(); i++ { - dp := dps.At(i) - if dp.IsNil() { - continue - } - addLabelKeys(keySet, dp.LabelsMap()) + addLabelKeys(keySet, dps.At(i).LabelsMap()) } } func collectLabelKeysIntHistogramDataPoints(ihdp pdata.IntHistogramDataPointSlice, keySet map[string]struct{}) { for i := 0; i < ihdp.Len(); i++ { - hp := ihdp.At(i) - if hp.IsNil() { - continue - } - addLabelKeys(keySet, hp.LabelsMap()) + addLabelKeys(keySet, ihdp.At(i).LabelsMap()) } } func collectLabelKeysDoubleHistogramDataPoints(dhdp pdata.DoubleHistogramDataPointSlice, keySet map[string]struct{}) { for i := 0; i < dhdp.Len(); i++ { - hp := dhdp.At(i) - if hp.IsNil() { - continue - } - addLabelKeys(keySet, hp.LabelsMap()) + addLabelKeys(keySet, dhdp.At(i).LabelsMap()) } } func collectLabelKeysDoubleSummaryDataPoints(dhdp pdata.DoubleSummaryDataPointSlice, keySet map[string]struct{}) { for i := 0; i < dhdp.Len(); i++ { - hp := dhdp.At(i) - if hp.IsNil() { - continue - } - addLabelKeys(keySet, hp.LabelsMap()) + addLabelKeys(keySet, dhdp.At(i).LabelsMap()) } } @@ -216,9 +185,6 @@ func addLabelKeys(keySet map[string]struct{}, labels pdata.StringMap) { } func descriptorToOC(metric pdata.Metric, labelKeys *labelKeys) *ocmetrics.MetricDescriptor { - if metric.IsNil() { - return nil - } return &ocmetrics.MetricDescriptor{ Name: metric.Name(), Description: metric.Description(), @@ -292,9 +258,6 @@ func intPointsToOC(dps pdata.IntDataPointSlice, labelKeys *labelKeys) []*ocmetri timeseries := make([]*ocmetrics.TimeSeries, 0, dps.Len()) for i := 0; i < dps.Len(); i++ { ip := dps.At(i) - if ip.IsNil() { - continue - } ts := &ocmetrics.TimeSeries{ StartTimestamp: pdata.UnixNanoToTimestamp(ip.StartTime()), LabelValues: labelValuesToOC(ip.LabelsMap(), labelKeys), @@ -319,9 +282,6 @@ func doublePointToOC(dps pdata.DoubleDataPointSlice, labelKeys *labelKeys) []*oc timeseries := make([]*ocmetrics.TimeSeries, 0, dps.Len()) for i := 0; i < dps.Len(); i++ { dp := dps.At(i) - if dp.IsNil() { - continue - } ts := &ocmetrics.TimeSeries{ StartTimestamp: pdata.UnixNanoToTimestamp(dp.StartTime()), LabelValues: labelValuesToOC(dp.LabelsMap(), labelKeys), @@ -346,10 +306,6 @@ func doubleHistogramPointToOC(dps pdata.DoubleHistogramDataPointSlice, labelKeys timeseries := make([]*ocmetrics.TimeSeries, 0, dps.Len()) for i := 0; i < dps.Len(); i++ { dp := dps.At(i) - if dp.IsNil() { - continue - } - buckets := histogramBucketsToOC(dp.BucketCounts()) doubleExemplarsToOC(dp.ExplicitBounds(), buckets, dp.Exemplars()) @@ -383,10 +339,6 @@ func intHistogramPointToOC(dps pdata.IntHistogramDataPointSlice, labelKeys *labe timeseries := make([]*ocmetrics.TimeSeries, 0, dps.Len()) for i := 0; i < dps.Len(); i++ { dp := dps.At(i) - if dp.IsNil() { - continue - } - buckets := histogramBucketsToOC(dp.BucketCounts()) intExemplarsToOC(dp.ExplicitBounds(), buckets, dp.Exemplars()) @@ -448,10 +400,6 @@ func doubleSummaryPointToOC(dps pdata.DoubleSummaryDataPointSlice, labelKeys *la timeseries := make([]*ocmetrics.TimeSeries, 0, dps.Len()) for i := 0; i < dps.Len(); i++ { dp := dps.At(i) - if dp.IsNil() { - continue - } - percentileValues := summaryPercentilesToOC(dp.QuantileValues()) ts := &ocmetrics.TimeSeries{ @@ -485,10 +433,6 @@ func summaryPercentilesToOC(qtls pdata.ValueAtQuantileSlice) []*ocmetrics.Summar ocPercentiles := make([]*ocmetrics.SummaryValue_Snapshot_ValueAtPercentile, 0, qtls.Len()) for i := 0; i < qtls.Len(); i++ { quantile := qtls.At(i) - if quantile.IsNil() { - continue - } - ocPercentiles = append(ocPercentiles, &ocmetrics.SummaryValue_Snapshot_ValueAtPercentile{ Percentile: quantile.Quantile() * 100, Value: quantile.Value(), @@ -504,9 +448,6 @@ func doubleExemplarsToOC(bounds []float64, ocBuckets []*ocmetrics.DistributionVa for i := 0; i < exemplars.Len(); i++ { exemplar := exemplars.At(i) - if exemplar.IsNil() { - continue - } val := exemplar.Value() pos := 0 for ; pos < len(bounds); pos++ { @@ -526,9 +467,6 @@ func intExemplarsToOC(bounds []float64, ocBuckets []*ocmetrics.DistributionValue for i := 0; i < exemplars.Len(); i++ { exemplar := exemplars.At(i) - if exemplar.IsNil() { - continue - } val := float64(exemplar.Value()) pos := 0 for ; pos < len(bounds); pos++ { diff --git a/translator/internaldata/metrics_to_oc_test.go b/translator/internaldata/metrics_to_oc_test.go index 7d367d0985a..e6488e9666c 100644 --- a/translator/internaldata/metrics_to_oc_test.go +++ b/translator/internaldata/metrics_to_oc_test.go @@ -59,14 +59,6 @@ func TestMetricsToOC(t *testing.T) { }, }, - { - name: "one-empty-one-nil-resource-metrics", - internal: testdata.GenerateMetricsOneEmptyOneNilResourceMetrics(), - oc: []consumerdata.MetricsData{ - {}, - }, - }, - { name: "no-libraries", internal: testdata.GenerateMetricsNoLibraries(), @@ -83,14 +75,6 @@ func TestMetricsToOC(t *testing.T) { }, }, - { - name: "one-empty-one-nil-instrumentation-library", - internal: testdata.GenerateMetricsOneEmptyOneNilInstrumentationLibrary(), - oc: []consumerdata.MetricsData{ - generateOCTestDataNoMetrics(), - }, - }, - { name: "one-metric-no-resource", internal: testdata.GenerateMetricsOneMetricNoResource(), @@ -111,22 +95,6 @@ func TestMetricsToOC(t *testing.T) { }, }, - { - name: "one-metric-one-nil", - internal: testdata.GenerateMetricsOneMetricOneNil(), - oc: []consumerdata.MetricsData{ - generateOCTestDataMetricsOneMetric(), - }, - }, - - { - name: "one-metric-one-nil-point", - internal: testdata.GenerateMetricsOneMetricOneNilPoint(), - oc: []consumerdata.MetricsData{ - generateOCTestDataMetricsOneMetric(), - }, - }, - { name: "one-metric-no-labels", internal: testdata.GenerateMetricsOneMetricNoLabels(), diff --git a/translator/internaldata/oc_to_metrics.go b/translator/internaldata/oc_to_metrics.go index 5318c5ac57d..3233f4d4e59 100644 --- a/translator/internaldata/oc_to_metrics.go +++ b/translator/internaldata/oc_to_metrics.go @@ -191,35 +191,29 @@ func ocMetricToMetrics(ocMetric *ocmetrics.Metric, metric pdata.Metric) { func descriptorTypeToMetrics(t ocmetrics.MetricDescriptor_Type, metric pdata.Metric) pdata.MetricDataType { switch t { case ocmetrics.MetricDescriptor_GAUGE_INT64: - metric.InitEmpty() metric.SetDataType(pdata.MetricDataTypeIntGauge) return pdata.MetricDataTypeIntGauge case ocmetrics.MetricDescriptor_GAUGE_DOUBLE: - metric.InitEmpty() metric.SetDataType(pdata.MetricDataTypeDoubleGauge) return pdata.MetricDataTypeDoubleGauge case ocmetrics.MetricDescriptor_CUMULATIVE_INT64: - metric.InitEmpty() metric.SetDataType(pdata.MetricDataTypeIntSum) sum := metric.IntSum() sum.SetIsMonotonic(true) sum.SetAggregationTemporality(pdata.AggregationTemporalityCumulative) return pdata.MetricDataTypeIntSum case ocmetrics.MetricDescriptor_CUMULATIVE_DOUBLE: - metric.InitEmpty() metric.SetDataType(pdata.MetricDataTypeDoubleSum) sum := metric.DoubleSum() sum.SetIsMonotonic(true) sum.SetAggregationTemporality(pdata.AggregationTemporalityCumulative) return pdata.MetricDataTypeDoubleSum case ocmetrics.MetricDescriptor_CUMULATIVE_DISTRIBUTION: - metric.InitEmpty() metric.SetDataType(pdata.MetricDataTypeDoubleHistogram) histo := metric.DoubleHistogram() histo.SetAggregationTemporality(pdata.AggregationTemporalityCumulative) return pdata.MetricDataTypeDoubleHistogram case ocmetrics.MetricDescriptor_SUMMARY: - metric.InitEmpty() metric.SetDataType(pdata.MetricDataTypeDoubleSummary) // no temporality specified for summary metric return pdata.MetricDataTypeDoubleSummary @@ -394,7 +388,6 @@ func ocHistogramBucketsToMetrics(ocBuckets []*ocmetrics.DistributionValue_Bucket buckets[i] = uint64(ocBuckets[i].GetCount()) if ocBuckets[i].GetExemplar() != nil { exemplar := pdata.NewDoubleExemplar() - exemplar.InitEmpty() exemplarToMetrics(ocBuckets[i].GetExemplar(), exemplar) dp.Exemplars().Append(exemplar) } diff --git a/translator/internaldata/oc_to_traces_test.go b/translator/internaldata/oc_to_traces_test.go index 172a35c7d01..29bcd3b5ebb 100644 --- a/translator/internaldata/oc_to_traces_test.go +++ b/translator/internaldata/oc_to_traces_test.go @@ -397,15 +397,6 @@ func TestOcToInternal(t *testing.T) { }, } - // Extra tests: - // * "two-spans-and-separate-in-the-middle" - // * "one-span-zeroed-parent-id" - // Missing tests (impossible to generate): - // * GenerateTraceDataOneEmptyOneNilResourceSpans - // * GenerateTraceDataOneEmptyInstrumentationLibrary - // * GenerateTraceDataOneEmptyOneNilInstrumentationLibrary - assert.EqualValues(t, testdata.NumTraceTests-1, len(tests)) - for _, test := range tests { t.Run(test.name, func(t *testing.T) { assert.EqualValues(t, test.td, OCToTraceData(test.oc)) @@ -415,7 +406,6 @@ func TestOcToInternal(t *testing.T) { func TestOcSameProcessAsParentSpanToInternal(t *testing.T) { span := pdata.NewSpan() - span.InitEmpty() ocSameProcessAsParentSpanToInternal(nil, span) assert.Equal(t, 0, span.Attributes().Len()) diff --git a/translator/internaldata/traces_to_oc.go b/translator/internaldata/traces_to_oc.go index 4b97ccad435..98c3f072862 100644 --- a/translator/internaldata/traces_to_oc.go +++ b/translator/internaldata/traces_to_oc.go @@ -46,11 +46,7 @@ func TraceDataToOC(td pdata.Traces) []consumerdata.TraceData { ocResourceSpansList := make([]consumerdata.TraceData, 0, resourceSpans.Len()) for i := 0; i < resourceSpans.Len(); i++ { - rs := resourceSpans.At(i) - if rs.IsNil() { - continue - } - ocResourceSpansList = append(ocResourceSpansList, resourceSpansToOC(rs)) + ocResourceSpansList = append(ocResourceSpansList, resourceSpansToOC(resourceSpans.At(i))) } return ocResourceSpansList @@ -70,17 +66,10 @@ func resourceSpansToOC(rs pdata.ResourceSpans) consumerdata.TraceData { ocSpans := make([]*octrace.Span, 0, ilss.At(0).Spans().Len()) for i := 0; i < ilss.Len(); i++ { ils := ilss.At(i) - if ils.IsNil() { - continue - } // TODO: Handle instrumentation library name and version. spans := ils.Spans() for j := 0; j < spans.Len(); j++ { - span := spans.At(j) - if span.IsNil() { - continue - } - ocSpans = append(ocSpans, spanToOC(span)) + ocSpans = append(ocSpans, spanToOC(spans.At(j))) } } ocTraceData.Spans = ocSpans diff --git a/translator/internaldata/traces_to_oc_test.go b/translator/internaldata/traces_to_oc_test.go index ebf98fd1dbd..e089f778d40 100644 --- a/translator/internaldata/traces_to_oc_test.go +++ b/translator/internaldata/traces_to_oc_test.go @@ -332,19 +332,6 @@ func TestInternalToOC(t *testing.T) { }, }, - { - name: "one-empty-one-nil-resource-spans", - td: testdata.GenerateTraceDataOneEmptyOneNilResourceSpans(), - oc: []consumerdata.TraceData{ - { - Node: nil, - Resource: nil, - Spans: []*octrace.Span(nil), - SourceFormat: sourceFormat, - }, - }, - }, - { name: "no-libraries", td: testdata.GenerateTraceDataNoLibraries(), @@ -371,19 +358,6 @@ func TestInternalToOC(t *testing.T) { }, }, - { - name: "one-empty-one-nil-instrumentation-library", - td: testdata.GenerateTraceDataOneEmptyOneNilInstrumentationLibrary(), - oc: []consumerdata.TraceData{ - { - Node: ocNode, - Resource: ocResource1, - Spans: []*octrace.Span{}, - SourceFormat: sourceFormat, - }, - }, - }, - { name: "one-span-no-resource", td: testdata.GenerateTraceDataOneSpanNoResource(), @@ -410,19 +384,6 @@ func TestInternalToOC(t *testing.T) { }, }, - { - name: "one-span-one-nil", - td: testdata.GenerateTraceDataOneSpanOneNil(), - oc: []consumerdata.TraceData{ - { - Node: ocNode, - Resource: ocResource1, - Spans: []*octrace.Span{ocSpan1}, - SourceFormat: sourceFormat, - }, - }, - }, - { name: "two-spans-same-resource", td: testdata.GenerateTraceDataTwoSpansSameResource(), @@ -456,8 +417,6 @@ func TestInternalToOC(t *testing.T) { }, } - assert.EqualValues(t, testdata.NumTraceTests, len(tests)) - for _, test := range tests { t.Run(test.name, func(t *testing.T) { assert.EqualValues(t, test.oc, TraceDataToOC(test.td)) diff --git a/translator/trace/jaeger/jaegerproto_to_traces.go b/translator/trace/jaeger/jaegerproto_to_traces.go index 1cf2d8068d2..c6945d8bf89 100644 --- a/translator/trace/jaeger/jaegerproto_to_traces.go +++ b/translator/trace/jaeger/jaegerproto_to_traces.go @@ -146,7 +146,6 @@ func jSpansToInternal(spans []*model.Span) map[instrumentationLibrary]pdata.Inst ils, found := spansByLibrary[library] if !found { ils = pdata.NewInstrumentationLibrarySpans() - ils.InitEmpty() spansByLibrary[library] = ils if library.name != "" { @@ -165,7 +164,6 @@ type instrumentationLibrary struct { func jSpanToInternal(span *model.Span) (pdata.Span, instrumentationLibrary) { dest := pdata.NewSpan() - dest.InitEmpty() dest.SetTraceID(tracetranslator.UInt64ToTraceID(span.TraceID.High, span.TraceID.Low)) dest.SetSpanID(tracetranslator.UInt64ToSpanID(uint64(span.SpanID))) dest.SetName(span.OperationName) diff --git a/translator/trace/jaeger/traces_to_jaegerproto.go b/translator/trace/jaeger/traces_to_jaegerproto.go index ceec15729fb..7a47c484c4e 100644 --- a/translator/trace/jaeger/traces_to_jaegerproto.go +++ b/translator/trace/jaeger/traces_to_jaegerproto.go @@ -37,10 +37,6 @@ func InternalTracesToJaegerProto(td pdata.Traces) ([]*model.Batch, error) { for i := 0; i < resourceSpans.Len(); i++ { rs := resourceSpans.At(i) - if rs.IsNil() { - continue - } - batch, err := resourceSpansToJaegerProto(rs) if err != nil { return nil, err @@ -75,17 +71,9 @@ func resourceSpansToJaegerProto(rs pdata.ResourceSpans) (*model.Batch, error) { for i := 0; i < ilss.Len(); i++ { ils := ilss.At(i) - if ils.IsNil() { - continue - } - spans := ils.Spans() for j := 0; j < spans.Len(); j++ { span := spans.At(j) - if span.IsNil() { - continue - } - jSpan, err := spanToJaegerProto(span, ils.InstrumentationLibrary()) if err != nil { return nil, err @@ -172,10 +160,6 @@ func attributeToJaegerProtoTag(key string, attr pdata.AttributeValue) model.KeyV } func spanToJaegerProto(span pdata.Span, libraryTags pdata.InstrumentationLibrary) (*model.Span, error) { - if span.IsNil() { - return nil, nil - } - traceID, err := traceIDToJaegerProto(span.TraceID()) if err != nil { return nil, err @@ -321,10 +305,6 @@ func makeJaegerProtoReferences( for i := 0; i < links.Len(); i++ { link := links.At(i) - if link.IsNil() { - continue - } - traceID, err := traceIDToJaegerProto(link.TraceID()) if err != nil { continue // skip invalid link @@ -357,10 +337,6 @@ func spanEventsToJaegerProtoLogs(events pdata.SpanEventSlice) []model.Log { logs := make([]model.Log, 0, events.Len()) for i := 0; i < events.Len(); i++ { event := events.At(i) - if event.IsNil() { - continue - } - fields := make([]model.KeyValue, 0, event.Attributes().Len()+1) if event.Name() != "" { fields = append(fields, model.KeyValue{ diff --git a/translator/trace/zipkin/traces_to_zipkinv2.go b/translator/trace/zipkin/traces_to_zipkinv2.go index a8378c2cd22..bd4988bdfc3 100644 --- a/translator/trace/zipkin/traces_to_zipkinv2.go +++ b/translator/trace/zipkin/traces_to_zipkinv2.go @@ -43,12 +43,7 @@ func InternalTracesToZipkinSpans(td pdata.Traces) ([]*zipkinmodel.SpanModel, err zSpans := make([]*zipkinmodel.SpanModel, 0, td.SpanCount()) for i := 0; i < resourceSpans.Len(); i++ { - rs := resourceSpans.At(i) - if rs.IsNil() { - continue - } - - batch, err := resourceSpansToZipkinSpans(rs, td.SpanCount()/resourceSpans.Len()) + batch, err := resourceSpansToZipkinSpans(resourceSpans.At(i), td.SpanCount()/resourceSpans.Len()) if err != nil { return zSpans, err } @@ -73,17 +68,10 @@ func resourceSpansToZipkinSpans(rs pdata.ResourceSpans, estSpanCount int) ([]*zi zSpans := make([]*zipkinmodel.SpanModel, 0, estSpanCount) for i := 0; i < ilss.Len(); i++ { ils := ilss.At(i) - if ils.IsNil() { - continue - } extractInstrumentationLibraryTags(ils.InstrumentationLibrary(), zTags) spans := ils.Spans() for j := 0; j < spans.Len(); j++ { - span := spans.At(j) - if span.IsNil() { - continue - } - zSpan, err := spanToZipkinSpan(span, localServiceName, zTags) + zSpan, err := spanToZipkinSpan(spans.At(j), localServiceName, zTags) if err != nil { return zSpans, err } @@ -188,9 +176,6 @@ func spanEventsToZipkinAnnotations(events pdata.SpanEventSlice, zs *zipkinmodel. zAnnos := make([]zipkinmodel.Annotation, events.Len()) for i := 0; i < events.Len(); i++ { event := events.At(i) - if event.IsNil() { - continue - } if event.Attributes().Len() == 0 && event.DroppedAttributesCount() == 0 { zAnnos[i] = zipkinmodel.Annotation{ Timestamp: pdata.UnixNanoToTime(event.Timestamp()), @@ -216,15 +201,13 @@ func spanEventsToZipkinAnnotations(events pdata.SpanEventSlice, zs *zipkinmodel. func spanLinksToZipkinTags(links pdata.SpanLinkSlice, zTags map[string]string) error { for i := 0; i < links.Len(); i++ { link := links.At(i) - if !link.IsNil() { - key := fmt.Sprintf("otlp.link.%d", i) - jsonStr, err := json.Marshal(tracetranslator.AttributeMapToMap(link.Attributes())) - if err != nil { - return err - } - zTags[key] = fmt.Sprintf(tracetranslator.SpanLinkDataFormat, link.TraceID().HexString(), - link.SpanID().HexString(), link.TraceState(), jsonStr, link.DroppedAttributesCount()) + key := fmt.Sprintf("otlp.link.%d", i) + jsonStr, err := json.Marshal(tracetranslator.AttributeMapToMap(link.Attributes())) + if err != nil { + return err } + zTags[key] = fmt.Sprintf(tracetranslator.SpanLinkDataFormat, link.TraceID().HexString(), + link.SpanID().HexString(), link.TraceState(), jsonStr, link.DroppedAttributesCount()) } return nil } diff --git a/translator/trace/zipkin/traces_to_zipkinv2_test.go b/translator/trace/zipkin/traces_to_zipkinv2_test.go index 791514e4b2b..b3d5d66fb7b 100644 --- a/translator/trace/zipkin/traces_to_zipkinv2_test.go +++ b/translator/trace/zipkin/traces_to_zipkinv2_test.go @@ -47,12 +47,6 @@ func TestInternalTracesToZipkinSpans(t *testing.T) { zs: make([]*zipkinmodel.SpanModel, 0), err: nil, }, - { - name: "oneEmptyOneNil", - td: testdata.GenerateTraceDataOneEmptyOneNilResourceSpans(), - zs: make([]*zipkinmodel.SpanModel, 0), - err: nil, - }, { name: "noLibs", td: testdata.GenerateTraceDataNoLibraries(), @@ -65,12 +59,6 @@ func TestInternalTracesToZipkinSpans(t *testing.T) { zs: make([]*zipkinmodel.SpanModel, 0), err: nil, }, - { - name: "oneEmptyLibOneNilLib", - td: testdata.GenerateTraceDataOneEmptyOneNilInstrumentationLibrary(), - zs: make([]*zipkinmodel.SpanModel, 0), - err: nil, - }, { name: "oneSpanNoResrouce", td: testdata.GenerateTraceDataOneSpanNoResource(), @@ -78,8 +66,8 @@ func TestInternalTracesToZipkinSpans(t *testing.T) { err: errors.New("TraceID is invalid"), }, { - name: "oneSpanOneNil", - td: generateTraceOneSpanOneNilWithTraceID(), + name: "oneSpan", + td: generateTraceOneSpanOneTraceID(), zs: []*zipkinmodel.SpanModel{zipkinOneSpan()}, err: nil, }, @@ -118,8 +106,8 @@ func TestInternalTracesToZipkinSpansAndBack(t *testing.T) { } } -func generateTraceOneSpanOneNilWithTraceID() pdata.Traces { - td := testdata.GenerateTraceDataOneSpanOneNil() +func generateTraceOneSpanOneTraceID() pdata.Traces { + td := testdata.GenerateTraceDataOneSpan() span := td.ResourceSpans().At(0).InstrumentationLibrarySpans().At(0).Spans().At(0) span.SetTraceID(pdata.NewTraceID([16]byte{0x01, 0x02, 0x03, 0x04, 0x05, 0x06, 0x07, 0x08, 0x09, 0x0a, 0x0b, 0x0c, 0x0d, 0x0e, 0x0f, 0x10})) diff --git a/translator/trace/zipkin/zipkinv2_to_traces.go b/translator/trace/zipkin/zipkinv2_to_traces.go index d2e4d8b4f57..95b1c80575f 100644 --- a/translator/trace/zipkin/zipkinv2_to_traces.go +++ b/translator/trace/zipkin/zipkinv2_to_traces.go @@ -96,7 +96,6 @@ func V2SpansToInternalTraces(zipkinSpans []*zipkinmodel.SpanModel, parseStringTa prevServiceName = localServiceName rss.Resize(rsCount + 1) curRscSpans = rss.At(rsCount) - curRscSpans.InitEmpty() rsCount++ populateResourceFromZipkinSpan(tags, localServiceName, curRscSpans.Resource()) prevInstrLibName = "" @@ -107,7 +106,6 @@ func V2SpansToInternalTraces(zipkinSpans []*zipkinmodel.SpanModel, parseStringTa prevInstrLibName = instrLibName curRscSpans.InstrumentationLibrarySpans().Resize(ilsCount + 1) curILSpans = curRscSpans.InstrumentationLibrarySpans().At(ilsCount) - curILSpans.InitEmpty() ilsCount++ populateILFromZipkinSpan(tags, instrLibName, curILSpans.InstrumentationLibrary()) spanCount = 0 @@ -125,8 +123,6 @@ func V2SpansToInternalTraces(zipkinSpans []*zipkinmodel.SpanModel, parseStringTa } func zSpanToInternal(zspan *zipkinmodel.SpanModel, tags map[string]string, dest pdata.Span, parseStringTags bool) error { - dest.InitEmpty() - dest.SetTraceID(tracetranslator.UInt64ToTraceID(zspan.TraceID.High, zspan.TraceID.Low)) dest.SetSpanID(tracetranslator.UInt64ToSpanID(uint64(zspan.ID))) if value, ok := tags[tracetranslator.TagW3CTraceState]; ok { @@ -210,7 +206,6 @@ func zTagsToSpanLinks(tags map[string]string, dest pdata.SpanLinkSlice) error { dest.Resize(index + 1) link := dest.At(index) index++ - link.InitEmpty() // Convert trace id. rawTrace := data.TraceID{} diff --git a/translator/trace/zipkin/zipkinv2_to_traces_test.go b/translator/trace/zipkin/zipkinv2_to_traces_test.go index 50737b86b0d..eb81a52866a 100644 --- a/translator/trace/zipkin/zipkinv2_to_traces_test.go +++ b/translator/trace/zipkin/zipkinv2_to_traces_test.go @@ -105,10 +105,8 @@ func generateTraceSingleSpanNoResourceOrInstrLibrary() pdata.Traces { td := pdata.NewTraces() td.ResourceSpans().Resize(1) rs := td.ResourceSpans().At(0) - rs.InitEmpty() rs.InstrumentationLibrarySpans().Resize(1) ils := rs.InstrumentationLibrarySpans().At(0) - ils.InitEmpty() ils.Spans().Resize(1) span := ils.Spans().At(0) span.SetTraceID(