Skip to content

Commit a1e0813

Browse files
authored
Merge pull request #331 from replicatedhq/condition-analyzers
2 parents ce53dbc + d6acd6d commit a1e0813

File tree

4 files changed

+40
-9
lines changed

4 files changed

+40
-9
lines changed

pkg/apis/troubleshoot/v1beta2/hostanalyzer_shared.go

Lines changed: 11 additions & 7 deletions
Original file line numberDiff line numberDiff line change
@@ -1,5 +1,7 @@
11
package v1beta2
22

3+
import "github.com/replicatedhq/troubleshoot/pkg/multitype"
4+
35
type CPUAnalyze struct {
46
AnalyzeMeta `json:",inline" yaml:",inline"`
57
Outcomes []*Outcome `json:"outcomes" yaml:"outcomes"`
@@ -85,17 +87,19 @@ type HostAnalyze struct {
8587

8688
TCPPortStatus *TCPPortStatusAnalyze `json:"tcpPortStatus,omitempty" yaml:"tcpPortStatus,omitempty"`
8789

88-
HTTP *HTTPAnalyze `json:"http" yaml:"http"`
90+
HTTP *HTTPAnalyze `json:"http,omitempty" yaml:"http,omitempty"`
91+
92+
Time *TimeAnalyze `json:"time,omitempty" yaml:"time,omitempty"`
8993

90-
Time *TimeAnalyze `json:"time" yaml:"time"`
94+
BlockDevices *BlockDevicesAnalyze `json:"blockDevices,omitempty" yaml:"blockDevices,omitempty"`
9195

92-
BlockDevices *BlockDevicesAnalyze `json:"blockDevices" yaml:"blockDevices"`
96+
TCPConnect *TCPConnectAnalyze `json:"tcpConnect,omitempty" yaml:"tcpConnect,omitempty"`
9397

94-
TCPConnect *TCPConnectAnalyze `json:"tcpConnect" yaml:"tcpConnect"`
98+
IPV4Interfaces *IPV4InterfacesAnalyze `json:"ipv4Interfaces,omitempty" yaml:"ipv4Interfaces,omitempty"`
9599

96-
IPV4Interfaces *IPV4InterfacesAnalyze `json:"ipv4Interfaces" yaml:"ipv4Interfaces"`
100+
FilesystemPerformance *FilesystemPerformanceAnalyze `json:"filesystemPerformance,omitempty" yaml:"filesystemPerformance,omitempty"`
97101

98-
FilesystemPerformance *FilesystemPerformanceAnalyze `json:"filesystemPerformance" yaml:"filesystemPerformance"`
102+
Certificate *CertificateAnalyze `json:"certificate,omitempty" yaml:"certificate,omitempty"`
99103

100-
Certificate *CertificateAnalyze `json:"certificate" yaml:"certificate"`
104+
Exclude multitype.BoolOrString `json:"exclude,omitempty" yaml:"exclude,omitempty"`
101105
}

pkg/apis/troubleshoot/v1beta2/hostcollector_shared.go

Lines changed: 3 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -101,8 +101,9 @@ type HostCollect struct {
101101
Time *HostTime `json:"time,omitempty" yaml:"time,omitempty"`
102102
BlockDevices *HostBlockDevices `json:"blockDevices,omitempty" yaml:"blockDevices,omitempty"`
103103
TCPConnect *TCPConnect `json:"tcpConnect,omitempty" yaml:"tcpConnect,omitempty"`
104-
FilesystemPerformance *FilesystemPerformance `json:"filesystemPerformance" yaml:"filesystemPerformance"`
105-
Certificate *Certificate `json:"certificate" yaml:"certificate" yaml:"certificate"`
104+
FilesystemPerformance *FilesystemPerformance `json:"filesystemPerformance,omitempty" yaml:"filesystemPerformance,omitempty"`
105+
Certificate *Certificate `json:"certificate,omitempty" yaml:"certificate,omitempty"`
106+
Exclude multitype.BoolOrString `json:"exclude,omitempty" yaml:"exclude,omitempty"`
106107
}
107108

108109
func (c *HostCollect) GetName() string {

pkg/preflight/analyze.go

Lines changed: 23 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -3,10 +3,13 @@ package preflight
33
import (
44
"fmt"
55
"path/filepath"
6+
"strconv"
67
"strings"
78

9+
"github.com/pkg/errors"
810
analyze "github.com/replicatedhq/troubleshoot/pkg/analyze"
911
troubleshootv1beta2 "github.com/replicatedhq/troubleshoot/pkg/apis/troubleshoot/v1beta2"
12+
"github.com/replicatedhq/troubleshoot/pkg/multitype"
1013
)
1114

1215
// Analyze runs the analyze phase of preflight checks
@@ -64,6 +67,9 @@ func doAnalyze(allCollectedData map[string][]byte, analyzers []*troubleshootv1be
6467
}
6568

6669
for _, hostAnalyzer := range hostAnalyzers {
70+
if excluded, _ := isExcluded(hostAnalyzer.Exclude); excluded {
71+
continue
72+
}
6773
analyzeResult, err := analyze.HostAnalyze(hostAnalyzer, getCollectedFileContents, getChildCollectedFileContents)
6874
if err != nil {
6975
analyzeResult = []*analyze.AnalyzeResult{
@@ -81,3 +87,20 @@ func doAnalyze(allCollectedData map[string][]byte, analyzers []*troubleshootv1be
8187
}
8288
return analyzeResults
8389
}
90+
91+
func isExcluded(excludeVal multitype.BoolOrString) (bool, error) {
92+
if excludeVal.Type == multitype.Bool {
93+
return excludeVal.BoolVal, nil
94+
}
95+
96+
if excludeVal.StrVal == "" {
97+
return false, nil
98+
}
99+
100+
parsed, err := strconv.ParseBool(excludeVal.StrVal)
101+
if err != nil {
102+
return false, errors.Wrap(err, "failed to parse bool string")
103+
}
104+
105+
return parsed, nil
106+
}

pkg/preflight/collect.go

Lines changed: 3 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -67,6 +67,9 @@ func CollectHost(opts CollectOpts, p *troubleshootv1beta2.HostPreflight) (Collec
6767
}
6868

6969
for _, collector := range collectors {
70+
if excluded, _ := isExcluded(collector.Collect.Exclude); excluded {
71+
continue
72+
}
7073
result, err := collector.RunCollectorSync()
7174
if err != nil {
7275
opts.ProgressChan <- errors.Errorf("failed to run collector: %s: %v\n", collector.GetDisplayName(), err)

0 commit comments

Comments
 (0)