diff --git a/.chloggen/add-confmap-to-mdatagen.yaml b/.chloggen/add-confmap-to-mdatagen.yaml new file mode 100644 index 000000000000..bfc7b0d76343 --- /dev/null +++ b/.chloggen/add-confmap-to-mdatagen.yaml @@ -0,0 +1,25 @@ +# Use this changelog template to create an entry for release notes. + +# One of 'breaking', 'deprecation', 'new_component', 'enhancement', 'bug_fix' +change_type: enhancement + +# The name of the component, or a single word describing the area of concern, (e.g. otlpreceiver) +component: mdatagen + +# A brief description of the change. Surround your text with quotes ("") if it needs to start with a backtick (`). +note: Add `converter` and `provider` module classes + +# One or more tracking issues or pull requests related to the change +issues: [12467] + +# (Optional) One or more lines of additional information to render under the primary note. +# These lines will be padded with 2 spaces and then inserted directly into the document. +# Use pipe (|) for multiline entries. +subtext: + +# Optional: The change log or logs in which this entry should be included. +# e.g. '[user]' or '[user, api]' +# Include 'user' if the change is relevant to end users. +# Include 'api' if there is a change to a library API. +# Default: '[user]' +change_logs: [] diff --git a/cmd/mdatagen/internal/command.go b/cmd/mdatagen/internal/command.go index 9c5293f5fa14..7fe90ff22bdf 100644 --- a/cmd/mdatagen/internal/command.go +++ b/cmd/mdatagen/internal/command.go @@ -13,6 +13,7 @@ import ( "path/filepath" "regexp" "runtime/debug" + "slices" "strings" "text/template" @@ -26,6 +27,13 @@ const ( statusEnd = "" ) +var nonComponents = []string{ + "cmd", + "converter", + "pkg", + "provider", +} + func getVersion() (string, error) { // the second returned value is a boolean, which is true if the binaries are built with module support. info, ok := debug.ReadBuildInfo() @@ -78,7 +86,7 @@ func run(ymlPath string) error { codeDir := filepath.Join(ymlDir, "internal", md.GeneratedPackageName) toGenerate := map[string]string{} if md.Status != nil { - if md.Status.Class != "cmd" && md.Status.Class != "pkg" { + if !slices.Contains(nonComponents, md.Status.Class) { toGenerate[filepath.Join(tmplDir, "status.go.tmpl")] = filepath.Join(codeDir, "generated_status.go") if err = generateFile(filepath.Join(tmplDir, "component_test.go.tmpl"), filepath.Join(ymlDir, "generated_component_test.go"), md, packageName); err != nil { diff --git a/cmd/mdatagen/internal/command_test.go b/cmd/mdatagen/internal/command_test.go index 058b7bff9cdc..f846adbb0060 100644 --- a/cmd/mdatagen/internal/command_test.go +++ b/cmd/mdatagen/internal/command_test.go @@ -330,6 +330,32 @@ Some info about a component componentClass: "extension", distros: []string{"contrib"}, }, + { + name: "readme with status for converter", + markdown: `# Some component + + + + +Some info about a component +`, + outputFile: "readme_with_status_converter.md", + componentClass: "converter", + distros: []string{"contrib"}, + }, + { + name: "readme with status for provider", + markdown: `# Some component + + + + +Some info about a component +`, + outputFile: "readme_with_status_provider.md", + componentClass: "provider", + distros: []string{"contrib"}, + }, { name: "readme with status with codeowners and seeking new", markdown: `# Some component diff --git a/cmd/mdatagen/internal/status.go b/cmd/mdatagen/internal/status.go index ebc95cff9835..c8a06c06a081 100644 --- a/cmd/mdatagen/internal/status.go +++ b/cmd/mdatagen/internal/status.go @@ -6,6 +6,7 @@ package internal // import "go.opentelemetry.io/collector/cmd/mdatagen/internal" import ( "errors" "fmt" + "slices" "sort" "go.opentelemetry.io/collector/component" @@ -48,6 +49,45 @@ type Status struct { UnsupportedPlatforms []string `mapstructure:"unsupported_platforms"` } +var validClasses = []string{ + "cmd", + "connector", + "converter", + "exporter", + "extension", + "pkg", + "processor", + "provider", + "receiver", + "scraper", +} + +var validStabilityKeys = []string{ + "converter", + "extension", + "logs", + "logs_to_traces", + "logs_to_metrics", + "logs_to_logs", + "logs_to_profiles", + "metrics", + "metrics_to_traces", + "metrics_to_metrics", + "metrics_to_logs", + "metrics_to_profiles", + "profiles", + "profiles_to_profiles", + "profiles_to_traces", + "profiles_to_metrics", + "profiles_to_logs", + "provider", + "traces_to_traces", + "traces_to_metrics", + "traces_to_logs", + "traces_to_profiles", + "traces", +} + func (s *Status) SortedDistributions() []string { sorted := s.Distributions sort.Slice(sorted, func(i, j int) bool { @@ -87,10 +127,7 @@ func (s *Status) validateClass() error { if s.Class == "" { return errors.New("missing class") } - if s.Class != "receiver" && s.Class != "processor" && - s.Class != "exporter" && s.Class != "connector" && - s.Class != "extension" && s.Class != "scraper" && - s.Class != "cmd" && s.Class != "pkg" { + if !slices.Contains(validClasses, s.Class) { return fmt.Errorf("invalid class: %v", s.Class) } return nil @@ -108,27 +145,7 @@ func (ms StabilityMap) Validate() error { errs = errors.Join(errs, fmt.Errorf("missing component for stability: %v", stability)) } for _, c := range cmps { - if c != "metrics" && - c != "traces" && - c != "logs" && - c != "profiles" && - c != "traces_to_traces" && - c != "traces_to_metrics" && - c != "traces_to_logs" && - c != "traces_to_profiles" && - c != "metrics_to_traces" && - c != "metrics_to_metrics" && - c != "metrics_to_logs" && - c != "metrics_to_profiles" && - c != "logs_to_traces" && - c != "logs_to_metrics" && - c != "logs_to_logs" && - c != "logs_to_profiles" && - c != "profiles_to_profiles" && - c != "profiles_to_traces" && - c != "profiles_to_metrics" && - c != "profiles_to_logs" && - c != "extension" { + if !slices.Contains(validStabilityKeys, c) { errs = errors.Join(errs, fmt.Errorf("invalid component: %v", c)) } } diff --git a/cmd/mdatagen/internal/templates/readme.md.tmpl b/cmd/mdatagen/internal/templates/readme.md.tmpl index c99a9bde13a5..7fe5ae902d8b 100644 --- a/cmd/mdatagen/internal/templates/readme.md.tmpl +++ b/cmd/mdatagen/internal/templates/readme.md.tmpl @@ -7,7 +7,7 @@ {{- if ne $class "connector" }} {{- $idx := 0 }} {{- range $stability, $value := .Status.Stability }} -| {{ if not $idx }}Stability{{ else }} {{ end }} | [{{ toLowerCase $stability.String }}]{{ if ne $class "extension" }}: {{ stringsJoin $value ", " }} {{ end }} | +| {{ if not $idx }}Stability{{ else }} {{ end }} | [{{ toLowerCase $stability.String }}]{{ if and (ne $class "extension") (ne $class "converter") (ne $class "provider") }}: {{ stringsJoin $value ", " }} {{ end }} | {{- $idx = inc $idx }} {{- end }} {{- end}} diff --git a/cmd/mdatagen/internal/testdata/readme_with_status_converter.md b/cmd/mdatagen/internal/testdata/readme_with_status_converter.md new file mode 100644 index 000000000000..cb693070eaaf --- /dev/null +++ b/cmd/mdatagen/internal/testdata/readme_with_status_converter.md @@ -0,0 +1,14 @@ +# Some component + + +| Status | | +| ------------- |-----------| +| Stability | [beta] | +| Distributions | [contrib] | +| Issues | [![Open issues](https://img.shields.io/github/issues-search/open-telemetry/opentelemetry-collector-contrib?query=is%3Aissue%20is%3Aopen%20label%3Aconverter%2Ffoo%20&label=open&color=orange&logo=opentelemetry)](https://github.com/open-telemetry/opentelemetry-collector-contrib/issues?q=is%3Aopen+is%3Aissue+label%3Aconverter%2Ffoo) [![Closed issues](https://img.shields.io/github/issues-search/open-telemetry/opentelemetry-collector-contrib?query=is%3Aissue%20is%3Aclosed%20label%3Aconverter%2Ffoo%20&label=closed&color=blue&logo=opentelemetry)](https://github.com/open-telemetry/opentelemetry-collector-contrib/issues?q=is%3Aclosed+is%3Aissue+label%3Aconverter%2Ffoo) | + +[beta]: https://github.com/open-telemetry/opentelemetry-collector/blob/main/docs/component-stability.md#beta +[contrib]: https://github.com/open-telemetry/opentelemetry-collector-releases/tree/main/distributions/otelcol-contrib + + +Some info about a component diff --git a/cmd/mdatagen/internal/testdata/readme_with_status_provider.md b/cmd/mdatagen/internal/testdata/readme_with_status_provider.md new file mode 100644 index 000000000000..e4ab8542de46 --- /dev/null +++ b/cmd/mdatagen/internal/testdata/readme_with_status_provider.md @@ -0,0 +1,14 @@ +# Some component + + +| Status | | +| ------------- |-----------| +| Stability | [beta] | +| Distributions | [contrib] | +| Issues | [![Open issues](https://img.shields.io/github/issues-search/open-telemetry/opentelemetry-collector-contrib?query=is%3Aissue%20is%3Aopen%20label%3Aprovider%2Ffoo%20&label=open&color=orange&logo=opentelemetry)](https://github.com/open-telemetry/opentelemetry-collector-contrib/issues?q=is%3Aopen+is%3Aissue+label%3Aprovider%2Ffoo) [![Closed issues](https://img.shields.io/github/issues-search/open-telemetry/opentelemetry-collector-contrib?query=is%3Aissue%20is%3Aclosed%20label%3Aprovider%2Ffoo%20&label=closed&color=blue&logo=opentelemetry)](https://github.com/open-telemetry/opentelemetry-collector-contrib/issues?q=is%3Aclosed+is%3Aissue+label%3Aprovider%2Ffoo) | + +[beta]: https://github.com/open-telemetry/opentelemetry-collector/blob/main/docs/component-stability.md#beta +[contrib]: https://github.com/open-telemetry/opentelemetry-collector-releases/tree/main/distributions/otelcol-contrib + + +Some info about a component diff --git a/cmd/mdatagen/metadata-schema.yaml b/cmd/mdatagen/metadata-schema.yaml index 375c5b0fbcfe..5a40cbade751 100644 --- a/cmd/mdatagen/metadata-schema.yaml +++ b/cmd/mdatagen/metadata-schema.yaml @@ -13,15 +13,15 @@ generated_package_name: string # Required for components (Optional for subcomponents): A high-level view of the development status and use of this component status: # Required: The class of the component (For example receiver) - class: + class: # Required: The stability of the component - See https://github.com/open-telemetry/opentelemetry-collector/blob/main/docs/component-stability.md#stability-levels stability: - development: [] - alpha: [] - beta: [] - stable: [] - deprecated: [] - unmaintained: [] + development: [] + alpha: [] + beta: [] + stable: [] + deprecated: [] + unmaintained: [] # Optional: The distributions that this component is bundled with (For example core or contrib). See statusdata.go for a list of common distros. distributions: [string] # Optional: A list of warnings that should be brought to the attention of users looking to use this component