Conditional Analyzers

This commit is contained in:
Ethan Mosbaugh
2021-02-26 04:33:11 +00:00
parent 7589b4fed0
commit d6acd6d906
4 changed files with 40 additions and 9 deletions

View File

@@ -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"`
@@ -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" yaml:"time"`
Time *TimeAnalyze `json:"time,omitempty" yaml:"time,omitempty"`
BlockDevices *BlockDevicesAnalyze `json:"blockDevices" yaml:"blockDevices"`
BlockDevices *BlockDevicesAnalyze `json:"blockDevices,omitempty" yaml:"blockDevices,omitempty"`
TCPConnect *TCPConnectAnalyze `json:"tcpConnect" yaml:"tcpConnect"`
TCPConnect *TCPConnectAnalyze `json:"tcpConnect,omitempty" yaml:"tcpConnect,omitempty"`
IPV4Interfaces *IPV4InterfacesAnalyze `json:"ipv4Interfaces" yaml:"ipv4Interfaces"`
IPV4Interfaces *IPV4InterfacesAnalyze `json:"ipv4Interfaces,omitempty" yaml:"ipv4Interfaces,omitempty"`
FilesystemPerformance *FilesystemPerformanceAnalyze `json:"filesystemPerformance" yaml:"filesystemPerformance"`
FilesystemPerformance *FilesystemPerformanceAnalyze `json:"filesystemPerformance,omitempty" yaml:"filesystemPerformance,omitempty"`
Certificate *CertificateAnalyze `json:"certificate" yaml:"certificate"`
Certificate *CertificateAnalyze `json:"certificate,omitempty" yaml:"certificate,omitempty"`
Exclude multitype.BoolOrString `json:"exclude,omitempty" yaml:"exclude,omitempty"`
}

View File

@@ -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 {

View File

@@ -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
@@ -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{
@@ -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
}

View File

@@ -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)