Skip to content

Commit

Permalink
fix(config): Prevent loading malformed yaml
Browse files Browse the repository at this point in the history
If the YAML config contains malformed content the
error is ignored silently. To prevent this, we
only proceed with default settings loading if the
config file doesn't exist. On the contrary, the
error is raised.
  • Loading branch information
rabbitstack committed Oct 17, 2024
1 parent dd0a1a6 commit c78eb4b
Show file tree
Hide file tree
Showing 2 changed files with 11 additions and 6 deletions.
2 changes: 1 addition & 1 deletion internal/bootstrap/bootstrap.go
Original file line number Diff line number Diff line change
Expand Up @@ -180,7 +180,7 @@ func (f *App) Run(args []string) error {
}

log.Infof("bootstrapping with pid %d. Version: %s", os.Getpid(), version.Get())
log.Infof("configuration dump %s", cfg.Print())
log.Infof("rendering config flags... %s", cfg.Print())

// build the filter from the CLI argument. If we got
// a valid expression the filter is attached to the
Expand Down
15 changes: 10 additions & 5 deletions internal/bootstrap/config.go
Original file line number Diff line number Diff line change
Expand Up @@ -22,28 +22,33 @@ import (
"github.com/rabbitstack/fibratus/pkg/config"
"github.com/rabbitstack/fibratus/pkg/util/log"
"github.com/sirupsen/logrus"
"os"
)

// InitConfigAndLogger initializes the configuration and sets up the logger.
// We allow continuing with the initialization process even if the config file
// loading fails. In this situation, the default config flag values are used
// to tweak any of the internal behaviours.
func InitConfigAndLogger(cfg *config.Config) error {
isLoaded := cfg.TryLoadFile(cfg.File()) == nil
err := cfg.TryLoadFile(cfg.File())
notExists := os.IsNotExist(err)
if err != nil && !notExists {
return err
}
if err := cfg.Init(); err != nil {
return err
}
if isLoaded {
if err == nil {
if err := cfg.Validate(); err != nil {
return err
}
}
if err := log.InitFromConfig(cfg.Log, "fibratus.log"); err != nil {
return err
}
if !isLoaded {
logrus.Warnf("unable to load configuration "+
"from %s file. Falling back to default "+
if notExists {
logrus.Infof("configuration file "+
"%s not found. Continuing with default "+
"settings...", cfg.File())
}
return nil
Expand Down

0 comments on commit c78eb4b

Please sign in to comment.