mirror of
https://github.com/replicatedhq/troubleshoot.git
synced 2026-04-15 07:16:34 +00:00
Fixed bug caused by host preflights not handling empty when clauses, this cropped up because we now handle multiple host preflight results. Also expanded test coverage and added integration test script.
105 lines
2.5 KiB
Go
105 lines
2.5 KiB
Go
package analyzer
|
|
|
|
import (
|
|
"encoding/json"
|
|
"fmt"
|
|
"path"
|
|
|
|
"github.com/pkg/errors"
|
|
troubleshootv1beta2 "github.com/replicatedhq/troubleshoot/pkg/apis/troubleshoot/v1beta2"
|
|
"github.com/replicatedhq/troubleshoot/pkg/collect"
|
|
)
|
|
|
|
type AnalyzeHostHTTPLoadBalancer struct {
|
|
hostAnalyzer *troubleshootv1beta2.HTTPLoadBalancerAnalyze
|
|
}
|
|
|
|
func (a *AnalyzeHostHTTPLoadBalancer) Title() string {
|
|
return hostAnalyzerTitleOrDefault(a.hostAnalyzer.AnalyzeMeta, "HTTP Load Balancer")
|
|
}
|
|
|
|
func (a *AnalyzeHostHTTPLoadBalancer) IsExcluded() (bool, error) {
|
|
return isExcluded(a.hostAnalyzer.Exclude)
|
|
}
|
|
|
|
func (a *AnalyzeHostHTTPLoadBalancer) Analyze(getCollectedFileContents func(string) ([]byte, error)) ([]*AnalyzeResult, error) {
|
|
hostAnalyzer := a.hostAnalyzer
|
|
|
|
collectorName := hostAnalyzer.CollectorName
|
|
if collectorName == "" {
|
|
collectorName = "httpLoadBalancer"
|
|
}
|
|
fullPath := path.Join("httpLoadBalancer", fmt.Sprintf("%s.json", collectorName))
|
|
|
|
collected, err := getCollectedFileContents(fullPath)
|
|
if err != nil {
|
|
return nil, errors.Wrapf(err, "failed to read collected file name: %s", fullPath)
|
|
}
|
|
actual := collect.NetworkStatusResult{}
|
|
if err := json.Unmarshal(collected, &actual); err != nil {
|
|
return nil, errors.Wrap(err, "failed to unmarshal collected")
|
|
}
|
|
|
|
var coll resultCollector
|
|
|
|
for _, outcome := range hostAnalyzer.Outcomes {
|
|
result := &AnalyzeResult{Title: a.Title()}
|
|
|
|
if outcome.Fail != nil {
|
|
if outcome.Fail.When == "" {
|
|
result.IsFail = true
|
|
result.Message = outcome.Fail.Message
|
|
result.URI = outcome.Fail.URI
|
|
|
|
coll.push(result)
|
|
continue
|
|
}
|
|
|
|
if string(actual.Status) == outcome.Fail.When {
|
|
result.IsFail = true
|
|
result.Message = outcome.Fail.Message
|
|
result.URI = outcome.Fail.URI
|
|
|
|
coll.push(result)
|
|
}
|
|
} else if outcome.Warn != nil {
|
|
if outcome.Warn.When == "" {
|
|
result.IsWarn = true
|
|
result.Message = outcome.Warn.Message
|
|
result.URI = outcome.Warn.URI
|
|
|
|
coll.push(result)
|
|
continue
|
|
}
|
|
|
|
if string(actual.Status) == outcome.Warn.When {
|
|
result.IsWarn = true
|
|
result.Message = outcome.Warn.Message
|
|
result.URI = outcome.Warn.URI
|
|
|
|
coll.push(result)
|
|
}
|
|
} else if outcome.Pass != nil {
|
|
if outcome.Pass.When == "" {
|
|
result.IsPass = true
|
|
result.Message = outcome.Pass.Message
|
|
result.URI = outcome.Pass.URI
|
|
|
|
coll.push(result)
|
|
continue
|
|
}
|
|
|
|
if string(actual.Status) == outcome.Pass.When {
|
|
result.IsPass = true
|
|
result.Message = outcome.Pass.Message
|
|
result.URI = outcome.Pass.URI
|
|
|
|
coll.push(result)
|
|
}
|
|
|
|
}
|
|
}
|
|
|
|
return coll.get(a.Title()), nil
|
|
}
|