Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Bumps Agent version to 5.9.3 from 5.8.0 #4

Draft
wants to merge 6 commits into
base: main
Choose a base branch
from
Draft
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
20 changes: 12 additions & 8 deletions collector/collector.go
Original file line number Diff line number Diff line change
Expand Up @@ -24,6 +24,8 @@ const (
BusyAgentPercentage = "BusyAgentPercentage"

PollDurationHeader = `Buildkite-Agent-Metrics-Poll-Duration`

BintiRequiredAgentCount = "BintiRequiredAgentCount"
)

var (
Expand Down Expand Up @@ -223,6 +225,7 @@ func (c *Collector) collectAllQueues(httpClient *http.Client, result *Result) er
result.Queues[queueName][RunningJobsCount] = queueJobMetrics.Running
result.Queues[queueName][UnfinishedJobsCount] = queueJobMetrics.Total
result.Queues[queueName][WaitingJobsCount] = queueJobMetrics.Waiting
result.Queues[queueName][BintiRequiredAgentCount] = queueJobMetrics.Waiting + queueJobMetrics.Running
}

for queueName, queueAgentMetrics := range allMetrics.Agents.Queues {
Expand Down Expand Up @@ -312,14 +315,15 @@ func (c *Collector) collectQueue(httpClient *http.Client, result *Result, queue
result.Cluster = queueMetrics.Cluster.Name

result.Queues[queue] = map[string]int{
ScheduledJobsCount: queueMetrics.Jobs.Scheduled,
RunningJobsCount: queueMetrics.Jobs.Running,
UnfinishedJobsCount: queueMetrics.Jobs.Total,
WaitingJobsCount: queueMetrics.Jobs.Waiting,
IdleAgentCount: queueMetrics.Agents.Idle,
BusyAgentCount: queueMetrics.Agents.Busy,
TotalAgentCount: queueMetrics.Agents.Total,
BusyAgentPercentage: busyAgentPercentage(queueMetrics.Agents),
ScheduledJobsCount: queueMetrics.Jobs.Scheduled,
RunningJobsCount: queueMetrics.Jobs.Running,
UnfinishedJobsCount: queueMetrics.Jobs.Total,
WaitingJobsCount: queueMetrics.Jobs.Waiting,
IdleAgentCount: queueMetrics.Agents.Idle,
BusyAgentCount: queueMetrics.Agents.Busy,
TotalAgentCount: queueMetrics.Agents.Total,
BusyAgentPercentage: busyAgentPercentage(queueMetrics.Agents),
BintiRequiredAgentCount: queueMetrics.Jobs.Waiting + queueMetrics.Jobs.Running,
}
return nil
}
Expand Down
39 changes: 31 additions & 8 deletions collector/collector_test.go
Original file line number Diff line number Diff line change
Expand Up @@ -134,6 +134,7 @@ func TestCollectorWithSomeJobsAndAgentsForAllQueues(t *testing.T) {
"scheduled": 3,
"running": 1,
"total": 4,
"waiting": 2,
"queues": {
"default": {
"scheduled": 2,
Expand All @@ -143,20 +144,30 @@ func TestCollectorWithSomeJobsAndAgentsForAllQueues(t *testing.T) {
"deploy": {
"scheduled": 1,
"running": 0,
"total": 1
}
"total": 1,
"waiting": 1
},
"binti": {
"scheduled": 1,
"running": 1
}
}
},
"agents": {
"idle": 0,
"busy": 1,
"total": 1,
"busy": 2,
"total": 2,
"queues": {
"default": {
"idle": 0,
"busy": 1,
"total": 1
}
},
"binti": {
"busy": 1,
"idle": 0,
"total": 1
}
}
}
}`)
Expand All @@ -182,29 +193,38 @@ func TestCollectorWithSomeJobsAndAgentsForAllQueues(t *testing.T) {
{"Totals", res.Totals, RunningJobsCount, 1},
{"Totals", res.Totals, ScheduledJobsCount, 3},
{"Totals", res.Totals, UnfinishedJobsCount, 4},
{"Totals", res.Totals, TotalAgentCount, 1},
{"Totals", res.Totals, BusyAgentCount, 1},
{"Totals", res.Totals, TotalAgentCount, 2},
{"Totals", res.Totals, BusyAgentCount, 2},
{"Totals", res.Totals, IdleAgentCount, 0},
{"Totals", res.Totals, BusyAgentPercentage, 100},
{"Totals", res.Totals, WaitingJobsCount, 2},

{"Queue.default", res.Queues["default"], RunningJobsCount, 1},
{"Queue.default", res.Queues["default"], ScheduledJobsCount, 2},
{"Queue.default", res.Queues["default"], UnfinishedJobsCount, 3},
{"Queue.default", res.Queues["default"], TotalAgentCount, 1},
{"Queue.default", res.Queues["default"], BusyAgentCount, 1},
{"Queue.default", res.Queues["default"], IdleAgentCount, 0},
{"Queue.default", res.Queues["default"], WaitingJobsCount, 0},
{"Queue.default", res.Queues["default"], BintiRequiredAgentCount, 1},

{"Queue.deploy", res.Queues["deploy"], RunningJobsCount, 0},
{"Queue.deploy", res.Queues["deploy"], ScheduledJobsCount, 1},
{"Queue.deploy", res.Queues["deploy"], UnfinishedJobsCount, 1},
{"Queue.deploy", res.Queues["deploy"], TotalAgentCount, 0},
{"Queue.deploy", res.Queues["deploy"], BusyAgentCount, 0},
{"Queue.deploy", res.Queues["deploy"], IdleAgentCount, 0},
{"Queue.deploy", res.Queues["deploy"], WaitingJobsCount, 1},
{"Queue.deploy", res.Queues["deploy"], BintiRequiredAgentCount, 1},

{"Queue.default", res.Queues["binti"], TotalAgentCount, 1},
{"Queue.deploy", res.Queues["binti"], BusyAgentCount, 1},
{"Queue.deploy", res.Queues["binti"], BintiRequiredAgentCount, 1},
}

for queue := range res.Queues {
switch queue {
case "default", "deploy":
case "default", "deploy", "binti":
continue
default:
t.Fatalf("Unexpected queue %s", queue)
Expand All @@ -231,6 +251,7 @@ func TestCollectorWithSomeJobsAndAgentsForAQueue(t *testing.T) {
"jobs": {
"scheduled": 3,
"running": 1,
"waiting": 1,
"total": 4
},
"agents": {
Expand Down Expand Up @@ -265,10 +286,12 @@ func TestCollectorWithSomeJobsAndAgentsForAQueue(t *testing.T) {
{"Queue.deploy", res.Queues["deploy"], RunningJobsCount, 1},
{"Queue.deploy", res.Queues["deploy"], ScheduledJobsCount, 3},
{"Queue.deploy", res.Queues["deploy"], UnfinishedJobsCount, 4},
{"Queue.deploy", res.Queues["deploy"], WaitingJobsCount, 1},
{"Queue.deploy", res.Queues["deploy"], TotalAgentCount, 1},
{"Queue.deploy", res.Queues["deploy"], BusyAgentCount, 1},
{"Queue.deploy", res.Queues["deploy"], IdleAgentCount, 0},
{"Queue.deploy", res.Queues["deploy"], BusyAgentPercentage, 100},
{"Queue.deploy", res.Queues["deploy"], BintiRequiredAgentCount, 2},
}

for _, tc := range testCases {
Expand Down