Skip to content

Commit a029c2a

Browse files
thc1006steveyiyo
andcommitted
[mdatagen] Add optional display_name field to metadata.yaml
- Added display_name field to metadata-schema.yaml - Updated Metadata struct to include DisplayName field - Implemented automatic capitalization of type field when display_name not provided - Modified readme.md.tmpl to generate README titles from display_name - Fixed unused import issue in config_test.go.tmpl - Added test cases for display_name handling - Regenerated internal test code and README files Fixes #14114 Co-authored-by: SteveYi <[email protected]> Signed-off-by: thc1006 <[email protected]>
1 parent 82f2534 commit a029c2a

File tree

18 files changed

+120
-5
lines changed

18 files changed

+120
-5
lines changed
Lines changed: 27 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,27 @@
1+
# Use this changelog template to create an entry for release notes.
2+
3+
# One of 'breaking', 'deprecation', 'new_component', 'enhancement', 'bug_fix'
4+
change_type: enhancement
5+
6+
# The name of the component, or a single word describing the area of concern, (e.g. otlpreceiver)
7+
component: cmd/mdatagen
8+
9+
# A brief description of the change. Surround your text with quotes ("") if it needs to start with a backtick (`).
10+
note: Add optional `display_name` field to metadata.yaml for human-readable component names
11+
12+
# One or more tracking issues or pull requests related to the change
13+
issues: [14114]
14+
15+
# (Optional) One or more lines of additional information to render under the primary note.
16+
# These lines will be padded with 2 spaces and then inserted directly into the document.
17+
# Use pipe (|) for multiline entries.
18+
subtext: |
19+
The `display_name` field allows components to specify a human-readable name in metadata.yaml.
20+
If not provided, the component type will be used with the first letter capitalized.
21+
22+
# Optional: The change log or logs in which this entry should be included.
23+
# e.g. '[user]' or '[user, api]'
24+
# Include 'user' if the change is relevant to end users.
25+
# Include 'api' if there is a change to a library API.
26+
# Default: '[user]'
27+
change_logs: [user]

cmd/mdatagen/README.md

Lines changed: 3 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -1,5 +1,8 @@
11
# Metadata Generator
22

3+
4+
# Mdatagen
5+
36
<!-- status autogenerated section -->
47
| Status | |
58
| ------------- |-----------|

cmd/mdatagen/internal/loader.go

Lines changed: 10 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -59,6 +59,9 @@ func LoadMetadata(filePath string) (Metadata, error) {
5959
if md.GeneratedPackageName == "" {
6060
md.GeneratedPackageName = "metadata"
6161
}
62+
if md.DisplayName == "" {
63+
md.DisplayName = generateDefaultDisplayName(md.Type)
64+
}
6265

6366
if err := md.Validate(); err != nil {
6467
return md, err
@@ -70,6 +73,13 @@ func LoadMetadata(filePath string) (Metadata, error) {
7073
return md, nil
7174
}
7275

76+
func generateDefaultDisplayName(componentType string) string {
77+
if componentType == "" {
78+
return ""
79+
}
80+
return strings.ToUpper(componentType[:1]) + componentType[1:]
81+
}
82+
7383
var componentTypes = []string{
7484
"connector",
7585
"exporter",

cmd/mdatagen/internal/loader_test.go

Lines changed: 40 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -47,6 +47,7 @@ func TestLoadMetadata(t *testing.T) {
4747
GithubProject: "open-telemetry/opentelemetry-collector",
4848
GeneratedPackageName: "metadata",
4949
Type: "sample",
50+
DisplayName: "Sample",
5051
SemConvVersion: "1.9.0",
5152
PackageName: "go.opentelemetry.io/collector/cmd/mdatagen/internal/samplereceiver",
5253
Status: &Status{
@@ -440,6 +441,7 @@ func TestLoadMetadata(t *testing.T) {
440441
name: "testdata/parent.yaml",
441442
want: Metadata{
442443
Type: "subcomponent",
444+
DisplayName: "Subcomponent",
443445
Parent: "parentComponent",
444446
GeneratedPackageName: "metadata",
445447
ScopeName: "go.opentelemetry.io/collector/cmd/mdatagen/internal/testdata",
@@ -452,6 +454,7 @@ func TestLoadMetadata(t *testing.T) {
452454
name: "testdata/generated_package_name.yaml",
453455
want: Metadata{
454456
Type: "custom",
457+
DisplayName: "Custom",
455458
GeneratedPackageName: "customname",
456459
ScopeName: "go.opentelemetry.io/collector/cmd/mdatagen/internal/testdata",
457460
PackageName: "go.opentelemetry.io/collector/cmd/mdatagen/internal/testdata",
@@ -471,6 +474,7 @@ func TestLoadMetadata(t *testing.T) {
471474
name: "testdata/empty_test_config.yaml",
472475
want: Metadata{
473476
Type: "test",
477+
DisplayName: "Test",
474478
GeneratedPackageName: "metadata",
475479
ScopeName: "go.opentelemetry.io/collector/cmd/mdatagen/internal/testdata",
476480
PackageName: "go.opentelemetry.io/collector/cmd/mdatagen/internal/testdata",
@@ -533,6 +537,42 @@ func TestLoadMetadata(t *testing.T) {
533537
name: "testdata/~~this file doesn't exist~~.yaml",
534538
wantErr: "unable to read the file file:testdata/~~this file doesn't exist~~.yaml",
535539
},
540+
{
541+
name: "testdata/display_name.yaml",
542+
want: Metadata{
543+
Type: "test",
544+
DisplayName: "Test Receiver",
545+
GeneratedPackageName: "metadata",
546+
ScopeName: "go.opentelemetry.io/collector/cmd/mdatagen/internal/testdata",
547+
PackageName: "go.opentelemetry.io/collector/cmd/mdatagen/internal/testdata",
548+
ShortFolderName: "testdata",
549+
Tests: Tests{Host: "newMdatagenNopHost()"},
550+
Status: &Status{
551+
Class: "receiver",
552+
Stability: map[component.StabilityLevel][]string{
553+
component.StabilityLevelBeta: {"logs"},
554+
},
555+
},
556+
},
557+
},
558+
{
559+
name: "testdata/no_display_name.yaml",
560+
want: Metadata{
561+
Type: "nodisplayname",
562+
DisplayName: "Nodisplayname",
563+
GeneratedPackageName: "metadata",
564+
ScopeName: "go.opentelemetry.io/collector/cmd/mdatagen/internal/testdata",
565+
PackageName: "go.opentelemetry.io/collector/cmd/mdatagen/internal/testdata",
566+
ShortFolderName: "testdata",
567+
Tests: Tests{Host: "newMdatagenNopHost()"},
568+
Status: &Status{
569+
Class: "receiver",
570+
Stability: map[component.StabilityLevel][]string{
571+
component.StabilityLevelBeta: {"logs"},
572+
},
573+
},
574+
},
575+
},
536576
}
537577
for _, tt := range tests {
538578
t.Run(tt.name, func(t *testing.T) {

cmd/mdatagen/internal/metadata.go

Lines changed: 2 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -18,6 +18,8 @@ import (
1818
type Metadata struct {
1919
// Type of the component.
2020
Type string `mapstructure:"type"`
21+
// DisplayName is a human-readable name for the component.
22+
DisplayName string `mapstructure:"display_name"`
2123
// Type of the parent component (applicable to subcomponents).
2224
Parent string `mapstructure:"parent"`
2325
// Status information for the component.

cmd/mdatagen/internal/sampleconnector/internal/metadata/generated_config_test.go

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

cmd/mdatagen/internal/samplefactoryreceiver/README.md

Lines changed: 3 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -1,5 +1,8 @@
11
# Sample Receiver
22
This receiver is used for testing purposes to check the output of mdatagen.
3+
4+
# Sample
5+
36
<!-- status autogenerated section -->
47
| Status | |
58
| ------------- |-----------|

cmd/mdatagen/internal/sampleprocessor/README.md

Lines changed: 3 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -1,5 +1,8 @@
11
# Sample Processor
22
This processor is used for testing purposes to check the output of mdatagen.
3+
4+
# Sample
5+
36
<!-- status autogenerated section -->
47
| Status | |
58
| ------------- |-----------|

cmd/mdatagen/internal/sampleprocessor/internal/metadata/generated_config_test.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.

cmd/mdatagen/internal/samplereceiver/README.md

Lines changed: 3 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -1,5 +1,8 @@
11
# Sample Receiver
22
This receiver is used for testing purposes to check the output of mdatagen.
3+
4+
# Sample
5+
36
<!-- status autogenerated section -->
47
| Status | |
58
| ------------- |-----------|

0 commit comments

Comments
 (0)