From 04c7a18da374d14a948cf3281d732f0b68154a35 Mon Sep 17 00:00:00 2001 From: Diamon Wiggins <38189728+diamonwiggins@users.noreply.github.com> Date: Fri, 14 Oct 2022 12:29:59 -0400 Subject: [PATCH] Fix Progress Callback for Support Bundle Collection (#781) fix progress callback for support bundle and revert collector title changes --- pkg/collect/cluster_info.go | 2 +- pkg/collect/cluster_resources.go | 2 +- pkg/collect/collectd.go | 2 +- pkg/collect/collector.go | 82 ++++++++++++++++++++++++++++++++ pkg/collect/configmap.go | 2 +- pkg/collect/copy.go | 2 +- pkg/collect/copy_from_host.go | 2 +- pkg/collect/data.go | 2 +- pkg/collect/exec.go | 2 +- pkg/collect/http.go | 2 +- pkg/collect/logs.go | 2 +- pkg/collect/longhorn.go | 2 +- pkg/collect/mysql.go | 2 +- pkg/collect/postgres.go | 2 +- pkg/collect/redis.go | 2 +- pkg/collect/registry.go | 2 +- pkg/collect/run.go | 2 +- pkg/collect/run_pod.go | 2 +- pkg/collect/secret.go | 2 +- pkg/collect/sysctl.go | 2 +- pkg/supportbundle/collect.go | 2 +- 21 files changed, 102 insertions(+), 20 deletions(-) diff --git a/pkg/collect/cluster_info.go b/pkg/collect/cluster_info.go index 96b2c58d..10aa5e6d 100644 --- a/pkg/collect/cluster_info.go +++ b/pkg/collect/cluster_info.go @@ -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) { diff --git a/pkg/collect/cluster_resources.go b/pkg/collect/cluster_resources.go index 6400faab..c57168e4 100644 --- a/pkg/collect/cluster_resources.go +++ b/pkg/collect/cluster_resources.go @@ -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) { diff --git a/pkg/collect/collectd.go b/pkg/collect/collectd.go index 022fdd82..4d30cc14 100644 --- a/pkg/collect/collectd.go +++ b/pkg/collect/collectd.go @@ -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) { diff --git a/pkg/collect/collector.go b/pkg/collect/collector.go index c7140dc5..50e5d20b 100644 --- a/pkg/collect/collector.go +++ b/pkg/collect/collector.go @@ -2,7 +2,9 @@ package collect import ( "context" + "fmt" "strconv" + "strings" "time" "github.com/pkg/errors" @@ -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 = "" + } + + if name != "" { + return fmt.Sprintf("%s/%s", collector, name) + } + if selector != "" { + return fmt.Sprintf("%s/%s", collector, selector) + } + return collector +} diff --git a/pkg/collect/configmap.go b/pkg/collect/configmap.go index 23766c26..1161ce8f 100644 --- a/pkg/collect/configmap.go +++ b/pkg/collect/configmap.go @@ -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) { diff --git a/pkg/collect/copy.go b/pkg/collect/copy.go index 1f508993..a19e6304 100644 --- a/pkg/collect/copy.go +++ b/pkg/collect/copy.go @@ -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) { diff --git a/pkg/collect/copy_from_host.go b/pkg/collect/copy_from_host.go index 54301366..b4ecef1a 100644 --- a/pkg/collect/copy_from_host.go +++ b/pkg/collect/copy_from_host.go @@ -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) { diff --git a/pkg/collect/data.go b/pkg/collect/data.go index 437f4240..2e79583d 100644 --- a/pkg/collect/data.go +++ b/pkg/collect/data.go @@ -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) { diff --git a/pkg/collect/exec.go b/pkg/collect/exec.go index 82dabd84..f41e681a 100644 --- a/pkg/collect/exec.go +++ b/pkg/collect/exec.go @@ -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) { diff --git a/pkg/collect/http.go b/pkg/collect/http.go index 72c49015..a87db79d 100644 --- a/pkg/collect/http.go +++ b/pkg/collect/http.go @@ -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) { diff --git a/pkg/collect/logs.go b/pkg/collect/logs.go index 777156c6..58504616 100644 --- a/pkg/collect/logs.go +++ b/pkg/collect/logs.go @@ -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) { diff --git a/pkg/collect/longhorn.go b/pkg/collect/longhorn.go index 7fd39283..178c8e41 100644 --- a/pkg/collect/longhorn.go +++ b/pkg/collect/longhorn.go @@ -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) { diff --git a/pkg/collect/mysql.go b/pkg/collect/mysql.go index 76323da3..f292d56c 100644 --- a/pkg/collect/mysql.go +++ b/pkg/collect/mysql.go @@ -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) { diff --git a/pkg/collect/postgres.go b/pkg/collect/postgres.go index 71960dba..d79a7151 100644 --- a/pkg/collect/postgres.go +++ b/pkg/collect/postgres.go @@ -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) { diff --git a/pkg/collect/redis.go b/pkg/collect/redis.go index 81110cd9..07fb466e 100644 --- a/pkg/collect/redis.go +++ b/pkg/collect/redis.go @@ -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) { diff --git a/pkg/collect/registry.go b/pkg/collect/registry.go index 35a4b18b..43409b43 100644 --- a/pkg/collect/registry.go +++ b/pkg/collect/registry.go @@ -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) { diff --git a/pkg/collect/run.go b/pkg/collect/run.go index 5685659d..79128382 100644 --- a/pkg/collect/run.go +++ b/pkg/collect/run.go @@ -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) { diff --git a/pkg/collect/run_pod.go b/pkg/collect/run_pod.go index b58033ab..20a0f1a8 100644 --- a/pkg/collect/run_pod.go +++ b/pkg/collect/run_pod.go @@ -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) { diff --git a/pkg/collect/secret.go b/pkg/collect/secret.go index 682207f6..7dc13995 100644 --- a/pkg/collect/secret.go +++ b/pkg/collect/secret.go @@ -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) { diff --git a/pkg/collect/sysctl.go b/pkg/collect/sysctl.go index 71bab874..dfddfce0 100644 --- a/pkg/collect/sysctl.go +++ b/pkg/collect/sysctl.go @@ -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) { diff --git a/pkg/supportbundle/collect.go b/pkg/supportbundle/collect.go index a3469518..f3344a7c 100644 --- a/pkg/supportbundle/collect.go +++ b/pkg/supportbundle/collect.go @@ -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)