Merge branch 'main' into el-analyze-typo-20220615

This commit is contained in:
Edgar Lanting
2022-07-01 15:32:56 +02:00
committed by GitHub
7 changed files with 198 additions and 17 deletions

View File

@@ -219,14 +219,14 @@ func Test_cephStatus(t *testing.T) {
}`,
},
{
name: "warn case with multiple health status messages",
name: "warn case with health status message and summary",
analyzer: troubleshootv1beta2.CephStatusAnalyze{},
expectResult: AnalyzeResult{
IsPass: false,
IsWarn: true,
IsFail: false,
Title: "Ceph Status",
Message: "Ceph status is HEALTH_WARN\nPOOL_NO_REDUNDANCY: 11 pool(s) have no replicas configured\nPOOL_PG_NUM_NOT_POWER_OF_TWO: 8 pool(s) have non-power-of-two pg_num",
Message: "Ceph status is HEALTH_WARN\nPOOL_NO_REDUNDANCY: 11 pool(s) have no replicas configured",
URI: "https://rook.io/docs/rook/v1.4/ceph-common-issues.html",
IconKey: "rook",
IconURI: "https://troubleshoot.sh/images/analyzer-icons/rook.svg?w=11&h=16",
@@ -244,12 +244,6 @@ func Test_cephStatus(t *testing.T) {
"count": 11
},
"muted": false
},
"POOL_PG_NUM_NOT_POWER_OF_TWO": {
"severity": "HEALTH_WARN",
"summary": {
"message": "8 pool(s) have non-power-of-two pg_num"
}
}
}
}

View File

@@ -39,12 +39,6 @@ func analyzePostgres(analyzer *troubleshootv1beta2.DatabaseAnalyze, getCollected
IconURI: "https://troubleshoot.sh/images/analyzer-icons/postgres-analyze.svg",
}
if databaseConnection.Error != "" {
result.IsFail = true
result.Message = databaseConnection.Error
return result, nil
}
for _, outcome := range analyzer.Outcomes {
if outcome.Fail != nil {
if outcome.Fail.When == "" {
@@ -61,8 +55,14 @@ func analyzePostgres(analyzer *troubleshootv1beta2.DatabaseAnalyze, getCollected
}
if isMatch {
if databaseConnection.Error != "" {
result.Message = outcome.Fail.Message + " " + databaseConnection.Error
} else {
result.Message = outcome.Fail.Message
}
result.IsFail = true
result.Message = outcome.Fail.Message
result.URI = outcome.Fail.URI
return result, nil

View File

@@ -150,6 +150,12 @@ type HostServices struct {
HostCollectorMeta `json:",inline" yaml:",inline"`
}
type HostRun struct {
HostCollectorMeta `json:",inline" yaml:",inline"`
Command string `json:"command"`
Args []string `json:"args"`
}
type HostCollect struct {
CPU *CPU `json:"cpu,omitempty" yaml:"cpu,omitempty"`
Memory *Memory `json:"memory,omitempty" yaml:"memory,omitempty"`
@@ -169,6 +175,7 @@ type HostCollect struct {
Certificate *Certificate `json:"certificate,omitempty" yaml:"certificate,omitempty"`
HostServices *HostServices `json:"hostServices,omitempty" yaml:"hostServices,omitempty"`
HostOS *HostOS `json:"hostOS,omitempty" yaml:"hostOS,omitempty"`
HostRun *HostRun `json:"run,omitempty" yaml:"run,omitempty"`
}
func (c *HostCollect) GetName() string {

View File

@@ -51,6 +51,8 @@ func GetHostCollector(collector *troubleshootv1beta2.HostCollect, bundlePath str
return &CollectHostServices{collector.HostServices, bundlePath}, true
case collector.HostOS != nil:
return &CollectHostOS{collector.HostOS, bundlePath}, true
case collector.HostRun != nil:
return &CollectHostRun{collector.HostRun, bundlePath}, true
default:
return nil, false
}

79
pkg/collect/host_run.go Normal file
View File

@@ -0,0 +1,79 @@
package collect
import (
"bytes"
"encoding/json"
"os/exec"
"path/filepath"
"strings"
"github.com/pkg/errors"
troubleshootv1beta2 "github.com/replicatedhq/troubleshoot/pkg/apis/troubleshoot/v1beta2"
)
type HostRunInfo struct {
Command string `json:"command"`
ExitCode string `json:"exitCode"`
Error string `json:"error"`
}
type CollectHostRun struct {
hostCollector *troubleshootv1beta2.HostRun
BundlePath string
}
func (c *CollectHostRun) Title() string {
return hostCollectorTitleOrDefault(c.hostCollector.HostCollectorMeta, "Run Host")
}
func (c *CollectHostRun) IsExcluded() (bool, error) {
return isExcluded(c.hostCollector.Exclude)
}
func (c *CollectHostRun) Collect(progressChan chan<- interface{}) (map[string][]byte, error) {
runHostCollector := c.hostCollector
cmd := exec.Command(runHostCollector.Command, runHostCollector.Args...)
var stdout, stderr bytes.Buffer
cmd.Stdout = &stdout
cmd.Stderr = &stderr
runInfo := HostRunInfo{
Command: cmd.String(),
ExitCode: "0",
}
err := cmd.Run()
if err != nil {
if werr, ok := err.(*exec.ExitError); ok {
runInfo.ExitCode = strings.TrimPrefix(werr.Error(), "exit status ")
runInfo.Error = stderr.String()
} else {
return nil, errors.Wrap(err, "failed to run")
}
}
collectorName := c.hostCollector.CollectorName
if collectorName == "" {
collectorName = "run-host"
}
resultInfo := filepath.Join("host-collectors/run-host", collectorName+"-info.json")
result := filepath.Join("host-collectors/run-host", collectorName+".txt")
b, err := json.Marshal(runInfo)
if err != nil {
return nil, errors.Wrap(err, "failed to marshal run host result")
}
output := NewResult()
output.SaveResult(c.BundlePath, resultInfo, bytes.NewBuffer(b))
output.SaveResult(c.BundlePath, result, bytes.NewBuffer(stdout.Bytes()))
runHostOutput := map[string][]byte{
resultInfo: b,
result: stdout.Bytes(),
}
return runHostOutput, nil
}

View File

@@ -304,6 +304,11 @@ func getRedactors(path string) ([]Redactor, error) {
line2: `(?i)("value": *")(?P<mask>.*[^\"]*)(")`,
name: "Redact usernames in multiline JSON",
},
{
line1: `(?i)"entity": *"(osd|client|mgr)\..*[^\"]*"`,
line2: `(?i)("key": *")(?P<mask>.{38}==[^\"]*)(")`,
name: "Redact 'key' values found in Ceph auth lists",
},
}
for _, l := range doubleLines {

View File

@@ -816,6 +816,53 @@ func Test_Redactors(t *testing.T) {
"status": {
"loadBalancer": {}
}
},
{
"auth_dump": [
{
"entity": "osd.0",
"key": "ABCxyzABCxyz/foo/bar123xyz/BAZAABBCCDD==",
"caps": {
"mgr": "allow profile osd",
"mon": "allow profile osd",
"osd": "allow *"
}
},
{
"entity": "client.admin",
"key": "ABCxyzABCxyz/foo/bar123xyz/BAZAABBCCDD==",
"caps": {
"mds": "allow *",
"mgr": "allow *",
"mon": "allow *",
"osd": "allow *"
}
},
{
"entity": "client.bootstrap-mds",
"key": "ABCxyzABCxyz/foo/bar123xyz/BAZAABBCCDD==",
"caps": {
"mon": "allow profile bootstrap-mds"
}
},
{
"entity": "client.rgw.rook.ceph.store.a",
"key": "ABCxyzABCxyz/foo/bar123xyz/BAZAABBCCDD==",
"caps": {
"mon": "allow rw",
"osd": "allow rwx"
}
},
{
"entity": "mgr.a",
"key": "ABCxyzABCxyz/foo/bar123xyz/BAZAABBCCDD==",
"caps": {
"mds": "allow *",
"mon": "allow profile mgr",
"osd": "allow *"
}
}
]
}
]`
@@ -1624,11 +1671,58 @@ func Test_Redactors(t *testing.T) {
"status": {
"loadBalancer": {}
}
},
{
"auth_dump": [
{
"entity": "osd.0",
"key": "***HIDDEN***",
"caps": {
"mgr": "allow profile osd",
"mon": "allow profile osd",
"osd": "allow *"
}
},
{
"entity": "client.admin",
"key": "***HIDDEN***",
"caps": {
"mds": "allow *",
"mgr": "allow *",
"mon": "allow *",
"osd": "allow *"
}
},
{
"entity": "client.bootstrap-mds",
"key": "***HIDDEN***",
"caps": {
"mon": "allow profile bootstrap-mds"
}
},
{
"entity": "client.rgw.rook.ceph.store.a",
"key": "***HIDDEN***",
"caps": {
"mon": "allow rw",
"osd": "allow rwx"
}
},
{
"entity": "mgr.a",
"key": "***HIDDEN***",
"caps": {
"mds": "allow *",
"mon": "allow profile mgr",
"osd": "allow *"
}
}
]
}
]`
wantRedactionsLen := 39
wantRedactionsCount := 25
wantRedactionsLen := 44
wantRedactionsCount := 26
t.Run("test default redactors", func(t *testing.T) {
req := require.New(t)