Skip to content

Commit 408303b

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 open-telemetry#14114 Co-authored-by: SteveYi <[email protected]> Signed-off-by: thc1006 <[email protected]>
1 parent a9691ee commit 408303b

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.37.0",
5152
PackageName: "go.opentelemetry.io/collector/cmd/mdatagen/internal/samplereceiver",
5253
Status: &Status{
@@ -455,6 +456,7 @@ func TestLoadMetadata(t *testing.T) {
455456
name: "testdata/parent.yaml",
456457
want: Metadata{
457458
Type: "subcomponent",
459+
DisplayName: "Subcomponent",
458460
Parent: "parentComponent",
459461
GeneratedPackageName: "metadata",
460462
ScopeName: "go.opentelemetry.io/collector/cmd/mdatagen/internal/testdata",
@@ -467,6 +469,7 @@ func TestLoadMetadata(t *testing.T) {
467469
name: "testdata/generated_package_name.yaml",
468470
want: Metadata{
469471
Type: "custom",
472+
DisplayName: "Custom",
470473
GeneratedPackageName: "customname",
471474
ScopeName: "go.opentelemetry.io/collector/cmd/mdatagen/internal/testdata",
472475
PackageName: "go.opentelemetry.io/collector/cmd/mdatagen/internal/testdata",
@@ -486,6 +489,7 @@ func TestLoadMetadata(t *testing.T) {
486489
name: "testdata/empty_test_config.yaml",
487490
want: Metadata{
488491
Type: "test",
492+
DisplayName: "Test",
489493
GeneratedPackageName: "metadata",
490494
ScopeName: "go.opentelemetry.io/collector/cmd/mdatagen/internal/testdata",
491495
PackageName: "go.opentelemetry.io/collector/cmd/mdatagen/internal/testdata",
@@ -553,6 +557,42 @@ func TestLoadMetadata(t *testing.T) {
553557
name: "testdata/~~this file doesn't exist~~.yaml",
554558
wantErr: "unable to read the file file:testdata/~~this file doesn't exist~~.yaml",
555559
},
560+
{
561+
name: "testdata/display_name.yaml",
562+
want: Metadata{
563+
Type: "test",
564+
DisplayName: "Test Receiver",
565+
GeneratedPackageName: "metadata",
566+
ScopeName: "go.opentelemetry.io/collector/cmd/mdatagen/internal/testdata",
567+
PackageName: "go.opentelemetry.io/collector/cmd/mdatagen/internal/testdata",
568+
ShortFolderName: "testdata",
569+
Tests: Tests{Host: "newMdatagenNopHost()"},
570+
Status: &Status{
571+
Class: "receiver",
572+
Stability: map[component.StabilityLevel][]string{
573+
component.StabilityLevelBeta: {"logs"},
574+
},
575+
},
576+
},
577+
},
578+
{
579+
name: "testdata/no_display_name.yaml",
580+
want: Metadata{
581+
Type: "nodisplayname",
582+
DisplayName: "Nodisplayname",
583+
GeneratedPackageName: "metadata",
584+
ScopeName: "go.opentelemetry.io/collector/cmd/mdatagen/internal/testdata",
585+
PackageName: "go.opentelemetry.io/collector/cmd/mdatagen/internal/testdata",
586+
ShortFolderName: "testdata",
587+
Tests: Tests{Host: "newMdatagenNopHost()"},
588+
Status: &Status{
589+
Class: "receiver",
590+
Stability: map[component.StabilityLevel][]string{
591+
component.StabilityLevelBeta: {"logs"},
592+
},
593+
},
594+
},
595+
},
556596
}
557597
for _, tt := range tests {
558598
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)