Skip to content

Commit

Permalink
Fix Progress Callback for Support Bundle Collection (#781)
Browse files Browse the repository at this point in the history
fix progress callback for support bundle and revert collector title changes
  • Loading branch information
diamonwiggins authored Oct 14, 2022
1 parent 9b37b98 commit 04c7a18
Show file tree
Hide file tree
Showing 21 changed files with 102 additions and 20 deletions.
2 changes: 1 addition & 1 deletion pkg/collect/cluster_info.go
Original file line number Diff line number Diff line change
Expand Up @@ -26,7 +26,7 @@ type CollectClusterInfo struct {
}

func (c *CollectClusterInfo) Title() string {
return collectorTitleOrDefault(c.Collector.CollectorMeta, "Cluster Info")
return getCollectorName(c)
}

func (c *CollectClusterInfo) IsExcluded() (bool, error) {
Expand Down
2 changes: 1 addition & 1 deletion pkg/collect/cluster_resources.go
Original file line number Diff line number Diff line change
Expand Up @@ -43,7 +43,7 @@ type CollectClusterResources struct {
}

func (c *CollectClusterResources) Title() string {
return collectorTitleOrDefault(c.Collector.CollectorMeta, "Cluster Resources")
return getCollectorName(c)
}

func (c *CollectClusterResources) IsExcluded() (bool, error) {
Expand Down
2 changes: 1 addition & 1 deletion pkg/collect/collectd.go
Original file line number Diff line number Diff line change
Expand Up @@ -19,7 +19,7 @@ type CollectCollectd struct {
}

func (c *CollectCollectd) Title() string {
return collectorTitleOrDefault(c.Collector.CollectorMeta, "CollectD")
return getCollectorName(c)
}

func (c *CollectCollectd) IsExcluded() (bool, error) {
Expand Down
82 changes: 82 additions & 0 deletions pkg/collect/collector.go
Original file line number Diff line number Diff line change
Expand Up @@ -2,7 +2,9 @@ package collect

import (
"context"
"fmt"
"strconv"
"strings"
"time"

"github.com/pkg/errors"
Expand Down Expand Up @@ -107,3 +109,83 @@ func collectorTitleOrDefault(meta troubleshootv1beta2.CollectorMeta, defaultTitl
}
return defaultTitle
}

func getCollectorName(c interface{}) string {
var collector, name, selector string

switch v := c.(type) {
case *CollectClusterInfo:
collector = "cluster-info"
case *CollectClusterResources:
collector = "cluster-resources"
case *CollectSecret:
collector = "secret"
name = v.Collector.CollectorName
selector = strings.Join(v.Collector.Selector, ",")
case *CollectConfigMap:
collector = "configmap"
name = v.Collector.CollectorName
selector = strings.Join(v.Collector.Selector, ",")
case *CollectLogs:
collector = "logs"
name = v.Collector.CollectorName
selector = strings.Join(v.Collector.Selector, ",")
case *CollectRun:
collector = "run"
name = v.Collector.CollectorName
case *CollectRunPod:
collector = "run-pod"
name = v.Collector.CollectorName
case *CollectExec:
collector = "exec"
name = v.Collector.CollectorName
selector = strings.Join(v.Collector.Selector, ",")
case *CollectData:
collector = "data"
name = v.Collector.CollectorName
case *CollectCopy:
collector = "copy"
name = v.Collector.CollectorName
selector = strings.Join(v.Collector.Selector, ",")
case *CollectCopyFromHost:
collector = "copy-from-host"
name = v.Collector.CollectorName
case *CollectHTTP:
collector = "http"
name = v.Collector.CollectorName
case *CollectPostgres:
collector = "postgres"
name = v.Collector.CollectorName
case *CollectMysql:
collector = "mysql"
name = v.Collector.CollectorName
case *CollectRedis:
collector = "redis"
name = v.Collector.CollectorName
case *CollectCollectd:
collector = "collectd"
name = v.Collector.CollectorName
case *CollectCeph:
collector = "ceph"
name = v.Collector.CollectorName
case *CollectLonghorn:
collector = "longhorn"
name = v.Collector.CollectorName
case *CollectRegistry:
collector = "registry-images"
name = v.Collector.CollectorName
case *CollectSysctl:
collector = "sysctl"
name = v.Collector.Name
default:
collector = "<none>"
}

if name != "" {
return fmt.Sprintf("%s/%s", collector, name)
}
if selector != "" {
return fmt.Sprintf("%s/%s", collector, selector)
}
return collector
}
2 changes: 1 addition & 1 deletion pkg/collect/configmap.go
Original file line number Diff line number Diff line change
Expand Up @@ -38,7 +38,7 @@ type CollectConfigMap struct {
}

func (c *CollectConfigMap) Title() string {
return collectorTitleOrDefault(c.Collector.CollectorMeta, "ConfigMap")
return getCollectorName(c)
}

func (c *CollectConfigMap) IsExcluded() (bool, error) {
Expand Down
2 changes: 1 addition & 1 deletion pkg/collect/copy.go
Original file line number Diff line number Diff line change
Expand Up @@ -31,7 +31,7 @@ type CollectCopy struct {
}

func (c *CollectCopy) Title() string {
return collectorTitleOrDefault(c.Collector.CollectorMeta, "Copy")
return getCollectorName(c)
}

func (c *CollectCopy) IsExcluded() (bool, error) {
Expand Down
2 changes: 1 addition & 1 deletion pkg/collect/copy_from_host.go
Original file line number Diff line number Diff line change
Expand Up @@ -37,7 +37,7 @@ type CollectCopyFromHost struct {
}

func (c *CollectCopyFromHost) Title() string {
return collectorTitleOrDefault(c.Collector.CollectorMeta, "Copy from Host")
return getCollectorName(c)
}

func (c *CollectCopyFromHost) IsExcluded() (bool, error) {
Expand Down
2 changes: 1 addition & 1 deletion pkg/collect/data.go
Original file line number Diff line number Diff line change
Expand Up @@ -21,7 +21,7 @@ type CollectData struct {
}

func (c *CollectData) Title() string {
return collectorTitleOrDefault(c.Collector.CollectorMeta, "Data")
return getCollectorName(c)
}

func (c *CollectData) IsExcluded() (bool, error) {
Expand Down
2 changes: 1 addition & 1 deletion pkg/collect/exec.go
Original file line number Diff line number Diff line change
Expand Up @@ -27,7 +27,7 @@ type CollectExec struct {
}

func (c *CollectExec) Title() string {
return collectorTitleOrDefault(c.Collector.CollectorMeta, "Exec")
return getCollectorName(c)
}

func (c *CollectExec) IsExcluded() (bool, error) {
Expand Down
2 changes: 1 addition & 1 deletion pkg/collect/http.go
Original file line number Diff line number Diff line change
Expand Up @@ -45,7 +45,7 @@ type CollectHTTP struct {
}

func (c *CollectHTTP) Title() string {
return collectorTitleOrDefault(c.Collector.CollectorMeta, "HTTP")
return getCollectorName(c)
}

func (c *CollectHTTP) IsExcluded() (bool, error) {
Expand Down
2 changes: 1 addition & 1 deletion pkg/collect/logs.go
Original file line number Diff line number Diff line change
Expand Up @@ -28,7 +28,7 @@ type CollectLogs struct {
}

func (c *CollectLogs) Title() string {
return collectorTitleOrDefault(c.Collector.CollectorMeta, "Logs")
return getCollectorName(c)
}

func (c *CollectLogs) IsExcluded() (bool, error) {
Expand Down
2 changes: 1 addition & 1 deletion pkg/collect/longhorn.go
Original file line number Diff line number Diff line change
Expand Up @@ -40,7 +40,7 @@ type CollectLonghorn struct {
}

func (c *CollectLonghorn) Title() string {
return collectorTitleOrDefault(c.Collector.CollectorMeta, "Longhorn")
return getCollectorName(c)
}

func (c *CollectLonghorn) IsExcluded() (bool, error) {
Expand Down
2 changes: 1 addition & 1 deletion pkg/collect/mysql.go
Original file line number Diff line number Diff line change
Expand Up @@ -25,7 +25,7 @@ type CollectMysql struct {
}

func (c *CollectMysql) Title() string {
return collectorTitleOrDefault(c.Collector.CollectorMeta, "Mysql")
return getCollectorName(c)
}

func (c *CollectMysql) IsExcluded() (bool, error) {
Expand Down
2 changes: 1 addition & 1 deletion pkg/collect/postgres.go
Original file line number Diff line number Diff line change
Expand Up @@ -26,7 +26,7 @@ type CollectPostgres struct {
}

func (c *CollectPostgres) Title() string {
return collectorTitleOrDefault(c.Collector.CollectorMeta, "Postgres")
return getCollectorName(c)
}

func (c *CollectPostgres) IsExcluded() (bool, error) {
Expand Down
2 changes: 1 addition & 1 deletion pkg/collect/redis.go
Original file line number Diff line number Diff line change
Expand Up @@ -25,7 +25,7 @@ type CollectRedis struct {
}

func (c *CollectRedis) Title() string {
return collectorTitleOrDefault(c.Collector.CollectorMeta, "Cluster Info")
return getCollectorName(c)
}

func (c *CollectRedis) IsExcluded() (bool, error) {
Expand Down
2 changes: 1 addition & 1 deletion pkg/collect/registry.go
Original file line number Diff line number Diff line change
Expand Up @@ -48,7 +48,7 @@ type CollectRegistry struct {
}

func (c *CollectRegistry) Title() string {
return collectorTitleOrDefault(c.Collector.CollectorMeta, "Registry Images")
return getCollectorName(c)
}

func (c *CollectRegistry) IsExcluded() (bool, error) {
Expand Down
2 changes: 1 addition & 1 deletion pkg/collect/run.go
Original file line number Diff line number Diff line change
Expand Up @@ -20,7 +20,7 @@ type CollectRun struct {
}

func (c *CollectRun) Title() string {
return collectorTitleOrDefault(c.Collector.CollectorMeta, "Run")
return getCollectorName(c)
}

func (c *CollectRun) IsExcluded() (bool, error) {
Expand Down
2 changes: 1 addition & 1 deletion pkg/collect/run_pod.go
Original file line number Diff line number Diff line change
Expand Up @@ -33,7 +33,7 @@ type CollectRunPod struct {
}

func (c *CollectRunPod) Title() string {
return collectorTitleOrDefault(c.Collector.CollectorMeta, "Run Pod")
return getCollectorName(c)
}

func (c *CollectRunPod) IsExcluded() (bool, error) {
Expand Down
2 changes: 1 addition & 1 deletion pkg/collect/secret.go
Original file line number Diff line number Diff line change
Expand Up @@ -37,7 +37,7 @@ type CollectSecret struct {
}

func (c *CollectSecret) Title() string {
return collectorTitleOrDefault(c.Collector.CollectorMeta, "Secret")
return getCollectorName(c)
}

func (c *CollectSecret) IsExcluded() (bool, error) {
Expand Down
2 changes: 1 addition & 1 deletion pkg/collect/sysctl.go
Original file line number Diff line number Diff line change
Expand Up @@ -27,7 +27,7 @@ type CollectSysctl struct {
}

func (c *CollectSysctl) Title() string {
return collectorTitleOrDefault(c.Collector.CollectorMeta, "Sysctl")
return getCollectorName(c)
}

func (c *CollectSysctl) IsExcluded() (bool, error) {
Expand Down
2 changes: 1 addition & 1 deletion pkg/supportbundle/collect.go
Original file line number Diff line number Diff line change
Expand Up @@ -131,7 +131,7 @@ func runCollectors(collectors []*troubleshootv1beta2.Collect, additionalRedactor
}
}

opts.ProgressChan <- fmt.Sprintf("[%s] Running collector...", collector.Title())
opts.CollectorProgressCallback(opts.ProgressChan, collector.Title())
result, err := collector.Collect(opts.ProgressChan)
if err != nil {
opts.ProgressChan <- errors.Errorf("failed to run collector: %s: %v", collector.Title(), err)
Expand Down

0 comments on commit 04c7a18

Please sign in to comment.