mirror of
https://github.com/replicatedhq/troubleshoot.git
synced 2026-04-15 07:16:34 +00:00
errors are masked when collector fails
This commit is contained in:
@@ -11,6 +11,7 @@ import (
|
||||
"time"
|
||||
|
||||
"github.com/ahmetalpbalkan/go-cursor"
|
||||
"github.com/fatih/color"
|
||||
"github.com/mholt/archiver"
|
||||
troubleshootv1beta1 "github.com/replicatedhq/troubleshoot/pkg/apis/troubleshoot/v1beta1"
|
||||
"github.com/replicatedhq/troubleshoot/pkg/collect"
|
||||
@@ -62,13 +63,19 @@ func runTroubleshootNoCRD(v *viper.Viper, arg string) error {
|
||||
|
||||
s := spin.New()
|
||||
finishedCh := make(chan bool, 1)
|
||||
progressChan := make(chan string, 1)
|
||||
progressChan := make(chan interface{}, 1)
|
||||
go func() {
|
||||
currentDir := ""
|
||||
for {
|
||||
select {
|
||||
case dir := <-progressChan:
|
||||
currentDir = filepath.Base(dir)
|
||||
case msg := <-progressChan:
|
||||
switch msg := msg.(type) {
|
||||
case error:
|
||||
c := color.New(color.FgHiRed)
|
||||
c.Println(fmt.Sprintf("%s * %v", cursor.ClearEntireLine(), msg))
|
||||
case string:
|
||||
currentDir = filepath.Base(msg)
|
||||
}
|
||||
case <-finishedCh:
|
||||
fmt.Printf("\r")
|
||||
return
|
||||
@@ -105,7 +112,7 @@ the %s Admin Console to begin analysis.`
|
||||
return nil
|
||||
}
|
||||
|
||||
func runCollectors(v *viper.Viper, collector troubleshootv1beta1.Collector, progressChan chan string) (string, error) {
|
||||
func runCollectors(v *viper.Viper, collector troubleshootv1beta1.Collector, progressChan chan interface{}) (string, error) {
|
||||
bundlePath, err := ioutil.TempDir("", "troubleshoot")
|
||||
if err != nil {
|
||||
return "", err
|
||||
@@ -135,13 +142,13 @@ func runCollectors(v *viper.Viper, collector troubleshootv1beta1.Collector, prog
|
||||
|
||||
result, err := collector.RunCollectorSync()
|
||||
if err != nil {
|
||||
progressChan <- fmt.Sprintf("failed to run collector %v", collector)
|
||||
progressChan <- fmt.Errorf("failed to run collector %q: %v", collector.GetDisplayName(), err)
|
||||
continue
|
||||
}
|
||||
|
||||
collectorDir, err := parseAndSaveCollectorOutput(string(result), bundlePath)
|
||||
if err != nil {
|
||||
progressChan <- fmt.Sprintf("failed to parse collector spec: %v", collector)
|
||||
progressChan <- fmt.Errorf("failed to parse collector spec %q: %v", collector.GetDisplayName(), err)
|
||||
continue
|
||||
}
|
||||
|
||||
|
||||
@@ -15,6 +15,7 @@ require (
|
||||
github.com/docker/go-units v0.4.0 // indirect
|
||||
github.com/docker/spdystream v0.0.0-20181023171402-6480d4af844c // indirect
|
||||
github.com/dsnet/compress v0.0.1 // indirect
|
||||
github.com/fatih/color v1.7.0
|
||||
github.com/gin-gonic/gin v1.4.0
|
||||
github.com/gizak/termui/v3 v3.1.0
|
||||
github.com/golang/snappy v0.0.1 // indirect
|
||||
|
||||
@@ -94,6 +94,7 @@ github.com/evanphx/json-patch v4.2.0+incompatible h1:fUDGZCv/7iAN7u0puUVhvKCcsR6
|
||||
github.com/evanphx/json-patch v4.2.0+incompatible/go.mod h1:50XU6AFN0ol/bzJsmQLiYLvXMP4fmwYFNcr97nuDLSk=
|
||||
github.com/evanphx/json-patch v4.5.0+incompatible h1:ouOWdg56aJriqS0huScTkVXPC5IcNrDCXZ6OoTAWu7M=
|
||||
github.com/evanphx/json-patch v4.5.0+incompatible/go.mod h1:50XU6AFN0ol/bzJsmQLiYLvXMP4fmwYFNcr97nuDLSk=
|
||||
github.com/fatih/color v1.7.0 h1:DkWD4oS2D8LGGgTQ6IvwJJXSL5Vp2ffcQg58nFV38Ys=
|
||||
github.com/fatih/color v1.7.0/go.mod h1:Zm6kSWBoL9eyXnKyktHP6abPY2pDugNf5KwzbycvMj4=
|
||||
github.com/flynn/go-shlex v0.0.0-20150515145356-3f9db97f8568/go.mod h1:xEzjJPgXI435gkrCt3MPfRiAkVrwSbHsst4LCFVfpJc=
|
||||
github.com/fsnotify/fsnotify v1.4.7 h1:IXs+QLmnXW2CcXuY+8Mzv/fWEsPGWxqefPtCP5CnV9I=
|
||||
|
||||
@@ -2,6 +2,8 @@ package collect
|
||||
|
||||
import (
|
||||
"errors"
|
||||
"fmt"
|
||||
"strings"
|
||||
|
||||
troubleshootv1beta1 "github.com/replicatedhq/troubleshoot/pkg/apis/troubleshoot/v1beta1"
|
||||
"gopkg.in/yaml.v2"
|
||||
@@ -41,6 +43,54 @@ func (c *Collector) RunCollectorSync() ([]byte, error) {
|
||||
return nil, errors.New("no spec found to run")
|
||||
}
|
||||
|
||||
func (c *Collector) GetDisplayName() string {
|
||||
var collector, name, selector string
|
||||
if c.Collect.ClusterInfo != nil {
|
||||
collector = "cluster-info"
|
||||
}
|
||||
if c.Collect.ClusterResources != nil {
|
||||
collector = "cluster-resources"
|
||||
}
|
||||
if c.Collect.Secret != nil {
|
||||
collector = "secret"
|
||||
name = c.Collect.Secret.CollectorName
|
||||
}
|
||||
if c.Collect.Logs != nil {
|
||||
collector = "logs"
|
||||
name = c.Collect.Logs.CollectorName
|
||||
selector = strings.Join(c.Collect.Logs.Selector, ",")
|
||||
}
|
||||
if c.Collect.Run != nil {
|
||||
collector = "run"
|
||||
name = c.Collect.Run.CollectorName
|
||||
}
|
||||
if c.Collect.Exec != nil {
|
||||
collector = "exec"
|
||||
name = c.Collect.Exec.CollectorName
|
||||
selector = strings.Join(c.Collect.Exec.Selector, ",")
|
||||
}
|
||||
if c.Collect.Copy != nil {
|
||||
collector = "copy"
|
||||
name = c.Collect.Copy.CollectorName
|
||||
selector = strings.Join(c.Collect.Copy.Selector, ",")
|
||||
}
|
||||
if c.Collect.HTTP != nil {
|
||||
collector = "http"
|
||||
name = c.Collect.HTTP.CollectorName
|
||||
}
|
||||
|
||||
if collector == "" {
|
||||
return "<none>"
|
||||
}
|
||||
if name != "" {
|
||||
return fmt.Sprintf("%s/%s", collector, name)
|
||||
}
|
||||
if selector != "" {
|
||||
return fmt.Sprintf("%s/%s", collector, selector)
|
||||
}
|
||||
return collector
|
||||
}
|
||||
|
||||
func ParseSpec(specContents string) (*troubleshootv1beta1.Collect, error) {
|
||||
collect := troubleshootv1beta1.Collect{}
|
||||
|
||||
|
||||
Reference in New Issue
Block a user