From e4d225c8259a780f5c742967a80ec03321fded05 Mon Sep 17 00:00:00 2001
From: Pavel Vorobyov
Date: Tue, 24 Sep 2019 15:00:34 +0300
Subject: [PATCH] more debug logging
---
remote/executer.go | 16 +++++++++++-----
remote/runcmd.go | 2 +-
remote/worker.go | 2 +-
3 files changed, 13 insertions(+), 7 deletions(-)
diff --git a/remote/executer.go b/remote/executer.go
index ab48529..9b620c4 100644
--- a/remote/executer.go
+++ b/remote/executer.go
@@ -189,6 +189,9 @@ func RunCollapse(hosts []string, cmd string) *ExecResult {
case d := <-pool.Data:
switch d.Type {
case MTData:
+ if currentDebug {
+ log.Debugf("DATASTREAM @ %s:\n%v\n[%v]\n", d.Hostname, d.Data, string(d.Data))
+ }
outputs[d.Hostname] += string(d.Data)
logData := make([]byte, len(d.Data))
copy(logData, d.Data)
@@ -198,7 +201,7 @@ func RunCollapse(hosts []string, cmd string) *ExecResult {
writeHostOutput(d.Hostname, logData)
case MTDebug:
if currentDebug {
- log.Debugf("DATASTREAM @ %s\n%v\n[%v]", d.Hostname, d.Data, string(d.Data))
+ log.Debugf("DEBUGSTREAM @ %s:\n%v\n[%v]\n", d.Hostname, d.Data, string(d.Data))
}
case MTCopyFinished:
if d.StatusCode == 0 {
@@ -226,12 +229,15 @@ func RunCollapse(hosts []string, cmd string) *ExecResult {
bar.Finish()
}
- for k, v := range outputs {
- _, found := r.Outputs[v]
+ for host, hostOutput := range outputs {
+ _, found := r.Outputs[hostOutput]
if !found {
- r.Outputs[v] = make([]string, 0)
+ if currentDebug {
+ log.Debugf("Collapse mode found a new output:\n\"%s\"\n%v\n", hostOutput, []byte(hostOutput))
+ }
+ r.Outputs[hostOutput] = make([]string, 0)
}
- r.Outputs[v] = append(r.Outputs[v], k)
+ r.Outputs[hostOutput] = append(r.Outputs[hostOutput], host)
}
return r
diff --git a/remote/runcmd.go b/remote/runcmd.go
index e802ef2..3187540 100644
--- a/remote/runcmd.go
+++ b/remote/runcmd.go
@@ -74,7 +74,7 @@ execLoop:
continue
}
- w.data <- &Message{buf, MTDebug, task.Hostname, -1}
+ w.data <- &Message{buf[:n], MTDebug, task.Hostname, -1}
msgCount++
chunks := bytes.SplitAfter(buf[:n], []byte{'\n'})
diff --git a/remote/worker.go b/remote/worker.go
index 1a2b84a..58b9b28 100644
--- a/remote/worker.go
+++ b/remote/worker.go
@@ -154,7 +154,7 @@ func (w *Worker) run() {
// does the task have anything to run?
if task.Cmd != "" {
- log.Debugf("WRK[%d] runcmd(%s) at %s", task.Cmd, task.Hostname)
+ log.Debugf("WRK[%d] runcmd(%s) at %s", w.id, task.Cmd, task.Hostname)
result = w.runcmd(task)
w.data <- &Message{nil, MTExecFinished, task.Hostname, result}
}