Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

[chore] [cmd/mdatagen] Use enum for stability levels #31530

Merged
merged 1 commit into from
Mar 1, 2024
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
22 changes: 22 additions & 0 deletions .chloggen/mdatagen-use-enums-for-stability-levels.yaml
Original file line number Diff line number Diff line change
@@ -0,0 +1,22 @@
# Use this changelog template to create an entry for release notes.

# One of 'breaking', 'deprecation', 'new_component', 'enhancement', 'bug_fix'
change_type: 'breaking'

# The name of the component, or a single word describing the area of concern, (e.g. filelogreceiver)
component: 'cmd/mdatagen'

# A brief description of the change. Surround your text with quotes ("") if it needs to start with a backtick (`).
note: "Use enum for stability levels in the Metadata struct"

# Mandatory: One or more tracking issues related to the change. You can use the PR number here if no issue exists.
issues: [31530]

# If your change doesn't affect end users or the exported elements of any package,
# you should instead start your pull request title with [chore] or use the "Skip Changelog" label.
# 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: [api]

Some generated files are not rendered by default. Learn more about how customized files appear on GitHub.

9 changes: 5 additions & 4 deletions cmd/mdatagen/loader_test.go
Original file line number Diff line number Diff line change
Expand Up @@ -7,6 +7,7 @@ import (
"testing"

"github.com/stretchr/testify/require"
"go.opentelemetry.io/collector/component"
"go.opentelemetry.io/collector/pdata/pcommon"
"go.opentelemetry.io/collector/pdata/pmetric"
)
Expand All @@ -24,10 +25,10 @@ func TestLoadMetadata(t *testing.T) {
SemConvVersion: "1.9.0",
Status: &Status{
Class: "receiver",
Stability: map[string][]string{
"development": {"logs"},
"beta": {"traces"},
"stable": {"metrics"},
Stability: map[component.StabilityLevel][]string{
component.StabilityLevelDevelopment: {"logs"},
component.StabilityLevelBeta: {"traces"},
component.StabilityLevelStable: {"metrics"},
},
Distributions: []string{},
Codeowners: &Codeowners{
Expand Down
3 changes: 2 additions & 1 deletion cmd/mdatagen/main.go
Original file line number Diff line number Diff line change
Expand Up @@ -165,7 +165,8 @@ func templatize(tmplFile string, md metadata) *template.Template {
}
return result
},
"casesTitle": cases.Title(language.English).String,
"casesTitle": cases.Title(language.English).String,
"toLowerCase": strings.ToLower,
"toCamelCase": func(s string) string {
caser := cases.Title(language.English).String
parts := strings.Split(s, "_")
Expand Down
27 changes: 19 additions & 8 deletions cmd/mdatagen/main_test.go
Original file line number Diff line number Diff line change
Expand Up @@ -11,6 +11,7 @@ import (
"testing"

"github.com/stretchr/testify/require"
"go.opentelemetry.io/collector/component"
)

func TestRunContents(t *testing.T) {
Expand Down Expand Up @@ -129,7 +130,7 @@ func TestInlineReplace(t *testing.T) {
outputFile string
componentClass string
warnings []string
stability map[string][]string
stability map[component.StabilityLevel][]string
distros []string
codeowners *Codeowners
}{
Expand Down Expand Up @@ -258,8 +259,11 @@ Some warning there.
Some info about a component
`,
outputFile: "readme_with_multiple_signals.md",
stability: map[string][]string{"beta": {"metrics"}, "alpha": {"logs"}},
distros: []string{"contrib"},
stability: map[component.StabilityLevel][]string{
component.StabilityLevelBeta: {"metrics"},
component.StabilityLevelAlpha: {"logs"},
},
distros: []string{"contrib"},
},
{
name: "readme with cmd class",
Expand All @@ -270,15 +274,18 @@ Some info about a component

Some info about a component
`,
outputFile: "readme_with_cmd_class.md",
stability: map[string][]string{"beta": {"metrics"}, "alpha": {"logs"}},
outputFile: "readme_with_cmd_class.md",
stability: map[component.StabilityLevel][]string{
component.StabilityLevelBeta: {"metrics"},
component.StabilityLevelAlpha: {"logs"},
},
componentClass: "cmd",
distros: []string{},
},
}
for _, tt := range tests {
t.Run(tt.name, func(t *testing.T) {
stability := map[string][]string{"beta": {"metrics"}}
stability := map[component.StabilityLevel][]string{component.StabilityLevelBeta: {"metrics"}}
if len(tt.stability) > 0 {
stability = tt.stability
}
Expand Down Expand Up @@ -327,7 +334,9 @@ func TestGenerateStatusMetadata(t *testing.T) {
md: metadata{
Type: "foo",
Status: &Status{
Stability: map[string][]string{"beta": {"metrics"}},
Stability: map[component.StabilityLevel][]string{
component.StabilityLevelBeta: {"metrics"},
},
Distributions: []string{"contrib"},
Class: "receiver",
},
Expand Down Expand Up @@ -364,7 +373,9 @@ func Tracer(settings component.TelemetrySettings) trace.Tracer {
md: metadata{
Type: "foo",
Status: &Status{
Stability: map[string][]string{"alpha": {"metrics"}},
Stability: map[component.StabilityLevel][]string{
component.StabilityLevelAlpha: {"metrics"},
},
Distributions: []string{"contrib"},
Class: "receiver",
},
Expand Down
47 changes: 41 additions & 6 deletions cmd/mdatagen/statusdata.go
Original file line number Diff line number Diff line change
Expand Up @@ -4,7 +4,12 @@
package main

import (
"errors"
"sort"
"strings"

"go.opentelemetry.io/collector/component"
"go.opentelemetry.io/collector/confmap"
)

// distros is a collection of distributions that can be referenced in the metadata.yaml files.
Expand Down Expand Up @@ -32,13 +37,15 @@ type Codeowners struct {
SeekingNew bool `mapstructure:"seeking_new"`
}

type StabilityMap map[component.StabilityLevel][]string

type Status struct {
Stability map[string][]string `mapstructure:"stability"`
Distributions []string `mapstructure:"distributions"`
Class string `mapstructure:"class"`
Warnings []string `mapstructure:"warnings"`
Codeowners *Codeowners `mapstructure:"codeowners"`
UnsupportedPlatforms []string `mapstructure:"unsupported_platforms"`
Stability StabilityMap `mapstructure:"stability"`
Distributions []string `mapstructure:"distributions"`
Class string `mapstructure:"class"`
Warnings []string `mapstructure:"warnings"`
Codeowners *Codeowners `mapstructure:"codeowners"`
UnsupportedPlatforms []string `mapstructure:"unsupported_platforms"`
}

func (s *Status) SortedDistributions() []string {
Expand All @@ -60,3 +67,31 @@ func (s *Status) SortedDistributions() []string {
})
return sorted
}

func (ms *StabilityMap) Unmarshal(parser *confmap.Conf) error {
Copy link
Member

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Should we make component.StabilityLevel implement UnmarshalText instead?

*ms = make(StabilityMap)
raw := make(map[string][]string)
err := parser.Unmarshal(&raw)
if err != nil {
return err
}
for k, v := range raw {
switch strings.ToLower(k) {
case strings.ToLower(component.StabilityLevelUnmaintained.String()):
(*ms)[component.StabilityLevelUnmaintained] = v
case strings.ToLower(component.StabilityLevelDeprecated.String()):
(*ms)[component.StabilityLevelDeprecated] = v
case strings.ToLower(component.StabilityLevelDevelopment.String()):
(*ms)[component.StabilityLevelDevelopment] = v
case strings.ToLower(component.StabilityLevelAlpha.String()):
(*ms)[component.StabilityLevelAlpha] = v
case strings.ToLower(component.StabilityLevelBeta.String()):
(*ms)[component.StabilityLevelBeta] = v
case strings.ToLower(component.StabilityLevelStable.String()):
(*ms)[component.StabilityLevelStable] = v
default:
return errors.New("invalid stability level: " + k)
}
}
return nil
}
6 changes: 3 additions & 3 deletions cmd/mdatagen/templates/readme.md.tmpl
Original file line number Diff line number Diff line change
Expand Up @@ -7,7 +7,7 @@
{{- if ne $class "connector" }}
{{- $idx := 0 }}
{{- range $stability, $value := .Status.Stability }}
| {{ if not $idx }}Stability{{ else }} {{ end }} | [{{ $stability }}]{{ if ne $class "extension" }}: {{ stringsJoin $value ", " }} {{ end }} |
| {{ if not $idx }}Stability{{ else }} {{ end }} | [{{ toLowerCase $stability.String }}]{{ if ne $class "extension" }}: {{ stringsJoin $value ", " }} {{ end }} |
{{- $idx = inc $idx }}
{{- end }}
{{- end}}
Expand All @@ -29,7 +29,7 @@
{{- end }}
{{- end }}
{{range $stability, $val := .Status.Stability}}
[{{ $stability }}]: https://github.com/open-telemetry/opentelemetry-collector#{{ $stability }}
[{{ toLowerCase $stability.String }}]: https://github.com/open-telemetry/opentelemetry-collector#{{ toLowerCase $stability.String }}
{{- end }}
{{- range .Status.SortedDistributions }}
[{{.}}]: {{ distroURL . }}
Expand All @@ -43,7 +43,7 @@
{{- range $stability, $pipelines := .Status.Stability }}
{{- range $pipeline := $pipelines }}
{{- $parts := stringsSplit $pipeline "_to_" }}
| {{index $parts 0}} | {{index $parts 1}} | [{{$stability}}] |
| {{index $parts 0}} | {{index $parts 1}} | [{{ toLowerCase $stability.String }}] |
{{- end }}
{{- end }}

Expand Down
2 changes: 1 addition & 1 deletion cmd/mdatagen/templates/status.go.tmpl
Original file line number Diff line number Diff line change
Expand Up @@ -17,7 +17,7 @@ var (
const (
{{- range $stability, $signals := .Status.Stability }}
{{- range $signal := $signals }}
{{ toCamelCase $signal }}Stability = component.StabilityLevel{{ casesTitle $stability }}
{{ toCamelCase $signal }}Stability = component.StabilityLevel{{ $stability.String }}
{{- end }}
{{- end }}
)
Expand Down
5 changes: 1 addition & 4 deletions cmd/mdatagen/validate.go
Original file line number Diff line number Diff line change
Expand Up @@ -89,10 +89,7 @@ func (s *Status) validateStability() error {
return errors.New("missing stability")
}
for stability, component := range s.Stability {
if stability != "development" && stability != "alpha" && stability != "beta" && stability != "stable" && stability != "deprecated" && stability != "unmaintained" {
errs = multierr.Append(errs, fmt.Errorf("invalid stability: %v", stability))
}
if component == nil {
if len(component) == 0 {
errs = multierr.Append(errs, fmt.Errorf("missing component for stability: %v", stability))
}
for _, c := range component {
Expand Down
4 changes: 2 additions & 2 deletions cmd/mdatagen/validate_test.go
Original file line number Diff line number Diff line change
Expand Up @@ -40,11 +40,11 @@ func TestValidate(t *testing.T) {
},
{
name: "testdata/invalid_stability.yaml",
wantErr: "invalid stability: incorrectstability",
wantErr: "1 error(s) decoding:\n\n* error decoding 'status.stability': invalid stability level: incorrectstability",
},
{
name: "testdata/no_stability_component.yaml",
wantErr: "missing component for stability: beta",
wantErr: "missing component for stability: Beta",
},
{
name: "testdata/invalid_stability_component.yaml",
Expand Down
6 changes: 3 additions & 3 deletions cmd/telemetrygen/README.md
Original file line number Diff line number Diff line change
Expand Up @@ -3,13 +3,13 @@
<!-- status autogenerated section -->
| Status | |
| ------------- |-----------|
| Stability | [alpha]: traces |
| | [development]: metrics, logs |
| Stability | [development]: metrics, logs |
| | [alpha]: traces |
| Issues | [![Open issues](https://img.shields.io/github/issues-search/open-telemetry/opentelemetry-collector-contrib?query=is%3Aissue%20is%3Aopen%20label%3Acmd%2Ftelemetrygen%20&label=open&color=orange&logo=opentelemetry)](https://github.com/open-telemetry/opentelemetry-collector-contrib/issues?q=is%3Aopen+is%3Aissue+label%3Acmd%2Ftelemetrygen) [![Closed issues](https://img.shields.io/github/issues-search/open-telemetry/opentelemetry-collector-contrib?query=is%3Aissue%20is%3Aclosed%20label%3Acmd%2Ftelemetrygen%20&label=closed&color=blue&logo=opentelemetry)](https://github.com/open-telemetry/opentelemetry-collector-contrib/issues?q=is%3Aclosed+is%3Aissue+label%3Acmd%2Ftelemetrygen) |
| [Code Owners](https://github.com/open-telemetry/opentelemetry-collector-contrib/blob/main/CONTRIBUTING.md#becoming-a-code-owner) | [@mx-psi](https://www.github.com/mx-psi), [@codeboten](https://www.github.com/codeboten) |

[alpha]: https://github.com/open-telemetry/opentelemetry-collector#alpha
[development]: https://github.com/open-telemetry/opentelemetry-collector#development
[alpha]: https://github.com/open-telemetry/opentelemetry-collector#alpha
<!-- end autogenerated section -->

This utility simulates a client generating **traces**, **metrics**, and **logs**. It is useful for testing and demonstration purposes.
Expand Down
6 changes: 3 additions & 3 deletions exporter/loadbalancingexporter/README.md
Original file line number Diff line number Diff line change
Expand Up @@ -3,14 +3,14 @@
<!-- status autogenerated section -->
| Status | |
| ------------- |-----------|
| Stability | [beta]: traces, logs |
| | [development]: metrics |
| Stability | [development]: metrics |
| | [beta]: traces, logs |
| Distributions | [contrib], [aws], [grafana], [observiq], [splunk], [sumo] |
| Issues | [![Open issues](https://img.shields.io/github/issues-search/open-telemetry/opentelemetry-collector-contrib?query=is%3Aissue%20is%3Aopen%20label%3Aexporter%2Floadbalancing%20&label=open&color=orange&logo=opentelemetry)](https://github.com/open-telemetry/opentelemetry-collector-contrib/issues?q=is%3Aopen+is%3Aissue+label%3Aexporter%2Floadbalancing) [![Closed issues](https://img.shields.io/github/issues-search/open-telemetry/opentelemetry-collector-contrib?query=is%3Aissue%20is%3Aclosed%20label%3Aexporter%2Floadbalancing%20&label=closed&color=blue&logo=opentelemetry)](https://github.com/open-telemetry/opentelemetry-collector-contrib/issues?q=is%3Aclosed+is%3Aissue+label%3Aexporter%2Floadbalancing) |
| [Code Owners](https://github.com/open-telemetry/opentelemetry-collector-contrib/blob/main/CONTRIBUTING.md#becoming-a-code-owner) | [@jpkrohling](https://www.github.com/jpkrohling) |

[beta]: https://github.com/open-telemetry/opentelemetry-collector#beta
[development]: https://github.com/open-telemetry/opentelemetry-collector#development
[beta]: https://github.com/open-telemetry/opentelemetry-collector#beta
[contrib]: https://github.com/open-telemetry/opentelemetry-collector-releases/tree/main/distributions/otelcol-contrib
[aws]: https://github.com/aws-observability/aws-otel-collector
[grafana]: https://github.com/grafana/agent
Expand Down

Some generated files are not rendered by default. Learn more about how customized files appear on GitHub.

6 changes: 3 additions & 3 deletions exporter/opensearchexporter/README.md
Original file line number Diff line number Diff line change
Expand Up @@ -3,14 +3,14 @@
<!-- status autogenerated section -->
| Status | |
| ------------- |-----------|
| Stability | [alpha]: traces |
| | [development]: logs |
| Stability | [development]: logs |
| | [alpha]: traces |
| Distributions | [contrib] |
| Issues | [![Open issues](https://img.shields.io/github/issues-search/open-telemetry/opentelemetry-collector-contrib?query=is%3Aissue%20is%3Aopen%20label%3Aexporter%2Fopensearch%20&label=open&color=orange&logo=opentelemetry)](https://github.com/open-telemetry/opentelemetry-collector-contrib/issues?q=is%3Aopen+is%3Aissue+label%3Aexporter%2Fopensearch) [![Closed issues](https://img.shields.io/github/issues-search/open-telemetry/opentelemetry-collector-contrib?query=is%3Aissue%20is%3Aclosed%20label%3Aexporter%2Fopensearch%20&label=closed&color=blue&logo=opentelemetry)](https://github.com/open-telemetry/opentelemetry-collector-contrib/issues?q=is%3Aclosed+is%3Aissue+label%3Aexporter%2Fopensearch) |
| [Code Owners](https://github.com/open-telemetry/opentelemetry-collector-contrib/blob/main/CONTRIBUTING.md#becoming-a-code-owner) | [@Aneurysm9](https://www.github.com/Aneurysm9), [@MitchellGale](https://www.github.com/MitchellGale), [@MaxKsyunz](https://www.github.com/MaxKsyunz), [@YANG-DB](https://www.github.com/YANG-DB) |

[alpha]: https://github.com/open-telemetry/opentelemetry-collector#alpha
[development]: https://github.com/open-telemetry/opentelemetry-collector#development
[alpha]: https://github.com/open-telemetry/opentelemetry-collector#alpha
[contrib]: https://github.com/open-telemetry/opentelemetry-collector-releases/tree/main/distributions/otelcol-contrib
<!-- end autogenerated section -->

Expand Down

Some generated files are not rendered by default. Learn more about how customized files appear on GitHub.

6 changes: 3 additions & 3 deletions receiver/k8sclusterreceiver/README.md
Original file line number Diff line number Diff line change
Expand Up @@ -3,14 +3,14 @@
<!-- status autogenerated section -->
| Status | |
| ------------- |-----------|
| Stability | [beta]: metrics |
| | [development]: logs |
| Stability | [development]: logs |
| | [beta]: metrics |
| Distributions | [contrib], [liatrio], [observiq], [splunk], [sumo] |
| Issues | [![Open issues](https://img.shields.io/github/issues-search/open-telemetry/opentelemetry-collector-contrib?query=is%3Aissue%20is%3Aopen%20label%3Areceiver%2Fk8scluster%20&label=open&color=orange&logo=opentelemetry)](https://github.com/open-telemetry/opentelemetry-collector-contrib/issues?q=is%3Aopen+is%3Aissue+label%3Areceiver%2Fk8scluster) [![Closed issues](https://img.shields.io/github/issues-search/open-telemetry/opentelemetry-collector-contrib?query=is%3Aissue%20is%3Aclosed%20label%3Areceiver%2Fk8scluster%20&label=closed&color=blue&logo=opentelemetry)](https://github.com/open-telemetry/opentelemetry-collector-contrib/issues?q=is%3Aclosed+is%3Aissue+label%3Areceiver%2Fk8scluster) |
| [Code Owners](https://github.com/open-telemetry/opentelemetry-collector-contrib/blob/main/CONTRIBUTING.md#becoming-a-code-owner) | [@dmitryax](https://www.github.com/dmitryax), [@TylerHelmuth](https://www.github.com/TylerHelmuth), [@povilasv](https://www.github.com/povilasv) |

[beta]: https://github.com/open-telemetry/opentelemetry-collector#beta
[development]: https://github.com/open-telemetry/opentelemetry-collector#development
[beta]: https://github.com/open-telemetry/opentelemetry-collector#beta
[contrib]: https://github.com/open-telemetry/opentelemetry-collector-releases/tree/main/distributions/otelcol-contrib
[liatrio]: https://github.com/liatrio/liatrio-otel-collector
[observiq]: https://github.com/observIQ/observiq-otel-collector
Expand Down

Some generated files are not rendered by default. Learn more about how customized files appear on GitHub.

6 changes: 3 additions & 3 deletions receiver/skywalkingreceiver/README.md
Original file line number Diff line number Diff line change
Expand Up @@ -3,14 +3,14 @@
<!-- status autogenerated section -->
| Status | |
| ------------- |-----------|
| Stability | [beta]: traces |
| | [development]: metrics |
| Stability | [development]: metrics |
| | [beta]: traces |
| Distributions | [contrib], [sumo] |
| Issues | [![Open issues](https://img.shields.io/github/issues-search/open-telemetry/opentelemetry-collector-contrib?query=is%3Aissue%20is%3Aopen%20label%3Areceiver%2Fskywalking%20&label=open&color=orange&logo=opentelemetry)](https://github.com/open-telemetry/opentelemetry-collector-contrib/issues?q=is%3Aopen+is%3Aissue+label%3Areceiver%2Fskywalking) [![Closed issues](https://img.shields.io/github/issues-search/open-telemetry/opentelemetry-collector-contrib?query=is%3Aissue%20is%3Aclosed%20label%3Areceiver%2Fskywalking%20&label=closed&color=blue&logo=opentelemetry)](https://github.com/open-telemetry/opentelemetry-collector-contrib/issues?q=is%3Aclosed+is%3Aissue+label%3Areceiver%2Fskywalking) |
| [Code Owners](https://github.com/open-telemetry/opentelemetry-collector-contrib/blob/main/CONTRIBUTING.md#becoming-a-code-owner) | [@JaredTan95](https://www.github.com/JaredTan95) |

[beta]: https://github.com/open-telemetry/opentelemetry-collector#beta
[development]: https://github.com/open-telemetry/opentelemetry-collector#development
[beta]: https://github.com/open-telemetry/opentelemetry-collector#beta
[contrib]: https://github.com/open-telemetry/opentelemetry-collector-releases/tree/main/distributions/otelcol-contrib
[sumo]: https://github.com/SumoLogic/sumologic-otel-collector
<!-- end autogenerated section -->
Expand Down

Some generated files are not rendered by default. Learn more about how customized files appear on GitHub.

Loading
Loading