Skip to content

Commit aeb89e5

Browse files
authored
Merge pull request #556 from replicatedhq/emosbaugh/sc-45934/longhorn-logs-collector-all-files-are-empty
Fix missing longhorn logs
2 parents fe5dd3e + 8d1a0f6 commit aeb89e5

File tree

4 files changed

+12
-14
lines changed

4 files changed

+12
-14
lines changed

pkg/collect/ceph.go

Lines changed: 2 additions & 6 deletions
Original file line numberDiff line numberDiff line change
@@ -3,7 +3,6 @@ package collect
33
import (
44
"context"
55
"fmt"
6-
"io"
76
"os"
87
"path"
98
"strings"
@@ -133,8 +132,8 @@ func cephCommandExec(ctx context.Context, c *Collector, cephCollector *troublesh
133132
return errors.Wrap(err, "failed to exec command")
134133
}
135134

135+
pathPrefix := GetCephCollectorFilepath(cephCollector.CollectorName, cephCollector.Namespace)
136136
for srcFilename, _ := range results {
137-
pathPrefix := GetCephCollectorFilepath(cephCollector.CollectorName, cephCollector.Namespace)
138137
var dstFileName string
139138
switch {
140139
case strings.HasSuffix(srcFilename, "-stdout.txt"):
@@ -203,10 +202,7 @@ func copyResult(srcResult CollectorResult, dstResult CollectorResult, bundlePath
203202
}
204203
return errors.Wrap(err, "failed to get reader")
205204
}
206-
207-
if reader, ok := reader.(io.ReadCloser); ok {
208-
defer reader.Close()
209-
}
205+
defer reader.Close()
210206

211207
err = dstResult.SaveResult(bundlePath, dstKey, reader)
212208
if err != nil {

pkg/collect/longhorn.go

Lines changed: 7 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -5,6 +5,7 @@ import (
55
"bytes"
66
"context"
77
"fmt"
8+
"path"
89
"path/filepath"
910
"regexp"
1011
"sync"
@@ -205,9 +206,12 @@ func Longhorn(c *Collector, longhornCollector *troubleshootv1beta2.Longhorn) (Co
205206
return nil, errors.Wrap(err, "collect longhorn logs")
206207
}
207208
logsDir := GetLonghornLogsDirectory(ns)
208-
for key, log := range logs {
209-
key = filepath.Join(logsDir, key)
210-
output.SaveResult(c.BundlePath, key, bytes.NewBuffer(log))
209+
for srcFilename, _ := range logs {
210+
dstFileName := path.Join(logsDir, srcFilename)
211+
err := copyResult(logs, output, c.BundlePath, srcFilename, dstFileName)
212+
if err != nil {
213+
logger.Printf("Failed to copy file %s; %v", srcFilename, err)
214+
}
211215
}
212216

213217
// https://longhorn.io/docs/1.1.1/advanced-resources/data-recovery/corrupted-replica/

pkg/collect/redact.go

Lines changed: 1 addition & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -26,9 +26,7 @@ func redactResult(bundlePath string, input CollectorResult, additionalRedactors
2626
}
2727
return errors.Wrap(err, "failed to get reader")
2828
}
29-
if r, ok := r.(io.ReadCloser); ok {
30-
defer r.Close()
31-
}
29+
defer r.Close()
3230

3331
reader = r
3432
} else {

pkg/collect/result.go

Lines changed: 2 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -85,9 +85,9 @@ func (r CollectorResult) ReplaceResult(bundlePath string, relativePath string, r
8585
return nil
8686
}
8787

88-
func (r CollectorResult) GetReader(bundlePath string, relativePath string) (io.Reader, error) {
88+
func (r CollectorResult) GetReader(bundlePath string, relativePath string) (io.ReadCloser, error) {
8989
if r[relativePath] != nil {
90-
return bytes.NewReader(r[relativePath]), nil
90+
return ioutil.NopCloser(bytes.NewReader(r[relativePath])), nil
9191
}
9292

9393
if bundlePath == "" {

0 commit comments

Comments
 (0)