Skip to content

Commit 4db9157

Browse files
thc1006mx-psi
andauthored
[mdatagen] Add optional display_name field to metadata.yaml (#14115)
## Description This PR adds an optional `display_name` field to metadata.yaml for human-readable component names, as requested in #14114. ## Changes - 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 ## Implementation Following the implementation guide from @mx-psi: 1. Added the field to the Metadata struct 2. Added title generation section to readme.md.tmpl template 3. Added comprehensive tests covering both explicit and default display names 4. Verified functionality with OTLP receiver (tested locally) ## Behavior - When `display_name` is set in metadata.yaml, it will be used as the README title - When not set, the component type will be automatically capitalized (e.g., "otlp" becomes "Otlp") - Fully backward compatible - existing components without display_name continue to work ## Testing - Unit tests added for display_name loading - Default value generation tested - Generated test files verified - CI checks passing (gotidy, misspell, multimod-verify, crosslink) Fixes #14114 Co-authored-by: SteveYi <[email protected]> --------- Co-authored-by: Pablo Baeyens <[email protected]>
1 parent ae38f54 commit 4db9157

File tree

18 files changed

+149
-6
lines changed

18 files changed

+149
-6
lines changed
Lines changed: 28 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,28 @@
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` and `description` fields 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+
When provided, this name is used as the title in generated README files.
21+
The `description` field allows components to include a brief description in generated README files.
22+
23+
# Optional: The change log or logs in which this entry should be included.
24+
# e.g. '[user]' or '[user, api]'
25+
# Include 'user' if the change is relevant to end users.
26+
# Include 'api' if there is a change to a library API.
27+
# Default: '[user]'
28+
change_logs: [user]

.github/workflows/utils/cspell.json

Lines changed: 2 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -322,6 +322,7 @@
322322
"myreceiver",
323323
"myrepo",
324324
"mysite",
325+
"nodisplayname",
325326
"nonclobbering",
326327
"nopexporter",
327328
"nopreceiver",
@@ -458,6 +459,7 @@
458459
"testcomponents",
459460
"testconverter",
460461
"testdata",
462+
"testdesc",
461463
"testfunc",
462464
"testonly",
463465
"testprocessor",

cmd/mdatagen/internal/loader_test.go

Lines changed: 57 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -47,6 +47,8 @@ func TestLoadMetadata(t *testing.T) {
4747
GithubProject: "open-telemetry/opentelemetry-collector",
4848
GeneratedPackageName: "metadata",
4949
Type: "sample",
50+
DisplayName: "Sample Receiver",
51+
Description: "This receiver is used for testing purposes to check the output of mdatagen.",
5052
SemConvVersion: "1.38.0",
5153
PackageName: "go.opentelemetry.io/collector/cmd/mdatagen/internal/samplereceiver",
5254
Status: &Status{
@@ -553,6 +555,61 @@ func TestLoadMetadata(t *testing.T) {
553555
name: "testdata/~~this file doesn't exist~~.yaml",
554556
wantErr: "unable to read the file file:testdata/~~this file doesn't exist~~.yaml",
555557
},
558+
{
559+
name: "testdata/display_name.yaml",
560+
want: Metadata{
561+
Type: "test",
562+
DisplayName: "Test Receiver",
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+
},
576+
{
577+
name: "testdata/no_display_name.yaml",
578+
want: Metadata{
579+
Type: "nodisplayname",
580+
DisplayName: "",
581+
GeneratedPackageName: "metadata",
582+
ScopeName: "go.opentelemetry.io/collector/cmd/mdatagen/internal/testdata",
583+
PackageName: "go.opentelemetry.io/collector/cmd/mdatagen/internal/testdata",
584+
ShortFolderName: "testdata",
585+
Tests: Tests{Host: "newMdatagenNopHost()"},
586+
Status: &Status{
587+
Class: "receiver",
588+
Stability: map[component.StabilityLevel][]string{
589+
component.StabilityLevelBeta: {"logs"},
590+
},
591+
},
592+
},
593+
},
594+
{
595+
name: "testdata/with_description.yaml",
596+
want: Metadata{
597+
Type: "testdesc",
598+
DisplayName: "Test Component",
599+
Description: "This is a test component with a description.",
600+
GeneratedPackageName: "metadata",
601+
ScopeName: "go.opentelemetry.io/collector/cmd/mdatagen/internal/testdata",
602+
PackageName: "go.opentelemetry.io/collector/cmd/mdatagen/internal/testdata",
603+
ShortFolderName: "testdata",
604+
Tests: Tests{Host: "newMdatagenNopHost()"},
605+
Status: &Status{
606+
Class: "receiver",
607+
Stability: map[component.StabilityLevel][]string{
608+
component.StabilityLevelBeta: {"logs"},
609+
},
610+
},
611+
},
612+
},
556613
}
557614
for _, tt := range tests {
558615
t.Run(tt.name, func(t *testing.T) {

cmd/mdatagen/internal/metadata.go

Lines changed: 4 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -18,6 +18,10 @@ import (
1818
type Metadata struct {
1919
// Type of the component.
2020
Type string `mapstructure:"type"`
21+
// DisplayName is a human-readable display name for the component.
22+
DisplayName string `mapstructure:"display_name"`
23+
// Description is a brief description of the component.
24+
Description string `mapstructure:"description"`
2125
// Type of the parent component (applicable to subcomponents).
2226
Parent string `mapstructure:"parent"`
2327
// Status information for the component.

cmd/mdatagen/internal/sampleconnector/metadata.yaml

Lines changed: 2 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -1,6 +1,8 @@
11
# Sample metadata file with all available configurations for a connector.
22

33
type: sample
4+
display_name: Sample Connector
5+
description: This connector is used for testing purposes to check the output of mdatagen.
46
github_project: open-telemetry/opentelemetry-collector
57

68
sem_conv_version: 1.9.0

cmd/mdatagen/internal/samplefactoryreceiver/README.md

Lines changed: 4 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -1,6 +1,8 @@
1-
# Sample Receiver
2-
This receiver is used for testing purposes to check the output of mdatagen.
31
<!-- status autogenerated section -->
2+
# Sample Factory Receiver
3+
4+
This receiver is used for testing purposes to check the output of mdatagen.
5+
46
| Status | |
57
| ------------- |-----------|
68
| Stability | [deprecated]: profiles |

cmd/mdatagen/internal/samplefactoryreceiver/metadata.yaml

Lines changed: 2 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -1,6 +1,8 @@
11
# Sample metadata file with all available configurations for a receiver.
22

33
type: sample
4+
display_name: Sample Factory Receiver
5+
description: This receiver is used for testing purposes to check the output of mdatagen.
46
scope_name: go.opentelemetry.io/collector/internal/receiver/samplefactoryreceiver
57
github_project: open-telemetry/opentelemetry-collector
68

cmd/mdatagen/internal/sampleprocessor/README.md

Lines changed: 3 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -1,6 +1,8 @@
1+
<!-- status autogenerated section -->
12
# Sample Processor
3+
24
This processor is used for testing purposes to check the output of mdatagen.
3-
<!-- status autogenerated section -->
5+
46
| Status | |
57
| ------------- |-----------|
68
| Stability | [development]: logs |

cmd/mdatagen/internal/sampleprocessor/metadata.yaml

Lines changed: 3 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -1,6 +1,8 @@
1-
# Sample metadata file with all available configurations for a receiver.
1+
# Sample metadata file with all available configurations for a processor.
22

33
type: sample
4+
display_name: Sample Processor
5+
description: This processor is used for testing purposes to check the output of mdatagen.
46
scope_name: go.opentelemetry.io/collector/internal/receiver/samplereceiver
57
github_project: open-telemetry/opentelemetry-collector
68

cmd/mdatagen/internal/samplereceiver/README.md

Lines changed: 3 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -1,6 +1,8 @@
1+
<!-- status autogenerated section -->
12
# Sample Receiver
3+
24
This receiver is used for testing purposes to check the output of mdatagen.
3-
<!-- status autogenerated section -->
5+
46
| Status | |
57
| ------------- |-----------|
68
| Stability | [deprecated]: profiles |

0 commit comments

Comments
 (0)