diff --git a/example-config.yml b/example-config.yml index cf467bab..1c72243b 100644 --- a/example-config.yml +++ b/example-config.yml @@ -3,7 +3,8 @@ InstallDir: WriteDirectory: Verbose: AllPacks: -Run: # must be all-lowercase +LogLevel: info +Run: # must match the name of an installed service pack binary file - "kubernetes" # - "storage" ServicePacks: diff --git a/go.mod b/go.mod index 786cd8a5..8a517196 100644 --- a/go.mod +++ b/go.mod @@ -3,9 +3,8 @@ module github.com/probr/probr go 1.14 require ( - github.com/hashicorp/go-hclog v0.14.1 github.com/hashicorp/go-plugin v1.4.0 - github.com/probr/probr-sdk v0.1.1 + github.com/probr/probr-sdk v0.1.5 ) // For Development Only diff --git a/go.sum b/go.sum index 2daea282..9ac83ae4 100644 --- a/go.sum +++ b/go.sum @@ -398,8 +398,8 @@ github.com/pkg/profile v1.2.1/go.mod h1:hJw3o1OdXxsrSjjVksARp5W95eeEaEfptyVZyv6J github.com/pmezard/go-difflib v1.0.0 h1:4DBwDE0NGyQoBHbLQYPwSUPoCMWR5BEzIk/f1lZbAQM= github.com/pmezard/go-difflib v1.0.0/go.mod h1:iKH77koFhYxTK1pcRnkKkqfTogsbg7gZNVY4sRDYZ/4= github.com/posener/complete v1.1.1/go.mod h1:em0nMJCgc9GFtwrmVmEMR/ZL6WyhyjMBndrE9hABlRI= -github.com/probr/probr-sdk v0.1.1 h1:al8a1/Qgw41Dh/2KkpmFdmnotrtzu0g5RiFeAWv73ss= -github.com/probr/probr-sdk v0.1.1/go.mod h1:Cp/BmkTE08Q0Kw+t3YcVn89ZjMuET2sSeEKsYEiYTFQ= +github.com/probr/probr-sdk v0.1.5 h1:EqFfBiiXBCbAACL/AsGj4ynXksCXvZjeafYAiwiN2vo= +github.com/probr/probr-sdk v0.1.5/go.mod h1:Cp/BmkTE08Q0Kw+t3YcVn89ZjMuET2sSeEKsYEiYTFQ= github.com/prometheus/client_golang v0.9.1/go.mod h1:7SWBe2y4D6OKWSNQJUaRYU/AaXPKyh/dDVn+NZz0KFw= github.com/prometheus/client_golang v0.9.2/go.mod h1:OsXs2jCmiKlQ1lTBmv21f2mNfw4xf/QclQDMrYNZzcM= github.com/prometheus/client_golang v0.9.3-0.20190127221311-3c4408c8b829/go.mod h1:p2iRAGwDERtqlqzRXnrOVns+ignqQo//hLXqYxZYVNs= diff --git a/internal/config/config.go b/internal/config/config.go index 4fb74381..6c731130 100644 --- a/internal/config/config.go +++ b/internal/config/config.go @@ -7,6 +7,7 @@ import ( sdkConfig "github.com/probr/probr-sdk/config" "github.com/probr/probr-sdk/config/setter" + "github.com/probr/probr-sdk/logging" ) type varOptions struct { @@ -23,6 +24,7 @@ var Vars varOptions // Init will set values with the content retrieved from a filepath, env vars, or defaults func (ctx *varOptions) Init() (err error) { + if ctx.varsFileIsFound() { sdkConfig.GlobalConfig.VarsFile = *ctx.VarsFile ctx.decode() @@ -31,11 +33,12 @@ func (ctx *varOptions) Init() (err error) { return } } else { - log.Printf("[DEBUG] No vars file provided, unexpected behavior may occur") + log.Printf("[WARN] No vars file provided, unexpected behavior may occur") } sdkConfig.GlobalConfig.Init() + logging.UseLogger("core") + sdkConfig.GlobalConfig.PrepareOutputDirectory() ctx.setEnvAndDefaults() - return } diff --git a/main.go b/main.go index 1aa0ea0f..7fe376bb 100644 --- a/main.go +++ b/main.go @@ -33,7 +33,6 @@ var ( ) func main() { - var subCommand string if len(os.Args) > 1 { subCommand = os.Args[1] diff --git a/run/run.go b/run/run.go index d21a8bf5..a5c0c22d 100644 --- a/run/run.go +++ b/run/run.go @@ -11,8 +11,9 @@ import ( "strings" "syscall" - hclog "github.com/hashicorp/go-hclog" hcplugin "github.com/hashicorp/go-plugin" + sdkconfig "github.com/probr/probr-sdk/config" + "github.com/probr/probr-sdk/logging" "github.com/probr/probr-sdk/plugin" "github.com/probr/probr-sdk/probeengine" "github.com/probr/probr-sdk/utils" @@ -33,17 +34,17 @@ func CLIContext() { // Run all plugins if err := AllPlugins(cmdSet); err != nil { + log.Printf("[INFO] Output directory: %s", sdkconfig.GlobalConfig.WriteDirectory) switch e := err.(type) { case *ServicePackErrors: - log.Printf("Test Failures: %d out of %d test service packs failed", len(e.Errors), len(cmdSet)) - log.Print(e.Error()) + log.Printf("[ERROR] %d out of %d test service packs failed. %v", len(e.Errors), len(cmdSet), e) os.Exit(1) // At least one service pack failed default: - log.Printf("Internal plugin error: %v", err) + log.Print(utils.ReformatError(err.Error())) os.Exit(2) // Internal error } } - log.Printf("Success") + log.Printf("[INFO] No errors encountered during plugin execution. Output directory: %s", sdkconfig.GlobalConfig.WriteDirectory) os.Exit(0) } @@ -137,16 +138,13 @@ func getCommands() (cmdSet []*exec.Cmd, err error) { // TODO: give any exec errors a familiar format for _, pack := range config.Vars.Run { - binaryName, binErr := GetPackBinary(pack) - if binErr != nil { - err = binErr + cmd, err := getCommand(pack) + if err != nil { break } - cmd := exec.Command(binaryName) - cmd.Args = append(cmd.Args, fmt.Sprintf("--varsfile=%s", *config.Vars.VarsFile)) cmdSet = append(cmdSet, cmd) } - log.Printf("BIN: %s", config.Vars.BinariesPath) + log.Printf("[DEBUG] Using bin: %s", config.Vars.BinariesPath) if err == nil && len(cmdSet) == 0 { available, _ := hcplugin.Discover("*", config.Vars.BinariesPath) err = utils.ReformatError("No valid service packs specified. Requested: %v, Available: %v", config.Vars.Run, available) @@ -154,15 +152,22 @@ func getCommands() (cmdSet []*exec.Cmd, err error) { return } +// TODO +func getCommand(pack string) (cmd *exec.Cmd, err error) { + binaryName, binErr := GetPackBinary(pack) + if binErr != nil { + err = binErr + return + } + cmd = exec.Command(binaryName) + cmd.Args = append(cmd.Args, fmt.Sprintf("--varsfile=%s", *config.Vars.VarsFile)) + return +} + // newClient client handles the lifecycle of a plugin application // Plugin hosts should use one Client for each plugin executable // (this is different from the client that manages gRPC) func newClient(cmd *exec.Cmd) *hcplugin.Client { - logger := hclog.New(&hclog.LoggerOptions{ - Name: plugin.ServicePackPluginName, - Output: os.Stdout, - Level: hclog.Debug, - }) var pluginMap = map[string]hcplugin.Plugin{ plugin.ServicePackPluginName: &plugin.ServicePackPlugin{}, } @@ -171,6 +176,6 @@ func newClient(cmd *exec.Cmd) *hcplugin.Client { HandshakeConfig: handshakeConfig, Plugins: pluginMap, Cmd: cmd, - Logger: logger, + Logger: logging.GetLogger("core"), }) }