diff --git a/.circleci/config.yml b/.circleci/config.yml index bf44d341e2b..593d6009597 100644 --- a/.circleci/config.yml +++ b/.circleci/config.yml @@ -236,12 +236,17 @@ workflows: jobs: - setup-environment: filters: + branches: + ignore: master tags: only: /^v[0-9]+\.[0-9]+\.[0-9]+.*/ - contribtest: requires: - setup-environment filters: + branches: + # Don't run contribtest on master. We only want to run it for PRs and releases. + ignore: master tags: only: /^v[0-9]+\.[0-9]+\.[0-9]+.*/ diff --git a/cmd/pdatagen/internal/base_fields.go b/cmd/pdatagen/internal/base_fields.go index 0e867a767a0..32b9d05bd52 100644 --- a/cmd/pdatagen/internal/base_fields.go +++ b/cmd/pdatagen/internal/base_fields.go @@ -28,33 +28,12 @@ func (ms ${structName}) ${fieldName}() ${returnType} { const accessorsSliceTestTemplate = `func Test${structName}_${fieldName}(t *testing.T) { ms := New${structName}() - ms.InitEmpty() assert.EqualValues(t, New${returnType}(), ms.${fieldName}()) fillTest${returnType}(ms.${fieldName}()) testVal${fieldName} := generateTest${returnType}() assert.EqualValues(t, testVal${fieldName}, ms.${fieldName}()) }` -const accessorsMessagePtrTemplate = `// ${fieldName} returns the ${lowerFieldName} associated with this ${structName}. -// If no ${lowerFieldName} available, it creates an empty message and associates it with this ${structName}. -// -// Empty initialized ${structName} will return "nil" ${returnType}. -// -// Important: This causes a runtime error if IsNil() returns "true". -func (ms ${structName}) ${fieldName}() ${returnType} { - return new${returnType}(&(*ms.orig).${originFieldName}) -}` - -const accessorsMessagePtrTestTemplate = `func Test${structName}_${fieldName}(t *testing.T) { - ms := New${structName}() - ms.InitEmpty() - assert.True(t, ms.${fieldName}().IsNil()) - ms.${fieldName}().InitEmpty() - assert.False(t, ms.${fieldName}().IsNil()) - fillTest${returnType}(ms.${fieldName}()) - assert.EqualValues(t, generateTest${returnType}(), ms.${fieldName}()) -}` - const accessorsMessageValueTemplate = `// ${fieldName} returns the ${lowerFieldName} associated with this ${structName}. // // Important: This causes a runtime error if IsNil() returns "true". @@ -64,7 +43,6 @@ func (ms ${structName}) ${fieldName}() ${returnType} { const accessorsMessageValueTestTemplate = `func Test${structName}_${fieldName}(t *testing.T) { ms := New${structName}() - ms.InitEmpty() fillTest${returnType}(ms.${fieldName}()) assert.EqualValues(t, generateTest${returnType}(), ms.${fieldName}()) }` @@ -85,7 +63,6 @@ func (ms ${structName}) Set${fieldName}(v ${returnType}) { const accessorsPrimitiveTestTemplate = `func Test${structName}_${fieldName}(t *testing.T) { ms := New${structName}() - ms.InitEmpty() assert.EqualValues(t, ${defaultVal}, ms.${fieldName}()) testVal${fieldName} := ${testValue} ms.Set${fieldName}(testVal${fieldName}) @@ -171,59 +148,6 @@ func (sf *sliceField) generateCopyToValue(sb *strings.Builder) { var _ baseField = (*sliceField)(nil) -type messagePtrField struct { - fieldName string - originFieldName string - returnMessage *messagePtrStruct -} - -func (mf *messagePtrField) generateAccessors(ms baseStruct, sb *strings.Builder) { - sb.WriteString(os.Expand(accessorsMessagePtrTemplate, func(name string) string { - switch name { - case "structName": - return ms.getName() - case "fieldName": - return mf.fieldName - case "lowerFieldName": - return strings.ToLower(mf.fieldName) - case "returnType": - return mf.returnMessage.structName - case "structOriginFullName": - return mf.returnMessage.originFullName - case "originFieldName": - return mf.originFieldName - default: - panic(name) - } - })) -} - -func (mf *messagePtrField) generateAccessorsTest(ms baseStruct, sb *strings.Builder) { - sb.WriteString(os.Expand(accessorsMessagePtrTestTemplate, func(name string) string { - switch name { - case "structName": - return ms.getName() - case "fieldName": - return mf.fieldName - case "returnType": - return mf.returnMessage.structName - default: - panic(name) - } - })) -} - -func (mf *messagePtrField) generateSetWithTestValue(sb *strings.Builder) { - sb.WriteString("\ttv." + mf.fieldName + "().InitEmpty()\n") - sb.WriteString("\tfillTest" + mf.returnMessage.structName + "(tv." + mf.fieldName + "())") -} - -func (mf *messagePtrField) generateCopyToValue(sb *strings.Builder) { - sb.WriteString("\tms." + mf.fieldName + "().CopyTo(dest." + mf.fieldName + "())") -} - -var _ baseField = (*messagePtrField)(nil) - type messageValueField struct { fieldName string originFieldName string @@ -409,7 +333,6 @@ func (one oneofField) generateAccessorsTest(baseStruct, *strings.Builder) {} func (one oneofField) generateSetWithTestValue(sb *strings.Builder) { sb.WriteString("\t(*tv.orig)." + one.originFieldName + " = " + one.testVal + "\n") - sb.WriteString("\ttv." + one.fillTestName + "().InitEmpty()\n") sb.WriteString("\tfillTest" + one.fillTestName + "(tv." + one.fillTestName + "())") } diff --git a/cmd/pdatagen/internal/base_structs.go b/cmd/pdatagen/internal/base_structs.go index 21e7d0798e4..c2686679577 100644 --- a/cmd/pdatagen/internal/base_structs.go +++ b/cmd/pdatagen/internal/base_structs.go @@ -19,81 +19,6 @@ import ( "strings" ) -const messagePtrTemplate = `${description} -// -// This is a reference type, if passed by value and callee modifies it the -// caller will see the modification. -// -// Must use New${structName} function to create new instances. -// Important: zero-initialized instance is not valid for use. -type ${structName} struct { - // orig points to the pointer ${originName} field contained somewhere else. - // We use pointer-to-pointer to be able to modify it in InitEmpty func. - orig **${originName} -} - -func new${structName}(orig **${originName}) ${structName} { - return ${structName}{orig} -} - -// New${structName} creates a new "nil" ${structName}. -// To initialize the struct call "InitEmpty". -// -// This must be used only in testing code since no "Set" method available. -func New${structName}() ${structName} { - orig := (*${originName})(nil) - return new${structName}(&orig) -} - -// InitEmpty overwrites the current value with empty. -func (ms ${structName}) InitEmpty() { - *ms.orig = &${originName}{} -} - -// IsNil returns true if the underlying data are nil. -// -// Important: All other functions will cause a runtime error if this returns "true". -func (ms ${structName}) IsNil() bool { - return *ms.orig == nil -}` - -const messagePtrCopyToHeaderTemplate = `// CopyTo copies all properties from the current struct to the dest. -func (ms ${structName}) CopyTo(dest ${structName}) { - if ms.IsNil() { - *dest.orig = nil - return - } - if dest.IsNil() { - dest.InitEmpty() - }` - -const messagePtrCopyToFooterTemplate = `}` - -const messagePtrTestTemplate = `func Test${structName}_InitEmpty(t *testing.T) { - ms := New${structName}() - assert.True(t, ms.IsNil()) - ms.InitEmpty() - assert.False(t, ms.IsNil()) -} - -func Test${structName}_CopyTo(t *testing.T) { - ms := New${structName}() - New${structName}().CopyTo(ms) - assert.True(t, ms.IsNil()) - generateTest${structName}().CopyTo(ms) - assert.EqualValues(t, generateTest${structName}(), ms) -}` - -const messagePtrGenerateTestTemplate = `func generateTest${structName}() ${structName} { - tv := New${structName}() - tv.InitEmpty() - fillTest${structName}(tv) - return tv -}` - -const messagePtrFillTestHeaderTemplate = `func fillTest${structName}(tv ${structName}) {` -const messagePtrFillTestFooterTemplate = `}` - const messageValueTemplate = `${description} // // This is a reference type, if passed by value and callee modifies it the @@ -114,11 +39,6 @@ func new${structName}(orig *${originName}) ${structName} { // This must be used only in testing code since no "Set" method available. func New${structName}() ${structName} { return new${structName}(&${originName}{}) -} - -// Deprecated: This function will be removed soon. -func (ms ${structName}) InitEmpty() { - *ms.orig = ${originName}{} }` const messageValueCopyToHeaderTemplate = `// CopyTo copies all properties from the current struct to the dest. @@ -154,104 +74,6 @@ type baseStruct interface { generateTestValueHelpers(sb *strings.Builder) } -type messagePtrStruct struct { - structName string - description string - originFullName string - fields []baseField -} - -func (ms *messagePtrStruct) getName() string { - return ms.structName -} - -func (ms *messagePtrStruct) generateStruct(sb *strings.Builder) { - sb.WriteString(os.Expand(messagePtrTemplate, func(name string) string { - switch name { - case "structName": - return ms.structName - case "originName": - return ms.originFullName - case "description": - return ms.description - default: - panic(name) - } - })) - // Write accessors for the struct - for _, f := range ms.fields { - sb.WriteString(newLine + newLine) - f.generateAccessors(ms, sb) - } - sb.WriteString(newLine + newLine) - sb.WriteString(os.Expand(messagePtrCopyToHeaderTemplate, func(name string) string { - switch name { - case "structName": - return ms.structName - default: - panic(name) - } - })) - // Write accessors CopyTo for the struct - for _, f := range ms.fields { - sb.WriteString(newLine) - f.generateCopyToValue(sb) - } - sb.WriteString(newLine) - sb.WriteString(os.Expand(messagePtrCopyToFooterTemplate, func(name string) string { - panic(name) - })) -} - -func (ms *messagePtrStruct) generateTests(sb *strings.Builder) { - sb.WriteString(os.Expand(messagePtrTestTemplate, func(name string) string { - switch name { - case "structName": - return ms.structName - default: - panic(name) - } - })) - // Write accessors tests for the struct - for _, f := range ms.fields { - sb.WriteString(newLine + newLine) - f.generateAccessorsTest(ms, sb) - } -} - -func (ms *messagePtrStruct) generateTestValueHelpers(sb *strings.Builder) { - sb.WriteString(os.Expand(messagePtrGenerateTestTemplate, func(name string) string { - switch name { - case "structName": - return ms.structName - case "originName": - return ms.originFullName - default: - panic(name) - } - })) - sb.WriteString(newLine + newLine) - sb.WriteString(os.Expand(messagePtrFillTestHeaderTemplate, func(name string) string { - switch name { - case "structName": - return ms.structName - default: - panic(name) - } - })) - // Write accessors test value for the struct - for _, f := range ms.fields { - sb.WriteString(newLine) - f.generateSetWithTestValue(sb) - } - sb.WriteString(newLine) - sb.WriteString(os.Expand(messagePtrFillTestFooterTemplate, func(name string) string { - panic(name) - })) -} - -var _ baseStruct = (*messagePtrStruct)(nil) - type messageValueStruct struct { structName string description string diff --git a/consumer/pdata/generated_common.go b/consumer/pdata/generated_common.go index c54f817e4c7..9c5e7f73dd5 100644 --- a/consumer/pdata/generated_common.go +++ b/consumer/pdata/generated_common.go @@ -43,11 +43,6 @@ func NewInstrumentationLibrary() InstrumentationLibrary { return newInstrumentationLibrary(&otlpcommon.InstrumentationLibrary{}) } -// Deprecated: This function will be removed soon. -func (ms InstrumentationLibrary) InitEmpty() { - *ms.orig = otlpcommon.InstrumentationLibrary{} -} - // Name returns the name associated with this InstrumentationLibrary. // // Important: This causes a runtime error if IsNil() returns "true". diff --git a/consumer/pdata/generated_common_test.go b/consumer/pdata/generated_common_test.go index 3a720aca7d1..a7765894034 100644 --- a/consumer/pdata/generated_common_test.go +++ b/consumer/pdata/generated_common_test.go @@ -33,7 +33,6 @@ func TestInstrumentationLibrary_CopyTo(t *testing.T) { func TestInstrumentationLibrary_Name(t *testing.T) { ms := NewInstrumentationLibrary() - ms.InitEmpty() assert.EqualValues(t, "", ms.Name()) testValName := "test_name" ms.SetName(testValName) @@ -42,7 +41,6 @@ func TestInstrumentationLibrary_Name(t *testing.T) { func TestInstrumentationLibrary_Version(t *testing.T) { ms := NewInstrumentationLibrary() - ms.InitEmpty() assert.EqualValues(t, "", ms.Version()) testValVersion := "test_version" ms.SetVersion(testValVersion) diff --git a/consumer/pdata/generated_log.go b/consumer/pdata/generated_log.go index 918b274f9bf..82110449f8d 100644 --- a/consumer/pdata/generated_log.go +++ b/consumer/pdata/generated_log.go @@ -158,11 +158,6 @@ func NewResourceLogs() ResourceLogs { return newResourceLogs(&otlplogs.ResourceLogs{}) } -// Deprecated: This function will be removed soon. -func (ms ResourceLogs) InitEmpty() { - *ms.orig = otlplogs.ResourceLogs{} -} - // Resource returns the resource associated with this ResourceLogs. // // Important: This causes a runtime error if IsNil() returns "true". @@ -319,11 +314,6 @@ func NewInstrumentationLibraryLogs() InstrumentationLibraryLogs { return newInstrumentationLibraryLogs(&otlplogs.InstrumentationLibraryLogs{}) } -// Deprecated: This function will be removed soon. -func (ms InstrumentationLibraryLogs) InitEmpty() { - *ms.orig = otlplogs.InstrumentationLibraryLogs{} -} - // InstrumentationLibrary returns the instrumentationlibrary associated with this InstrumentationLibraryLogs. // // Important: This causes a runtime error if IsNil() returns "true". @@ -481,11 +471,6 @@ func NewLogRecord() LogRecord { return newLogRecord(&otlplogs.LogRecord{}) } -// Deprecated: This function will be removed soon. -func (ms LogRecord) InitEmpty() { - *ms.orig = otlplogs.LogRecord{} -} - // Timestamp returns the timestamp associated with this LogRecord. // // Important: This causes a runtime error if IsNil() returns "true". diff --git a/consumer/pdata/generated_log_test.go b/consumer/pdata/generated_log_test.go index 0991f5a2e2a..3c25eed6d14 100644 --- a/consumer/pdata/generated_log_test.go +++ b/consumer/pdata/generated_log_test.go @@ -146,14 +146,12 @@ func TestResourceLogs_CopyTo(t *testing.T) { func TestResourceLogs_Resource(t *testing.T) { ms := NewResourceLogs() - ms.InitEmpty() fillTestResource(ms.Resource()) assert.EqualValues(t, generateTestResource(), ms.Resource()) } func TestResourceLogs_InstrumentationLibraryLogs(t *testing.T) { ms := NewResourceLogs() - ms.InitEmpty() assert.EqualValues(t, NewInstrumentationLibraryLogsSlice(), ms.InstrumentationLibraryLogs()) fillTestInstrumentationLibraryLogsSlice(ms.InstrumentationLibraryLogs()) testValInstrumentationLibraryLogs := generateTestInstrumentationLibraryLogsSlice() @@ -281,14 +279,12 @@ func TestInstrumentationLibraryLogs_CopyTo(t *testing.T) { func TestInstrumentationLibraryLogs_InstrumentationLibrary(t *testing.T) { ms := NewInstrumentationLibraryLogs() - ms.InitEmpty() fillTestInstrumentationLibrary(ms.InstrumentationLibrary()) assert.EqualValues(t, generateTestInstrumentationLibrary(), ms.InstrumentationLibrary()) } func TestInstrumentationLibraryLogs_Logs(t *testing.T) { ms := NewInstrumentationLibraryLogs() - ms.InitEmpty() assert.EqualValues(t, NewLogSlice(), ms.Logs()) fillTestLogSlice(ms.Logs()) testValLogs := generateTestLogSlice() @@ -416,7 +412,6 @@ func TestLogRecord_CopyTo(t *testing.T) { func TestLogRecord_Timestamp(t *testing.T) { ms := NewLogRecord() - ms.InitEmpty() assert.EqualValues(t, TimestampUnixNano(0), ms.Timestamp()) testValTimestamp := TimestampUnixNano(1234567890) ms.SetTimestamp(testValTimestamp) @@ -425,7 +420,6 @@ func TestLogRecord_Timestamp(t *testing.T) { func TestLogRecord_TraceID(t *testing.T) { ms := NewLogRecord() - ms.InitEmpty() assert.EqualValues(t, NewTraceID([16]byte{}), ms.TraceID()) testValTraceID := NewTraceID([16]byte{1, 2, 3, 4, 5, 6, 7, 8, 8, 7, 6, 5, 4, 3, 2, 1}) ms.SetTraceID(testValTraceID) @@ -434,7 +428,6 @@ func TestLogRecord_TraceID(t *testing.T) { func TestLogRecord_SpanID(t *testing.T) { ms := NewLogRecord() - ms.InitEmpty() assert.EqualValues(t, NewSpanID([8]byte{}), ms.SpanID()) testValSpanID := NewSpanID([8]byte{1, 2, 3, 4, 5, 6, 7, 8}) ms.SetSpanID(testValSpanID) @@ -443,7 +436,6 @@ func TestLogRecord_SpanID(t *testing.T) { func TestLogRecord_Flags(t *testing.T) { ms := NewLogRecord() - ms.InitEmpty() assert.EqualValues(t, uint32(0), ms.Flags()) testValFlags := uint32(0x01) ms.SetFlags(testValFlags) @@ -452,7 +444,6 @@ func TestLogRecord_Flags(t *testing.T) { func TestLogRecord_SeverityText(t *testing.T) { ms := NewLogRecord() - ms.InitEmpty() assert.EqualValues(t, "", ms.SeverityText()) testValSeverityText := "INFO" ms.SetSeverityText(testValSeverityText) @@ -461,7 +452,6 @@ func TestLogRecord_SeverityText(t *testing.T) { func TestLogRecord_SeverityNumber(t *testing.T) { ms := NewLogRecord() - ms.InitEmpty() assert.EqualValues(t, SeverityNumberUNDEFINED, ms.SeverityNumber()) testValSeverityNumber := SeverityNumberINFO ms.SetSeverityNumber(testValSeverityNumber) @@ -470,7 +460,6 @@ func TestLogRecord_SeverityNumber(t *testing.T) { func TestLogRecord_Name(t *testing.T) { ms := NewLogRecord() - ms.InitEmpty() assert.EqualValues(t, "", ms.Name()) testValName := "test_name" ms.SetName(testValName) @@ -479,14 +468,12 @@ func TestLogRecord_Name(t *testing.T) { func TestLogRecord_Body(t *testing.T) { ms := NewLogRecord() - ms.InitEmpty() fillTestAttributeValue(ms.Body()) assert.EqualValues(t, generateTestAttributeValue(), ms.Body()) } func TestLogRecord_Attributes(t *testing.T) { ms := NewLogRecord() - ms.InitEmpty() assert.EqualValues(t, NewAttributeMap(), ms.Attributes()) fillTestAttributeMap(ms.Attributes()) testValAttributes := generateTestAttributeMap() @@ -495,7 +482,6 @@ func TestLogRecord_Attributes(t *testing.T) { func TestLogRecord_DroppedAttributesCount(t *testing.T) { ms := NewLogRecord() - ms.InitEmpty() assert.EqualValues(t, uint32(0), ms.DroppedAttributesCount()) testValDroppedAttributesCount := uint32(17) ms.SetDroppedAttributesCount(testValDroppedAttributesCount) diff --git a/consumer/pdata/generated_metrics.go b/consumer/pdata/generated_metrics.go index 9876ef292a0..5aa528023be 100644 --- a/consumer/pdata/generated_metrics.go +++ b/consumer/pdata/generated_metrics.go @@ -157,11 +157,6 @@ func NewResourceMetrics() ResourceMetrics { return newResourceMetrics(&otlpmetrics.ResourceMetrics{}) } -// Deprecated: This function will be removed soon. -func (ms ResourceMetrics) InitEmpty() { - *ms.orig = otlpmetrics.ResourceMetrics{} -} - // Resource returns the resource associated with this ResourceMetrics. // // Important: This causes a runtime error if IsNil() returns "true". @@ -318,11 +313,6 @@ func NewInstrumentationLibraryMetrics() InstrumentationLibraryMetrics { return newInstrumentationLibraryMetrics(&otlpmetrics.InstrumentationLibraryMetrics{}) } -// Deprecated: This function will be removed soon. -func (ms InstrumentationLibraryMetrics) InitEmpty() { - *ms.orig = otlpmetrics.InstrumentationLibraryMetrics{} -} - // InstrumentationLibrary returns the instrumentationlibrary associated with this InstrumentationLibraryMetrics. // // Important: This causes a runtime error if IsNil() returns "true". @@ -480,11 +470,6 @@ func NewMetric() Metric { return newMetric(&otlpmetrics.Metric{}) } -// Deprecated: This function will be removed soon. -func (ms Metric) InitEmpty() { - *ms.orig = otlpmetrics.Metric{} -} - // Name returns the name associated with this Metric. // // Important: This causes a runtime error if IsNil() returns "true". @@ -557,11 +542,6 @@ func NewIntGauge() IntGauge { return newIntGauge(&otlpmetrics.IntGauge{}) } -// Deprecated: This function will be removed soon. -func (ms IntGauge) InitEmpty() { - *ms.orig = otlpmetrics.IntGauge{} -} - // DataPoints returns the DataPoints associated with this IntGauge. // // Important: This causes a runtime error if IsNil() returns "true". @@ -596,11 +576,6 @@ func NewDoubleGauge() DoubleGauge { return newDoubleGauge(&otlpmetrics.DoubleGauge{}) } -// Deprecated: This function will be removed soon. -func (ms DoubleGauge) InitEmpty() { - *ms.orig = otlpmetrics.DoubleGauge{} -} - // DataPoints returns the DataPoints associated with this DoubleGauge. // // Important: This causes a runtime error if IsNil() returns "true". @@ -635,11 +610,6 @@ func NewIntSum() IntSum { return newIntSum(&otlpmetrics.IntSum{}) } -// Deprecated: This function will be removed soon. -func (ms IntSum) InitEmpty() { - *ms.orig = otlpmetrics.IntSum{} -} - // AggregationTemporality returns the aggregationtemporality associated with this IntSum. // // Important: This causes a runtime error if IsNil() returns "true". @@ -704,11 +674,6 @@ func NewDoubleSum() DoubleSum { return newDoubleSum(&otlpmetrics.DoubleSum{}) } -// Deprecated: This function will be removed soon. -func (ms DoubleSum) InitEmpty() { - *ms.orig = otlpmetrics.DoubleSum{} -} - // AggregationTemporality returns the aggregationtemporality associated with this DoubleSum. // // Important: This causes a runtime error if IsNil() returns "true". @@ -773,11 +738,6 @@ func NewIntHistogram() IntHistogram { return newIntHistogram(&otlpmetrics.IntHistogram{}) } -// Deprecated: This function will be removed soon. -func (ms IntHistogram) InitEmpty() { - *ms.orig = otlpmetrics.IntHistogram{} -} - // AggregationTemporality returns the aggregationtemporality associated with this IntHistogram. // // Important: This causes a runtime error if IsNil() returns "true". @@ -827,11 +787,6 @@ func NewDoubleHistogram() DoubleHistogram { return newDoubleHistogram(&otlpmetrics.DoubleHistogram{}) } -// Deprecated: This function will be removed soon. -func (ms DoubleHistogram) InitEmpty() { - *ms.orig = otlpmetrics.DoubleHistogram{} -} - // AggregationTemporality returns the aggregationtemporality associated with this DoubleHistogram. // // Important: This causes a runtime error if IsNil() returns "true". @@ -881,11 +836,6 @@ func NewDoubleSummary() DoubleSummary { return newDoubleSummary(&otlpmetrics.DoubleSummary{}) } -// Deprecated: This function will be removed soon. -func (ms DoubleSummary) InitEmpty() { - *ms.orig = otlpmetrics.DoubleSummary{} -} - // DataPoints returns the DataPoints associated with this DoubleSummary. // // Important: This causes a runtime error if IsNil() returns "true". @@ -1034,11 +984,6 @@ func NewIntDataPoint() IntDataPoint { return newIntDataPoint(&otlpmetrics.IntDataPoint{}) } -// Deprecated: This function will be removed soon. -func (ms IntDataPoint) InitEmpty() { - *ms.orig = otlpmetrics.IntDataPoint{} -} - // LabelsMap returns the Labels associated with this IntDataPoint. // // Important: This causes a runtime error if IsNil() returns "true". @@ -1240,11 +1185,6 @@ func NewDoubleDataPoint() DoubleDataPoint { return newDoubleDataPoint(&otlpmetrics.DoubleDataPoint{}) } -// Deprecated: This function will be removed soon. -func (ms DoubleDataPoint) InitEmpty() { - *ms.orig = otlpmetrics.DoubleDataPoint{} -} - // LabelsMap returns the Labels associated with this DoubleDataPoint. // // Important: This causes a runtime error if IsNil() returns "true". @@ -1446,11 +1386,6 @@ func NewIntHistogramDataPoint() IntHistogramDataPoint { return newIntHistogramDataPoint(&otlpmetrics.IntHistogramDataPoint{}) } -// Deprecated: This function will be removed soon. -func (ms IntHistogramDataPoint) InitEmpty() { - *ms.orig = otlpmetrics.IntHistogramDataPoint{} -} - // LabelsMap returns the Labels associated with this IntHistogramDataPoint. // // Important: This causes a runtime error if IsNil() returns "true". @@ -1697,11 +1632,6 @@ func NewDoubleHistogramDataPoint() DoubleHistogramDataPoint { return newDoubleHistogramDataPoint(&otlpmetrics.DoubleHistogramDataPoint{}) } -// Deprecated: This function will be removed soon. -func (ms DoubleHistogramDataPoint) InitEmpty() { - *ms.orig = otlpmetrics.DoubleHistogramDataPoint{} -} - // LabelsMap returns the Labels associated with this DoubleHistogramDataPoint. // // Important: This causes a runtime error if IsNil() returns "true". @@ -1948,11 +1878,6 @@ func NewDoubleSummaryDataPoint() DoubleSummaryDataPoint { return newDoubleSummaryDataPoint(&otlpmetrics.DoubleSummaryDataPoint{}) } -// Deprecated: This function will be removed soon. -func (ms DoubleSummaryDataPoint) InitEmpty() { - *ms.orig = otlpmetrics.DoubleSummaryDataPoint{} -} - // LabelsMap returns the Labels associated with this DoubleSummaryDataPoint. // // Important: This causes a runtime error if IsNil() returns "true". @@ -2169,11 +2094,6 @@ func NewValueAtQuantile() ValueAtQuantile { return newValueAtQuantile(&otlpmetrics.DoubleSummaryDataPoint_ValueAtQuantile{}) } -// Deprecated: This function will be removed soon. -func (ms ValueAtQuantile) InitEmpty() { - *ms.orig = otlpmetrics.DoubleSummaryDataPoint_ValueAtQuantile{} -} - // Quantile returns the quantile associated with this ValueAtQuantile. // // Important: This causes a runtime error if IsNil() returns "true". @@ -2347,11 +2267,6 @@ func NewIntExemplar() IntExemplar { return newIntExemplar(&otlpmetrics.IntExemplar{}) } -// Deprecated: This function will be removed soon. -func (ms IntExemplar) InitEmpty() { - *ms.orig = otlpmetrics.IntExemplar{} -} - // Timestamp returns the timestamp associated with this IntExemplar. // // Important: This causes a runtime error if IsNil() returns "true". @@ -2533,11 +2448,6 @@ func NewDoubleExemplar() DoubleExemplar { return newDoubleExemplar(&otlpmetrics.DoubleExemplar{}) } -// Deprecated: This function will be removed soon. -func (ms DoubleExemplar) InitEmpty() { - *ms.orig = otlpmetrics.DoubleExemplar{} -} - // Timestamp returns the timestamp associated with this DoubleExemplar. // // Important: This causes a runtime error if IsNil() returns "true". diff --git a/consumer/pdata/generated_metrics_test.go b/consumer/pdata/generated_metrics_test.go index e504d250543..c99bce13092 100644 --- a/consumer/pdata/generated_metrics_test.go +++ b/consumer/pdata/generated_metrics_test.go @@ -146,14 +146,12 @@ func TestResourceMetrics_CopyTo(t *testing.T) { func TestResourceMetrics_Resource(t *testing.T) { ms := NewResourceMetrics() - ms.InitEmpty() fillTestResource(ms.Resource()) assert.EqualValues(t, generateTestResource(), ms.Resource()) } func TestResourceMetrics_InstrumentationLibraryMetrics(t *testing.T) { ms := NewResourceMetrics() - ms.InitEmpty() assert.EqualValues(t, NewInstrumentationLibraryMetricsSlice(), ms.InstrumentationLibraryMetrics()) fillTestInstrumentationLibraryMetricsSlice(ms.InstrumentationLibraryMetrics()) testValInstrumentationLibraryMetrics := generateTestInstrumentationLibraryMetricsSlice() @@ -281,14 +279,12 @@ func TestInstrumentationLibraryMetrics_CopyTo(t *testing.T) { func TestInstrumentationLibraryMetrics_InstrumentationLibrary(t *testing.T) { ms := NewInstrumentationLibraryMetrics() - ms.InitEmpty() fillTestInstrumentationLibrary(ms.InstrumentationLibrary()) assert.EqualValues(t, generateTestInstrumentationLibrary(), ms.InstrumentationLibrary()) } func TestInstrumentationLibraryMetrics_Metrics(t *testing.T) { ms := NewInstrumentationLibraryMetrics() - ms.InitEmpty() assert.EqualValues(t, NewMetricSlice(), ms.Metrics()) fillTestMetricSlice(ms.Metrics()) testValMetrics := generateTestMetricSlice() @@ -416,7 +412,6 @@ func TestMetric_CopyTo(t *testing.T) { func TestMetric_Name(t *testing.T) { ms := NewMetric() - ms.InitEmpty() assert.EqualValues(t, "", ms.Name()) testValName := "test_name" ms.SetName(testValName) @@ -425,7 +420,6 @@ func TestMetric_Name(t *testing.T) { func TestMetric_Description(t *testing.T) { ms := NewMetric() - ms.InitEmpty() assert.EqualValues(t, "", ms.Description()) testValDescription := "test_description" ms.SetDescription(testValDescription) @@ -434,7 +428,6 @@ func TestMetric_Description(t *testing.T) { func TestMetric_Unit(t *testing.T) { ms := NewMetric() - ms.InitEmpty() assert.EqualValues(t, "", ms.Unit()) testValUnit := "1" ms.SetUnit(testValUnit) @@ -449,7 +442,6 @@ func TestIntGauge_CopyTo(t *testing.T) { func TestIntGauge_DataPoints(t *testing.T) { ms := NewIntGauge() - ms.InitEmpty() assert.EqualValues(t, NewIntDataPointSlice(), ms.DataPoints()) fillTestIntDataPointSlice(ms.DataPoints()) testValDataPoints := generateTestIntDataPointSlice() @@ -464,7 +456,6 @@ func TestDoubleGauge_CopyTo(t *testing.T) { func TestDoubleGauge_DataPoints(t *testing.T) { ms := NewDoubleGauge() - ms.InitEmpty() assert.EqualValues(t, NewDoubleDataPointSlice(), ms.DataPoints()) fillTestDoubleDataPointSlice(ms.DataPoints()) testValDataPoints := generateTestDoubleDataPointSlice() @@ -479,7 +470,6 @@ func TestIntSum_CopyTo(t *testing.T) { func TestIntSum_AggregationTemporality(t *testing.T) { ms := NewIntSum() - ms.InitEmpty() assert.EqualValues(t, AggregationTemporalityUnspecified, ms.AggregationTemporality()) testValAggregationTemporality := AggregationTemporalityCumulative ms.SetAggregationTemporality(testValAggregationTemporality) @@ -488,7 +478,6 @@ func TestIntSum_AggregationTemporality(t *testing.T) { func TestIntSum_IsMonotonic(t *testing.T) { ms := NewIntSum() - ms.InitEmpty() assert.EqualValues(t, false, ms.IsMonotonic()) testValIsMonotonic := true ms.SetIsMonotonic(testValIsMonotonic) @@ -497,7 +486,6 @@ func TestIntSum_IsMonotonic(t *testing.T) { func TestIntSum_DataPoints(t *testing.T) { ms := NewIntSum() - ms.InitEmpty() assert.EqualValues(t, NewIntDataPointSlice(), ms.DataPoints()) fillTestIntDataPointSlice(ms.DataPoints()) testValDataPoints := generateTestIntDataPointSlice() @@ -512,7 +500,6 @@ func TestDoubleSum_CopyTo(t *testing.T) { func TestDoubleSum_AggregationTemporality(t *testing.T) { ms := NewDoubleSum() - ms.InitEmpty() assert.EqualValues(t, AggregationTemporalityUnspecified, ms.AggregationTemporality()) testValAggregationTemporality := AggregationTemporalityCumulative ms.SetAggregationTemporality(testValAggregationTemporality) @@ -521,7 +508,6 @@ func TestDoubleSum_AggregationTemporality(t *testing.T) { func TestDoubleSum_IsMonotonic(t *testing.T) { ms := NewDoubleSum() - ms.InitEmpty() assert.EqualValues(t, false, ms.IsMonotonic()) testValIsMonotonic := true ms.SetIsMonotonic(testValIsMonotonic) @@ -530,7 +516,6 @@ func TestDoubleSum_IsMonotonic(t *testing.T) { func TestDoubleSum_DataPoints(t *testing.T) { ms := NewDoubleSum() - ms.InitEmpty() assert.EqualValues(t, NewDoubleDataPointSlice(), ms.DataPoints()) fillTestDoubleDataPointSlice(ms.DataPoints()) testValDataPoints := generateTestDoubleDataPointSlice() @@ -545,7 +530,6 @@ func TestIntHistogram_CopyTo(t *testing.T) { func TestIntHistogram_AggregationTemporality(t *testing.T) { ms := NewIntHistogram() - ms.InitEmpty() assert.EqualValues(t, AggregationTemporalityUnspecified, ms.AggregationTemporality()) testValAggregationTemporality := AggregationTemporalityCumulative ms.SetAggregationTemporality(testValAggregationTemporality) @@ -554,7 +538,6 @@ func TestIntHistogram_AggregationTemporality(t *testing.T) { func TestIntHistogram_DataPoints(t *testing.T) { ms := NewIntHistogram() - ms.InitEmpty() assert.EqualValues(t, NewIntHistogramDataPointSlice(), ms.DataPoints()) fillTestIntHistogramDataPointSlice(ms.DataPoints()) testValDataPoints := generateTestIntHistogramDataPointSlice() @@ -569,7 +552,6 @@ func TestDoubleHistogram_CopyTo(t *testing.T) { func TestDoubleHistogram_AggregationTemporality(t *testing.T) { ms := NewDoubleHistogram() - ms.InitEmpty() assert.EqualValues(t, AggregationTemporalityUnspecified, ms.AggregationTemporality()) testValAggregationTemporality := AggregationTemporalityCumulative ms.SetAggregationTemporality(testValAggregationTemporality) @@ -578,7 +560,6 @@ func TestDoubleHistogram_AggregationTemporality(t *testing.T) { func TestDoubleHistogram_DataPoints(t *testing.T) { ms := NewDoubleHistogram() - ms.InitEmpty() assert.EqualValues(t, NewDoubleHistogramDataPointSlice(), ms.DataPoints()) fillTestDoubleHistogramDataPointSlice(ms.DataPoints()) testValDataPoints := generateTestDoubleHistogramDataPointSlice() @@ -593,7 +574,6 @@ func TestDoubleSummary_CopyTo(t *testing.T) { func TestDoubleSummary_DataPoints(t *testing.T) { ms := NewDoubleSummary() - ms.InitEmpty() assert.EqualValues(t, NewDoubleSummaryDataPointSlice(), ms.DataPoints()) fillTestDoubleSummaryDataPointSlice(ms.DataPoints()) testValDataPoints := generateTestDoubleSummaryDataPointSlice() @@ -721,7 +701,6 @@ func TestIntDataPoint_CopyTo(t *testing.T) { func TestIntDataPoint_LabelsMap(t *testing.T) { ms := NewIntDataPoint() - ms.InitEmpty() assert.EqualValues(t, NewStringMap(), ms.LabelsMap()) fillTestStringMap(ms.LabelsMap()) testValLabelsMap := generateTestStringMap() @@ -730,7 +709,6 @@ func TestIntDataPoint_LabelsMap(t *testing.T) { func TestIntDataPoint_StartTime(t *testing.T) { ms := NewIntDataPoint() - ms.InitEmpty() assert.EqualValues(t, TimestampUnixNano(0), ms.StartTime()) testValStartTime := TimestampUnixNano(1234567890) ms.SetStartTime(testValStartTime) @@ -739,7 +717,6 @@ func TestIntDataPoint_StartTime(t *testing.T) { func TestIntDataPoint_Timestamp(t *testing.T) { ms := NewIntDataPoint() - ms.InitEmpty() assert.EqualValues(t, TimestampUnixNano(0), ms.Timestamp()) testValTimestamp := TimestampUnixNano(1234567890) ms.SetTimestamp(testValTimestamp) @@ -748,7 +725,6 @@ func TestIntDataPoint_Timestamp(t *testing.T) { func TestIntDataPoint_Value(t *testing.T) { ms := NewIntDataPoint() - ms.InitEmpty() assert.EqualValues(t, int64(0), ms.Value()) testValValue := int64(-17) ms.SetValue(testValValue) @@ -757,7 +733,6 @@ func TestIntDataPoint_Value(t *testing.T) { func TestIntDataPoint_Exemplars(t *testing.T) { ms := NewIntDataPoint() - ms.InitEmpty() assert.EqualValues(t, NewIntExemplarSlice(), ms.Exemplars()) fillTestIntExemplarSlice(ms.Exemplars()) testValExemplars := generateTestIntExemplarSlice() @@ -885,7 +860,6 @@ func TestDoubleDataPoint_CopyTo(t *testing.T) { func TestDoubleDataPoint_LabelsMap(t *testing.T) { ms := NewDoubleDataPoint() - ms.InitEmpty() assert.EqualValues(t, NewStringMap(), ms.LabelsMap()) fillTestStringMap(ms.LabelsMap()) testValLabelsMap := generateTestStringMap() @@ -894,7 +868,6 @@ func TestDoubleDataPoint_LabelsMap(t *testing.T) { func TestDoubleDataPoint_StartTime(t *testing.T) { ms := NewDoubleDataPoint() - ms.InitEmpty() assert.EqualValues(t, TimestampUnixNano(0), ms.StartTime()) testValStartTime := TimestampUnixNano(1234567890) ms.SetStartTime(testValStartTime) @@ -903,7 +876,6 @@ func TestDoubleDataPoint_StartTime(t *testing.T) { func TestDoubleDataPoint_Timestamp(t *testing.T) { ms := NewDoubleDataPoint() - ms.InitEmpty() assert.EqualValues(t, TimestampUnixNano(0), ms.Timestamp()) testValTimestamp := TimestampUnixNano(1234567890) ms.SetTimestamp(testValTimestamp) @@ -912,7 +884,6 @@ func TestDoubleDataPoint_Timestamp(t *testing.T) { func TestDoubleDataPoint_Value(t *testing.T) { ms := NewDoubleDataPoint() - ms.InitEmpty() assert.EqualValues(t, float64(0.0), ms.Value()) testValValue := float64(17.13) ms.SetValue(testValValue) @@ -921,7 +892,6 @@ func TestDoubleDataPoint_Value(t *testing.T) { func TestDoubleDataPoint_Exemplars(t *testing.T) { ms := NewDoubleDataPoint() - ms.InitEmpty() assert.EqualValues(t, NewDoubleExemplarSlice(), ms.Exemplars()) fillTestDoubleExemplarSlice(ms.Exemplars()) testValExemplars := generateTestDoubleExemplarSlice() @@ -1049,7 +1019,6 @@ func TestIntHistogramDataPoint_CopyTo(t *testing.T) { func TestIntHistogramDataPoint_LabelsMap(t *testing.T) { ms := NewIntHistogramDataPoint() - ms.InitEmpty() assert.EqualValues(t, NewStringMap(), ms.LabelsMap()) fillTestStringMap(ms.LabelsMap()) testValLabelsMap := generateTestStringMap() @@ -1058,7 +1027,6 @@ func TestIntHistogramDataPoint_LabelsMap(t *testing.T) { func TestIntHistogramDataPoint_StartTime(t *testing.T) { ms := NewIntHistogramDataPoint() - ms.InitEmpty() assert.EqualValues(t, TimestampUnixNano(0), ms.StartTime()) testValStartTime := TimestampUnixNano(1234567890) ms.SetStartTime(testValStartTime) @@ -1067,7 +1035,6 @@ func TestIntHistogramDataPoint_StartTime(t *testing.T) { func TestIntHistogramDataPoint_Timestamp(t *testing.T) { ms := NewIntHistogramDataPoint() - ms.InitEmpty() assert.EqualValues(t, TimestampUnixNano(0), ms.Timestamp()) testValTimestamp := TimestampUnixNano(1234567890) ms.SetTimestamp(testValTimestamp) @@ -1076,7 +1043,6 @@ func TestIntHistogramDataPoint_Timestamp(t *testing.T) { func TestIntHistogramDataPoint_Count(t *testing.T) { ms := NewIntHistogramDataPoint() - ms.InitEmpty() assert.EqualValues(t, uint64(0), ms.Count()) testValCount := uint64(17) ms.SetCount(testValCount) @@ -1085,7 +1051,6 @@ func TestIntHistogramDataPoint_Count(t *testing.T) { func TestIntHistogramDataPoint_Sum(t *testing.T) { ms := NewIntHistogramDataPoint() - ms.InitEmpty() assert.EqualValues(t, int64(0.0), ms.Sum()) testValSum := int64(1713) ms.SetSum(testValSum) @@ -1094,7 +1059,6 @@ func TestIntHistogramDataPoint_Sum(t *testing.T) { func TestIntHistogramDataPoint_BucketCounts(t *testing.T) { ms := NewIntHistogramDataPoint() - ms.InitEmpty() assert.EqualValues(t, []uint64(nil), ms.BucketCounts()) testValBucketCounts := []uint64{1, 2, 3} ms.SetBucketCounts(testValBucketCounts) @@ -1103,7 +1067,6 @@ func TestIntHistogramDataPoint_BucketCounts(t *testing.T) { func TestIntHistogramDataPoint_ExplicitBounds(t *testing.T) { ms := NewIntHistogramDataPoint() - ms.InitEmpty() assert.EqualValues(t, []float64(nil), ms.ExplicitBounds()) testValExplicitBounds := []float64{1, 2, 3} ms.SetExplicitBounds(testValExplicitBounds) @@ -1112,7 +1075,6 @@ func TestIntHistogramDataPoint_ExplicitBounds(t *testing.T) { func TestIntHistogramDataPoint_Exemplars(t *testing.T) { ms := NewIntHistogramDataPoint() - ms.InitEmpty() assert.EqualValues(t, NewIntExemplarSlice(), ms.Exemplars()) fillTestIntExemplarSlice(ms.Exemplars()) testValExemplars := generateTestIntExemplarSlice() @@ -1240,7 +1202,6 @@ func TestDoubleHistogramDataPoint_CopyTo(t *testing.T) { func TestDoubleHistogramDataPoint_LabelsMap(t *testing.T) { ms := NewDoubleHistogramDataPoint() - ms.InitEmpty() assert.EqualValues(t, NewStringMap(), ms.LabelsMap()) fillTestStringMap(ms.LabelsMap()) testValLabelsMap := generateTestStringMap() @@ -1249,7 +1210,6 @@ func TestDoubleHistogramDataPoint_LabelsMap(t *testing.T) { func TestDoubleHistogramDataPoint_StartTime(t *testing.T) { ms := NewDoubleHistogramDataPoint() - ms.InitEmpty() assert.EqualValues(t, TimestampUnixNano(0), ms.StartTime()) testValStartTime := TimestampUnixNano(1234567890) ms.SetStartTime(testValStartTime) @@ -1258,7 +1218,6 @@ func TestDoubleHistogramDataPoint_StartTime(t *testing.T) { func TestDoubleHistogramDataPoint_Timestamp(t *testing.T) { ms := NewDoubleHistogramDataPoint() - ms.InitEmpty() assert.EqualValues(t, TimestampUnixNano(0), ms.Timestamp()) testValTimestamp := TimestampUnixNano(1234567890) ms.SetTimestamp(testValTimestamp) @@ -1267,7 +1226,6 @@ func TestDoubleHistogramDataPoint_Timestamp(t *testing.T) { func TestDoubleHistogramDataPoint_Count(t *testing.T) { ms := NewDoubleHistogramDataPoint() - ms.InitEmpty() assert.EqualValues(t, uint64(0), ms.Count()) testValCount := uint64(17) ms.SetCount(testValCount) @@ -1276,7 +1234,6 @@ func TestDoubleHistogramDataPoint_Count(t *testing.T) { func TestDoubleHistogramDataPoint_Sum(t *testing.T) { ms := NewDoubleHistogramDataPoint() - ms.InitEmpty() assert.EqualValues(t, float64(0.0), ms.Sum()) testValSum := float64(17.13) ms.SetSum(testValSum) @@ -1285,7 +1242,6 @@ func TestDoubleHistogramDataPoint_Sum(t *testing.T) { func TestDoubleHistogramDataPoint_BucketCounts(t *testing.T) { ms := NewDoubleHistogramDataPoint() - ms.InitEmpty() assert.EqualValues(t, []uint64(nil), ms.BucketCounts()) testValBucketCounts := []uint64{1, 2, 3} ms.SetBucketCounts(testValBucketCounts) @@ -1294,7 +1250,6 @@ func TestDoubleHistogramDataPoint_BucketCounts(t *testing.T) { func TestDoubleHistogramDataPoint_ExplicitBounds(t *testing.T) { ms := NewDoubleHistogramDataPoint() - ms.InitEmpty() assert.EqualValues(t, []float64(nil), ms.ExplicitBounds()) testValExplicitBounds := []float64{1, 2, 3} ms.SetExplicitBounds(testValExplicitBounds) @@ -1303,7 +1258,6 @@ func TestDoubleHistogramDataPoint_ExplicitBounds(t *testing.T) { func TestDoubleHistogramDataPoint_Exemplars(t *testing.T) { ms := NewDoubleHistogramDataPoint() - ms.InitEmpty() assert.EqualValues(t, NewDoubleExemplarSlice(), ms.Exemplars()) fillTestDoubleExemplarSlice(ms.Exemplars()) testValExemplars := generateTestDoubleExemplarSlice() @@ -1431,7 +1385,6 @@ func TestDoubleSummaryDataPoint_CopyTo(t *testing.T) { func TestDoubleSummaryDataPoint_LabelsMap(t *testing.T) { ms := NewDoubleSummaryDataPoint() - ms.InitEmpty() assert.EqualValues(t, NewStringMap(), ms.LabelsMap()) fillTestStringMap(ms.LabelsMap()) testValLabelsMap := generateTestStringMap() @@ -1440,7 +1393,6 @@ func TestDoubleSummaryDataPoint_LabelsMap(t *testing.T) { func TestDoubleSummaryDataPoint_StartTime(t *testing.T) { ms := NewDoubleSummaryDataPoint() - ms.InitEmpty() assert.EqualValues(t, TimestampUnixNano(0), ms.StartTime()) testValStartTime := TimestampUnixNano(1234567890) ms.SetStartTime(testValStartTime) @@ -1449,7 +1401,6 @@ func TestDoubleSummaryDataPoint_StartTime(t *testing.T) { func TestDoubleSummaryDataPoint_Timestamp(t *testing.T) { ms := NewDoubleSummaryDataPoint() - ms.InitEmpty() assert.EqualValues(t, TimestampUnixNano(0), ms.Timestamp()) testValTimestamp := TimestampUnixNano(1234567890) ms.SetTimestamp(testValTimestamp) @@ -1458,7 +1409,6 @@ func TestDoubleSummaryDataPoint_Timestamp(t *testing.T) { func TestDoubleSummaryDataPoint_Count(t *testing.T) { ms := NewDoubleSummaryDataPoint() - ms.InitEmpty() assert.EqualValues(t, uint64(0), ms.Count()) testValCount := uint64(17) ms.SetCount(testValCount) @@ -1467,7 +1417,6 @@ func TestDoubleSummaryDataPoint_Count(t *testing.T) { func TestDoubleSummaryDataPoint_Sum(t *testing.T) { ms := NewDoubleSummaryDataPoint() - ms.InitEmpty() assert.EqualValues(t, float64(0.0), ms.Sum()) testValSum := float64(17.13) ms.SetSum(testValSum) @@ -1476,7 +1425,6 @@ func TestDoubleSummaryDataPoint_Sum(t *testing.T) { func TestDoubleSummaryDataPoint_QuantileValues(t *testing.T) { ms := NewDoubleSummaryDataPoint() - ms.InitEmpty() assert.EqualValues(t, NewValueAtQuantileSlice(), ms.QuantileValues()) fillTestValueAtQuantileSlice(ms.QuantileValues()) testValQuantileValues := generateTestValueAtQuantileSlice() @@ -1604,7 +1552,6 @@ func TestValueAtQuantile_CopyTo(t *testing.T) { func TestValueAtQuantile_Quantile(t *testing.T) { ms := NewValueAtQuantile() - ms.InitEmpty() assert.EqualValues(t, float64(0.0), ms.Quantile()) testValQuantile := float64(17.13) ms.SetQuantile(testValQuantile) @@ -1613,7 +1560,6 @@ func TestValueAtQuantile_Quantile(t *testing.T) { func TestValueAtQuantile_Value(t *testing.T) { ms := NewValueAtQuantile() - ms.InitEmpty() assert.EqualValues(t, float64(0.0), ms.Value()) testValValue := float64(17.13) ms.SetValue(testValValue) @@ -1741,7 +1687,6 @@ func TestIntExemplar_CopyTo(t *testing.T) { func TestIntExemplar_Timestamp(t *testing.T) { ms := NewIntExemplar() - ms.InitEmpty() assert.EqualValues(t, TimestampUnixNano(0), ms.Timestamp()) testValTimestamp := TimestampUnixNano(1234567890) ms.SetTimestamp(testValTimestamp) @@ -1750,7 +1695,6 @@ func TestIntExemplar_Timestamp(t *testing.T) { func TestIntExemplar_Value(t *testing.T) { ms := NewIntExemplar() - ms.InitEmpty() assert.EqualValues(t, int64(0), ms.Value()) testValValue := int64(-17) ms.SetValue(testValValue) @@ -1759,7 +1703,6 @@ func TestIntExemplar_Value(t *testing.T) { func TestIntExemplar_FilteredLabels(t *testing.T) { ms := NewIntExemplar() - ms.InitEmpty() assert.EqualValues(t, NewStringMap(), ms.FilteredLabels()) fillTestStringMap(ms.FilteredLabels()) testValFilteredLabels := generateTestStringMap() @@ -1887,7 +1830,6 @@ func TestDoubleExemplar_CopyTo(t *testing.T) { func TestDoubleExemplar_Timestamp(t *testing.T) { ms := NewDoubleExemplar() - ms.InitEmpty() assert.EqualValues(t, TimestampUnixNano(0), ms.Timestamp()) testValTimestamp := TimestampUnixNano(1234567890) ms.SetTimestamp(testValTimestamp) @@ -1896,7 +1838,6 @@ func TestDoubleExemplar_Timestamp(t *testing.T) { func TestDoubleExemplar_Value(t *testing.T) { ms := NewDoubleExemplar() - ms.InitEmpty() assert.EqualValues(t, float64(0.0), ms.Value()) testValValue := float64(17.13) ms.SetValue(testValValue) @@ -1905,7 +1846,6 @@ func TestDoubleExemplar_Value(t *testing.T) { func TestDoubleExemplar_FilteredLabels(t *testing.T) { ms := NewDoubleExemplar() - ms.InitEmpty() assert.EqualValues(t, NewStringMap(), ms.FilteredLabels()) fillTestStringMap(ms.FilteredLabels()) testValFilteredLabels := generateTestStringMap() @@ -1984,7 +1924,6 @@ func fillTestMetric(tv Metric) { tv.SetDescription("test_description") tv.SetUnit("1") (*tv.orig).Data = &otlpmetrics.Metric_IntGauge{IntGauge: &otlpmetrics.IntGauge{}} - tv.IntGauge().InitEmpty() fillTestIntGauge(tv.IntGauge()) } diff --git a/consumer/pdata/generated_resource.go b/consumer/pdata/generated_resource.go index e8e7e75bc53..d50abb781e6 100644 --- a/consumer/pdata/generated_resource.go +++ b/consumer/pdata/generated_resource.go @@ -43,11 +43,6 @@ func NewResource() Resource { return newResource(&otlpresource.Resource{}) } -// Deprecated: This function will be removed soon. -func (ms Resource) InitEmpty() { - *ms.orig = otlpresource.Resource{} -} - // Attributes returns the Attributes associated with this Resource. // // Important: This causes a runtime error if IsNil() returns "true". diff --git a/consumer/pdata/generated_resource_test.go b/consumer/pdata/generated_resource_test.go index a74781ca262..cff3992e35f 100644 --- a/consumer/pdata/generated_resource_test.go +++ b/consumer/pdata/generated_resource_test.go @@ -31,7 +31,6 @@ func TestResource_CopyTo(t *testing.T) { func TestResource_Attributes(t *testing.T) { ms := NewResource() - ms.InitEmpty() assert.EqualValues(t, NewAttributeMap(), ms.Attributes()) fillTestAttributeMap(ms.Attributes()) testValAttributes := generateTestAttributeMap() diff --git a/consumer/pdata/generated_trace.go b/consumer/pdata/generated_trace.go index b904c6381e9..2158d3ebf79 100644 --- a/consumer/pdata/generated_trace.go +++ b/consumer/pdata/generated_trace.go @@ -158,11 +158,6 @@ func NewResourceSpans() ResourceSpans { return newResourceSpans(&otlptrace.ResourceSpans{}) } -// Deprecated: This function will be removed soon. -func (ms ResourceSpans) InitEmpty() { - *ms.orig = otlptrace.ResourceSpans{} -} - // Resource returns the resource associated with this ResourceSpans. // // Important: This causes a runtime error if IsNil() returns "true". @@ -319,11 +314,6 @@ func NewInstrumentationLibrarySpans() InstrumentationLibrarySpans { return newInstrumentationLibrarySpans(&otlptrace.InstrumentationLibrarySpans{}) } -// Deprecated: This function will be removed soon. -func (ms InstrumentationLibrarySpans) InitEmpty() { - *ms.orig = otlptrace.InstrumentationLibrarySpans{} -} - // InstrumentationLibrary returns the instrumentationlibrary associated with this InstrumentationLibrarySpans. // // Important: This causes a runtime error if IsNil() returns "true". @@ -481,11 +471,6 @@ func NewSpan() Span { return newSpan(&otlptrace.Span{}) } -// Deprecated: This function will be removed soon. -func (ms Span) InitEmpty() { - *ms.orig = otlptrace.Span{} -} - // TraceID returns the traceid associated with this Span. // // Important: This causes a runtime error if IsNil() returns "true". @@ -824,11 +809,6 @@ func NewSpanEvent() SpanEvent { return newSpanEvent(&otlptrace.Span_Event{}) } -// Deprecated: This function will be removed soon. -func (ms SpanEvent) InitEmpty() { - *ms.orig = otlptrace.Span_Event{} -} - // Timestamp returns the timestamp associated with this SpanEvent. // // Important: This causes a runtime error if IsNil() returns "true". @@ -1023,11 +1003,6 @@ func NewSpanLink() SpanLink { return newSpanLink(&otlptrace.Span_Link{}) } -// Deprecated: This function will be removed soon. -func (ms SpanLink) InitEmpty() { - *ms.orig = otlptrace.Span_Link{} -} - // TraceID returns the traceid associated with this SpanLink. // // Important: This causes a runtime error if IsNil() returns "true". @@ -1123,11 +1098,6 @@ func NewSpanStatus() SpanStatus { return newSpanStatus(&otlptrace.Status{}) } -// Deprecated: This function will be removed soon. -func (ms SpanStatus) InitEmpty() { - *ms.orig = otlptrace.Status{} -} - // Code returns the code associated with this SpanStatus. // // Important: This causes a runtime error if IsNil() returns "true". diff --git a/consumer/pdata/generated_trace_test.go b/consumer/pdata/generated_trace_test.go index 2d382037f6a..c3188829bdc 100644 --- a/consumer/pdata/generated_trace_test.go +++ b/consumer/pdata/generated_trace_test.go @@ -146,14 +146,12 @@ func TestResourceSpans_CopyTo(t *testing.T) { func TestResourceSpans_Resource(t *testing.T) { ms := NewResourceSpans() - ms.InitEmpty() fillTestResource(ms.Resource()) assert.EqualValues(t, generateTestResource(), ms.Resource()) } func TestResourceSpans_InstrumentationLibrarySpans(t *testing.T) { ms := NewResourceSpans() - ms.InitEmpty() assert.EqualValues(t, NewInstrumentationLibrarySpansSlice(), ms.InstrumentationLibrarySpans()) fillTestInstrumentationLibrarySpansSlice(ms.InstrumentationLibrarySpans()) testValInstrumentationLibrarySpans := generateTestInstrumentationLibrarySpansSlice() @@ -281,14 +279,12 @@ func TestInstrumentationLibrarySpans_CopyTo(t *testing.T) { func TestInstrumentationLibrarySpans_InstrumentationLibrary(t *testing.T) { ms := NewInstrumentationLibrarySpans() - ms.InitEmpty() fillTestInstrumentationLibrary(ms.InstrumentationLibrary()) assert.EqualValues(t, generateTestInstrumentationLibrary(), ms.InstrumentationLibrary()) } func TestInstrumentationLibrarySpans_Spans(t *testing.T) { ms := NewInstrumentationLibrarySpans() - ms.InitEmpty() assert.EqualValues(t, NewSpanSlice(), ms.Spans()) fillTestSpanSlice(ms.Spans()) testValSpans := generateTestSpanSlice() @@ -416,7 +412,6 @@ func TestSpan_CopyTo(t *testing.T) { func TestSpan_TraceID(t *testing.T) { ms := NewSpan() - ms.InitEmpty() assert.EqualValues(t, NewTraceID([16]byte{}), ms.TraceID()) testValTraceID := NewTraceID([16]byte{1, 2, 3, 4, 5, 6, 7, 8, 8, 7, 6, 5, 4, 3, 2, 1}) ms.SetTraceID(testValTraceID) @@ -425,7 +420,6 @@ func TestSpan_TraceID(t *testing.T) { func TestSpan_SpanID(t *testing.T) { ms := NewSpan() - ms.InitEmpty() assert.EqualValues(t, NewSpanID([8]byte{}), ms.SpanID()) testValSpanID := NewSpanID([8]byte{1, 2, 3, 4, 5, 6, 7, 8}) ms.SetSpanID(testValSpanID) @@ -434,7 +428,6 @@ func TestSpan_SpanID(t *testing.T) { func TestSpan_TraceState(t *testing.T) { ms := NewSpan() - ms.InitEmpty() assert.EqualValues(t, TraceState(""), ms.TraceState()) testValTraceState := TraceState("congo=congos") ms.SetTraceState(testValTraceState) @@ -443,7 +436,6 @@ func TestSpan_TraceState(t *testing.T) { func TestSpan_ParentSpanID(t *testing.T) { ms := NewSpan() - ms.InitEmpty() assert.EqualValues(t, NewSpanID([8]byte{}), ms.ParentSpanID()) testValParentSpanID := NewSpanID([8]byte{8, 7, 6, 5, 4, 3, 2, 1}) ms.SetParentSpanID(testValParentSpanID) @@ -452,7 +444,6 @@ func TestSpan_ParentSpanID(t *testing.T) { func TestSpan_Name(t *testing.T) { ms := NewSpan() - ms.InitEmpty() assert.EqualValues(t, "", ms.Name()) testValName := "test_name" ms.SetName(testValName) @@ -461,7 +452,6 @@ func TestSpan_Name(t *testing.T) { func TestSpan_Kind(t *testing.T) { ms := NewSpan() - ms.InitEmpty() assert.EqualValues(t, SpanKindUNSPECIFIED, ms.Kind()) testValKind := SpanKindSERVER ms.SetKind(testValKind) @@ -470,7 +460,6 @@ func TestSpan_Kind(t *testing.T) { func TestSpan_StartTime(t *testing.T) { ms := NewSpan() - ms.InitEmpty() assert.EqualValues(t, TimestampUnixNano(0), ms.StartTime()) testValStartTime := TimestampUnixNano(1234567890) ms.SetStartTime(testValStartTime) @@ -479,7 +468,6 @@ func TestSpan_StartTime(t *testing.T) { func TestSpan_EndTime(t *testing.T) { ms := NewSpan() - ms.InitEmpty() assert.EqualValues(t, TimestampUnixNano(0), ms.EndTime()) testValEndTime := TimestampUnixNano(1234567890) ms.SetEndTime(testValEndTime) @@ -488,7 +476,6 @@ func TestSpan_EndTime(t *testing.T) { func TestSpan_Attributes(t *testing.T) { ms := NewSpan() - ms.InitEmpty() assert.EqualValues(t, NewAttributeMap(), ms.Attributes()) fillTestAttributeMap(ms.Attributes()) testValAttributes := generateTestAttributeMap() @@ -497,7 +484,6 @@ func TestSpan_Attributes(t *testing.T) { func TestSpan_DroppedAttributesCount(t *testing.T) { ms := NewSpan() - ms.InitEmpty() assert.EqualValues(t, uint32(0), ms.DroppedAttributesCount()) testValDroppedAttributesCount := uint32(17) ms.SetDroppedAttributesCount(testValDroppedAttributesCount) @@ -506,7 +492,6 @@ func TestSpan_DroppedAttributesCount(t *testing.T) { func TestSpan_Events(t *testing.T) { ms := NewSpan() - ms.InitEmpty() assert.EqualValues(t, NewSpanEventSlice(), ms.Events()) fillTestSpanEventSlice(ms.Events()) testValEvents := generateTestSpanEventSlice() @@ -515,7 +500,6 @@ func TestSpan_Events(t *testing.T) { func TestSpan_DroppedEventsCount(t *testing.T) { ms := NewSpan() - ms.InitEmpty() assert.EqualValues(t, uint32(0), ms.DroppedEventsCount()) testValDroppedEventsCount := uint32(17) ms.SetDroppedEventsCount(testValDroppedEventsCount) @@ -524,7 +508,6 @@ func TestSpan_DroppedEventsCount(t *testing.T) { func TestSpan_Links(t *testing.T) { ms := NewSpan() - ms.InitEmpty() assert.EqualValues(t, NewSpanLinkSlice(), ms.Links()) fillTestSpanLinkSlice(ms.Links()) testValLinks := generateTestSpanLinkSlice() @@ -533,7 +516,6 @@ func TestSpan_Links(t *testing.T) { func TestSpan_DroppedLinksCount(t *testing.T) { ms := NewSpan() - ms.InitEmpty() assert.EqualValues(t, uint32(0), ms.DroppedLinksCount()) testValDroppedLinksCount := uint32(17) ms.SetDroppedLinksCount(testValDroppedLinksCount) @@ -542,7 +524,6 @@ func TestSpan_DroppedLinksCount(t *testing.T) { func TestSpan_Status(t *testing.T) { ms := NewSpan() - ms.InitEmpty() fillTestSpanStatus(ms.Status()) assert.EqualValues(t, generateTestSpanStatus(), ms.Status()) } @@ -668,7 +649,6 @@ func TestSpanEvent_CopyTo(t *testing.T) { func TestSpanEvent_Timestamp(t *testing.T) { ms := NewSpanEvent() - ms.InitEmpty() assert.EqualValues(t, TimestampUnixNano(0), ms.Timestamp()) testValTimestamp := TimestampUnixNano(1234567890) ms.SetTimestamp(testValTimestamp) @@ -677,7 +657,6 @@ func TestSpanEvent_Timestamp(t *testing.T) { func TestSpanEvent_Name(t *testing.T) { ms := NewSpanEvent() - ms.InitEmpty() assert.EqualValues(t, "", ms.Name()) testValName := "test_name" ms.SetName(testValName) @@ -686,7 +665,6 @@ func TestSpanEvent_Name(t *testing.T) { func TestSpanEvent_Attributes(t *testing.T) { ms := NewSpanEvent() - ms.InitEmpty() assert.EqualValues(t, NewAttributeMap(), ms.Attributes()) fillTestAttributeMap(ms.Attributes()) testValAttributes := generateTestAttributeMap() @@ -695,7 +673,6 @@ func TestSpanEvent_Attributes(t *testing.T) { func TestSpanEvent_DroppedAttributesCount(t *testing.T) { ms := NewSpanEvent() - ms.InitEmpty() assert.EqualValues(t, uint32(0), ms.DroppedAttributesCount()) testValDroppedAttributesCount := uint32(17) ms.SetDroppedAttributesCount(testValDroppedAttributesCount) @@ -823,7 +800,6 @@ func TestSpanLink_CopyTo(t *testing.T) { func TestSpanLink_TraceID(t *testing.T) { ms := NewSpanLink() - ms.InitEmpty() assert.EqualValues(t, NewTraceID([16]byte{}), ms.TraceID()) testValTraceID := NewTraceID([16]byte{1, 2, 3, 4, 5, 6, 7, 8, 8, 7, 6, 5, 4, 3, 2, 1}) ms.SetTraceID(testValTraceID) @@ -832,7 +808,6 @@ func TestSpanLink_TraceID(t *testing.T) { func TestSpanLink_SpanID(t *testing.T) { ms := NewSpanLink() - ms.InitEmpty() assert.EqualValues(t, NewSpanID([8]byte{}), ms.SpanID()) testValSpanID := NewSpanID([8]byte{1, 2, 3, 4, 5, 6, 7, 8}) ms.SetSpanID(testValSpanID) @@ -841,7 +816,6 @@ func TestSpanLink_SpanID(t *testing.T) { func TestSpanLink_TraceState(t *testing.T) { ms := NewSpanLink() - ms.InitEmpty() assert.EqualValues(t, TraceState(""), ms.TraceState()) testValTraceState := TraceState("congo=congos") ms.SetTraceState(testValTraceState) @@ -850,7 +824,6 @@ func TestSpanLink_TraceState(t *testing.T) { func TestSpanLink_Attributes(t *testing.T) { ms := NewSpanLink() - ms.InitEmpty() assert.EqualValues(t, NewAttributeMap(), ms.Attributes()) fillTestAttributeMap(ms.Attributes()) testValAttributes := generateTestAttributeMap() @@ -859,7 +832,6 @@ func TestSpanLink_Attributes(t *testing.T) { func TestSpanLink_DroppedAttributesCount(t *testing.T) { ms := NewSpanLink() - ms.InitEmpty() assert.EqualValues(t, uint32(0), ms.DroppedAttributesCount()) testValDroppedAttributesCount := uint32(17) ms.SetDroppedAttributesCount(testValDroppedAttributesCount) @@ -874,7 +846,6 @@ func TestSpanStatus_CopyTo(t *testing.T) { func TestSpanStatus_Code(t *testing.T) { ms := NewSpanStatus() - ms.InitEmpty() assert.EqualValues(t, StatusCode(0), ms.Code()) testValCode := StatusCode(1) ms.SetCode(testValCode) @@ -883,7 +854,6 @@ func TestSpanStatus_Code(t *testing.T) { func TestSpanStatus_DeprecatedCode(t *testing.T) { ms := NewSpanStatus() - ms.InitEmpty() assert.EqualValues(t, DeprecatedStatusCode(0), ms.DeprecatedCode()) testValDeprecatedCode := DeprecatedStatusCode(1) ms.SetDeprecatedCode(testValDeprecatedCode) @@ -892,7 +862,6 @@ func TestSpanStatus_DeprecatedCode(t *testing.T) { func TestSpanStatus_Message(t *testing.T) { ms := NewSpanStatus() - ms.InitEmpty() assert.EqualValues(t, "", ms.Message()) testValMessage := "cancelled" ms.SetMessage(testValMessage) diff --git a/consumer/pdata/trace_test.go b/consumer/pdata/trace_test.go index 2b554b45b97..a404f2cda3e 100644 --- a/consumer/pdata/trace_test.go +++ b/consumer/pdata/trace_test.go @@ -115,7 +115,6 @@ func TestSpanStatusCode(t *testing.T) { rss.At(0).InstrumentationLibrarySpans().Resize(1) rss.At(0).InstrumentationLibrarySpans().At(0).Spans().Resize(1) status := rss.At(0).InstrumentationLibrarySpans().At(0).Spans().At(0).Status() - status.InitEmpty() // Check handling of deprecated status code, see spec here: // https://github.com/open-telemetry/opentelemetry-proto/blob/59c488bfb8fb6d0458ad6425758b70259ff4a2bd/opentelemetry/proto/trace/v1/trace.proto#L231 diff --git a/docs/roadmap.md b/docs/roadmap.md index 02cd8459f9c..7583ca36943 100644 --- a/docs/roadmap.md +++ b/docs/roadmap.md @@ -1,9 +1,9 @@ # Long-term Roadmap -This is the long-term, draft Roadmap. Note that this a vision document that reflects our +This long-term roadmap (draft) is a vision document that reflects our current desires. It is not a commitment to implement everything listed in this roadmap. -The primary purpose of this document is to ensure all contributors work in alignment. -As our vision changes over time maintainers reserve the right to add, modify, and _remove_ +The primary purpose of this document is to ensure that all contributors work in alignment. +As our vision changes over time, maintainers reserve the right to add, modify, and _remove_ items from this roadmap. Description|Status|Links| diff --git a/examples/demo/app/go.mod b/examples/demo/app/go.mod index b8852feefcb..2fc4514de37 100644 --- a/examples/demo/app/go.mod +++ b/examples/demo/app/go.mod @@ -6,9 +6,9 @@ require ( github.com/davecgh/go-spew v1.1.1 // indirect github.com/golang/protobuf v1.4.3 // indirect github.com/kr/pretty v0.1.0 // indirect - go.opentelemetry.io/otel v0.14.0 + go.opentelemetry.io/otel v0.15.0 go.opentelemetry.io/otel/exporters/otlp v0.14.0 - go.opentelemetry.io/otel/sdk v0.14.0 + go.opentelemetry.io/otel/sdk v0.15.0 golang.org/x/net v0.0.0-20200625001655-4c5254603344 // indirect golang.org/x/sys v0.0.0-20201015000850-e3ed0017c211 // indirect golang.org/x/text v0.3.3 // indirect diff --git a/examples/demo/app/go.sum b/examples/demo/app/go.sum index 464a7b5777f..68bbba58267 100644 --- a/examples/demo/app/go.sum +++ b/examples/demo/app/go.sum @@ -39,6 +39,8 @@ github.com/google/go-cmp v0.4.0/go.mod h1:v8dTdLbMG2kIc/vJvl+f65V22dbkXbowE6jgT/ github.com/google/go-cmp v0.5.0/go.mod h1:v8dTdLbMG2kIc/vJvl+f65V22dbkXbowE6jgT/gNBxE= github.com/google/go-cmp v0.5.3 h1:x95R7cp+rSeeqAMI2knLtQ0DKlaBhv2NrtrOvafPHRo= github.com/google/go-cmp v0.5.3/go.mod h1:v8dTdLbMG2kIc/vJvl+f65V22dbkXbowE6jgT/gNBxE= +github.com/google/go-cmp v0.5.4 h1:L8R9j+yAqZuZjsqh/z+F1NCffTKKLShY6zXTItVIZ8M= +github.com/google/go-cmp v0.5.4/go.mod h1:v8dTdLbMG2kIc/vJvl+f65V22dbkXbowE6jgT/gNBxE= github.com/google/gofuzz v1.1.0 h1:Hsa8mG0dQ46ij8Sl2AYJDUv1oA9/d6Vk+3LG99Oe02g= github.com/google/gofuzz v1.1.0/go.mod h1:dBl0BpW6vV/+mYPU4Po3pmUjxk6FQPldtuIdl/M65Eg= github.com/google/uuid v1.1.2/go.mod h1:TIyPZe4MgqvfeYDBFedMoGGpEw/LqOeaOT+nhxU+yHo= @@ -58,10 +60,14 @@ github.com/stretchr/testify v1.6.1 h1:hDPOHmpOpP40lSULcqw7IrRb/u7w6RpDC9399XyoNd github.com/stretchr/testify v1.6.1/go.mod h1:6Fq8oRcR53rry900zMqJjRRixrwX3KX962/h/Wwjteg= go.opentelemetry.io/otel v0.14.0 h1:YFBEfjCk9MTjaytCNSUkp9Q8lF7QJezA06T71FbQxLQ= go.opentelemetry.io/otel v0.14.0/go.mod h1:vH5xEuwy7Rts0GNtsCW3HYQoZDY+OmBJ6t1bFGGlxgw= +go.opentelemetry.io/otel v0.15.0 h1:CZFy2lPhxd4HlhZnYK8gRyDotksO3Ip9rBweY1vVYJw= +go.opentelemetry.io/otel v0.15.0/go.mod h1:e4GKElweB8W2gWUqbghw0B8t5MCTccc9212eNHnOHwA= go.opentelemetry.io/otel/exporters/otlp v0.14.0 h1:B5uCGwaThlJMVpCeOxRkiVeOhT2t0GcZp8G+x219W5k= go.opentelemetry.io/otel/exporters/otlp v0.14.0/go.mod h1:DmFebmd697PT2nIQ6t6p1tx9KQFu+R2PGd+3W62OkAE= go.opentelemetry.io/otel/sdk v0.14.0 h1:Pqgd85y5XhyvHQlOxkKW+FD4DAX7AoeaNIDKC2VhfHQ= go.opentelemetry.io/otel/sdk v0.14.0/go.mod h1:kGO5pEMSNqSJppHAm8b73zztLxB5fgDQnD56/dl5xqE= +go.opentelemetry.io/otel/sdk v0.15.0 h1:Hf2dl1Ad9Hn03qjcAuAq51GP5Pv1SV5puIkS2nRhdd8= +go.opentelemetry.io/otel/sdk v0.15.0/go.mod h1:Qudkwgq81OcA9GYVlbyZ62wkLieeS1eWxIL0ufxgwoc= golang.org/x/crypto v0.0.0-20190308221718-c2843e01d9a2/go.mod h1:djNgcEr1/C05ACkg1iLfiJU5Ep61QUkGW8qpdssI0+w= golang.org/x/crypto v0.0.0-20200622213623-75b288015ac9/go.mod h1:LzIPMQfyMNhhGPhUkYOs5KpL4U8rLKemX1yGLhDgUto= golang.org/x/exp v0.0.0-20190121172915-509febef88a4/go.mod h1:CJ0aWSM057203Lf6IL+f9T1iT9GByDxfZKAQTCR3kQA= diff --git a/examples/demo/app/main.go b/examples/demo/app/main.go index 450d007392c..3476d88ea9c 100644 --- a/examples/demo/app/main.go +++ b/examples/demo/app/main.go @@ -87,8 +87,8 @@ func initProvider() func() { return func() { handleErr(tracerProvider.Shutdown(ctx), "failed to shutdown provider") - handleErr(exp.Shutdown(ctx), "failed to stop exporter") pusher.Stop() // pushes any last exports to the receiver + handleErr(exp.Shutdown(ctx), "failed to stop exporter") } } diff --git a/exporter/loggingexporter/logging_exporter.go b/exporter/loggingexporter/logging_exporter.go index 0e59d869e05..fbc1dd7e8cd 100644 --- a/exporter/loggingexporter/logging_exporter.go +++ b/exporter/loggingexporter/logging_exporter.go @@ -394,7 +394,7 @@ func (s *loggingExporter) pushMetricsData( // received data and logs debugging messages. func newTraceExporter(config configmodels.Exporter, level string, logger *zap.Logger) (component.TracesExporter, error) { s := &loggingExporter{ - debug: level == "debug", + debug: strings.ToLower(level) == "debug", logger: logger, } @@ -414,7 +414,7 @@ func newTraceExporter(config configmodels.Exporter, level string, logger *zap.Lo // received data and logs debugging messages. func newMetricsExporter(config configmodels.Exporter, level string, logger *zap.Logger) (component.MetricsExporter, error) { s := &loggingExporter{ - debug: level == "debug", + debug: strings.ToLower(level) == "debug", logger: logger, } @@ -434,7 +434,7 @@ func newMetricsExporter(config configmodels.Exporter, level string, logger *zap. // received data and logs debugging messages. func newLogsExporter(config configmodels.Exporter, level string, logger *zap.Logger) (component.LogsExporter, error) { s := &loggingExporter{ - debug: level == "debug", + debug: strings.ToLower(level) == "debug", logger: logger, } diff --git a/exporter/loggingexporter/logging_exporter_test.go b/exporter/loggingexporter/logging_exporter_test.go index a0c3bbba359..0f839264471 100644 --- a/exporter/loggingexporter/logging_exporter_test.go +++ b/exporter/loggingexporter/logging_exporter_test.go @@ -27,7 +27,7 @@ import ( ) func TestLoggingTraceExporterNoErrors(t *testing.T) { - lte, err := newTraceExporter(&configmodels.ExporterSettings{}, "debug", zap.NewNop()) + lte, err := newTraceExporter(&configmodels.ExporterSettings{}, "Debug", zap.NewNop()) require.NotNil(t, lte) assert.NoError(t, err) @@ -38,7 +38,7 @@ func TestLoggingTraceExporterNoErrors(t *testing.T) { } func TestLoggingMetricsExporterNoErrors(t *testing.T) { - lme, err := newMetricsExporter(&configmodels.ExporterSettings{}, "debug", zap.NewNop()) + lme, err := newMetricsExporter(&configmodels.ExporterSettings{}, "DEBUG", zap.NewNop()) require.NotNil(t, lme) assert.NoError(t, err) diff --git a/exporter/prometheusremotewriteexporter/README.md b/exporter/prometheusremotewriteexporter/README.md index 42a55337187..28e487f2f12 100644 --- a/exporter/prometheusremotewriteexporter/README.md +++ b/exporter/prometheusremotewriteexporter/README.md @@ -33,8 +33,8 @@ As a result, the following parameters are also required: The following settings can be optionally configured: - `external_labels`: list of labels to be attached to each metric data point -- `headers`: additional headers attached to each HTTP request. If - `X-Prometheus-Remote-Write-Version` is set, its value must be `0.1.0` +- `headers`: additional headers attached to each HTTP request. + - *Note the following headers cannot be changed: `Content-Encoding`, `Content-Type`, `X-Prometheus-Remote-Write-Version`, and `User-Agent`.* - `namespace`: prefix attached to each exported metric name. Example: diff --git a/exporter/prometheusremotewriteexporter/config_test.go b/exporter/prometheusremotewriteexporter/config_test.go index 6c4c29701cc..cfc7a9e638c 100644 --- a/exporter/prometheusremotewriteexporter/config_test.go +++ b/exporter/prometheusremotewriteexporter/config_test.go @@ -76,12 +76,9 @@ func Test_loadConfig(t *testing.T) { }, Insecure: false, }, - ReadBufferSize: 0, - + ReadBufferSize: 0, WriteBufferSize: 512 * 1024, - - Timeout: 5 * time.Second, - + Timeout: 5 * time.Second, Headers: map[string]string{ "prometheus-remote-write-version": "0.1.0", "x-scope-orgid": "234"}, diff --git a/exporter/prometheusremotewriteexporter/exporter.go b/exporter/prometheusremotewriteexporter/exporter.go index 00d88e5e9bd..e56143c9f40 100644 --- a/exporter/prometheusremotewriteexporter/exporter.go +++ b/exporter/prometheusremotewriteexporter/exporter.go @@ -12,7 +12,7 @@ // See the License for the specific language governing permissions and // limitations under the License. -// Note: implementation for this class is in a separate PR +// Package prometheusremotewriteexporter implements an exporter that sends Prometheus remote write requests. package prometheusremotewriteexporter import ( @@ -22,6 +22,7 @@ import ( "errors" "fmt" "io" + "math" "net/http" "net/url" "sync" @@ -37,7 +38,12 @@ import ( "go.opentelemetry.io/collector/internal/version" ) -// PrwExporter converts OTLP metrics to Prometheus remote write TimeSeries and sends them to a remote endpoint +const ( + maxConcurrentRequests = 5 + maxBatchByteSize = 3000000 +) + +// PrwExporter converts OTLP metrics to Prometheus remote write TimeSeries and sends them to a remote endpoint. type PrwExporter struct { namespace string externalLabels map[string]string @@ -50,7 +56,6 @@ type PrwExporter struct { // NewPrwExporter initializes a new PrwExporter instance and sets fields accordingly. // client parameter cannot be nil. func NewPrwExporter(namespace string, endpoint string, client *http.Client, externalLabels map[string]string) (*PrwExporter, error) { - if client == nil { return nil, errors.New("http client cannot be nil") } @@ -89,6 +94,7 @@ func (prwe *PrwExporter) Shutdown(context.Context) error { func (prwe *PrwExporter) PushMetrics(ctx context.Context, md pdata.Metrics) (int, error) { prwe.wg.Add(1) defer prwe.wg.Done() + select { case <-prwe.closeChan: return md.MetricCount(), errors.New("shutdown has been called") @@ -143,9 +149,9 @@ func (prwe *PrwExporter) PushMetrics(ctx context.Context, md pdata.Metrics) (int } } - if err := prwe.export(ctx, tsMap); err != nil { + if exportErrors := prwe.export(ctx, tsMap); len(exportErrors) != 0 { dropped = md.MetricCount() - errs = append(errs, consumererror.Permanent(err)) + errs = append(errs, exportErrors...) } if dropped != 0 { @@ -179,7 +185,6 @@ func validateAndSanitizeExternalLabels(externalLabels map[string]string) (map[st // its corresponding TimeSeries in tsMap. // tsMap and metric cannot be nil, and metric must have a non-nil descriptor func (prwe *PrwExporter) handleScalarMetric(tsMap map[string]*prompb.TimeSeries, metric *otlp.Metric) error { - switch metric.Data.(type) { // int points case *otlp.Metric_DoubleGauge: @@ -218,7 +223,6 @@ func (prwe *PrwExporter) handleScalarMetric(tsMap map[string]*prompb.TimeSeries, // bucket of every data point as a Sample, and adding each Sample to its corresponding TimeSeries. // tsMap and metric cannot be nil. func (prwe *PrwExporter) handleHistogramMetric(tsMap map[string]*prompb.TimeSeries, metric *otlp.Metric) error { - switch metric.Data.(type) { case *otlp.Metric_IntHistogram: if metric.GetIntHistogram().GetDataPoints() == nil { @@ -252,15 +256,51 @@ func (prwe *PrwExporter) handleSummaryMetric(tsMap map[string]*prompb.TimeSeries } // export sends a Snappy-compressed WriteRequest containing TimeSeries to a remote write endpoint in order -func (prwe *PrwExporter) export(ctx context.Context, tsMap map[string]*prompb.TimeSeries) error { - // Calls the helper function to convert the TsMap to the desired format - req, err := wrapTimeSeries(tsMap) +func (prwe *PrwExporter) export(ctx context.Context, tsMap map[string]*prompb.TimeSeries) []error { + var errs []error + // Calls the helper function to convert and batch the TsMap to the desired format + requests, err := batchTimeSeries(tsMap, maxBatchByteSize) if err != nil { - return consumererror.Permanent(err) + errs = append(errs, consumererror.Permanent(err)) + return errs + } + + input := make(chan *prompb.WriteRequest, len(requests)) + for _, request := range requests { + input <- request + } + close(input) + + var mu sync.Mutex + var wg sync.WaitGroup + + concurrencyLimit := int(math.Min(maxConcurrentRequests, float64(len(requests)))) + wg.Add(concurrencyLimit) // used to wait for workers to be finished + + // Run concurrencyLimit of workers until there + // is no more requests to execute in the input channel. + for i := 0; i < concurrencyLimit; i++ { + go func() { + defer wg.Done() + + for request := range input { + err := prwe.execute(ctx, request) + if err != nil { + mu.Lock() + errs = append(errs, err) + mu.Unlock() + } + } + }() } + wg.Wait() + + return errs +} +func (prwe *PrwExporter) execute(ctx context.Context, writeReq *prompb.WriteRequest) error { // Uses proto.Marshal to convert the WriteRequest into bytes array - data, err := proto.Marshal(req) + data, err := proto.Marshal(writeReq) if err != nil { return consumererror.Permanent(err) } @@ -268,19 +308,19 @@ func (prwe *PrwExporter) export(ctx context.Context, tsMap map[string]*prompb.Ti compressedData := snappy.Encode(buf, data) // Create the HTTP POST request to send to the endpoint - httpReq, err := http.NewRequestWithContext(ctx, "POST", prwe.endpointURL.String(), bytes.NewReader(compressedData)) + req, err := http.NewRequestWithContext(ctx, "POST", prwe.endpointURL.String(), bytes.NewReader(compressedData)) if err != nil { return consumererror.Permanent(err) } // Add necessary headers specified by: // https://cortexmetrics.io/docs/apis/#remote-api - httpReq.Header.Add("Content-Encoding", "snappy") - httpReq.Header.Set("Content-Type", "application/x-protobuf") - httpReq.Header.Set("X-Prometheus-Remote-Write-Version", "0.1.0") - httpReq.Header.Set("User-Agent", "OpenTelemetry-Collector/"+version.Version) + req.Header.Add("Content-Encoding", "snappy") + req.Header.Set("Content-Type", "application/x-protobuf") + req.Header.Set("X-Prometheus-Remote-Write-Version", "0.1.0") + req.Header.Set("User-Agent", "OpenTelemetry-Collector/"+version.Version) - httpResp, err := prwe.client.Do(httpReq) + resp, err := prwe.client.Do(req) if err != nil { return consumererror.Permanent(err) } @@ -289,18 +329,17 @@ func (prwe *PrwExporter) export(ctx context.Context, tsMap map[string]*prompb.Ti // 5xx errors are recoverable and the exporter should retry // Reference for different behavior according to status code: // https://github.com/prometheus/prometheus/pull/2552/files#diff-ae8db9d16d8057358e49d694522e7186 - if httpResp.StatusCode/100 != 2 { - scanner := bufio.NewScanner(io.LimitReader(httpResp.Body, 256)) - line := "" + if resp.StatusCode/100 != 2 { + scanner := bufio.NewScanner(io.LimitReader(resp.Body, 256)) + var line string if scanner.Scan() { line = scanner.Text() } - errMsg := "server returned HTTP status " + httpResp.Status + ": " + line - if httpResp.StatusCode >= 500 && httpResp.StatusCode < 600 { - return errors.New(errMsg) + err := fmt.Errorf("server returned HTTP status %v: %v ", resp.Status, line) + if resp.StatusCode >= 500 && resp.StatusCode < 600 { + return err } - return consumererror.Permanent(errors.New(errMsg)) - + return consumererror.Permanent(err) } return nil } diff --git a/exporter/prometheusremotewriteexporter/exporter_test.go b/exporter/prometheusremotewriteexporter/exporter_test.go index c0e31d496b3..2333f40eda3 100644 --- a/exporter/prometheusremotewriteexporter/exporter_test.go +++ b/exporter/prometheusremotewriteexporter/exporter_test.go @@ -227,17 +227,19 @@ func Test_export(t *testing.T) { if !tt.serverUp { server.Close() } - err := runExportPipeline(ts1, serverURL) + errs := runExportPipeline(ts1, serverURL) if tt.returnError { - assert.Error(t, err) + assert.Error(t, errs[0]) return } - assert.NoError(t, err) + assert.Len(t, errs, 0) }) } } -func runExportPipeline(ts *prompb.TimeSeries, endpoint *url.URL) error { +func runExportPipeline(ts *prompb.TimeSeries, endpoint *url.URL) []error { + var errs []error + // First we will construct a TimeSeries array from the testutils package testmap := make(map[string]*prompb.TimeSeries) testmap["test"] = ts @@ -246,10 +248,11 @@ func runExportPipeline(ts *prompb.TimeSeries, endpoint *url.URL) error { // after this, instantiate a CortexExporter with the current HTTP client and endpoint set to passed in endpoint prwe, err := NewPrwExporter("test", endpoint.String(), HTTPClient, map[string]string{}) if err != nil { - return err + errs = append(errs, err) + return errs } - err = prwe.export(context.Background(), testmap) - return err + errs = append(errs, prwe.export(context.Background(), testmap)...) + return errs } // Test_PushMetrics checks the number of TimeSeries received by server and the number of metrics dropped is the same as diff --git a/exporter/prometheusremotewriteexporter/factory.go b/exporter/prometheusremotewriteexporter/factory.go index 1fd272d28c2..af2c65154ab 100644 --- a/exporter/prometheusremotewriteexporter/factory.go +++ b/exporter/prometheusremotewriteexporter/factory.go @@ -45,13 +45,11 @@ func createMetricsExporter(_ context.Context, params component.ExporterCreatePar } client, err := prwCfg.HTTPClientSettings.ToClient() - if err != nil { return nil, err } prwe, err := NewPrwExporter(prwCfg.Namespace, prwCfg.HTTPClientSettings.Endpoint, client, prwCfg.ExternalLabels) - if err != nil { return nil, err } diff --git a/exporter/prometheusremotewriteexporter/helper.go b/exporter/prometheusremotewriteexporter/helper.go index ab704749bfe..b19b820c0b1 100644 --- a/exporter/prometheusremotewriteexporter/helper.go +++ b/exporter/prometheusremotewriteexporter/helper.go @@ -126,7 +126,6 @@ func timeSeriesSignature(metric *otlp.Metric, labels *[]prompb.Label) string { // Unpaired string value is ignored. String pairs overwrites OTLP labels if collision happens, and the overwrite is // logged. Resultant label names are sanitized. func createLabelSet(labels []common.StringKeyValue, externalLabels map[string]string, extras ...string) []prompb.Label { - // map ensures no duplicate label name l := map[string]prompb.Label{} @@ -165,7 +164,6 @@ func createLabelSet(labels []common.StringKeyValue, externalLabels map[string]st } s := make([]prompb.Label, 0, len(l)) - for _, lb := range l { s = append(s, lb) } @@ -176,7 +174,6 @@ func createLabelSet(labels []common.StringKeyValue, externalLabels map[string]st // getPromMetricName creates a Prometheus metric name by attaching namespace prefix, and _total suffix for Monotonic // metrics. func getPromMetricName(metric *otlp.Metric, ns string) string { - if metric == nil { return "" } @@ -215,21 +212,37 @@ func getPromMetricName(metric *otlp.Metric, ns string) string { return sanitize(b.String()) } -// Simple helper function that takes the map -// and creates a WriteRequest from the struct -- can move to the helper.go file -func wrapTimeSeries(tsMap map[string]*prompb.TimeSeries) (*prompb.WriteRequest, error) { +// batchTimeSeries splits series into multiple batch write requests. +func batchTimeSeries(tsMap map[string]*prompb.TimeSeries, maxBatchByteSize int) ([]*prompb.WriteRequest, error) { if len(tsMap) == 0 { return nil, errors.New("invalid tsMap: cannot be empty map") } + + var requests []*prompb.WriteRequest var tsArray []prompb.TimeSeries + sizeOfCurrentBatch := 0 + for _, v := range tsMap { + sizeOfSeries := v.Size() + + if sizeOfCurrentBatch+sizeOfSeries >= maxBatchByteSize { + wrapped := convertTimeseriesToRequest(tsArray) + requests = append(requests, wrapped) + + tsArray = make([]prompb.TimeSeries, 0) + sizeOfCurrentBatch = 0 + } + tsArray = append(tsArray, *v) + sizeOfCurrentBatch += sizeOfSeries } - wrapped := prompb.WriteRequest{ - Timeseries: tsArray, - // Other parameters of the WriteRequest are unnecessary for our Export + + if len(tsArray) != 0 { + wrapped := convertTimeseriesToRequest(tsArray) + requests = append(requests, wrapped) } - return &wrapped, nil + + return requests, nil } // convertTimeStamp converts OTLP timestamp in ns to timestamp in ms @@ -466,3 +479,11 @@ func addSingleDoubleSummaryDataPoint(pt *otlp.DoubleSummaryDataPoint, metric *ot addSample(tsMap, quantile, qtlabels, metric) } } + +func convertTimeseriesToRequest(tsArray []prompb.TimeSeries) *prompb.WriteRequest { + // the remote_write endpoint only requires the timeseries. + // otlp defines it's own way to handle metric metadata + return &prompb.WriteRequest{ + Timeseries: tsArray, + } +} diff --git a/exporter/prometheusremotewriteexporter/helper_test.go b/exporter/prometheusremotewriteexporter/helper_test.go index 97ce7d4aede..821d9947fe4 100644 --- a/exporter/prometheusremotewriteexporter/helper_test.go +++ b/exporter/prometheusremotewriteexporter/helper_test.go @@ -303,3 +303,61 @@ func Test_getPromMetricName(t *testing.T) { }) } } + +// Test_batchTimeSeries checks batchTimeSeries return the correct number of requests +// depending on byte size. +func Test_batchTimeSeries(t *testing.T) { + // First we will instantiate a dummy TimeSeries instance to pass into both the export call and compare the http request + labels := getPromLabels(label11, value11, label12, value12, label21, value21, label22, value22) + sample1 := getSample(floatVal1, msTime1) + sample2 := getSample(floatVal2, msTime2) + sample3 := getSample(floatVal3, msTime3) + ts1 := getTimeSeries(labels, sample1, sample2) + ts2 := getTimeSeries(labels, sample1, sample2, sample3) + + tsMap1 := getTimeseriesMap([]*prompb.TimeSeries{}) + tsMap2 := getTimeseriesMap([]*prompb.TimeSeries{ts1}) + tsMap3 := getTimeseriesMap([]*prompb.TimeSeries{ts1, ts2}) + + tests := []struct { + name string + tsMap map[string]*prompb.TimeSeries + maxBatchByteSize int + numExpectedRequests int + returnErr bool + }{ + { + "no_timeseries", + tsMap1, + 100, + -1, + true, + }, + { + "normal_case", + tsMap2, + 300, + 1, + false, + }, + { + "two_requests", + tsMap3, + 300, + 2, + false, + }, + } + // run tests + for _, tt := range tests { + t.Run(tt.name, func(t *testing.T) { + requests, err := batchTimeSeries(tt.tsMap, tt.maxBatchByteSize) + if tt.returnErr { + assert.Error(t, err) + return + } + assert.NoError(t, err) + assert.Equal(t, tt.numExpectedRequests, len(requests)) + }) + } +} diff --git a/exporter/prometheusremotewriteexporter/testutil_test.go b/exporter/prometheusremotewriteexporter/testutil_test.go index 1a603f3c223..62ddf2e4ff7 100644 --- a/exporter/prometheusremotewriteexporter/testutil_test.go +++ b/exporter/prometheusremotewriteexporter/testutil_test.go @@ -15,6 +15,7 @@ package prometheusremotewriteexporter import ( + "fmt" "time" "github.com/prometheus/prometheus/prompb" @@ -25,9 +26,11 @@ import ( var ( time1 = uint64(time.Now().UnixNano()) - time2 = uint64(time.Date(1970, 1, 0, 0, 0, 0, 0, time.UTC).UnixNano()) + time2 = uint64(time.Now().UnixNano() - 5) + time3 = uint64(time.Date(1970, 1, 0, 0, 0, 0, 0, time.UTC).UnixNano()) msTime1 = int64(time1 / uint64(int64(time.Millisecond)/int64(time.Nanosecond))) msTime2 = int64(time2 / uint64(int64(time.Millisecond)/int64(time.Nanosecond))) + msTime3 = int64(time3 / uint64(int64(time.Millisecond)/int64(time.Nanosecond))) label11 = "test_label11" value11 = "test_value11" @@ -50,6 +53,7 @@ var ( intVal2 int64 = 2 floatVal1 = 1.0 floatVal2 = 2.0 + floatVal3 = 3.0 lbs1 = getLabels(label11, value11, label12, value12) lbs2 = getLabels(label21, value21, label22, value22) @@ -564,3 +568,11 @@ func getQuantiles(bounds []float64, values []float64) []*otlp.DoubleSummaryDataP } return quantiles } + +func getTimeseriesMap(timeseries []*prompb.TimeSeries) map[string]*prompb.TimeSeries { + tsMap := make(map[string]*prompb.TimeSeries) + for i, v := range timeseries { + tsMap[fmt.Sprintf("%s%d", "timeseries_name", i)] = v + } + return tsMap +} diff --git a/extension/pprofextension/pprofextension.go b/extension/pprofextension/pprofextension.go index b1c04700a1e..bb9db577c76 100644 --- a/extension/pprofextension/pprofextension.go +++ b/extension/pprofextension/pprofextension.go @@ -58,7 +58,7 @@ func (p *pprofExtension) Start(_ context.Context, host component.Host) error { if err != nil { return err } - pprof.StartCPUProfile(f) + return pprof.StartCPUProfile(f) } return nil diff --git a/service/service.go b/service/service.go index 99b3a305741..d0ff423a199 100644 --- a/service/service.go +++ b/service/service.go @@ -231,7 +231,9 @@ func (app *Application) RegisterZPages(mux *http.ServeMux, pathPrefix string) { mux.HandleFunc(path.Join(pathPrefix, extensionzPath), app.handleExtensionzRequest) } -func (app *Application) SignalTestComplete() { +func (app *Application) Shutdown() { + // TODO: Implement a proper shutdown with graceful draining of the pipeline. + // See https://github.com/open-telemetry/opentelemetry-collector/issues/483. defer func() { if r := recover(); r != nil { app.logger.Info("stopTestChan already closed") diff --git a/service/service_test.go b/service/service_test.go index d3d1b181e59..2d1125d005c 100644 --- a/service/service_test.go +++ b/service/service_test.go @@ -167,8 +167,8 @@ func TestApplication_StartAsGoRoutine(t *testing.T) { assert.Equal(t, Starting, <-app.GetStateChannel()) assert.Equal(t, Running, <-app.GetStateChannel()) - app.SignalTestComplete() - app.SignalTestComplete() + app.Shutdown() + app.Shutdown() <-appDone assert.Equal(t, Closing, <-app.GetStateChannel()) assert.Equal(t, Closed, <-app.GetStateChannel()) diff --git a/testbed/testbed/otelcol_runner.go b/testbed/testbed/otelcol_runner.go index 56fafff5211..489fff4bc4e 100644 --- a/testbed/testbed/otelcol_runner.go +++ b/testbed/testbed/otelcol_runner.go @@ -142,7 +142,7 @@ func (ipp *InProcessCollector) Start(args StartParams) error { func (ipp *InProcessCollector) Stop() (stopped bool, err error) { if !ipp.stopped { ipp.stopped = true - ipp.svc.SignalTestComplete() + ipp.svc.Shutdown() } <-ipp.appDone stopped = ipp.stopped diff --git a/testutil/testutil.go b/testutil/testutil.go index 12833a511a6..b2f5f33ba62 100644 --- a/testutil/testutil.go +++ b/testutil/testutil.go @@ -23,6 +23,8 @@ import ( "io/ioutil" "net" "os" + "os/exec" + "runtime" "strconv" "strings" "testing" @@ -31,6 +33,11 @@ import ( "github.com/stretchr/testify/require" ) +type portpair struct { + first string + last string +} + // GenerateNormalizedJSON generates a normalized JSON from the string // given to the function. Useful to compare JSON contents that // may have differences due to formatting. It returns nil in case of @@ -73,9 +80,33 @@ func GetAvailableLocalAddress(t *testing.T) string { // available for opening when this function returns provided that there is no // race by some other code to grab the same port immediately. func GetAvailablePort(t *testing.T) uint16 { - endpoint := GetAvailableLocalAddress(t) - _, port, err := net.SplitHostPort(endpoint) - require.NoError(t, err) + // Retry has been added for windows as net.Listen can return a port that is not actually available. Details can be + // found in https://github.com/docker/for-win/issues/3171 but to summarize Hyper-V will reserve ranges of ports + // which do not show up under the "netstat -ano" but can only be found by + // "netsh interface ipv4 show excludedportrange protocol=tcp". We'll use []exclusions to hold those ranges and + // retry if the port returned by GetAvailableLocalAddress falls in one of those them. + var exclusions []portpair + portFound := false + var port string + var err error + if runtime.GOOS == "windows" { + exclusions = getExclusionsList(t) + } + + for !portFound { + endpoint := GetAvailableLocalAddress(t) + _, port, err = net.SplitHostPort(endpoint) + require.NoError(t, err) + portFound = true + if runtime.GOOS == "windows" { + for _, pair := range exclusions { + if port >= pair.first && port <= pair.last { + portFound = false + break + } + } + } + } portInt, err := strconv.Atoi(port) require.NoError(t, err) @@ -83,6 +114,35 @@ func GetAvailablePort(t *testing.T) uint16 { return uint16(portInt) } +// Get excluded ports on Windows from the command: netsh interface ipv4 show excludedportrange protocol=tcp +func getExclusionsList(t *testing.T) []portpair { + cmd := exec.Command("netsh", "interface", "ipv4", "show", "excludedportrange", "protocol=tcp") + output, err := cmd.CombinedOutput() + require.NoError(t, err) + + exclusions := createExclusionsList(string(output), t) + return exclusions +} + +func createExclusionsList(exclusionsText string, t *testing.T) []portpair { + exclusions := []portpair{} + + parts := strings.Split(exclusionsText, "--------") + require.Equal(t, len(parts), 3) + portsText := strings.Split(parts[2], "*") + require.Equal(t, len(portsText), 2) + lines := strings.Split(portsText[0], "\n") + for _, line := range lines { + if strings.TrimSpace(line) != "" { + entries := strings.Fields(strings.TrimSpace(line)) + require.Equal(t, len(entries), 2) + pair := portpair{entries[0], entries[1]} + exclusions = append(exclusions, pair) + } + } + return exclusions +} + // WaitForPort repeatedly attempts to open a local port until it either succeeds or 5 seconds pass // It is useful if you need to asynchronously start a service and wait for it to start func WaitForPort(t *testing.T, port uint16) error { diff --git a/testutil/testutil_test.go b/testutil/testutil_test.go index 6a83f66e457..08f9514eb1f 100644 --- a/testutil/testutil_test.go +++ b/testutil/testutil_test.go @@ -63,3 +63,30 @@ func testEndpointAvailable(t *testing.T, endpoint string) { require.Error(t, err) require.Nil(t, ln1) } + +func TestCreateExclusionsList(t *testing.T) { + // Test two examples of typical output from "netsh interface ipv4 show excludedportrange protocol=tcp" + emptyExclusionsText := ` + +Protocol tcp Port Exclusion Ranges + +Start Port End Port +---------- -------- + +* - Administered port exclusions.` + + exclusionsText := ` + +Start Port End Port +---------- -------- + 49697 49796 + 49797 49896 + +* - Administered port exclusions. +` + exclusions := createExclusionsList(exclusionsText, t) + require.Equal(t, len(exclusions), 2) + + emptyExclusions := createExclusionsList(emptyExclusionsText, t) + require.Equal(t, len(emptyExclusions), 0) +} diff --git a/translator/internaldata/resource_to_oc.go b/translator/internaldata/resource_to_oc.go index 565a94d4e50..6c99f2b623c 100644 --- a/translator/internaldata/resource_to_oc.go +++ b/translator/internaldata/resource_to_oc.go @@ -111,9 +111,6 @@ func internalResourceToOC(resource pdata.Resource) (*occommon.Node, *ocresource. } getProcessIdentifier(ocNode).Pid = uint32(pid) case conventions.AttributeTelemetrySDKVersion: - if ocNode.LibraryInfo == nil { - ocNode.LibraryInfo = &occommon.LibraryInfo{} - } getLibraryInfo(ocNode).CoreLibraryVersion = val case conventions.OCAttributeExporterVersion: getLibraryInfo(ocNode).ExporterVersion = val