Skip to content

Commit

Permalink
add special message to error if the inputs might be missing
Browse files Browse the repository at this point in the history
  • Loading branch information
kvch committed Feb 1, 2022
1 parent d7bf7b1 commit e2fef84
Showing 1 changed file with 8 additions and 5 deletions.
13 changes: 8 additions & 5 deletions x-pack/elastic-agent/pkg/config/loader.go
Original file line number Diff line number Diff line change
Expand Up @@ -37,28 +37,31 @@ func (l *Loader) Load(files []string) (*Config, error) {
for _, f := range files {
cfg, err := LoadFile(f)
if err != nil {
if l.isFileUnderInputsFolder(f) {
return nil, fmt.Errorf("failed to load external configuration file '%s': %w. Are you sure it contains an inputs section?", f, err)
}
return nil, fmt.Errorf("failed to load configuration file '%s': %w", f, err)
}
l.logger.Debug("Loaded configuration from %s", f)
l.logger.Debugf("Loaded configuration from %s", f)
if l.isFileUnderInputsFolder(f) {
inp, err := getInput(cfg)
if err != nil {
return nil, fmt.Errorf("cannot get configuration from '%s': %w", f, err)
}
inputsList = append(inputsList, inp...)
l.logger.Debug("Loaded %s input(s) from configuration from %s", len(inp), f)
l.logger.Debugf("Loaded %s input(s) from configuration from %s", len(inp), f)
} else {
if err := merger.Add(cfg.access(), err); err != nil {
return nil, fmt.Errorf("failed to merge configuration file '%s' to existing one: %w", f, err)
}
l.logger.Debug("Merged configuration from %s into result", f)
l.logger.Debugf("Merged configuration from %s into result", f)
}
}
config := merger.Config()

// if there is no input configuration, return what we have collected.
if len(inputsList) == 0 {
l.logger.Debug("Merged all configuration files from %v, no external input files", files)
l.logger.Debugf("Merged all configuration files from %v, no external input files", files)
return newConfigFrom(config), nil
}

Expand All @@ -78,7 +81,7 @@ func (l *Loader) Load(files []string) (*Config, error) {
}
}

l.logger.Debug("Merged all configuration files from %v, with external input files", files)
l.logger.Debugf("Merged all configuration files from %v, with external input files", files)
return newConfigFrom(config), nil
}

Expand Down

0 comments on commit e2fef84

Please sign in to comment.