From 7a52d7c55d46e5be60f39bfee0dff717ab0d22e4 Mon Sep 17 00:00:00 2001 From: Bogdan Drutu Date: Wed, 23 Oct 2024 14:43:50 -0700 Subject: [PATCH] [mdatagen]: Add otlp as supported distribution (#11527) Signed-off-by: Bogdan Drutu --- .chloggen/add-otlp-distro.yaml | 25 +++++++++++++++++++++ cmd/mdatagen/internal/command.go | 6 ++--- cmd/mdatagen/internal/status.go | 20 ++++++++++++----- cmd/mdatagen/internal/status_test.go | 33 ++++++++++++++++++++++++++++ 4 files changed, 74 insertions(+), 10 deletions(-) create mode 100644 .chloggen/add-otlp-distro.yaml diff --git a/.chloggen/add-otlp-distro.yaml b/.chloggen/add-otlp-distro.yaml new file mode 100644 index 00000000000..9c04d1189ed --- /dev/null +++ b/.chloggen/add-otlp-distro.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 otlp as supported distribution + +# One or more tracking issues or pull requests related to the change +issues: [11527] + +# (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: [user] diff --git a/cmd/mdatagen/internal/command.go b/cmd/mdatagen/internal/command.go index 5abe033a943..9d64f4492af 100644 --- a/cmd/mdatagen/internal/command.go +++ b/cmd/mdatagen/internal/command.go @@ -209,10 +209,8 @@ func templatize(tmplFile string, md Metadata) *template.Template { } return result }, - "inc": func(i int) int { return i + 1 }, - "distroURL": func(name string) string { - return Distros[name] - }, + "inc": func(i int) int { return i + 1 }, + "distroURL": distroURL, "isExporter": func() bool { return md.Status.Class == "exporter" }, diff --git a/cmd/mdatagen/internal/status.go b/cmd/mdatagen/internal/status.go index e61d88fe89a..69e757a0f91 100644 --- a/cmd/mdatagen/internal/status.go +++ b/cmd/mdatagen/internal/status.go @@ -11,15 +11,23 @@ import ( "go.opentelemetry.io/collector/component" ) -// Distros is a collection of distributions that can be referenced in the metadata.yaml files. +// distroURL returns the collection of distributions that can be referenced in the metadata.yaml files. // The rules below apply to every distribution added to this list: // - The distribution is open source and maintained by the OpenTelemetry project. // - The link must point to a publicly accessible repository. -var Distros = map[string]string{ - "core": "https://github.com/open-telemetry/opentelemetry-collector-releases/tree/main/distributions/otelcol", - "contrib": "https://github.com/open-telemetry/opentelemetry-collector-releases/tree/main/distributions/otelcol-contrib", - "k8s": "https://github.com/open-telemetry/opentelemetry-collector-releases/tree/main/distributions/otelcol-k8s", - "otlp": "https://github.com/open-telemetry/opentelemetry-collector-releases/tree/main/distributions/otelcol-otlp", +func distroURL(name string) string { + switch name { + case "core": + return "https://github.com/open-telemetry/opentelemetry-collector-releases/tree/main/distributions/otelcol" + case "contrib": + return "https://github.com/open-telemetry/opentelemetry-collector-releases/tree/main/distributions/otelcol-contrib" + case "k8s": + return "https://github.com/open-telemetry/opentelemetry-collector-releases/tree/main/distributions/otelcol-k8s" + case "otlp": + return "https://github.com/open-telemetry/opentelemetry-collector-releases/tree/main/distributions/otelcol-otlp" + default: + return "" + } } type Codeowners struct { diff --git a/cmd/mdatagen/internal/status_test.go b/cmd/mdatagen/internal/status_test.go index 30813d8d851..3d6d97fe7bd 100644 --- a/cmd/mdatagen/internal/status_test.go +++ b/cmd/mdatagen/internal/status_test.go @@ -9,6 +9,39 @@ import ( "github.com/stretchr/testify/assert" ) +func TestDistroURL(t *testing.T) { + tests := []struct { + input string + output string + }{ + { + input: "core", + output: "https://github.com/open-telemetry/opentelemetry-collector-releases/tree/main/distributions/otelcol", + }, + { + input: "contrib", + output: "https://github.com/open-telemetry/opentelemetry-collector-releases/tree/main/distributions/otelcol-contrib", + }, + { + input: "k8s", + output: "https://github.com/open-telemetry/opentelemetry-collector-releases/tree/main/distributions/otelcol-k8s", + }, + { + input: "otlp", + output: "https://github.com/open-telemetry/opentelemetry-collector-releases/tree/main/distributions/otelcol-otlp", + }, + { + input: "not_found", + output: "", + }, + } + for _, test := range tests { + t.Run(test.input, func(t *testing.T) { + assert.Equal(t, test.output, distroURL(test.input)) + }) + } +} + func TestSortedDistributions(t *testing.T) { tests := []struct { name string