From 335cd6ce9941acf8928c66af5763779ea9348e00 Mon Sep 17 00:00:00 2001 From: Joel Cooklin Date: Sun, 21 Aug 2016 12:36:00 -0700 Subject: [PATCH] Adds the use of appropriate log levels --- control/plugin/collector_proxy.go | 4 ++-- control/plugin/execution.go | 10 +++++++--- control/plugin/plugin.go | 9 ++++----- control/plugin/session.go | 15 +++++++-------- .../snap-plugin-collector-mock2/mock/mock.go | 8 ++++++++ scheduler/workflow.go | 2 +- 6 files changed, 29 insertions(+), 19 deletions(-) diff --git a/control/plugin/collector_proxy.go b/control/plugin/collector_proxy.go index d2dae131e..4668fb114 100644 --- a/control/plugin/collector_proxy.go +++ b/control/plugin/collector_proxy.go @@ -54,7 +54,7 @@ type collectorPluginProxy struct { func (c *collectorPluginProxy) GetMetricTypes(args []byte, reply *[]byte) error { defer catchPluginPanic(c.Session.Logger()) - c.Session.Logger().Println("GetMetricTypes called") + c.Session.Logger().Debugln("GetMetricTypes called") // Reset heartbeat c.Session.ResetHeartbeat() @@ -77,7 +77,7 @@ func (c *collectorPluginProxy) GetMetricTypes(args []byte, reply *[]byte) error func (c *collectorPluginProxy) CollectMetrics(args []byte, reply *[]byte) error { defer catchPluginPanic(c.Session.Logger()) - c.Session.Logger().Println("CollectMetrics called") + c.Session.Logger().Debugln("CollectMetrics called") // Reset heartbeat c.Session.ResetHeartbeat() diff --git a/control/plugin/execution.go b/control/plugin/execution.go index ed53f5ba3..b4bfdb207 100644 --- a/control/plugin/execution.go +++ b/control/plugin/execution.go @@ -124,8 +124,10 @@ func (e *ExecutablePlugin) Run(timeout time.Duration) (Response, error) { respReceived = true close(doneChan) } else { - execLogger.WithField("plugin", path.Base(e.cmd.Path())). - Debug(stdOutScanner.Text()) + execLogger.WithFields(log.Fields{ + "plugin": path.Base(e.cmd.Path()), + "io": "stdout", + }).Debug(stdOutScanner.Text()) } } }() @@ -157,7 +159,9 @@ func (e *ExecutablePlugin) captureStderr() { for stdErrScanner.Scan() { execLogger. WithField("io", "stderr"). - WithField("plugin", path.Base(e.cmd.Path())).Debug(stdErrScanner.Text()) + WithField("plugin", path.Base(e.cmd.Path())). + Debug(stdErrScanner.Text()) + } }() } diff --git a/control/plugin/plugin.go b/control/plugin/plugin.go index 406fc9d09..7ce77afe7 100644 --- a/control/plugin/plugin.go +++ b/control/plugin/plugin.go @@ -329,20 +329,19 @@ func Start(m *PluginMeta, c Plugin, requestString string) (error, int) { e := rpc.Register(s) if e != nil { if e.Error() != "rpc: service already defined: SessionState" { - log.Println(e.Error()) - s.Logger().Println(e.Error()) + s.Logger().Error(e.Error()) return e, 2 } } l, err := net.Listen("tcp", "127.0.0.1:"+s.ListenPort()) if err != nil { - s.Logger().Println(err.Error()) + s.Logger().Error(err.Error()) panic(err) } s.SetListenAddress(l.Addr().String()) - s.Logger().Printf("Listening %s\n", l.Addr()) - s.Logger().Printf("Session token %s\n", s.Token()) + s.Logger().Debugf("Listening %s\n", l.Addr()) + s.Logger().Debugf("Session token %s\n", s.Token()) switch r.Meta.RPCType { case JSONRPC: diff --git a/control/plugin/session.go b/control/plugin/session.go index 72a26220f..a888d7b81 100644 --- a/control/plugin/session.go +++ b/control/plugin/session.go @@ -100,7 +100,7 @@ type GetConfigPolicyReply struct { func (s *SessionState) GetConfigPolicy(args []byte, reply *[]byte) error { defer catchPluginPanic(s.Logger()) - s.logger.Println("GetConfigPolicy called") + s.logger.Debug("GetConfigPolicy called") policy, err := s.plugin.GetConfigPolicy() if err != nil { @@ -122,7 +122,7 @@ func (s *SessionState) Ping(arg []byte, reply *[]byte) error { // down or otherwise in a state we should signal poor health. // Reply should contain any context. s.ResetHeartbeat() - s.logger.Println("Ping received") + s.logger.Debug("Ping received") *reply = []byte{} return nil } @@ -134,7 +134,7 @@ func (s *SessionState) Kill(args []byte, reply *[]byte) error { if err != nil { return err } - s.logger.Printf("Kill called by agent, reason: %s\n", a.Reason) + s.logger.Debug("Kill called by agent, reason: %s\n", a.Reason) go func() { time.Sleep(time.Second * 2) s.killChan <- 0 @@ -186,7 +186,7 @@ type SetKeyArgs struct { } func (s *SessionState) SetKey(args SetKeyArgs, reply *[]byte) error { - s.logger.Println("SetKey called") + s.logger.Debug("SetKey called") out, err := s.DecryptKey(args.Key) if err != nil { return err @@ -208,19 +208,18 @@ func (s *SessionState) generateResponse(r *Response) []byte { } func (s *SessionState) heartbeatWatch(killChan chan int) { - s.logger.Println("Heartbeat started") + s.logger.Debug("Heartbeat started") count := 0 for { if time.Since(s.LastPing) >= s.PingTimeoutDuration { count++ - s.logger.Printf("Heartbeat timeout %v of %v. (Duration between checks %v)", count, PingTimeoutLimit, s.PingTimeoutDuration) + s.logger.Infof("Heartbeat timeout %v of %v. (Duration between checks %v)", count, PingTimeoutLimit, s.PingTimeoutDuration) if count >= PingTimeoutLimit { - s.logger.Println("Heartbeat timeout expired!") + s.logger.Error("Heartbeat timeout expired") defer close(killChan) return } } else { - s.logger.Println("Heartbeat timeout reset") // Reset count count = 0 } diff --git a/plugin/collector/snap-plugin-collector-mock2/mock/mock.go b/plugin/collector/snap-plugin-collector-mock2/mock/mock.go index 5a763344c..5cff01f50 100644 --- a/plugin/collector/snap-plugin-collector-mock2/mock/mock.go +++ b/plugin/collector/snap-plugin-collector-mock2/mock/mock.go @@ -53,6 +53,14 @@ func (f *Mock) CollectMetrics(mts []plugin.MetricType) ([]plugin.MetricType, err rand.Seed(time.Now().UTC().UnixNano()) metrics := []plugin.MetricType{} for i := range mts { + if c, ok := mts[i].Config().Table()["long_print"]; ok && c.(ctypes.ConfigValueBool).Value { + letterBytes := "abcdefghijklmnopqrstuvwxyzABCDEFGHIJKLMNOPQRSTUVWXYZ" + longLine := []byte{} + for i := 0; i < 8193; i++ { + longLine = append(longLine, letterBytes[rand.Intn(len(letterBytes))]) + } + fmt.Println(string(longLine)) + } if c, ok := mts[i].Config().Table()["panic"]; ok && c.(ctypes.ConfigValueBool).Value { panic("Oops!") } diff --git a/scheduler/workflow.go b/scheduler/workflow.go index ff8773399..9e2a48b9d 100644 --- a/scheduler/workflow.go +++ b/scheduler/workflow.go @@ -241,7 +241,7 @@ func (s *schedulerWorkflow) Start(t *task) { "_block": "workflow-start", "task-id": t.id, "task-name": t.name, - }).Info(fmt.Sprintf("Starting workflow for task (%s\\%s)", t.id, t.name)) + }).Debug("Starting workflow") s.state = WorkflowStarted j := newCollectorJob(s.metrics, t.deadlineDuration, t.metricsManager, t.workflow.configTree, t.id, s.tags)