Skip to content
This repository has been archived by the owner on Nov 8, 2022. It is now read-only.

Commit

Permalink
Adds the use of appropriate log levels
Browse files Browse the repository at this point in the history
  • Loading branch information
jcooklin committed Aug 30, 2016
1 parent 3d8056a commit 335cd6c
Show file tree
Hide file tree
Showing 6 changed files with 29 additions and 19 deletions.
4 changes: 2 additions & 2 deletions control/plugin/collector_proxy.go
Original file line number Diff line number Diff line change
Expand Up @@ -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()

Expand All @@ -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()

Expand Down
10 changes: 7 additions & 3 deletions control/plugin/execution.go
Original file line number Diff line number Diff line change
Expand Up @@ -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())
}
}
}()
Expand Down Expand Up @@ -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())

}
}()
}
9 changes: 4 additions & 5 deletions control/plugin/plugin.go
Original file line number Diff line number Diff line change
Expand Up @@ -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:
Expand Down
15 changes: 7 additions & 8 deletions control/plugin/session.go
Original file line number Diff line number Diff line change
Expand Up @@ -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 {
Expand All @@ -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
}
Expand All @@ -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
Expand Down Expand Up @@ -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
Expand All @@ -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
}
Expand Down
8 changes: 8 additions & 0 deletions plugin/collector/snap-plugin-collector-mock2/mock/mock.go
Original file line number Diff line number Diff line change
Expand Up @@ -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!")
}
Expand Down
2 changes: 1 addition & 1 deletion scheduler/workflow.go
Original file line number Diff line number Diff line change
Expand Up @@ -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)

Expand Down

0 comments on commit 335cd6c

Please sign in to comment.