Skip to content

Commit

Permalink
Conditional Analyzers
Browse files Browse the repository at this point in the history
  • Loading branch information
emosbaugh committed Feb 26, 2021
1 parent 7589b4f commit d6acd6d
Show file tree
Hide file tree
Showing 4 changed files with 40 additions and 9 deletions.
18 changes: 11 additions & 7 deletions pkg/apis/troubleshoot/v1beta2/hostanalyzer_shared.go
Original file line number Diff line number Diff line change
@@ -1,5 +1,7 @@
package v1beta2

import "github.com/replicatedhq/troubleshoot/pkg/multitype"

type CPUAnalyze struct {
AnalyzeMeta `json:",inline" yaml:",inline"`
Outcomes []*Outcome `json:"outcomes" yaml:"outcomes"`
Expand Down Expand Up @@ -85,17 +87,19 @@ type HostAnalyze struct {

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

HTTP *HTTPAnalyze `json:"http" yaml:"http"`
HTTP *HTTPAnalyze `json:"http,omitempty" yaml:"http,omitempty"`

Time *TimeAnalyze `json:"time,omitempty" yaml:"time,omitempty"`

Time *TimeAnalyze `json:"time" yaml:"time"`
BlockDevices *BlockDevicesAnalyze `json:"blockDevices,omitempty" yaml:"blockDevices,omitempty"`

BlockDevices *BlockDevicesAnalyze `json:"blockDevices" yaml:"blockDevices"`
TCPConnect *TCPConnectAnalyze `json:"tcpConnect,omitempty" yaml:"tcpConnect,omitempty"`

TCPConnect *TCPConnectAnalyze `json:"tcpConnect" yaml:"tcpConnect"`
IPV4Interfaces *IPV4InterfacesAnalyze `json:"ipv4Interfaces,omitempty" yaml:"ipv4Interfaces,omitempty"`

IPV4Interfaces *IPV4InterfacesAnalyze `json:"ipv4Interfaces" yaml:"ipv4Interfaces"`
FilesystemPerformance *FilesystemPerformanceAnalyze `json:"filesystemPerformance,omitempty" yaml:"filesystemPerformance,omitempty"`

FilesystemPerformance *FilesystemPerformanceAnalyze `json:"filesystemPerformance" yaml:"filesystemPerformance"`
Certificate *CertificateAnalyze `json:"certificate,omitempty" yaml:"certificate,omitempty"`

Certificate *CertificateAnalyze `json:"certificate" yaml:"certificate"`
Exclude multitype.BoolOrString `json:"exclude,omitempty" yaml:"exclude,omitempty"`
}
5 changes: 3 additions & 2 deletions pkg/apis/troubleshoot/v1beta2/hostcollector_shared.go
Original file line number Diff line number Diff line change
Expand Up @@ -101,8 +101,9 @@ type HostCollect struct {
Time *HostTime `json:"time,omitempty" yaml:"time,omitempty"`
BlockDevices *HostBlockDevices `json:"blockDevices,omitempty" yaml:"blockDevices,omitempty"`
TCPConnect *TCPConnect `json:"tcpConnect,omitempty" yaml:"tcpConnect,omitempty"`
FilesystemPerformance *FilesystemPerformance `json:"filesystemPerformance" yaml:"filesystemPerformance"`
Certificate *Certificate `json:"certificate" yaml:"certificate" yaml:"certificate"`
FilesystemPerformance *FilesystemPerformance `json:"filesystemPerformance,omitempty" yaml:"filesystemPerformance,omitempty"`
Certificate *Certificate `json:"certificate,omitempty" yaml:"certificate,omitempty"`
Exclude multitype.BoolOrString `json:"exclude,omitempty" yaml:"exclude,omitempty"`
}

func (c *HostCollect) GetName() string {
Expand Down
23 changes: 23 additions & 0 deletions pkg/preflight/analyze.go
Original file line number Diff line number Diff line change
Expand Up @@ -3,10 +3,13 @@ package preflight
import (
"fmt"
"path/filepath"
"strconv"
"strings"

"github.com/pkg/errors"
analyze "github.com/replicatedhq/troubleshoot/pkg/analyze"
troubleshootv1beta2 "github.com/replicatedhq/troubleshoot/pkg/apis/troubleshoot/v1beta2"
"github.com/replicatedhq/troubleshoot/pkg/multitype"
)

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

for _, hostAnalyzer := range hostAnalyzers {
if excluded, _ := isExcluded(hostAnalyzer.Exclude); excluded {
continue
}
analyzeResult, err := analyze.HostAnalyze(hostAnalyzer, getCollectedFileContents, getChildCollectedFileContents)
if err != nil {
analyzeResult = []*analyze.AnalyzeResult{
Expand All @@ -81,3 +87,20 @@ func doAnalyze(allCollectedData map[string][]byte, analyzers []*troubleshootv1be
}
return analyzeResults
}

func isExcluded(excludeVal multitype.BoolOrString) (bool, error) {
if excludeVal.Type == multitype.Bool {
return excludeVal.BoolVal, nil
}

if excludeVal.StrVal == "" {
return false, nil
}

parsed, err := strconv.ParseBool(excludeVal.StrVal)
if err != nil {
return false, errors.Wrap(err, "failed to parse bool string")
}

return parsed, nil
}
3 changes: 3 additions & 0 deletions pkg/preflight/collect.go
Original file line number Diff line number Diff line change
Expand Up @@ -67,6 +67,9 @@ func CollectHost(opts CollectOpts, p *troubleshootv1beta2.HostPreflight) (Collec
}

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

0 comments on commit d6acd6d

Please sign in to comment.