Skip to content

Commit

Permalink
ENG-15799 - Add custom binti metric
Browse files Browse the repository at this point in the history
  • Loading branch information
KaoruDev committed Jan 12, 2024
1 parent 455a2fa commit 88386e2
Show file tree
Hide file tree
Showing 2 changed files with 43 additions and 16 deletions.
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.Scheduled + 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.Scheduled + 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 @@ -262,13 +283,15 @@ func TestCollectorWithSomeJobsAndAgentsForAQueue(t *testing.T) {
Key string
Expected int
}{
{"Queue.deploy", res.Queues["deploy"], WaitingJobsCount, 1},
{"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"], 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

0 comments on commit 88386e2

Please sign in to comment.