Skip to content

Commit

Permalink
Debug flag now shows useful debugging, added dry-run
Browse files Browse the repository at this point in the history
HTTP debugging is now done with `--debug` and HTTP_TRACE=1
  • Loading branch information
lox committed Dec 17, 2016
1 parent 5e7c730 commit 64a4551
Showing 1 changed file with 24 additions and 13 deletions.
37 changes: 24 additions & 13 deletions main.go
Original file line number Diff line number Diff line change
Expand Up @@ -28,8 +28,9 @@ func main() {
orgSlug = flag.String("org", "", "A Buildkite Organization Slug")
interval = flag.Duration("interval", 0, "Update metrics every interval, rather than once")
history = flag.Duration("history", time.Hour*24, "Historical data to use for finished builds")
debug = flag.Bool("debug", false, "Show API debugging output")
debug = flag.Bool("debug", false, "Show debug output")
version = flag.Bool("version", false, "Show the version")
dryRun = flag.Bool("dry-run", false, "Whether to only print metrics")

// filters
queue = flag.String("queue", "", "Only include a specific queue")
Expand All @@ -56,7 +57,9 @@ func main() {
}

client := buildkite.NewClient(config.Client())
buildkite.SetHttpDebug(*debug)
if *debug && os.Getenv("TRACE_HTTP") != "" {
buildkite.SetHttpDebug(*debug)
}

f := func() error {
t := time.Now()
Expand All @@ -65,16 +68,19 @@ func main() {
OrgSlug: *orgSlug,
Historical: *history,
Queue: *queue,
Debug: *debug,
})
if err != nil {
return err
}

dumpResults(res)

err = cloudwatchSend(res)
if err != nil {
return err
if !*dryRun {
err = cloudwatchSend(res)
if err != nil {
return err
}
}

log.Printf("Finished in %s", time.Now().Sub(t))
Expand All @@ -98,6 +104,7 @@ type collectOpts struct {
OrgSlug string
Historical time.Duration
Queue string
Debug bool
}

func collectResults(client *buildkite.Client, opts collectOpts) (*result, error) {
Expand Down Expand Up @@ -240,8 +247,10 @@ func (r *result) addBuildAndJobMetrics(client *buildkite.Client, opts collectOpt

return currentBuilds.Pages(func(v interface{}) bool {
for _, build := range v.([]buildkite.Build) {
// log.Printf("Adding build to stats (id=%q, pipeline=%q, branch=%q, state=%q)",
// *build.ID, *build.Pipeline.Name, *build.Branch, *build.State)
if opts.Debug {
log.Printf("Adding build to stats (id=%q, pipeline=%q, branch=%q, state=%q)",
*build.ID, *build.Pipeline.Name, *build.Branch, *build.State)
}

if _, ok := r.pipelines[*build.Pipeline.Name]; !ok {
r.pipelines[*build.Pipeline.Name] = newCounts()
Expand Down Expand Up @@ -269,8 +278,10 @@ func (r *result) addBuildAndJobMetrics(client *buildkite.Client, opts collectOpt
state = *job.State
}

// log.Printf("Adding job to stats (id=%q, pipeline=%q, queue=%q, type=%q, state=%q)",
// *job.ID, *build.Pipeline.Name, queue(job), *job.Type, state)
if opts.Debug {
log.Printf("Adding job to stats (id=%q, pipeline=%q, queue=%q, type=%q, state=%q)",
*job.ID, *build.Pipeline.Name, queue(job), *job.Type, state)
}

if _, ok := r.queues[queue(job)]; !ok {
r.queues[queue(job)] = newCounts()
Expand Down Expand Up @@ -322,7 +333,6 @@ func (r *result) addAgentMetrics(client *buildkite.Client, opts collectOpts) err
if err != nil {
return nil, 0, err
}
log.Printf("Agents page %d has %d agents, next page is %d", page, len(agents), resp.NextPage)
return agents, resp.NextPage, err
},
}
Expand Down Expand Up @@ -356,8 +366,10 @@ func (r *result) addAgentMetrics(client *buildkite.Client, opts collectOpts) err
r.queues[queue][totalAgentCount] = 0
}

// log.Printf("Adding agent to stats (name=%q, queue=%q, job=%#v)",
// *agent.Name, queue, agent.Job != nil)
if opts.Debug {
log.Printf("Adding agent to stats (name=%q, queue=%q, job=%#v)",
*agent.Name, queue, agent.Job != nil)
}

if agent.Job != nil {
r.totals[busyAgentCount]++
Expand Down Expand Up @@ -409,7 +421,6 @@ func listBuildsByOrg(builds *buildkite.BuildsService, orgSlug string, opts build
if err != nil {
return nil, 0, err
}
log.Printf("Builds page %d has %d builds, next page is %d", page, len(builds), resp.NextPage)
return builds, resp.NextPage, err
},
}
Expand Down

0 comments on commit 64a4551

Please sign in to comment.