diff --git a/collector/collector.go b/collector/collector.go index 3dab5494..98589ef7 100644 --- a/collector/collector.go +++ b/collector/collector.go @@ -24,6 +24,8 @@ const ( BusyAgentPercentage = "BusyAgentPercentage" PollDurationHeader = `Buildkite-Agent-Metrics-Poll-Duration` + + BintiRequiredAgentCount = "BintiRequiredAgentCount" ) var ( @@ -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 { @@ -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 } diff --git a/collector/collector_test.go b/collector/collector_test.go index dbc6b970..e233aa68 100644 --- a/collector/collector_test.go +++ b/collector/collector_test.go @@ -134,6 +134,7 @@ func TestCollectorWithSomeJobsAndAgentsForAllQueues(t *testing.T) { "scheduled": 3, "running": 1, "total": 4, + "waiting": 2, "queues": { "default": { "scheduled": 2, @@ -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 + } } } }`) @@ -182,10 +193,11 @@ 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}, @@ -193,6 +205,8 @@ func TestCollectorWithSomeJobsAndAgentsForAllQueues(t *testing.T) { {"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}, @@ -200,11 +214,17 @@ func TestCollectorWithSomeJobsAndAgentsForAllQueues(t *testing.T) { {"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) @@ -231,6 +251,7 @@ func TestCollectorWithSomeJobsAndAgentsForAQueue(t *testing.T) { "jobs": { "scheduled": 3, "running": 1, + "waiting": 1, "total": 4 }, "agents": { @@ -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 {