Skip to content

Commit

Permalink
agent: fix golangcibot warnings in dgraph agent cmd
Browse files Browse the repository at this point in the history
Signed-off-by: fristonio <deepshpathak@gmail.com>
  • Loading branch information
fristonio committed Dec 23, 2019
1 parent 6093f3c commit f4868a0
Show file tree
Hide file tree
Showing 3 changed files with 31 additions and 21 deletions.
13 changes: 11 additions & 2 deletions dgraph/cmd/agent/debuginfo/pprof.go
Original file line number Diff line number Diff line change
Expand Up @@ -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
Expand Down Expand Up @@ -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)
Expand Down
13 changes: 9 additions & 4 deletions dgraph/cmd/agent/debuginfo/run.go
Original file line number Diff line number Diff line change
Expand Up @@ -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) {
Expand All @@ -77,7 +82,7 @@ func collectDebugInfo() (err error) {

collectPProfProfiles()

if debugInfoCmd.archive == true {
if debugInfoCmd.archive {
return archiveDebugInfo()
}
return nil
Expand Down
26 changes: 11 additions & 15 deletions dgraph/cmd/agent/run.go
Original file line number Diff line number Diff line change
Expand Up @@ -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()
Expand Down

0 comments on commit f4868a0

Please sign in to comment.