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 11, 2024
1 parent 455a2fa commit 6d68ff7
Show file tree
Hide file tree
Showing 2 changed files with 40 additions and 16 deletions.
21 changes: 13 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
}

for queueName, queueAgentMetrics := range allMetrics.Agents.Queues {
Expand All @@ -233,6 +236,7 @@ func (c *Collector) collectAllQueues(httpClient *http.Client, result *Result) er
result.Queues[queueName][BusyAgentCount] = queueAgentMetrics.Busy
result.Queues[queueName][TotalAgentCount] = queueAgentMetrics.Total
result.Queues[queueName][BusyAgentPercentage] = busyAgentPercentage(queueAgentMetrics)
result.Queues[queueName][BintiRequiredAgentCount] = result.Queues[queueName][BintiRequiredAgentCount] + queueAgentMetrics.Total
}

return nil
Expand Down Expand Up @@ -312,14 +316,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.Agents.Busy,
}
return nil
}
Expand Down
35 changes: 27 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,29 @@ func TestCollectorWithSomeJobsAndAgentsForAllQueues(t *testing.T) {
"deploy": {
"scheduled": 1,
"running": 0,
"total": 1
}
"total": 1,
"waiting": 1
},
"binti": {
"waiting": 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 +192,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, 2},
}

for queue := range res.Queues {
switch queue {
case "default", "deploy":
case "default", "deploy", "binti":
continue
default:
t.Fatalf("Unexpected queue %s", queue)
Expand Down

0 comments on commit 6d68ff7

Please sign in to comment.