fix: Paginate ListRepositoryWorkflowRuns (#295)
When we used `QueuedAndInProgressWorkflowRuns`-based autoscaling, it only fetched and considered only the first 30 workflow runs at the reconcilation time. This may have resulted in unreliable scaling behaviour, like scale-in/out not happening when it was expected.
This commit is contained in:
parent
ab1c39de57
commit
9301409aec
|
|
@ -138,12 +138,12 @@ func (r *HorizontalRunnerAutoscalerReconciler) calculateReplicasByQueuedAndInPro
|
||||||
|
|
||||||
for _, repo := range repos {
|
for _, repo := range repos {
|
||||||
user, repoName := repo[0], repo[1]
|
user, repoName := repo[0], repo[1]
|
||||||
list, _, err := r.GitHubClient.Actions.ListRepositoryWorkflowRuns(context.TODO(), user, repoName, nil)
|
workflowRuns, err := r.GitHubClient.ListRepositoryWorkflowRuns(context.TODO(), user, repoName)
|
||||||
if err != nil {
|
if err != nil {
|
||||||
return nil, err
|
return nil, err
|
||||||
}
|
}
|
||||||
|
|
||||||
for _, run := range list.WorkflowRuns {
|
for _, run := range workflowRuns {
|
||||||
total++
|
total++
|
||||||
|
|
||||||
// In May 2020, there are only 3 statuses.
|
// In May 2020, there are only 3 statuses.
|
||||||
|
|
|
||||||
|
|
@ -207,6 +207,34 @@ func (c *Client) listRunners(ctx context.Context, enterprise, org, repo string,
|
||||||
return c.Client.Enterprise.ListRunners(ctx, enterprise, opts)
|
return c.Client.Enterprise.ListRunners(ctx, enterprise, opts)
|
||||||
}
|
}
|
||||||
|
|
||||||
|
func (c *Client) ListRepositoryWorkflowRuns(ctx context.Context, user string, repoName string) ([]*github.WorkflowRun, error) {
|
||||||
|
c.Client.Actions.ListRepositoryWorkflowRuns(ctx, user, repoName, nil)
|
||||||
|
|
||||||
|
var workflowRuns []*github.WorkflowRun
|
||||||
|
|
||||||
|
opts := github.ListWorkflowRunsOptions{
|
||||||
|
ListOptions: github.ListOptions{
|
||||||
|
PerPage: 100,
|
||||||
|
},
|
||||||
|
}
|
||||||
|
|
||||||
|
for {
|
||||||
|
list, res, err := c.Client.Actions.ListRepositoryWorkflowRuns(ctx, user, repoName, &opts)
|
||||||
|
|
||||||
|
if err != nil {
|
||||||
|
return workflowRuns, fmt.Errorf("failed to list workflow runs: %v", err)
|
||||||
|
}
|
||||||
|
|
||||||
|
workflowRuns = append(workflowRuns, list.WorkflowRuns...)
|
||||||
|
if res.NextPage == 0 {
|
||||||
|
break
|
||||||
|
}
|
||||||
|
opts.Page = res.NextPage
|
||||||
|
}
|
||||||
|
|
||||||
|
return workflowRuns, nil
|
||||||
|
}
|
||||||
|
|
||||||
// Validates enterprise, organisation and repo arguments. Both are optional, but at least one should be specified
|
// Validates enterprise, organisation and repo arguments. Both are optional, but at least one should be specified
|
||||||
func getEnterpriseOrganisationAndRepo(enterprise, org, repo string) (string, string, string, error) {
|
func getEnterpriseOrganisationAndRepo(enterprise, org, repo string) (string, string, string, error) {
|
||||||
if len(repo) > 0 {
|
if len(repo) > 0 {
|
||||||
|
|
|
||||||
Loading…
Reference in New Issue