Merge pull request #5173 from hashicorp/b-log-levels

Plugins use parent loggers
This commit is contained in:
Alex Dadgar
2019-01-14 16:14:30 -08:00
committed by GitHub
26 changed files with 115 additions and 80 deletions

View File

@@ -250,7 +250,7 @@ func (e *UniversalExecutor) Version() (*ExecutorVersion, error) {
// Launch launches the main process and returns its state. It also
// configures an applies isolation on certain platforms.
func (e *UniversalExecutor) Launch(command *ExecCommand) (*ProcessState, error) {
e.logger.Info("launching command", "command", command.Cmd, "args", strings.Join(command.Args, " "))
e.logger.Debug("launching command", "command", command.Cmd, "args", strings.Join(command.Args, " "))
e.commandCfg = command
@@ -421,7 +421,7 @@ var (
// Exit cleans up the alloc directory, destroys resource container and kills the
// user process
func (e *UniversalExecutor) Shutdown(signal string, grace time.Duration) error {
e.logger.Info("shutdown requested", "signal", signal, "grace_period_ms", grace.Round(time.Millisecond))
e.logger.Debug("shutdown requested", "signal", signal, "grace_period_ms", grace.Round(time.Millisecond))
var merr multierror.Error
// If the executor did not launch a process, return.

View File

@@ -98,7 +98,7 @@ func NewExecutorWithIsolation(logger hclog.Logger) Executor {
// Launch creates a new container in libcontainer and starts a new process with it
func (l *LibcontainerExecutor) Launch(command *ExecCommand) (*ProcessState, error) {
l.logger.Info("launching command", "command", command.Cmd, "args", strings.Join(command.Args, " "))
l.logger.Debug("launching command", "command", command.Cmd, "args", strings.Join(command.Args, " "))
// Find the nomad executable to launch the executor process with
bin, err := discover.NomadExecutable()
if err != nil {

View File

@@ -63,7 +63,7 @@ func (e *UniversalExecutor) shutdownProcess(_ os.Signal, proc *os.Process) error
if err := sendCtrlBreak(proc.Pid); err != nil {
return fmt.Errorf("executor shutdown error: %v", err)
}
e.logger.Info("sent Ctrl-Break to process", "pid", proc.Pid)
e.logger.Debug("sent Ctrl-Break to process", "pid", proc.Pid)
return nil
}

View File

@@ -1,7 +1,6 @@
package executor
import (
"io"
"net"
hclog "github.com/hashicorp/go-hclog"
@@ -22,18 +21,12 @@ type ExecutorConfig struct {
FSIsolation bool
}
func GetPluginMap(w io.Writer, logLevel hclog.Level, fsIsolation bool) map[string]plugin.Plugin {
e := new(ExecutorPlugin)
e.logger = hclog.New(&hclog.LoggerOptions{
Output: w,
Level: logLevel,
})
e.fsIsolation = fsIsolation
func GetPluginMap(logger hclog.Logger, fsIsolation bool) map[string]plugin.Plugin {
return map[string]plugin.Plugin{
"executor": e,
"executor": &ExecutorPlugin{
logger: logger,
fsIsolation: fsIsolation,
},
}
}

View File

@@ -3,7 +3,6 @@ package executor
import (
"encoding/json"
"fmt"
"io"
"os/exec"
"github.com/golang/protobuf/ptypes"
@@ -26,7 +25,7 @@ const (
// CreateExecutor launches an executor plugin and returns an instance of the
// Executor interface
func CreateExecutor(w io.Writer, level hclog.Level, driverConfig *base.ClientDriverConfig,
func CreateExecutor(logger hclog.Logger, driverConfig *base.ClientDriverConfig,
executorConfig *ExecutorConfig) (Executor, *plugin.Client, error) {
c, err := json.Marshal(executorConfig)
@@ -39,11 +38,12 @@ func CreateExecutor(w io.Writer, level hclog.Level, driverConfig *base.ClientDri
}
config := &plugin.ClientConfig{
Cmd: exec.Command(bin, "executor", string(c)),
HandshakeConfig: base.Handshake,
Plugins: map[string]plugin.Plugin{"executor": &ExecutorPlugin{}},
Cmd: exec.Command(bin, "executor", string(c)),
AllowedProtocols: []plugin.Protocol{plugin.ProtocolGRPC},
Logger: logger.Named("executor"),
}
config.HandshakeConfig = base.Handshake
config.Plugins = GetPluginMap(w, level, executorConfig.FSIsolation)
config.AllowedProtocols = []plugin.Protocol{plugin.ProtocolGRPC}
if driverConfig != nil {
config.MaxPort = driverConfig.ClientMaxPort
@@ -74,15 +74,17 @@ func CreateExecutor(w io.Writer, level hclog.Level, driverConfig *base.ClientDri
}
// CreateExecutorWithConfig launches a plugin with a given plugin config
func CreateExecutorWithConfig(config *plugin.ClientConfig, w io.Writer) (Executor, *plugin.Client, error) {
config.HandshakeConfig = base.Handshake
func CreateExecutorWithConfig(reattachConfig *plugin.ReattachConfig, logger hclog.Logger) (Executor, *plugin.Client, error) {
config := &plugin.ClientConfig{
HandshakeConfig: base.Handshake,
Reattach: reattachConfig,
Plugins: map[string]plugin.Plugin{"executor": &ExecutorPlugin{}},
// Setting this to DEBUG since the log level at the executor server process
// is already set, and this effects only the executor client.
// TODO: Use versioned plugin map to support backwards compatibility with
// existing pre-0.9 executors
config.Plugins = GetPluginMap(w, hclog.Debug, false)
config.AllowedProtocols = []plugin.Protocol{plugin.ProtocolGRPC}
// TODO: Use versioned plugin map to support backwards compatibility with
// existing pre-0.9 executors
AllowedProtocols: []plugin.Protocol{plugin.ProtocolGRPC},
Logger: logger.Named("executor"),
}
executorClient := plugin.NewClient(config)
rpcClient, err := executorClient.Client()