diff --git a/.chloggen/otelcol_version.yaml b/.chloggen/otelcol_version.yaml new file mode 100644 index 00000000000..f13f4b02cde --- /dev/null +++ b/.chloggen/otelcol_version.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: breaking + +# The name of the component, or a single word describing the area of concern, (e.g. otlpreceiver) +component: builder + +# A brief description of the change. Surround your text with quotes ("") if it needs to start with a backtick (`). +note: Remove builder support to build old version, and the otelcol_version config + +# One or more tracking issues or pull requests related to the change +issues: [11405] + +# (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: User should remove this property from their config, to build older versions use older builders. + +# 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/builder/README.md b/cmd/builder/README.md index 8d26c3b5816..165ccc691aa 100644 --- a/cmd/builder/README.md +++ b/cmd/builder/README.md @@ -142,7 +142,6 @@ dist: module: github.com/open-telemetry/opentelemetry-collector # the module name for the new distribution, following Go mod conventions. Optional, but recommended. name: otelcol-custom # the binary name. Optional. description: "Custom OpenTelemetry Collector distribution" # a long name for the application. Optional. - otelcol_version: "0.40.0" # the OpenTelemetry Collector version to use as base for the distribution. Optional. output_path: /tmp/otelcol-distributionNNN # the path to write the output (sources and binary). Optional. version: "1.0.0" # the version for your custom OpenTelemetry Collector. Optional. go: "/usr/bin/go" # which Go binary to use to compile the generated sources. Optional. diff --git a/cmd/builder/internal/builder/config.go b/cmd/builder/internal/builder/config.go index 95a54b5a5f6..73f7a702793 100644 --- a/cmd/builder/internal/builder/config.go +++ b/cmd/builder/internal/builder/config.go @@ -16,7 +16,7 @@ import ( "go.uber.org/zap" ) -const defaultOtelColVersion = "0.112.0" +const defaultOtelColVersion = "v0.112.0" // ErrMissingGoMod indicates an empty gomod field var ErrMissingGoMod = errors.New("missing gomod specification for module") @@ -25,6 +25,7 @@ var ErrMissingGoMod = errors.New("missing gomod specification for module") type Config struct { Logger *zap.Logger + OtelColVersion string `mapstructure:"-"` // only used be the go.mod template SkipGenerate bool `mapstructure:"-"` SkipCompilation bool `mapstructure:"-"` SkipGetModules bool `mapstructure:"-"` @@ -56,10 +57,11 @@ type ConfResolver struct { // Distribution holds the parameters for the final binary type Distribution struct { - Module string `mapstructure:"module"` - Name string `mapstructure:"name"` - Go string `mapstructure:"go"` - Description string `mapstructure:"description"` + Module string `mapstructure:"module"` + Name string `mapstructure:"name"` + Go string `mapstructure:"go"` + Description string `mapstructure:"description"` + // Deprecated: only here OtelColVersion string `mapstructure:"otelcol_version"` OutputPath string `mapstructure:"output_path"` Version string `mapstructure:"version"` @@ -93,11 +95,11 @@ func NewDefaultConfig() Config { } return Config{ - Logger: log, + OtelColVersion: defaultOtelColVersion, + Logger: log, Distribution: Distribution{ - OutputPath: outputDir, - OtelColVersion: defaultOtelColVersion, - Module: "go.opentelemetry.io/collector/cmd/builder", + OutputPath: outputDir, + Module: "go.opentelemetry.io/collector/cmd/builder", }, // basic retry if error from go mod command (in case of transient network error). // retry 3 times with 5 second spacing interval @@ -110,6 +112,9 @@ func NewDefaultConfig() Config { // Validate checks whether the current configuration is valid func (c *Config) Validate() error { + if c.Distribution.OtelColVersion != "" { + return errors.New("`otelcol_version` has been removed. To build with an older Collector API, use an older (aligned) builder version instead") + } var providersError error if c.Providers != nil { providersError = validateModules("provider", *c.Providers) @@ -178,19 +183,19 @@ func (c *Config) ParseModules() error { } else { providers, err := parseModules([]Module{ { - GoMod: "go.opentelemetry.io/collector/confmap/provider/envprovider v" + c.Distribution.OtelColVersion, + GoMod: "go.opentelemetry.io/collector/confmap/provider/envprovider " + defaultOtelColVersion, }, { - GoMod: "go.opentelemetry.io/collector/confmap/provider/fileprovider v" + c.Distribution.OtelColVersion, + GoMod: "go.opentelemetry.io/collector/confmap/provider/fileprovider " + defaultOtelColVersion, }, { - GoMod: "go.opentelemetry.io/collector/confmap/provider/httpprovider v" + c.Distribution.OtelColVersion, + GoMod: "go.opentelemetry.io/collector/confmap/provider/httpprovider " + defaultOtelColVersion, }, { - GoMod: "go.opentelemetry.io/collector/confmap/provider/httpsprovider v" + c.Distribution.OtelColVersion, + GoMod: "go.opentelemetry.io/collector/confmap/provider/httpsprovider " + defaultOtelColVersion, }, { - GoMod: "go.opentelemetry.io/collector/confmap/provider/yamlprovider v" + c.Distribution.OtelColVersion, + GoMod: "go.opentelemetry.io/collector/confmap/provider/yamlprovider " + defaultOtelColVersion, }, }) if err != nil { diff --git a/cmd/builder/internal/builder/config_test.go b/cmd/builder/internal/builder/config_test.go index a73fa570d30..bc91d2d8cd6 100644 --- a/cmd/builder/internal/builder/config_test.go +++ b/cmd/builder/internal/builder/config_test.go @@ -235,3 +235,9 @@ func TestSkipsNilFieldValidation(t *testing.T) { cfg.Providers = nil assert.NoError(t, cfg.Validate()) } + +func TestValidateDeprecatedOtelColVersion(t *testing.T) { + cfg := NewDefaultConfig() + cfg.Distribution.OtelColVersion = "test" + assert.Error(t, cfg.Validate()) +} diff --git a/cmd/builder/internal/builder/main.go b/cmd/builder/internal/builder/main.go index fb5cd9645c2..2a1edd44e91 100644 --- a/cmd/builder/internal/builder/main.go +++ b/cmd/builder/internal/builder/main.go @@ -30,6 +30,8 @@ var ( skipStrictMsg = "Use --skip-strict-versioning to temporarily disable this check. This flag will be removed in a future minor version" ) +const otelcolPath = "go.opentelemetry.io/collector/otelcol" + func runGoCommand(cfg Config, args ...string) ([]byte, error) { if cfg.Verbose { cfg.Logger.Info("Running go subcommand.", zap.Any("arguments", args)) @@ -73,10 +75,6 @@ func Generate(cfg Config) error { cfg.Logger.Info("Skipping generating source codes.") return nil } - // create a warning message for non-aligned builder and collector base - if cfg.Distribution.OtelColVersion != defaultOtelColVersion { - cfg.Logger.Info("You're building a distribution with non-aligned version of the builder. The version mismatch may cause a compilation failure. It's recommended to use the same version.", zap.String("collector-version", cfg.Distribution.OtelColVersion), zap.String("builder-version", defaultOtelColVersion)) - } // if the file does not exist, try to create it if _, err := os.Stat(cfg.Distribution.OutputPath); os.IsNotExist(err) { if err = os.Mkdir(cfg.Distribution.OutputPath, 0750); err != nil { @@ -155,15 +153,14 @@ func GetModules(cfg Config) error { return err } - corePath, coreVersion := cfg.coreModuleAndVersion() - coreDepVersion, ok := dependencyVersions[corePath] + coreDepVersion, ok := dependencyVersions[otelcolPath] if !ok { - return fmt.Errorf("core collector %w: '%s'. %s", ErrDepNotFound, corePath, skipStrictMsg) + return fmt.Errorf("core collector %w: '%s'. %s", ErrDepNotFound, otelcolPath, skipStrictMsg) } - if semver.MajorMinor(coreDepVersion) != semver.MajorMinor(coreVersion) { + if semver.MajorMinor(coreDepVersion) != semver.MajorMinor(defaultOtelColVersion) { return fmt.Errorf( "%w: core collector version calculated by component dependencies %q does not match configured version %q. %s", - ErrVersionMismatch, coreDepVersion, coreVersion, skipStrictMsg) + ErrVersionMismatch, coreDepVersion, defaultOtelColVersion, skipStrictMsg) } for _, mod := range cfg.allComponents() { @@ -213,11 +210,6 @@ func processAndWrite(cfg Config, tmpl *template.Template, outFile string, tmplPa return tmpl.Execute(out, tmplParams) } -func (c *Config) coreModuleAndVersion() (string, string) { - module := "go.opentelemetry.io/collector/otelcol" - return module, "v" + c.Distribution.OtelColVersion -} - func (c *Config) allComponents() []Module { return slices.Concat[[]Module](c.Exporters, c.Receivers, c.Processors, c.Extensions, c.Connectors, *c.Providers) diff --git a/cmd/builder/internal/builder/main_test.go b/cmd/builder/internal/builder/main_test.go index dd49b66d9fd..485d77708af 100644 --- a/cmd/builder/internal/builder/main_test.go +++ b/cmd/builder/internal/builder/main_test.go @@ -171,7 +171,7 @@ func TestVersioning(t *testing.T) { cfg.Distribution.Go = "go" cfg.Exporters = []Module{ { - GoMod: "go.opentelemetry.io/collector/exporter/otlpexporter v0.97.0", + GoMod: "go.opentelemetry.io/collector/exporter/otlpexporter v0.112.0", }, } cfg.Providers = &[]Module{} @@ -188,7 +188,7 @@ func TestVersioning(t *testing.T) { cfg.SkipStrictVersioning = true cfg.Exporters = []Module{ { - GoMod: "go.opentelemetry.io/collector/exporter/otlpexporter v0.97.0", + GoMod: "go.opentelemetry.io/collector/exporter/otlpexporter v0.112.0", }, } cfg.Providers = &[]Module{} @@ -280,24 +280,12 @@ func TestGenerateAndCompile(t *testing.T) { return cfg }, }, - { - name: "Pre-confmap factories", - cfgBuilder: func(t *testing.T) Config { - cfg := newTestConfig() - cfg.Distribution.OutputPath = t.TempDir() - cfg.Replaces = append(cfg.Replaces, replaces...) - cfg.Distribution.OtelColVersion = "0.98.0" - cfg.SkipStrictVersioning = true - return cfg - }, - }, { name: "With confmap factories", cfgBuilder: func(t *testing.T) Config { cfg := newTestConfig() cfg.Distribution.OutputPath = t.TempDir() cfg.Replaces = append(cfg.Replaces, replaces...) - cfg.Distribution.OtelColVersion = "0.99.0" cfg.SkipStrictVersioning = true return cfg }, @@ -355,11 +343,6 @@ func TestReplaceStatementsAreComplete(t *testing.T) { cfg := NewDefaultConfig() cfg.Distribution.Go = "go" cfg.Distribution.OutputPath = dir - // Use a deliberately nonexistent version to simulate an unreleased - // version of the package. Not strictly necessary since this test - // will catch gaps in the replace statements before a release is in - // progress. - cfg.Distribution.OtelColVersion = "1.9999.9999" cfg.Replaces = append(cfg.Replaces, generateReplaces()...) // Configure all components that we want to use elsewhere in these tests. // This ensures the resulting go.mod file has maximum coverage of modules diff --git a/cmd/builder/internal/builder/templates/go.mod.tmpl b/cmd/builder/internal/builder/templates/go.mod.tmpl index 033a316ce90..7f0bb56725d 100644 --- a/cmd/builder/internal/builder/templates/go.mod.tmpl +++ b/cmd/builder/internal/builder/templates/go.mod.tmpl @@ -23,7 +23,7 @@ require ( {{- range .Processors}} {{if .GoMod}}{{.GoMod}}{{end}} {{- end}} - go.opentelemetry.io/collector/otelcol v{{.Distribution.OtelColVersion}} + go.opentelemetry.io/collector/otelcol {{.OtelColVersion}} ) require ( diff --git a/cmd/builder/internal/command.go b/cmd/builder/internal/command.go index 23e276fedbb..e903cbdc453 100644 --- a/cmd/builder/internal/command.go +++ b/cmd/builder/internal/command.go @@ -149,7 +149,6 @@ func applyCfgFromFile(flags *flag.FlagSet, cfgFromFile builder.Config) { cfg.Distribution.Name = cfgFromFile.Distribution.Name cfg.Distribution.Description = cfgFromFile.Distribution.Description cfg.Distribution.Version = cfgFromFile.Distribution.Version - cfg.Distribution.OtelColVersion = cfgFromFile.Distribution.OtelColVersion cfg.Distribution.Go = cfgFromFile.Distribution.Go cfg.Distribution.Module = cfgFromFile.Distribution.Module cfg.Distribution.BuildTags = cfgFromFile.Distribution.BuildTags diff --git a/cmd/builder/internal/command_test.go b/cmd/builder/internal/command_test.go index e27da29a60d..3454c5e977d 100644 --- a/cmd/builder/internal/command_test.go +++ b/cmd/builder/internal/command_test.go @@ -60,7 +60,6 @@ func Test_applyCfgFromFile(t *testing.T) { Name: "testName", Go: "testGO", Description: "testDescription", - OtelColVersion: "testOtelColVersion", OutputPath: "testOutputPath", Version: "testVersion", BuildTags: "", diff --git a/cmd/builder/internal/config/default.yaml b/cmd/builder/internal/config/default.yaml index d0866047524..c23fcb2e6f1 100644 --- a/cmd/builder/internal/config/default.yaml +++ b/cmd/builder/internal/config/default.yaml @@ -11,7 +11,6 @@ dist: name: otelcorecol description: Local OpenTelemetry Collector binary, testing only. version: 0.112.0-dev - otelcol_version: 0.112.0 receivers: - gomod: go.opentelemetry.io/collector/receiver/nopreceiver v0.112.0 diff --git a/cmd/builder/test/core.builder.yaml b/cmd/builder/test/core.builder.yaml index be41ea341f8..15f420d573c 100644 --- a/cmd/builder/test/core.builder.yaml +++ b/cmd/builder/test/core.builder.yaml @@ -1,7 +1,6 @@ dist: name: core module: go.opentelemetry.io/collector/builder/test/core - otelcol_version: 0.112.0 go: ${GOBIN} extensions: diff --git a/cmd/otelcorecol/builder-config.yaml b/cmd/otelcorecol/builder-config.yaml index 6cce4b4f45f..fcea130ab15 100644 --- a/cmd/otelcorecol/builder-config.yaml +++ b/cmd/otelcorecol/builder-config.yaml @@ -11,7 +11,6 @@ dist: name: otelcorecol description: Local OpenTelemetry Collector binary, testing only. version: 0.112.0-dev - otelcol_version: 0.112.0 receivers: - gomod: go.opentelemetry.io/collector/receiver/nopreceiver v0.112.0