Skip to content

Commit

Permalink
[chore] Remove unused version checks in builder config (open-telemetr…
Browse files Browse the repository at this point in the history
…y#11568)

Updates
open-telemetry#11405

Signed-off-by: Bogdan Drutu <[email protected]>
  • Loading branch information
bogdandrutu authored and HongChenTW committed Dec 19, 2024
1 parent d27ec89 commit 37a214b
Show file tree
Hide file tree
Showing 10 changed files with 11 additions and 240 deletions.
1 change: 0 additions & 1 deletion cmd/builder/go.mod
Original file line number Diff line number Diff line change
Expand Up @@ -6,7 +6,6 @@ module go.opentelemetry.io/collector/cmd/builder
go 1.22.0

require (
github.com/hashicorp/go-version v1.7.0
github.com/knadh/koanf/parsers/yaml v0.1.0
github.com/knadh/koanf/providers/env v1.0.0
github.com/knadh/koanf/providers/file v1.1.2
Expand Down
2 changes: 0 additions & 2 deletions cmd/builder/go.sum

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

56 changes: 9 additions & 47 deletions cmd/builder/internal/builder/config.go
Original file line number Diff line number Diff line change
Expand Up @@ -12,7 +12,6 @@ import (
"strings"
"time"

"github.com/hashicorp/go-version"
"go.uber.org/multierr"
"go.uber.org/zap"
)
Expand Down Expand Up @@ -57,18 +56,15 @@ 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"`
OtelColVersion string `mapstructure:"otelcol_version"`
RequireOtelColModule bool `mapstructure:"-"` // required for backwards-compatibility with builds older than 0.86.0
SupportsConfmapFactories bool `mapstructure:"-"` // Required for backwards-compatibility with builds older than 0.99.0
SupportsComponentModules bool `mapstructure:"-"` // Required for backwards-compatibility with builds older than 0.106.0
OutputPath string `mapstructure:"output_path"`
Version string `mapstructure:"version"`
BuildTags string `mapstructure:"build_tags"`
DebugCompilation bool `mapstructure:"debug_compilation"`
Module string `mapstructure:"module"`
Name string `mapstructure:"name"`
Go string `mapstructure:"go"`
Description string `mapstructure:"description"`
OtelColVersion string `mapstructure:"otelcol_version"`
OutputPath string `mapstructure:"output_path"`
Version string `mapstructure:"version"`
BuildTags string `mapstructure:"build_tags"`
DebugCompilation bool `mapstructure:"debug_compilation"`
}

// Module represents a receiver, exporter, processor or extension for the distribution
Expand Down Expand Up @@ -144,40 +140,6 @@ func (c *Config) SetGoPath() error {
return nil
}

func (c *Config) SetBackwardsCompatibility() error {
// Get the version of the collector
otelColVersion, err := version.NewVersion(c.Distribution.OtelColVersion)
if err != nil {
return err
}

// check whether we need to adjust the core API module import
constraint, err := version.NewConstraint(">= 0.86.0")
if err != nil {
return err
}

c.Distribution.RequireOtelColModule = constraint.Check(otelColVersion)

// check whether confmap factories are supported
constraint, err = version.NewConstraint(">= 0.99.0")
if err != nil {
return err
}

c.Distribution.SupportsConfmapFactories = constraint.Check(otelColVersion)

// check whether go modules are recorded for components
constraint, err = version.NewConstraint(">= 0.106.0")
if err != nil {
return err
}

c.Distribution.SupportsComponentModules = constraint.Check(otelColVersion)

return nil
}

// ParseModules will parse the Modules entries and populate the missing values
func (c *Config) ParseModules() error {
var err error
Expand Down
101 changes: 0 additions & 101 deletions cmd/builder/internal/builder/config_test.go
Original file line number Diff line number Diff line change
Expand Up @@ -223,107 +223,6 @@ func TestDebugOptionSetConfig(t *testing.T) {
assert.True(t, cfg.Distribution.DebugCompilation)
}

func TestRequireOtelColModule(t *testing.T) {
tests := []struct {
Version string
ExpectedRequireOtelColModule bool
}{
{
Version: "0.85.0",
ExpectedRequireOtelColModule: false,
},
{
Version: "0.86.0",
ExpectedRequireOtelColModule: true,
},
{
Version: "0.86.1",
ExpectedRequireOtelColModule: true,
},
{
Version: "1.0.0",
ExpectedRequireOtelColModule: true,
},
}

for _, tt := range tests {
t.Run(tt.Version, func(t *testing.T) {
cfg := NewDefaultConfig()
cfg.Distribution.OtelColVersion = tt.Version
require.NoError(t, cfg.SetBackwardsCompatibility())
assert.Equal(t, tt.ExpectedRequireOtelColModule, cfg.Distribution.RequireOtelColModule)
})
}
}

func TestConfmapFactoryVersions(t *testing.T) {
testCases := []struct {
version string
supported bool
err bool
}{
{
version: "x.0.0",
supported: false,
err: true,
},
{
version: "0.x.0",
supported: false,
err: true,
},
{
version: "0.0.0",
supported: false,
},
{
version: "0.98.0",
supported: false,
},
{
version: "0.98.1",
supported: false,
},
{
version: "0.99.0",
supported: true,
},
{
version: "0.99.7",
supported: true,
},
{
version: "0.100.0",
supported: true,
},
{
version: "0.100.1",
supported: true,
},
{
version: "1.0",
supported: true,
},
{
version: "1.0.0",
supported: true,
},
}

for _, tt := range testCases {
t.Run(tt.version, func(t *testing.T) {
cfg := NewDefaultConfig()
cfg.Distribution.OtelColVersion = tt.version
if !tt.err {
require.NoError(t, cfg.SetBackwardsCompatibility())
assert.Equal(t, tt.supported, cfg.Distribution.SupportsConfmapFactories)
} else {
require.Error(t, cfg.SetBackwardsCompatibility())
}
})
}
}

func TestAddsDefaultProviders(t *testing.T) {
cfg := NewDefaultConfig()
cfg.Providers = nil
Expand Down
5 changes: 1 addition & 4 deletions cmd/builder/internal/builder/main.go
Original file line number Diff line number Diff line change
Expand Up @@ -214,10 +214,7 @@ func processAndWrite(cfg Config, tmpl *template.Template, outFile string, tmplPa
}

func (c *Config) coreModuleAndVersion() (string, string) {
module := "go.opentelemetry.io/collector"
if c.Distribution.RequireOtelColModule {
module += "/otelcol"
}
module := "go.opentelemetry.io/collector/otelcol"
return module, "v" + c.Distribution.OtelColVersion
}

Expand Down
62 changes: 0 additions & 62 deletions cmd/builder/internal/builder/main_test.go
Original file line number Diff line number Diff line change
Expand Up @@ -117,7 +117,6 @@ func newInitializedConfig(t *testing.T) Config {
// Validate and ParseModules will be called before the config is
// given to Generate.
assert.NoError(t, cfg.Validate())
assert.NoError(t, cfg.SetBackwardsCompatibility())
assert.NoError(t, cfg.ParseModules())

return cfg
Expand Down Expand Up @@ -151,17 +150,6 @@ func TestVersioning(t *testing.T) {
},
expectedErr: nil,
},
{
name: "require otelcol",
cfgBuilder: func() Config {
cfg := newTestConfig()
cfg.Distribution.Go = "go"
cfg.Distribution.RequireOtelColModule = true
cfg.Replaces = append(cfg.Replaces, replaces...)
return cfg
},
expectedErr: nil,
},
{
name: "only gomod file, skip generate",
cfgBuilder: func() Config {
Expand All @@ -176,38 +164,6 @@ func TestVersioning(t *testing.T) {
},
expectedErr: ErrDepNotFound,
},
{
name: "old otel version",
cfgBuilder: func() Config {
cfg := newTestConfig()
cfg.Verbose = true
cfg.Distribution.Go = "go"
cfg.Distribution.OtelColVersion = "0.97.0"
cfg.Distribution.RequireOtelColModule = true
var err error
cfg.Exporters, err = parseModules([]Module{
{
GoMod: "go.opentelemetry.io/collector/exporter/otlpexporter v0.97.0",
},
})
require.NoError(t, err)
cfg.Receivers, err = parseModules([]Module{
{
GoMod: "go.opentelemetry.io/collector/receiver/otlpreceiver v0.97.0",
},
})
require.NoError(t, err)
providers, err := parseModules([]Module{
{
GoMod: "go.opentelemetry.io/collector/confmap/provider/envprovider v0.97.0",
},
})
require.NoError(t, err)
cfg.Providers = &providers
return cfg
},
expectedErr: nil,
},
{
name: "old component version",
cfgBuilder: func() Config {
Expand Down Expand Up @@ -245,7 +201,6 @@ func TestVersioning(t *testing.T) {
for _, tt := range tests {
t.Run(tt.name, func(t *testing.T) {
cfg := tt.cfgBuilder()
require.NoError(t, cfg.SetBackwardsCompatibility())
require.NoError(t, cfg.Validate())
require.NoError(t, cfg.ParseModules())
err := GenerateAndCompile(cfg)
Expand Down Expand Up @@ -279,8 +234,6 @@ func TestGenerateAndCompile(t *testing.T) {
name: "Default Configuration Compilation",
cfgBuilder: func(t *testing.T) Config {
cfg := newTestConfig()
err := cfg.SetBackwardsCompatibility()
require.NoError(t, err)
cfg.Distribution.OutputPath = t.TempDir()
cfg.Replaces = append(cfg.Replaces, replaces...)
return cfg
Expand All @@ -290,8 +243,6 @@ func TestGenerateAndCompile(t *testing.T) {
name: "LDFlags Compilation",
cfgBuilder: func(t *testing.T) Config {
cfg := newTestConfig()
err := cfg.SetBackwardsCompatibility()
require.NoError(t, err)
cfg.Distribution.OutputPath = t.TempDir()
cfg.Replaces = append(cfg.Replaces, replaces...)
cfg.LDFlags = `-X "test.gitVersion=0743dc6c6411272b98494a9b32a63378e84c34da" -X "test.gitTag=local-testing" -X "test.goVersion=go version go1.20.7 darwin/amd64"`
Expand All @@ -302,8 +253,6 @@ func TestGenerateAndCompile(t *testing.T) {
name: "Build Tags Compilation",
cfgBuilder: func(t *testing.T) Config {
cfg := newTestConfig()
err := cfg.SetBackwardsCompatibility()
require.NoError(t, err)
cfg.Distribution.OutputPath = t.TempDir()
cfg.Replaces = append(cfg.Replaces, replaces...)
cfg.Distribution.BuildTags = "customTag"
Expand All @@ -314,8 +263,6 @@ func TestGenerateAndCompile(t *testing.T) {
name: "Debug Compilation",
cfgBuilder: func(t *testing.T) Config {
cfg := newTestConfig()
err := cfg.SetBackwardsCompatibility()
require.NoError(t, err)
cfg.Distribution.OutputPath = t.TempDir()
cfg.Replaces = append(cfg.Replaces, replaces...)
cfg.Logger = zap.NewNop()
Expand All @@ -327,8 +274,6 @@ func TestGenerateAndCompile(t *testing.T) {
name: "No providers",
cfgBuilder: func(t *testing.T) Config {
cfg := newTestConfig()
err := cfg.SetBackwardsCompatibility()
require.NoError(t, err)
cfg.Distribution.OutputPath = t.TempDir()
cfg.Replaces = append(cfg.Replaces, replaces...)
cfg.Providers = &[]Module{}
Expand All @@ -339,8 +284,6 @@ func TestGenerateAndCompile(t *testing.T) {
name: "Pre-confmap factories",
cfgBuilder: func(t *testing.T) Config {
cfg := newTestConfig()
err := cfg.SetBackwardsCompatibility()
require.NoError(t, err)
cfg.Distribution.OutputPath = t.TempDir()
cfg.Replaces = append(cfg.Replaces, replaces...)
cfg.Distribution.OtelColVersion = "0.98.0"
Expand All @@ -352,8 +295,6 @@ func TestGenerateAndCompile(t *testing.T) {
name: "With confmap factories",
cfgBuilder: func(t *testing.T) Config {
cfg := newTestConfig()
err := cfg.SetBackwardsCompatibility()
require.NoError(t, err)
cfg.Distribution.OutputPath = t.TempDir()
cfg.Replaces = append(cfg.Replaces, replaces...)
cfg.Distribution.OtelColVersion = "0.99.0"
Expand All @@ -365,8 +306,6 @@ func TestGenerateAndCompile(t *testing.T) {
name: "ConfResolverDefaultURIScheme set",
cfgBuilder: func(t *testing.T) Config {
cfg := newTestConfig()
err := cfg.SetBackwardsCompatibility()
require.NoError(t, err)
cfg.ConfResolver = ConfResolver{
DefaultURIScheme: "env",
}
Expand Down Expand Up @@ -465,7 +404,6 @@ func TestReplaceStatementsAreComplete(t *testing.T) {
})
require.NoError(t, err)

require.NoError(t, cfg.SetBackwardsCompatibility())
require.NoError(t, cfg.Validate())
require.NoError(t, cfg.ParseModules())
err = GenerateAndCompile(cfg)
Expand Down
Loading

0 comments on commit 37a214b

Please sign in to comment.