Skip to content

Commit

Permalink
NET-4519 Collecting journald logs in "consul debug" bundle (#18797) (#…
Browse files Browse the repository at this point in the history
…18885)

NET-4519 Collecting journald logs in "consul debug" bundle (#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>
  • Loading branch information
absolutelightning and Ganeshrockz authored Sep 19, 2023
1 parent e5a247a commit 8f299ac
Show file tree
Hide file tree
Showing 6 changed files with 147 additions and 32 deletions.
3 changes: 3 additions & 0 deletions .changelog/18797.txt
Original file line number Diff line number Diff line change
@@ -0,0 +1,3 @@
```release-note:improvement
command: Adds -since flag in consul debug command which internally calls hcdiag for debug information in the past.
```
20 changes: 19 additions & 1 deletion command/debug/debug.go
Original file line number Diff line number Diff line change
Expand Up @@ -23,6 +23,8 @@ import (

"github.com/hashicorp/consul/api"
"github.com/hashicorp/consul/command/flags"

"github.com/hashicorp/hcdiag/command"
)

const (
Expand Down Expand Up @@ -78,6 +80,7 @@ type cmd struct {
interval time.Duration
duration time.Duration
output string
since string
archive bool
capture []string
client *api.Client
Expand Down Expand Up @@ -132,6 +135,8 @@ func (c *cmd) init() {
c.flags.StringVar(&c.output, "output", defaultFilename, "The path "+
"to the compressed archive that will be created with the "+
"information after collection.")
c.flags.StringVar(&c.since, "since", "", "Flag used for hcdiag command, time within"+
"which information is collected")

c.http = &flags.HTTPFlags{}
flags.Merge(c.flags, c.http.ClientFlags())
Expand Down Expand Up @@ -178,9 +183,17 @@ func (c *cmd) Run(args []string) int {
}

c.UI.Output("Starting debugger and capturing static information...")
c.UI.Info(fmt.Sprintf(" Agent Version: '%s'", version))

if c.since != "" {
runCommand := command.NewRunCommand(&cli.BasicUi{
Writer: os.Stdout, ErrorWriter: os.Stderr,
})
runCommand.Run([]string{"-consul", fmt.Sprintf("-since=%s", c.since)})
return 0
}

// Output metadata about target agent
c.UI.Info(fmt.Sprintf(" Agent Version: '%s'", version))
c.UI.Info(fmt.Sprintf(" Interval: '%s'", c.interval))
c.UI.Info(fmt.Sprintf(" Duration: '%s'", c.duration))
c.UI.Info(fmt.Sprintf(" Output: '%s'", archiveName))
Expand Down Expand Up @@ -769,6 +782,11 @@ Usage: consul debug [options]
strongly recommend review of the data within the archive prior to
transmitting it.
To get information from past, -since flag can be used. It internally uses
hcdiag -consul -since
$ consul debug -since 1h
For a full list of options and examples, please see the Consul
documentation.
`
27 changes: 27 additions & 0 deletions command/debug/debug_test.go
Original file line number Diff line number Diff line change
Expand Up @@ -92,6 +92,33 @@ func TestDebugCommand(t *testing.T) {
require.Equal(t, "", ui.ErrorWriter.String(), "expected no error output")
}

func TestDebugCommand_WithSinceFlag(t *testing.T) {
if testing.Short() {
t.Skip("too slow for testing.Short")
}

a := agent.NewTestAgent(t, `
enable_debug = true
`)

defer a.Shutdown()
testrpc.WaitForLeader(t, a.RPC, "dc1")

ui := cli.NewMockUi()
cmd := New(ui)
cmd.validateTiming = false

args := []string{
"-since=1m",
}

t.Setenv("CONSUL_HTTP_ADDR", a.HTTPAddr())

code := cmd.Run(args)
require.Equal(t, 0, code)
require.Equal(t, "", ui.ErrorWriter.String())
}

func validLogFile(raw []byte) fs.CompareResult {
scanner := bufio.NewScanner(bytes.NewReader(raw))
for scanner.Scan() {
Expand Down
36 changes: 25 additions & 11 deletions go.mod
Original file line number Diff line number Diff line change
Expand Up @@ -58,6 +58,7 @@ require (
github.com/hashicorp/go-uuid v1.0.2
github.com/hashicorp/go-version v1.2.1
github.com/hashicorp/golang-lru v0.5.4
github.com/hashicorp/hcdiag v0.5.1
github.com/hashicorp/hcl v1.0.0
github.com/hashicorp/hcp-scada-provider v0.2.3
github.com/hashicorp/hcp-sdk-go v0.61.0
Expand All @@ -75,7 +76,7 @@ require (
github.com/imdario/mergo v0.3.13
github.com/kr/text v0.2.0
github.com/miekg/dns v1.1.50
github.com/mitchellh/cli v1.1.0
github.com/mitchellh/cli v1.1.4
github.com/mitchellh/copystructure v1.2.0
github.com/mitchellh/go-testing-interface v1.14.0
github.com/mitchellh/hashstructure v0.0.0-20170609045927-2bca23e0e452
Expand All @@ -89,9 +90,9 @@ require (
github.com/prometheus/client_golang v1.14.0
github.com/rboyer/safeio v0.2.3
github.com/ryanuber/columnize v2.1.2+incompatible
github.com/shirou/gopsutil/v3 v3.22.8
github.com/shirou/gopsutil/v3 v3.22.9
github.com/stretchr/testify v1.8.3
go.etcd.io/bbolt v1.3.6
go.etcd.io/bbolt v1.3.7
go.opentelemetry.io/otel v1.16.0
go.opentelemetry.io/otel/metric v1.16.0
go.opentelemetry.io/otel/sdk v1.16.0
Expand Down Expand Up @@ -131,7 +132,12 @@ require (
github.com/Azure/go-autorest/logger v0.2.1 // indirect
github.com/Azure/go-autorest/tracing v0.6.0 // indirect
github.com/DataDog/datadog-go v4.8.2+incompatible // indirect
github.com/Microsoft/go-winio v0.5.1 // indirect
github.com/Masterminds/goutils v1.1.1 // indirect
github.com/Masterminds/semver/v3 v3.1.1 // indirect
github.com/Masterminds/sprig/v3 v3.2.2 // indirect
github.com/Microsoft/go-winio v0.6.1 // indirect
github.com/agext/levenshtein v1.2.3 // indirect
github.com/apparentlymart/go-textseg/v13 v13.0.0 // indirect
github.com/asaskevich/govalidator v0.0.0-20210307081110-f21760c49a8d // indirect
github.com/benbjohnson/immutable v0.4.0 // indirect
github.com/beorn7/perks v1.0.1 // indirect
Expand All @@ -146,6 +152,7 @@ require (
github.com/coreos/etcd v3.3.27+incompatible // indirect
github.com/coreos/go-systemd v0.0.0-20191104093116-d3cd4ed1dbcf // indirect
github.com/coreos/pkg v0.0.0-20220810130054-c7d1c02cb6cf // indirect
github.com/cosiner/argv v0.1.0 // indirect
github.com/davecgh/go-spew v1.1.2-0.20180830191138-d8f796af33cc // indirect
github.com/denverdino/aliyungo v0.0.0-20170926055100-d3308649c661 // indirect
github.com/digitalocean/godo v1.10.0 // indirect
Expand Down Expand Up @@ -185,22 +192,26 @@ require (
github.com/hashicorp/go-secure-stdlib/mlock v0.1.1 // indirect
github.com/hashicorp/go-secure-stdlib/parseutil v0.1.6 // indirect
github.com/hashicorp/go-secure-stdlib/strutil v0.1.2 // indirect
github.com/hashicorp/hcl/v2 v2.14.1 // indirect
github.com/hashicorp/mdns v1.0.4 // indirect
github.com/hashicorp/net-rpc-msgpackrpc/v2 v2.0.0 // indirect
github.com/hashicorp/vic v1.5.1-0.20190403131502-bbfe86ec9443 // indirect
github.com/huandu/xstrings v1.3.2 // indirect
github.com/jmespath/go-jmespath v0.4.0 // indirect
github.com/josharian/intern v1.0.0 // indirect
github.com/joyent/triton-go v1.7.1-0.20200416154420-6801d15b779f // indirect
github.com/json-iterator/go v1.1.12 // indirect
github.com/linode/linodego v0.10.0 // indirect
github.com/lufia/plan9stats v0.0.0-20211012122336-39d0f177ccd0 // indirect
github.com/lufia/plan9stats v0.0.0-20220913051719-115f729f3c8c // indirect
github.com/mailru/easyjson v0.7.7 // indirect
github.com/mattn/go-colorable v0.1.12 // indirect
github.com/mattn/go-isatty v0.0.14 // indirect
github.com/mattn/go-colorable v0.1.13 // indirect
github.com/mattn/go-isatty v0.0.16 // indirect
github.com/mattn/go-runewidth v0.0.7 // indirect
github.com/matttproud/golang_protobuf_extensions v1.0.4 // indirect
github.com/mitchellh/colorstring v0.0.0-20190213212951-d06e56a500db // indirect
github.com/mitchellh/go-homedir v1.1.0 // indirect
github.com/mitchellh/go-ps v1.0.0 // indirect
github.com/mitchellh/go-wordwrap v1.0.1 // indirect
github.com/modern-go/concurrent v0.0.0-20180306012644-bacd9c7ef1dd // indirect
github.com/modern-go/reflect2 v1.0.2 // indirect
github.com/munnerz/goautoneg v0.0.0-20191010083416-a7dc8b61c822 // indirect
Expand All @@ -209,10 +220,10 @@ require (
github.com/oklog/ulid v1.3.1 // indirect
github.com/opentracing/opentracing-go v1.2.0 // indirect
github.com/packethost/packngo v0.1.1-0.20180711074735-b9cb5096f54c // indirect
github.com/pierrec/lz4 v2.5.2+incompatible // indirect
github.com/pierrec/lz4 v2.6.1+incompatible // indirect
github.com/pmezard/go-difflib v1.0.1-0.20181226105442-5d4384ee4fb2 // indirect
github.com/posener/complete v1.2.3 // indirect
github.com/power-devops/perfstat v0.0.0-20210106213030-5aafc221ea8c // indirect
github.com/power-devops/perfstat v0.0.0-20220216144756-c35f1ee13d7c // indirect
github.com/pquerna/cachecontrol v0.0.0-20180517163645-1555304b9b35 // indirect
github.com/prometheus/client_model v0.3.0 // indirect
github.com/prometheus/common v0.39.0 // indirect
Expand All @@ -221,18 +232,21 @@ require (
github.com/ryanuber/go-glob v1.0.0 // indirect
github.com/sean-/seed v0.0.0-20170313163322-e2103e2c3529 // indirect
github.com/segmentio/fasthash v1.0.3 // indirect
github.com/sirupsen/logrus v1.7.0 // indirect
github.com/shopspring/decimal v1.3.1 // indirect
github.com/sirupsen/logrus v1.9.0 // indirect
github.com/skratchdot/open-golang v0.0.0-20200116055534-eef842397966 // indirect
github.com/softlayer/softlayer-go v0.0.0-20180806151055-260589d94c7d // indirect
github.com/spf13/cast v1.5.0 // indirect
github.com/spf13/pflag v1.0.5 // indirect
github.com/stretchr/objx v0.5.0 // indirect
github.com/tencentcloud/tencentcloud-sdk-go v1.0.162 // indirect
github.com/tklauser/go-sysconf v0.3.10 // indirect
github.com/tklauser/numcpus v0.4.0 // indirect
github.com/tklauser/numcpus v0.5.0 // indirect
github.com/tv42/httpunix v0.0.0-20150427012821-b75d8614f926 // indirect
github.com/vmware/govmomi v0.18.0 // indirect
github.com/xeipuuv/gojsonpointer v0.0.0-20190905194746-02993c407bfb // indirect
github.com/yusufpapurcu/wmi v1.2.2 // indirect
github.com/zclconf/go-cty v1.11.1 // indirect
go.mongodb.org/mongo-driver v1.11.0 // indirect
go.opencensus.io v0.24.0 // indirect
go.opentelemetry.io/otel/trace v1.16.0 // indirect
Expand Down
Loading

0 comments on commit 8f299ac

Please sign in to comment.