Skip to content

Commit

Permalink
[chore]: dont set path for go in validate (#6273)
Browse files Browse the repository at this point in the history
* fix: dont set path for go in validate

Signed-off-by: sakshi1215 <[email protected]>

* test

Signed-off-by: sakshi1215 <[email protected]>

* fix

Signed-off-by: sakshi1215 <[email protected]>

* add changelog entry

Signed-off-by: sakshi1215 <[email protected]>

* Update CHANGELOG.md

* Update CHANGELOG.md

* Update cmd/builder/internal/builder/config.go

Co-authored-by: Dmitrii Anoshin <[email protected]>

* fix

Signed-off-by: Sakshi Patle <[email protected]>

* fix

Signed-off-by: Sakshi Patle <[email protected]>

Signed-off-by: sakshi1215 <[email protected]>
Signed-off-by: Sakshi Patle <[email protected]>
Co-authored-by: Dmitrii Anoshin <[email protected]>
  • Loading branch information
sakshi1215 and dmitryax authored Oct 25, 2022
1 parent 9a43339 commit db0c250
Show file tree
Hide file tree
Showing 4 changed files with 16 additions and 4 deletions.
9 changes: 6 additions & 3 deletions cmd/builder/internal/builder/config.go
Original file line number Diff line number Diff line change
Expand Up @@ -90,6 +90,11 @@ func NewDefaultConfig() Config {

// Validate checks whether the current configuration is valid
func (c *Config) Validate() error {
return multierr.Combine(validateModules(c.Extensions), validateModules(c.Receivers), validateModules(c.Exporters), validateModules(c.Processors))
}

// SetGoPath sets go path
func (c *Config) SetGoPath() error {
if !c.SkipCompilation || !c.SkipGetModules {
// #nosec G204
if _, err := exec.Command(c.Distribution.Go, "env").CombinedOutput(); err != nil {
Expand All @@ -99,11 +104,9 @@ func (c *Config) Validate() error {
}
c.Distribution.Go = path
}

c.Logger.Info("Using go", zap.String("go-executable", c.Distribution.Go))
}

return multierr.Combine(validateModules(c.Extensions), validateModules(c.Receivers), validateModules(c.Exporters), validateModules(c.Processors))
return nil
}

// ParseModules will parse the Modules entries and populate the missing values
Expand Down
6 changes: 5 additions & 1 deletion cmd/builder/internal/builder/config_test.go
Original file line number Diff line number Diff line change
Expand Up @@ -143,7 +143,8 @@ func TestInvalidModule(t *testing.T) {
func TestNewDefaultConfig(t *testing.T) {
cfg := NewDefaultConfig()
require.NoError(t, cfg.ParseModules())
require.NoError(t, cfg.Validate())
assert.NoError(t, cfg.Validate())
assert.NoError(t, cfg.SetGoPath())
}

func TestNewBuiltinConfig(t *testing.T) {
Expand All @@ -156,6 +157,7 @@ func TestNewBuiltinConfig(t *testing.T) {
require.NoError(t, k.UnmarshalWithConf("", &cfg, koanf.UnmarshalConf{Tag: "mapstructure"}))
assert.NoError(t, cfg.ParseModules())
assert.NoError(t, cfg.Validate())
assert.NoError(t, cfg.SetGoPath())

// Unlike the config initialized in NewDefaultConfig(), we expect
// the builtin default to be practically useful, so there must be
Expand All @@ -175,6 +177,7 @@ func TestSkipGoValidation(t *testing.T) {
SkipGetModules: true,
}
assert.NoError(t, cfg.Validate())
assert.NoError(t, cfg.SetGoPath())
}

func TestSkipGoInitialization(t *testing.T) {
Expand All @@ -183,5 +186,6 @@ func TestSkipGoInitialization(t *testing.T) {
SkipGetModules: true,
}
assert.NoError(t, cfg.Validate())
assert.NoError(t, cfg.SetGoPath())
assert.Zero(t, cfg.Distribution.Go)
}
1 change: 1 addition & 0 deletions cmd/builder/internal/builder/main_test.go
Original file line number Diff line number Diff line change
Expand Up @@ -53,6 +53,7 @@ func TestGenerateAndCompileDefault(t *testing.T) {
cfg.Distribution.OtelColVersion = "0.52.0"

assert.NoError(t, cfg.Validate())
assert.NoError(t, cfg.SetGoPath())
require.NoError(t, GenerateAndCompile(cfg))

// Sleep for 1 second to make sure all processes using the files are completed
Expand Down
4 changes: 4 additions & 0 deletions cmd/builder/internal/command.go
Original file line number Diff line number Diff line change
Expand Up @@ -69,6 +69,10 @@ configuration is provided, ocb will generate a default Collector.
return fmt.Errorf("invalid configuration: %w", err)
}

if err := cfg.SetGoPath(); err != nil {
return fmt.Errorf("go not found: %w", err)
}

if err := cfg.ParseModules(); err != nil {
return fmt.Errorf("invalid module configuration: %w", err)
}
Expand Down

0 comments on commit db0c250

Please sign in to comment.