Skip to content

Commit

Permalink
Remove builder support to build old version, and the otelcol_version …
Browse files Browse the repository at this point in the history
…config (open-telemetry#11588)

Fixes
open-telemetry#11405

Signed-off-by: Bogdan Drutu <[email protected]>
  • Loading branch information
bogdandrutu authored and djaglowski committed Nov 21, 2024
1 parent 13f2495 commit 910f74f
Show file tree
Hide file tree
Showing 12 changed files with 59 additions and 54 deletions.
25 changes: 25 additions & 0 deletions .chloggen/otelcol_version.yaml
Original file line number Diff line number Diff line change
@@ -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]
1 change: 0 additions & 1 deletion cmd/builder/README.md
Original file line number Diff line number Diff line change
Expand Up @@ -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.
Expand Down
33 changes: 19 additions & 14 deletions cmd/builder/internal/builder/config.go
Original file line number Diff line number Diff line change
Expand Up @@ -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")
Expand All @@ -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:"-"`
Expand Down Expand Up @@ -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"`
Expand Down Expand Up @@ -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
Expand All @@ -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)
Expand Down Expand Up @@ -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 {
Expand Down
6 changes: 6 additions & 0 deletions cmd/builder/internal/builder/config_test.go
Original file line number Diff line number Diff line change
Expand Up @@ -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())
}
20 changes: 6 additions & 14 deletions cmd/builder/internal/builder/main.go
Original file line number Diff line number Diff line change
Expand Up @@ -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))
Expand Down Expand Up @@ -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 {
Expand Down Expand Up @@ -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() {
Expand Down Expand Up @@ -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)
Expand Down
21 changes: 2 additions & 19 deletions cmd/builder/internal/builder/main_test.go
Original file line number Diff line number Diff line change
Expand Up @@ -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{}
Expand All @@ -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{}
Expand Down Expand Up @@ -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
},
Expand Down Expand Up @@ -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
Expand Down
2 changes: 1 addition & 1 deletion cmd/builder/internal/builder/templates/go.mod.tmpl
Original file line number Diff line number Diff line change
Expand Up @@ -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 (
Expand Down
1 change: 0 additions & 1 deletion cmd/builder/internal/command.go
Original file line number Diff line number Diff line change
Expand Up @@ -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
Expand Down
1 change: 0 additions & 1 deletion cmd/builder/internal/command_test.go
Original file line number Diff line number Diff line change
Expand Up @@ -60,7 +60,6 @@ func Test_applyCfgFromFile(t *testing.T) {
Name: "testName",
Go: "testGO",
Description: "testDescription",
OtelColVersion: "testOtelColVersion",
OutputPath: "testOutputPath",
Version: "testVersion",
BuildTags: "",
Expand Down
1 change: 0 additions & 1 deletion cmd/builder/internal/config/default.yaml
Original file line number Diff line number Diff line change
Expand Up @@ -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
Expand Down
1 change: 0 additions & 1 deletion cmd/builder/test/core.builder.yaml
Original file line number Diff line number Diff line change
@@ -1,7 +1,6 @@
dist:
name: core
module: go.opentelemetry.io/collector/builder/test/core
otelcol_version: 0.112.0
go: ${GOBIN}

extensions:
Expand Down
1 change: 0 additions & 1 deletion cmd/otelcorecol/builder-config.yaml
Original file line number Diff line number Diff line change
Expand Up @@ -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
Expand Down

0 comments on commit 910f74f

Please sign in to comment.