Skip to content

Commit e91922d

Browse files
committed
[pdata] Add support for the new resource-entity references in xpdata
Add support for the new resource-entity reference API added to the proto as part of open-telemetry/opentelemetry-proto#635. This required moving CopyTo implementation to the internal package for the structures that are used by other packages
1 parent 3b627ad commit e91922d

14 files changed

+735
-1
lines changed

.chloggen/xpdata-entities-api.yaml

Lines changed: 18 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,18 @@
1+
# One of 'breaking', 'deprecation', 'new_component', 'enhancement', 'bug_fix'
2+
change_type: enhancement
3+
4+
# The name of the component, or a single word describing the area of concern, (e.g. otlpreceiver)
5+
component: pdata
6+
7+
# A brief description of the change. Surround your text with quotes ("") if it needs to start with a backtick (`).
8+
note: Add support for the new resource-entity reference API as part of the experimental xpdata package.
9+
10+
# One or more tracking issues or pull requests related to the change
11+
issues: [13264]
12+
13+
# Optional: The change log or logs in which this entry should be included.
14+
# e.g. '[user]' or '[user, api]'
15+
# Include 'user' if the change is relevant to end users.
16+
# Include 'api' if there is a change to a library API.
17+
# Default: '[user]'
18+
change_logs: [api]

pdata/internal/cmd/pdatagen/internal/base_fields.go

Lines changed: 7 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -343,14 +343,21 @@ type sliceField struct {
343343
fieldName string
344344
originFieldName string
345345
returnSlice baseSlice
346+
hideAccessors bool
346347
}
347348

348349
func (sf *sliceField) GenerateAccessors(ms *messageValueStruct) string {
350+
if sf.hideAccessors {
351+
return ""
352+
}
349353
t := template.Must(template.New("accessorSliceTemplate").Parse(accessorSliceTemplate))
350354
return executeTemplate(t, sf.templateFields(ms))
351355
}
352356

353357
func (sf *sliceField) GenerateAccessorsTest(ms *messageValueStruct) string {
358+
if sf.hideAccessors {
359+
return ""
360+
}
354361
t := template.Must(template.New("accessorsSliceTestTemplate").Parse(accessorsSliceTestTemplate))
355362
return executeTemplate(t, sf.templateFields(ms))
356363
}

pdata/internal/cmd/pdatagen/internal/packages.go

Lines changed: 2 additions & 1 deletion
Some generated files are not rendered by default. Learn more about customizing how changed files appear on GitHub.

pdata/internal/cmd/pdatagen/internal/pcommon_package.go

Lines changed: 7 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -160,6 +160,13 @@ var resource = &messageValueStruct{
160160
fields: []baseField{
161161
attributes,
162162
droppedAttributesCount,
163+
&sliceField{
164+
// Hide accessors for this field from 1.x public API since the proto field is experimental.
165+
// It's available via the xpdata/entity.ResourceEntityRefs.
166+
hideAccessors: true,
167+
originFieldName: "EntityRefs",
168+
returnSlice: entityRefSlice,
169+
},
163170
},
164171
}
165172

Lines changed: 60 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,60 @@
1+
// Copyright The OpenTelemetry Authors
2+
// SPDX-License-Identifier: Apache-2.0
3+
4+
package internal // import "go.opentelemetry.io/collector/pdata/internal/cmd/pdatagen/internal"
5+
6+
import "path/filepath"
7+
8+
var xpdataEntity = &Package{
9+
info: &PackageInfo{
10+
name: "entity",
11+
path: filepath.Join("xpdata", "entity"),
12+
imports: []string{
13+
`"go.opentelemetry.io/collector/pdata/internal"`,
14+
`"go.opentelemetry.io/collector/pdata/pcommon"`,
15+
`otlpcommon "go.opentelemetry.io/collector/pdata/internal/data/protogen/common/v1"`,
16+
`otlpresource "go.opentelemetry.io/collector/pdata/internal/data/protogen/resource/v1"`,
17+
},
18+
testImports: []string{
19+
`"testing"`,
20+
``,
21+
`"github.com/stretchr/testify/assert"`,
22+
``,
23+
`"go.opentelemetry.io/collector/pdata/internal"`,
24+
`"go.opentelemetry.io/collector/pdata/pcommon"`,
25+
},
26+
},
27+
structs: []baseStruct{
28+
entityRefSlice,
29+
entityRef,
30+
},
31+
}
32+
33+
var entityRefSlice = &sliceOfPtrs{
34+
structName: "EntityRefSlice",
35+
packageName: "entity",
36+
element: entityRef,
37+
}
38+
39+
var entityRef = &messageValueStruct{
40+
structName: "EntityRef",
41+
packageName: "entity",
42+
originFullName: "otlpcommon.EntityRef",
43+
fields: []baseField{
44+
schemaURLField,
45+
&primitiveField{
46+
fieldName: "Type",
47+
returnType: "string",
48+
defaultVal: `""`,
49+
testVal: `"host"`,
50+
},
51+
&sliceField{
52+
fieldName: "IdKeys",
53+
returnSlice: stringSlice,
54+
},
55+
&sliceField{
56+
fieldName: "DescriptionKeys",
57+
returnSlice: stringSlice,
58+
},
59+
},
60+
}

pdata/internal/generated_wrapper_entityref.go

Lines changed: 50 additions & 0 deletions
Some generated files are not rendered by default. Learn more about customizing how changed files appear on GitHub.

pdata/internal/generated_wrapper_entityrefslice.go

Lines changed: 59 additions & 0 deletions
Some generated files are not rendered by default. Learn more about customizing how changed files appear on GitHub.

pdata/internal/generated_wrapper_resource.go

Lines changed: 2 additions & 0 deletions
Some generated files are not rendered by default. Learn more about customizing how changed files appear on GitHub.

pdata/xpdata/entity/generated_entityref.go

Lines changed: 92 additions & 0 deletions
Some generated files are not rendered by default. Learn more about customizing how changed files appear on GitHub.

0 commit comments

Comments
 (0)