Skip to content

Commit cdbf189

Browse files
authored
Merge branch 'main' into el-analyze-typo-20220615
2 parents f1cff2c + ff5ee2b commit cdbf189

File tree

7 files changed

+198
-17
lines changed

7 files changed

+198
-17
lines changed

pkg/analyze/ceph_test.go

Lines changed: 2 additions & 8 deletions
Original file line numberDiff line numberDiff line change
@@ -219,14 +219,14 @@ func Test_cephStatus(t *testing.T) {
219219
}`,
220220
},
221221
{
222-
name: "warn case with multiple health status messages",
222+
name: "warn case with health status message and summary",
223223
analyzer: troubleshootv1beta2.CephStatusAnalyze{},
224224
expectResult: AnalyzeResult{
225225
IsPass: false,
226226
IsWarn: true,
227227
IsFail: false,
228228
Title: "Ceph Status",
229-
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",
229+
Message: "Ceph status is HEALTH_WARN\nPOOL_NO_REDUNDANCY: 11 pool(s) have no replicas configured",
230230
URI: "https://rook.io/docs/rook/v1.4/ceph-common-issues.html",
231231
IconKey: "rook",
232232
IconURI: "https://troubleshoot.sh/images/analyzer-icons/rook.svg?w=11&h=16",
@@ -244,12 +244,6 @@ func Test_cephStatus(t *testing.T) {
244244
"count": 11
245245
},
246246
"muted": false
247-
},
248-
"POOL_PG_NUM_NOT_POWER_OF_TWO": {
249-
"severity": "HEALTH_WARN",
250-
"summary": {
251-
"message": "8 pool(s) have non-power-of-two pg_num"
252-
}
253247
}
254248
}
255249
}

pkg/analyze/postgres.go

Lines changed: 7 additions & 7 deletions
Original file line numberDiff line numberDiff line change
@@ -39,12 +39,6 @@ func analyzePostgres(analyzer *troubleshootv1beta2.DatabaseAnalyze, getCollected
3939
IconURI: "https://troubleshoot.sh/images/analyzer-icons/postgres-analyze.svg",
4040
}
4141

42-
if databaseConnection.Error != "" {
43-
result.IsFail = true
44-
result.Message = databaseConnection.Error
45-
return result, nil
46-
}
47-
4842
for _, outcome := range analyzer.Outcomes {
4943
if outcome.Fail != nil {
5044
if outcome.Fail.When == "" {
@@ -61,8 +55,14 @@ func analyzePostgres(analyzer *troubleshootv1beta2.DatabaseAnalyze, getCollected
6155
}
6256

6357
if isMatch {
58+
59+
if databaseConnection.Error != "" {
60+
result.Message = outcome.Fail.Message + " " + databaseConnection.Error
61+
} else {
62+
result.Message = outcome.Fail.Message
63+
}
64+
6465
result.IsFail = true
65-
result.Message = outcome.Fail.Message
6666
result.URI = outcome.Fail.URI
6767

6868
return result, nil

pkg/apis/troubleshoot/v1beta2/hostcollector_shared.go

Lines changed: 7 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -150,6 +150,12 @@ type HostServices struct {
150150
HostCollectorMeta `json:",inline" yaml:",inline"`
151151
}
152152

153+
type HostRun struct {
154+
HostCollectorMeta `json:",inline" yaml:",inline"`
155+
Command string `json:"command"`
156+
Args []string `json:"args"`
157+
}
158+
153159
type HostCollect struct {
154160
CPU *CPU `json:"cpu,omitempty" yaml:"cpu,omitempty"`
155161
Memory *Memory `json:"memory,omitempty" yaml:"memory,omitempty"`
@@ -169,6 +175,7 @@ type HostCollect struct {
169175
Certificate *Certificate `json:"certificate,omitempty" yaml:"certificate,omitempty"`
170176
HostServices *HostServices `json:"hostServices,omitempty" yaml:"hostServices,omitempty"`
171177
HostOS *HostOS `json:"hostOS,omitempty" yaml:"hostOS,omitempty"`
178+
HostRun *HostRun `json:"run,omitempty" yaml:"run,omitempty"`
172179
}
173180

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

pkg/collect/host_collector.go

Lines changed: 2 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -51,6 +51,8 @@ func GetHostCollector(collector *troubleshootv1beta2.HostCollect, bundlePath str
5151
return &CollectHostServices{collector.HostServices, bundlePath}, true
5252
case collector.HostOS != nil:
5353
return &CollectHostOS{collector.HostOS, bundlePath}, true
54+
case collector.HostRun != nil:
55+
return &CollectHostRun{collector.HostRun, bundlePath}, true
5456
default:
5557
return nil, false
5658
}

pkg/collect/host_run.go

Lines changed: 79 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,79 @@
1+
package collect
2+
3+
import (
4+
"bytes"
5+
"encoding/json"
6+
"os/exec"
7+
"path/filepath"
8+
"strings"
9+
10+
"github.com/pkg/errors"
11+
troubleshootv1beta2 "github.com/replicatedhq/troubleshoot/pkg/apis/troubleshoot/v1beta2"
12+
)
13+
14+
type HostRunInfo struct {
15+
Command string `json:"command"`
16+
ExitCode string `json:"exitCode"`
17+
Error string `json:"error"`
18+
}
19+
20+
type CollectHostRun struct {
21+
hostCollector *troubleshootv1beta2.HostRun
22+
BundlePath string
23+
}
24+
25+
func (c *CollectHostRun) Title() string {
26+
return hostCollectorTitleOrDefault(c.hostCollector.HostCollectorMeta, "Run Host")
27+
}
28+
29+
func (c *CollectHostRun) IsExcluded() (bool, error) {
30+
return isExcluded(c.hostCollector.Exclude)
31+
}
32+
33+
func (c *CollectHostRun) Collect(progressChan chan<- interface{}) (map[string][]byte, error) {
34+
runHostCollector := c.hostCollector
35+
36+
cmd := exec.Command(runHostCollector.Command, runHostCollector.Args...)
37+
38+
var stdout, stderr bytes.Buffer
39+
cmd.Stdout = &stdout
40+
cmd.Stderr = &stderr
41+
42+
runInfo := HostRunInfo{
43+
Command: cmd.String(),
44+
ExitCode: "0",
45+
}
46+
47+
err := cmd.Run()
48+
if err != nil {
49+
if werr, ok := err.(*exec.ExitError); ok {
50+
runInfo.ExitCode = strings.TrimPrefix(werr.Error(), "exit status ")
51+
runInfo.Error = stderr.String()
52+
} else {
53+
return nil, errors.Wrap(err, "failed to run")
54+
}
55+
}
56+
57+
collectorName := c.hostCollector.CollectorName
58+
if collectorName == "" {
59+
collectorName = "run-host"
60+
}
61+
resultInfo := filepath.Join("host-collectors/run-host", collectorName+"-info.json")
62+
result := filepath.Join("host-collectors/run-host", collectorName+".txt")
63+
64+
b, err := json.Marshal(runInfo)
65+
if err != nil {
66+
return nil, errors.Wrap(err, "failed to marshal run host result")
67+
}
68+
69+
output := NewResult()
70+
output.SaveResult(c.BundlePath, resultInfo, bytes.NewBuffer(b))
71+
output.SaveResult(c.BundlePath, result, bytes.NewBuffer(stdout.Bytes()))
72+
73+
runHostOutput := map[string][]byte{
74+
resultInfo: b,
75+
result: stdout.Bytes(),
76+
}
77+
78+
return runHostOutput, nil
79+
}

pkg/redact/redact.go

Lines changed: 5 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -304,6 +304,11 @@ func getRedactors(path string) ([]Redactor, error) {
304304
line2: `(?i)("value": *")(?P<mask>.*[^\"]*)(")`,
305305
name: "Redact usernames in multiline JSON",
306306
},
307+
{
308+
line1: `(?i)"entity": *"(osd|client|mgr)\..*[^\"]*"`,
309+
line2: `(?i)("key": *")(?P<mask>.{38}==[^\"]*)(")`,
310+
name: "Redact 'key' values found in Ceph auth lists",
311+
},
307312
}
308313

309314
for _, l := range doubleLines {

pkg/redact/redact_test.go

Lines changed: 96 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -816,6 +816,53 @@ func Test_Redactors(t *testing.T) {
816816
"status": {
817817
"loadBalancer": {}
818818
}
819+
},
820+
{
821+
"auth_dump": [
822+
{
823+
"entity": "osd.0",
824+
"key": "ABCxyzABCxyz/foo/bar123xyz/BAZAABBCCDD==",
825+
"caps": {
826+
"mgr": "allow profile osd",
827+
"mon": "allow profile osd",
828+
"osd": "allow *"
829+
}
830+
},
831+
{
832+
"entity": "client.admin",
833+
"key": "ABCxyzABCxyz/foo/bar123xyz/BAZAABBCCDD==",
834+
"caps": {
835+
"mds": "allow *",
836+
"mgr": "allow *",
837+
"mon": "allow *",
838+
"osd": "allow *"
839+
}
840+
},
841+
{
842+
"entity": "client.bootstrap-mds",
843+
"key": "ABCxyzABCxyz/foo/bar123xyz/BAZAABBCCDD==",
844+
"caps": {
845+
"mon": "allow profile bootstrap-mds"
846+
}
847+
},
848+
{
849+
"entity": "client.rgw.rook.ceph.store.a",
850+
"key": "ABCxyzABCxyz/foo/bar123xyz/BAZAABBCCDD==",
851+
"caps": {
852+
"mon": "allow rw",
853+
"osd": "allow rwx"
854+
}
855+
},
856+
{
857+
"entity": "mgr.a",
858+
"key": "ABCxyzABCxyz/foo/bar123xyz/BAZAABBCCDD==",
859+
"caps": {
860+
"mds": "allow *",
861+
"mon": "allow profile mgr",
862+
"osd": "allow *"
863+
}
864+
}
865+
]
819866
}
820867
]`
821868

@@ -1624,11 +1671,58 @@ func Test_Redactors(t *testing.T) {
16241671
"status": {
16251672
"loadBalancer": {}
16261673
}
1674+
},
1675+
{
1676+
"auth_dump": [
1677+
{
1678+
"entity": "osd.0",
1679+
"key": "***HIDDEN***",
1680+
"caps": {
1681+
"mgr": "allow profile osd",
1682+
"mon": "allow profile osd",
1683+
"osd": "allow *"
1684+
}
1685+
},
1686+
{
1687+
"entity": "client.admin",
1688+
"key": "***HIDDEN***",
1689+
"caps": {
1690+
"mds": "allow *",
1691+
"mgr": "allow *",
1692+
"mon": "allow *",
1693+
"osd": "allow *"
1694+
}
1695+
},
1696+
{
1697+
"entity": "client.bootstrap-mds",
1698+
"key": "***HIDDEN***",
1699+
"caps": {
1700+
"mon": "allow profile bootstrap-mds"
1701+
}
1702+
},
1703+
{
1704+
"entity": "client.rgw.rook.ceph.store.a",
1705+
"key": "***HIDDEN***",
1706+
"caps": {
1707+
"mon": "allow rw",
1708+
"osd": "allow rwx"
1709+
}
1710+
},
1711+
{
1712+
"entity": "mgr.a",
1713+
"key": "***HIDDEN***",
1714+
"caps": {
1715+
"mds": "allow *",
1716+
"mon": "allow profile mgr",
1717+
"osd": "allow *"
1718+
}
1719+
}
1720+
]
16271721
}
16281722
]`
16291723

1630-
wantRedactionsLen := 39
1631-
wantRedactionsCount := 25
1724+
wantRedactionsLen := 44
1725+
wantRedactionsCount := 26
16321726

16331727
t.Run("test default redactors", func(t *testing.T) {
16341728
req := require.New(t)

0 commit comments

Comments
 (0)