Skip to content

Commit

Permalink
Remove agent.WithConfigFiles (open-telemetry#374)
Browse files Browse the repository at this point in the history
  • Loading branch information
djaglowski authored and jsirianni committed Mar 28, 2022
1 parent f6a5ca2 commit fcea3af
Show file tree
Hide file tree
Showing 2 changed files with 3 additions and 52 deletions.
21 changes: 2 additions & 19 deletions agent/builder.go
Original file line number Diff line number Diff line change
Expand Up @@ -31,7 +31,6 @@ type LogAgentBuilder struct {
config *Config
logger *zap.SugaredLogger
pluginDir string
configFiles []string
}

// NewBuilder creates a new LogAgentBuilder
Expand All @@ -47,12 +46,6 @@ func (b *LogAgentBuilder) WithPluginDir(pluginDir string) *LogAgentBuilder {
return b
}

// WithConfigFiles adds a list of globs to the search path for config files
func (b *LogAgentBuilder) WithConfigFiles(files []string) *LogAgentBuilder {
b.configFiles = files
return b
}

// WithConfig builds the agent with a given, pre-built config
func (b *LogAgentBuilder) WithConfig(cfg *Config) *LogAgentBuilder {
b.config = cfg
Expand All @@ -73,18 +66,8 @@ func (b *LogAgentBuilder) Build() (*LogAgent, error) {
}
}

if b.config != nil && len(b.configFiles) > 0 {
return nil, errors.NewError("agent can be built WithConfig or WithConfigFiles, but not both", "")
}
if b.config == nil && len(b.configFiles) == 0 {
return nil, errors.NewError("agent cannot be built without WithConfig or WithConfigFiles", "")
}
if len(b.configFiles) > 0 {
cfgs, err := NewConfigFromGlobs(b.configFiles)
if err != nil {
return nil, errors.Wrap(err, "read configs from globs")
}
b.config = cfgs
if b.config == nil {
return nil, errors.NewError("config must be specified", "")
}

if len(b.config.Pipeline) == 0 {
Expand Down
34 changes: 1 addition & 33 deletions agent/builder_test.go
Original file line number Diff line number Diff line change
Expand Up @@ -117,38 +117,6 @@ func TestBuildAgentFailureNoConfigOrGlobs(t *testing.T) {
WithDefaultOutput(mockOutput).
Build()
require.Error(t, err)
require.Contains(t, err.Error(), "cannot be built without")
require.Nil(t, agent)
}

func TestBuildAgentFailureWithBothConfigAndGlobs(t *testing.T) {
mockCfg := Config{}
mockLogger := zap.NewNop().Sugar()
mockPluginDir := "/some/plugin/path"
mockOutput := testutil.NewFakeOutput(t)

agent, err := NewBuilder(mockLogger).
WithConfig(&mockCfg).
WithConfigFiles([]string{"test"}).
WithPluginDir(mockPluginDir).
WithDefaultOutput(mockOutput).
Build()
require.Error(t, err)
require.Contains(t, err.Error(), "not both")
require.Nil(t, agent)
}

func TestBuildAgentFailureNonexistGlobs(t *testing.T) {
mockLogger := zap.NewNop().Sugar()
mockPluginDir := "/some/plugin/path"
mockOutput := testutil.NewFakeOutput(t)

agent, err := NewBuilder(mockLogger).
WithConfigFiles([]string{"/tmp/nonexist"}).
WithPluginDir(mockPluginDir).
WithDefaultOutput(mockOutput).
Build()
require.Error(t, err)
require.Contains(t, err.Error(), "read configs from globs")
require.Contains(t, err.Error(), "config must be specified")
require.Nil(t, agent)
}

0 comments on commit fcea3af

Please sign in to comment.