Skip to content

Commit

Permalink
add gh registration stats and reduce cull time to 10min
Browse files Browse the repository at this point in the history
  • Loading branch information
elasticroentgen committed Apr 23, 2024
1 parent e4ae706 commit 9c8b0a1
Showing 1 changed file with 20 additions and 3 deletions.
23 changes: 20 additions & 3 deletions PoolManager.cs
Original file line number Diff line number Diff line change
Expand Up @@ -26,6 +26,8 @@ public class PoolManager : BackgroundService
.CreateCounter("github_machines_created", "Number of created machines", labelNames: ["org","size"]);
private static readonly Gauge QueueSize = Metrics
.CreateGauge("github_queue", "Number of queued runner tasks");
private static readonly Gauge GithubRunnersGauge = Metrics
.CreateGauge("github_registered_runners", "Number of runners registered to github actions", labelNames: ["org", "status"]);

private readonly RunnerQueue _queues;

Expand Down Expand Up @@ -56,10 +58,26 @@ protected override async Task ExecuteAsync(CancellationToken stoppingToken)
await Task.Yield();

DateTime crudeTimer = DateTime.UtcNow;
int cullMinutes = 30;
int cullMinutes = 10;

while (!stoppingToken.IsCancellationRequested)
{
// Grab some stats
QueueSize.Set(_queues.CreateTasks.Count + _queues.DeleteTasks.Count);

foreach (var org in orgConfig)
{
var orgRunners = await GitHubApi.GetRunners(org.GitHubToken, org.OrgName);
var ghStatus = orgRunners.runners.GroupBy(x => x.status).Select(x => new {Status = x.Key, Count = x.Count()});
foreach (var ghs in ghStatus)
{
GithubRunnersGauge.Labels(org.OrgName, ghs.Status).Set(ghs.Count);
_logger.LogInformation($"GitHub register stats for {org.OrgName}: {ghs.Status}={ghs.Count}");
}

}


// check for culling interval
if (DateTime.UtcNow - crudeTimer > TimeSpan.FromMinutes(cullMinutes))
{
Expand All @@ -68,8 +86,7 @@ protected override async Task ExecuteAsync(CancellationToken stoppingToken)
await StartPoolRunners(orgConfig);
crudeTimer = DateTime.UtcNow;
}

QueueSize.Set(_queues.CreateTasks.Count + _queues.DeleteTasks.Count);


if (_queues.DeleteTasks.TryDequeue(out DeleteRunnerTask? dtask))
{
Expand Down

0 comments on commit 9c8b0a1

Please sign in to comment.