Skip to content

Commit 6fd33ba

Browse files
NET-4519 Collecting journald logs in "consul debug" bundle (hashicorp#18797)
* debug since * fix docs * chagelog added * fix go mod * debug test fix * fix test * tabs test fix * Update .changelog/18797.txt Co-authored-by: Ganesh S <ganesh.seetharaman@hashicorp.com> --------- Co-authored-by: Ganesh S <ganesh.seetharaman@hashicorp.com>
1 parent 212793a commit 6fd33ba

File tree

10 files changed

+141
-54
lines changed

10 files changed

+141
-54
lines changed

.changelog/18797.txt

Lines changed: 3 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,3 @@
1+
```release-note:improvement
2+
command: Adds -since flag in consul debug command which internally calls hcdiag for debug information in the past.
3+
```

command/debug/debug.go

Lines changed: 19 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -26,6 +26,8 @@ import (
2626

2727
"github.com/hashicorp/consul/api"
2828
"github.com/hashicorp/consul/command/flags"
29+
30+
"github.com/hashicorp/hcdiag/command"
2931
)
3032

3133
const (
@@ -81,6 +83,7 @@ type cmd struct {
8183
interval time.Duration
8284
duration time.Duration
8385
output string
86+
since string
8487
archive bool
8588
capture []string
8689
client *api.Client
@@ -135,6 +138,8 @@ func (c *cmd) init() {
135138
c.flags.StringVar(&c.output, "output", defaultFilename, "The path "+
136139
"to the compressed archive that will be created with the "+
137140
"information after collection.")
141+
c.flags.StringVar(&c.since, "since", "", "Flag used for hcdiag command, time within"+
142+
"which information is collected")
138143

139144
c.http = &flags.HTTPFlags{}
140145
flags.Merge(c.flags, c.http.ClientFlags())
@@ -181,9 +186,17 @@ func (c *cmd) Run(args []string) int {
181186
}
182187

183188
c.UI.Output("Starting debugger and capturing static information...")
189+
c.UI.Info(fmt.Sprintf(" Agent Version: '%s'", version))
190+
191+
if c.since != "" {
192+
runCommand := command.NewRunCommand(&cli.BasicUi{
193+
Writer: os.Stdout, ErrorWriter: os.Stderr,
194+
})
195+
runCommand.Run([]string{"-consul", fmt.Sprintf("-since=%s", c.since)})
196+
return 0
197+
}
184198

185199
// Output metadata about target agent
186-
c.UI.Info(fmt.Sprintf(" Agent Version: '%s'", version))
187200
c.UI.Info(fmt.Sprintf(" Interval: '%s'", c.interval))
188201
c.UI.Info(fmt.Sprintf(" Duration: '%s'", c.duration))
189202
c.UI.Info(fmt.Sprintf(" Output: '%s'", archiveName))
@@ -772,6 +785,11 @@ Usage: consul debug [options]
772785
strongly recommend review of the data within the archive prior to
773786
transmitting it.
774787
788+
To get information from past, -since flag can be used. It internally uses
789+
hcdiag -consul -since
790+
791+
$ consul debug -since 1h
792+
775793
For a full list of options and examples, please see the Consul
776794
documentation.
777795
`

command/debug/debug_test.go

Lines changed: 27 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -95,6 +95,33 @@ func TestDebugCommand(t *testing.T) {
9595
require.Equal(t, "", ui.ErrorWriter.String(), "expected no error output")
9696
}
9797

98+
func TestDebugCommand_WithSinceFlag(t *testing.T) {
99+
if testing.Short() {
100+
t.Skip("too slow for testing.Short")
101+
}
102+
103+
a := agent.NewTestAgent(t, `
104+
enable_debug = true
105+
`)
106+
107+
defer a.Shutdown()
108+
testrpc.WaitForLeader(t, a.RPC, "dc1")
109+
110+
ui := cli.NewMockUi()
111+
cmd := New(ui)
112+
cmd.validateTiming = false
113+
114+
args := []string{
115+
"-since=1m",
116+
}
117+
118+
t.Setenv("CONSUL_HTTP_ADDR", a.HTTPAddr())
119+
120+
code := cmd.Run(args)
121+
require.Equal(t, 0, code)
122+
require.Equal(t, "", ui.ErrorWriter.String())
123+
}
124+
98125
func validLogFile(raw []byte) fs.CompareResult {
99126
scanner := bufio.NewScanner(bytes.NewReader(raw))
100127
for scanner.Scan() {

go.mod

Lines changed: 20 additions & 12 deletions
Original file line numberDiff line numberDiff line change
@@ -60,8 +60,9 @@ require (
6060
github.com/hashicorp/go-uuid v1.0.3
6161
github.com/hashicorp/go-version v1.2.1
6262
github.com/hashicorp/golang-lru v0.5.4
63+
github.com/hashicorp/hcdiag v0.5.1
6364
github.com/hashicorp/hcl v1.0.0
64-
github.com/hashicorp/hcl/v2 v2.6.0
65+
github.com/hashicorp/hcl/v2 v2.14.1
6566
github.com/hashicorp/hcp-scada-provider v0.2.3
6667
github.com/hashicorp/hcp-sdk-go v0.61.0
6768
github.com/hashicorp/hil v0.0.0-20200423225030-a18a1cd20038
@@ -79,7 +80,7 @@ require (
7980
github.com/imdario/mergo v0.3.15
8081
github.com/kr/text v0.2.0
8182
github.com/miekg/dns v1.1.50
82-
github.com/mitchellh/cli v1.1.0
83+
github.com/mitchellh/cli v1.1.4
8384
github.com/mitchellh/copystructure v1.2.0
8485
github.com/mitchellh/go-testing-interface v1.14.0
8586
github.com/mitchellh/hashstructure v0.0.0-20170609045927-2bca23e0e452
@@ -96,10 +97,10 @@ require (
9697
github.com/prometheus/client_golang v1.14.0
9798
github.com/rboyer/safeio v0.2.3
9899
github.com/ryanuber/columnize v2.1.2+incompatible
99-
github.com/shirou/gopsutil/v3 v3.22.8
100+
github.com/shirou/gopsutil/v3 v3.22.9
100101
github.com/stretchr/testify v1.8.3
101102
github.com/xeipuuv/gojsonschema v1.2.0
102-
github.com/zclconf/go-cty v1.2.0
103+
github.com/zclconf/go-cty v1.11.1
103104
go.etcd.io/bbolt v1.3.7
104105
go.opentelemetry.io/otel v1.16.0
105106
go.opentelemetry.io/otel/metric v1.16.0
@@ -141,10 +142,12 @@ require (
141142
github.com/Azure/go-autorest/logger v0.2.1 // indirect
142143
github.com/Azure/go-autorest/tracing v0.6.0 // indirect
143144
github.com/DataDog/datadog-go v4.8.2+incompatible // indirect
145+
github.com/Masterminds/goutils v1.1.1 // indirect
146+
github.com/Masterminds/semver/v3 v3.1.1 // indirect
147+
github.com/Masterminds/sprig/v3 v3.2.2 // indirect
144148
github.com/Microsoft/go-winio v0.6.1 // indirect
145-
github.com/agext/levenshtein v1.2.1 // indirect
146-
github.com/apparentlymart/go-textseg v1.0.0 // indirect
147-
github.com/apparentlymart/go-textseg/v12 v12.0.0 // indirect
149+
github.com/agext/levenshtein v1.2.3 // indirect
150+
github.com/apparentlymart/go-textseg/v13 v13.0.0 // indirect
148151
github.com/asaskevich/govalidator v0.0.0-20210307081110-f21760c49a8d // indirect
149152
github.com/benbjohnson/immutable v0.4.0 // indirect
150153
github.com/beorn7/perks v1.0.1 // indirect
@@ -159,6 +162,7 @@ require (
159162
github.com/coreos/etcd v3.3.27+incompatible // indirect
160163
github.com/coreos/go-systemd v0.0.0-20191104093116-d3cd4ed1dbcf // indirect
161164
github.com/coreos/pkg v0.0.0-20220810130054-c7d1c02cb6cf // indirect
165+
github.com/cosiner/argv v0.1.0 // indirect
162166
github.com/davecgh/go-spew v1.1.2-0.20180830191138-d8f796af33cc // indirect
163167
github.com/denverdino/aliyungo v0.0.0-20170926055100-d3308649c661 // indirect
164168
github.com/digitalocean/godo v1.10.0 // indirect
@@ -201,31 +205,33 @@ require (
201205
github.com/hashicorp/mdns v1.0.4 // indirect
202206
github.com/hashicorp/net-rpc-msgpackrpc/v2 v2.0.0 // indirect
203207
github.com/hashicorp/vic v1.5.1-0.20190403131502-bbfe86ec9443 // indirect
208+
github.com/huandu/xstrings v1.3.2 // indirect
204209
github.com/jmespath/go-jmespath v0.4.0 // indirect
205210
github.com/josharian/intern v1.0.0 // indirect
206211
github.com/joyent/triton-go v1.7.1-0.20200416154420-6801d15b779f // indirect
207212
github.com/json-iterator/go v1.1.12 // indirect
208213
github.com/linode/linodego v0.10.0 // indirect
209-
github.com/lufia/plan9stats v0.0.0-20211012122336-39d0f177ccd0 // indirect
214+
github.com/lufia/plan9stats v0.0.0-20220913051719-115f729f3c8c // indirect
210215
github.com/mailru/easyjson v0.7.7 // indirect
211216
github.com/mattn/go-colorable v0.1.13 // indirect
212217
github.com/mattn/go-isatty v0.0.17 // indirect
213218
github.com/mattn/go-runewidth v0.0.13 // indirect
214219
github.com/matttproud/golang_protobuf_extensions v1.0.4 // indirect
215220
github.com/mitchellh/colorstring v0.0.0-20190213212951-d06e56a500db // indirect
216221
github.com/mitchellh/go-homedir v1.1.0 // indirect
217-
github.com/mitchellh/go-wordwrap v1.0.0 // indirect
222+
github.com/mitchellh/go-ps v1.0.0 // indirect
223+
github.com/mitchellh/go-wordwrap v1.0.1 // indirect
218224
github.com/modern-go/concurrent v0.0.0-20180306012644-bacd9c7ef1dd // indirect
219225
github.com/modern-go/reflect2 v1.0.2 // indirect
220226
github.com/munnerz/goautoneg v0.0.0-20191010083416-a7dc8b61c822 // indirect
221227
github.com/nicolai86/scaleway-sdk v1.10.2-0.20180628010248-798f60e20bb2 // indirect
222228
github.com/oklog/run v1.0.0 // indirect
223229
github.com/opentracing/opentracing-go v1.2.1-0.20220228012449-10b1cf09e00b // indirect
224230
github.com/packethost/packngo v0.1.1-0.20180711074735-b9cb5096f54c // indirect
225-
github.com/pierrec/lz4 v2.5.2+incompatible // indirect
231+
github.com/pierrec/lz4 v2.6.1+incompatible // indirect
226232
github.com/pmezard/go-difflib v1.0.1-0.20181226105442-5d4384ee4fb2 // indirect
227233
github.com/posener/complete v1.2.3 // indirect
228-
github.com/power-devops/perfstat v0.0.0-20210106213030-5aafc221ea8c // indirect
234+
github.com/power-devops/perfstat v0.0.0-20220216144756-c35f1ee13d7c // indirect
229235
github.com/pquerna/cachecontrol v0.0.0-20180517163645-1555304b9b35 // indirect
230236
github.com/prometheus/client_model v0.3.0 // indirect
231237
github.com/prometheus/common v0.39.0 // indirect
@@ -235,14 +241,16 @@ require (
235241
github.com/ryanuber/go-glob v1.0.0 // indirect
236242
github.com/sean-/seed v0.0.0-20170313163322-e2103e2c3529 // indirect
237243
github.com/segmentio/fasthash v1.0.3 // indirect
244+
github.com/shopspring/decimal v1.3.1 // indirect
238245
github.com/sirupsen/logrus v1.9.0 // indirect
239246
github.com/skratchdot/open-golang v0.0.0-20200116055534-eef842397966 // indirect
240247
github.com/softlayer/softlayer-go v0.0.0-20180806151055-260589d94c7d // indirect
248+
github.com/spf13/cast v1.5.0 // indirect
241249
github.com/spf13/pflag v1.0.5 // indirect
242250
github.com/stretchr/objx v0.5.0 // indirect
243251
github.com/tencentcloud/tencentcloud-sdk-go v1.0.162 // indirect
244252
github.com/tklauser/go-sysconf v0.3.10 // indirect
245-
github.com/tklauser/numcpus v0.4.0 // indirect
253+
github.com/tklauser/numcpus v0.5.0 // indirect
246254
github.com/tv42/httpunix v0.0.0-20150427012821-b75d8614f926 // indirect
247255
github.com/vmware/govmomi v0.18.0 // indirect
248256
github.com/xeipuuv/gojsonpointer v0.0.0-20190905194746-02993c407bfb // indirect

0 commit comments

Comments
 (0)