Skip to content

Commit

Permalink
Update builder default providers to lastest stable (#11566)
Browse files Browse the repository at this point in the history
Signed-off-by: Bogdan Drutu <[email protected]>
  • Loading branch information
bogdandrutu authored Nov 5, 2024
1 parent 27bcaf6 commit 084aa63
Show file tree
Hide file tree
Showing 7 changed files with 110 additions and 86 deletions.
25 changes: 25 additions & 0 deletions .chloggen/fixbuilderproviders2.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: 'bug_fix'

# 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: Update builder default providers to lastest stable releases

# One or more tracking issues or pull requests related to the change
issues: [11566]

# (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]
75 changes: 33 additions & 42 deletions cmd/builder/internal/builder/config.go
Original file line number Diff line number Diff line change
Expand Up @@ -16,10 +16,13 @@ import (
"go.uber.org/zap"
)

const defaultOtelColVersion = "v0.112.0"
const defaultBetaOtelColVersion = "v0.112.0"
const defaultStableOtelColVersion = "v1.17.0"

// ErrMissingGoMod indicates an empty gomod field
var ErrMissingGoMod = errors.New("missing gomod specification for module")
var (
// errMissingGoMod indicates an empty gomod field
errMissingGoMod = errors.New("missing gomod specification for module")
)

// Config holds the builder's configuration
type Config struct {
Expand All @@ -39,7 +42,7 @@ type Config struct {
Receivers []Module `mapstructure:"receivers"`
Processors []Module `mapstructure:"processors"`
Connectors []Module `mapstructure:"connectors"`
Providers *[]Module `mapstructure:"providers"`
Providers []Module `mapstructure:"providers"`
Replaces []string `mapstructure:"replaces"`
Excludes []string `mapstructure:"excludes"`

Expand Down Expand Up @@ -83,19 +86,19 @@ type retry struct {
}

// NewDefaultConfig creates a new config, with default values
func NewDefaultConfig() *Config {
func NewDefaultConfig() (*Config, error) {
log, err := zap.NewDevelopment()
if err != nil {
panic(fmt.Sprintf("failed to obtain a logger instance: %v", err))
}

outputDir, err := os.MkdirTemp("", "otelcol-distribution")
if err != nil {
log.Error("failed to obtain a temporary directory", zap.Error(err))
return nil, err
}

return &Config{
OtelColVersion: defaultOtelColVersion,
OtelColVersion: defaultBetaOtelColVersion,
Logger: log,
Distribution: Distribution{
OutputPath: outputDir,
Expand All @@ -107,25 +110,38 @@ func NewDefaultConfig() *Config {
numRetries: 3,
wait: 5 * time.Second,
},
}
Providers: []Module{
{
GoMod: "go.opentelemetry.io/collector/confmap/provider/envprovider " + defaultStableOtelColVersion,
},
{
GoMod: "go.opentelemetry.io/collector/confmap/provider/fileprovider " + defaultStableOtelColVersion,
},
{
GoMod: "go.opentelemetry.io/collector/confmap/provider/httpprovider " + defaultStableOtelColVersion,
},
{
GoMod: "go.opentelemetry.io/collector/confmap/provider/httpsprovider " + defaultStableOtelColVersion,
},
{
GoMod: "go.opentelemetry.io/collector/confmap/provider/yamlprovider " + defaultStableOtelColVersion,
},
},
}, nil
}

// 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)
}
return multierr.Combine(
validateModules("extension", c.Extensions),
validateModules("receiver", c.Receivers),
validateModules("exporter", c.Exporters),
validateModules("processor", c.Processors),
validateModules("connector", c.Connectors),
providersError,
validateModules("provider", c.Providers),
)
}

Expand Down Expand Up @@ -174,34 +190,9 @@ func (c *Config) ParseModules() error {
return err
}

if c.Providers != nil {
providers, err := parseModules(*c.Providers)
if err != nil {
return err
}
c.Providers = &providers
} else {
providers, err := parseModules([]Module{
{
GoMod: "go.opentelemetry.io/collector/confmap/provider/envprovider " + defaultOtelColVersion,
},
{
GoMod: "go.opentelemetry.io/collector/confmap/provider/fileprovider " + defaultOtelColVersion,
},
{
GoMod: "go.opentelemetry.io/collector/confmap/provider/httpprovider " + defaultOtelColVersion,
},
{
GoMod: "go.opentelemetry.io/collector/confmap/provider/httpsprovider " + defaultOtelColVersion,
},
{
GoMod: "go.opentelemetry.io/collector/confmap/provider/yamlprovider " + defaultOtelColVersion,
},
})
if err != nil {
return err
}
c.Providers = &providers
c.Providers, err = parseModules(c.Providers)
if err != nil {
return err
}

return nil
Expand All @@ -210,7 +201,7 @@ func (c *Config) ParseModules() error {
func validateModules(name string, mods []Module) error {
for i, mod := range mods {
if mod.GoMod == "" {
return fmt.Errorf("%s module at index %v: %w", name, i, ErrMissingGoMod)
return fmt.Errorf("%s module at index %v: %w", name, i, errMissingGoMod)
}
}
return nil
Expand Down
29 changes: 16 additions & 13 deletions cmd/builder/internal/builder/config_test.go
Original file line number Diff line number Diff line change
Expand Up @@ -88,11 +88,11 @@ func TestMissingModule(t *testing.T) {
{
cfg: Config{
Logger: zap.NewNop(),
Providers: &[]Module{{
Providers: []Module{{
Import: "invalid",
}},
},
err: ErrMissingGoMod,
err: errMissingGoMod,
},
{
cfg: Config{
Expand All @@ -101,7 +101,7 @@ func TestMissingModule(t *testing.T) {
Import: "invalid",
}},
},
err: ErrMissingGoMod,
err: errMissingGoMod,
},
{
cfg: Config{
Expand All @@ -110,7 +110,7 @@ func TestMissingModule(t *testing.T) {
Import: "invalid",
}},
},
err: ErrMissingGoMod,
err: errMissingGoMod,
},
{
cfg: Config{
Expand All @@ -119,7 +119,7 @@ func TestMissingModule(t *testing.T) {
Import: "invali",
}},
},
err: ErrMissingGoMod,
err: errMissingGoMod,
},
{
cfg: Config{
Expand All @@ -128,7 +128,7 @@ func TestMissingModule(t *testing.T) {
Import: "invalid",
}},
},
err: ErrMissingGoMod,
err: errMissingGoMod,
},
{
cfg: Config{
Expand All @@ -137,7 +137,7 @@ func TestMissingModule(t *testing.T) {
Import: "invalid",
}},
},
err: ErrMissingGoMod,
err: errMissingGoMod,
},
}

Expand All @@ -147,7 +147,8 @@ func TestMissingModule(t *testing.T) {
}

func TestNewDefaultConfig(t *testing.T) {
cfg := NewDefaultConfig()
cfg, err := NewDefaultConfig()
require.NoError(t, err)
require.NoError(t, cfg.ParseModules())
assert.NoError(t, cfg.Validate())
assert.NoError(t, cfg.SetGoPath())
Expand Down Expand Up @@ -224,20 +225,22 @@ func TestDebugOptionSetConfig(t *testing.T) {
}

func TestAddsDefaultProviders(t *testing.T) {
cfg := NewDefaultConfig()
cfg.Providers = nil
cfg, err := NewDefaultConfig()
require.NoError(t, err)
require.NoError(t, cfg.ParseModules())
assert.Len(t, *cfg.Providers, 5)
assert.Len(t, cfg.Providers, 5)
}

func TestSkipsNilFieldValidation(t *testing.T) {
cfg := NewDefaultConfig()
cfg, err := NewDefaultConfig()
require.NoError(t, err)
cfg.Providers = nil
assert.NoError(t, cfg.Validate())
}

func TestValidateDeprecatedOtelColVersion(t *testing.T) {
cfg := NewDefaultConfig()
cfg, err := NewDefaultConfig()
require.NoError(t, err)
cfg.Distribution.OtelColVersion = "test"
assert.Error(t, cfg.Validate())
}
9 changes: 5 additions & 4 deletions cmd/builder/internal/builder/main.go
Original file line number Diff line number Diff line change
Expand Up @@ -75,6 +75,7 @@ func Generate(cfg *Config) error {
cfg.Logger.Info("Skipping generating source codes.")
return nil
}

// 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 @@ -154,13 +155,14 @@ func GetModules(cfg *Config) error {
}

coreDepVersion, ok := dependencyVersions[otelcolPath]
betaVersion := semver.MajorMinor(defaultBetaOtelColVersion)
if !ok {
return fmt.Errorf("core collector %w: '%s'. %s", ErrDepNotFound, otelcolPath, skipStrictMsg)
}
if semver.MajorMinor(coreDepVersion) != semver.MajorMinor(defaultOtelColVersion) {
if semver.MajorMinor(coreDepVersion) != betaVersion {
return fmt.Errorf(
"%w: core collector version calculated by component dependencies %q does not match configured version %q. %s",
ErrVersionMismatch, coreDepVersion, defaultOtelColVersion, skipStrictMsg)
ErrVersionMismatch, coreDepVersion, betaVersion, skipStrictMsg)
}

for _, mod := range cfg.allComponents() {
Expand Down Expand Up @@ -211,8 +213,7 @@ func processAndWrite(cfg *Config, tmpl *template.Template, outFile string, tmplP
}

func (c *Config) allComponents() []Module {
return slices.Concat[[]Module](c.Exporters, c.Receivers, c.Processors,
c.Extensions, c.Connectors, *c.Providers)
return slices.Concat[[]Module](c.Exporters, c.Receivers, c.Processors, c.Extensions, c.Connectors, c.Providers)
}

func (c *Config) readGoModFile() (string, map[string]string, error) {
Expand Down
Loading

0 comments on commit 084aa63

Please sign in to comment.