diff --git a/dgraph/cmd/agent/debuginfo/pprof.go b/dgraph/cmd/agent/debuginfo/pprof.go index a9e239bbb7b..ed401dabdf6 100644 --- a/dgraph/cmd/agent/debuginfo/pprof.go +++ b/dgraph/cmd/agent/debuginfo/pprof.go @@ -41,7 +41,15 @@ type pprofCollector struct { tr http.RoundTripper } -var profileTypes = []string{"goroutine", "heap", "threadcreate", "block", "mutex", "profile", "trace"} +var profileTypes = []string{ + "goroutine", + "heap", + "threadcreate", + "block", + "mutex", + "profile", + "trace", +} func newPprofCollector(host, baseDir, filePrefix string, duration time.Duration) *pprofCollector { timeout := duration + duration/2 @@ -128,7 +136,8 @@ func fetchURL(source string, timeout time.Duration, tr http.RoundTripper) (io.Re } func statusCodeError(resp *http.Response) error { - if resp.Header.Get("X-Go-Pprof") != "" && strings.Contains(resp.Header.Get("Content-Type"), "text/plain") { + if resp.Header.Get("X-Go-Pprof") != "" && + strings.Contains(resp.Header.Get("Content-Type"), "text/plain") { // error is from pprof endpoint if body, err := ioutil.ReadAll(resp.Body); err == nil { return fmt.Errorf("server response: %s - %s", resp.Status, body) diff --git a/dgraph/cmd/agent/debuginfo/run.go b/dgraph/cmd/agent/debuginfo/run.go index 9f62a8dda25..18188446c41 100644 --- a/dgraph/cmd/agent/debuginfo/run.go +++ b/dgraph/cmd/agent/debuginfo/run.go @@ -57,9 +57,14 @@ func init() { flags := DebugInfo.Cmd.Flags() flags.StringVarP(&debugInfoCmd.alphaAddr, "alpha", "a", "", "Address of running dgraph alpha.") flags.StringVarP(&debugInfoCmd.zeroAddr, "zero", "z", "", "Address of running dgraph zero.") - flags.StringVarP(&debugInfoCmd.directory, "directory", "d", "", "Directory to generate the debuginfo in, if the directory is not present agent will try to create the directory.") - flags.BoolVarP(&debugInfoCmd.archive, "archive", "x", true, "whether or not to archive the agent info, this could come handy when we need to export the dump.") - flags.Uint32VarP(&debugInfoCmd.infoDurationSecs, "duration", "s", 15, "Duration to collect the debuginfo for, this is used for info like pprof profiles etc.") + flags.StringVarP(&debugInfoCmd.directory, "directory", "d", "", + "Directory to generate the debuginfo in, if the directory is not present agent will "+ + "try to create the directory.") + flags.BoolVarP(&debugInfoCmd.archive, "archive", "x", true, + "whether or not to archive the agent info, this could come handy when we need to export "+ + "the dump.") + flags.Uint32VarP(&debugInfoCmd.infoDurationSecs, "duration", "s", 15, + "Duration to collect the debuginfo for, this is used for info like pprof profiles etc.") } func collectDebugInfo() (err error) { @@ -77,7 +82,7 @@ func collectDebugInfo() (err error) { collectPProfProfiles() - if debugInfoCmd.archive == true { + if debugInfoCmd.archive { return archiveDebugInfo() } return nil diff --git a/dgraph/cmd/agent/run.go b/dgraph/cmd/agent/run.go index 6b42c3d76f4..2133f3c8f47 100644 --- a/dgraph/cmd/agent/run.go +++ b/dgraph/cmd/agent/run.go @@ -17,36 +17,32 @@ package agent import ( + "os" "strings" - "github.com/dgraph-io/dgraph/x" - "github.com/dgraph-io/dgraph/dgraph/cmd/agent/debuginfo" + "github.com/dgraph-io/dgraph/dgraph/cmd/agent/debuginfo" + "github.com/dgraph-io/dgraph/x" "github.com/spf13/cobra" "github.com/spf13/viper" ) -type agentCmdOpts struct { - alphaAddr string - zeroAddr string - compress bool -} - -var ( - Agent x.SubCommand - agentCmd = agentCmdOpts{} -) +// Agent is the subcommand for dgraph agent. +var Agent x.SubCommand func init() { Agent.Cmd = &cobra.Command{ Use: "agent", Short: "Run the Dgraph agent tool", Run: func(cmd *cobra.Command, args []string) { - cmd.Help() + err := cmd.Help() + if err != nil { + os.Exit(1) + } }, } - Agent.EnvPrefix = "DGRAPH_AGENT" - sc := debuginfo.DebugInfo + Agent.EnvPrefix = "DGRAPH_AGENT" + sc := debuginfo.DebugInfo Agent.Cmd.AddCommand(sc.Cmd) sc.Conf = viper.New()