Skip to content

Commit

Permalink
trigger(buildkite): expose running and total jobs count (#28)
Browse files Browse the repository at this point in the history
* Update aws_ec2_asg.go

* Revert "Update aws_ec2_asg.go", get running jobs

This reverts commit 827d70a.

* fetch waiting, total job counts; update example

* add it to queue config
  • Loading branch information
ananya-2410 authored Jul 3, 2023
1 parent b552d53 commit 59b47fd
Show file tree
Hide file tree
Showing 2 changed files with 12 additions and 2 deletions.
2 changes: 1 addition & 1 deletion examples/cron-buildkite-aws-ec2-asg.toml
Original file line number Diff line number Diff line change
Expand Up @@ -58,7 +58,7 @@ method = "go_template"
template = """
{
"asg_name": "{{ .queue }}",
"desired_count": {{ .scheduled_jobs_count }},
"desired_count": {{ .scheduled_jobs_count + .running_jobs_count }},
"tags": [
{
"key": "buildkite-agent-tag:queue",
Expand Down
12 changes: 11 additions & 1 deletion internal/trigger/buildkite/buildkite.go
Original file line number Diff line number Diff line change
Expand Up @@ -83,6 +83,8 @@ func (t *Trigger) Do(_ []byte) error {
// example: job B depends on job C and job C is not present in the build.
// Hence, it is better to neglect it during auto-scaling.
Waiting int
Running int
Total int
}
} `json:"jobs"`
}
Expand All @@ -94,6 +96,9 @@ func (t *Trigger) Do(_ []byte) error {
type outputData struct {
Queue string `json:"queue"`
ScheduledJobsCount int `json:"scheduled_jobs_count"`
RunningJobsCount int `json:"running_jobs_count"`
WaitingJobsCount int `json:"waiting_jobs_count"`
TotalJobsCount int `json:"total_jobs_count"`
}

queues := metrics.Jobs.Queues
Expand All @@ -107,10 +112,15 @@ func (t *Trigger) Do(_ []byte) error {
}

for qName, q := range queues {
t.log.Debugf("qName: %s, waitingSize: %d \n", qName, q.Scheduled)
t.log.Debugf(
"qName: %s, scheduledSize: %d, waitingSize: %d, runningSize: %d, totalSize: %d \n",
qName, q.Scheduled, q.Waiting, q.Running, q.Total)
data := outputData{
Queue: qName,
ScheduledJobsCount: q.Scheduled,
WaitingJobsCount: q.Waiting,
RunningJobsCount: q.Running,
TotalJobsCount: q.Total,
}
rawData, err := json.Marshal(data)
if err != nil {
Expand Down

0 comments on commit 59b47fd

Please sign in to comment.