Skip to content

Commit 0060862

Browse files
authored
feat: filter GitHub workflows via query parameter for better queue count accuracy (#6519)
Signed-off-by: Silviu Dinu <[email protected]>
1 parent 3d47f70 commit 0060862

File tree

3 files changed

+22
-8
lines changed

3 files changed

+22
-8
lines changed

CHANGELOG.md

+1
Original file line numberDiff line numberDiff line change
@@ -77,6 +77,7 @@ Here is an overview of all new **experimental** features:
7777
### Improvements
7878

7979
- **General**: Add SecretKey to AWS SecretsManager TriggerAuthentication to allow parsing JSON / Key/Value Pairs in secrets ([#5940](https://github.com/kedacore/keda/issues/5940))
80+
- **GitHub Scaler**: Filter workflows via query parameter for improved queue count accuracy ([#6519](https://github.com/kedacore/keda/pull/6519))
8081
- **IBMMQ Scaler**: Handling StatusNotFound in IBMMQ scaler ([#6472](https://github.com/kedacore/keda/pull/6472))
8182
- **RabbitMQ Scaler**: Support use of the ‘vhostName’ parameter in the ‘TriggerAuthentication’ resource ([#6369](https://github.com/kedacore/keda/issues/6369))
8283
- **Selenium Grid**: Add trigger param to set custom capabilities for matching specific Nodes ([#6536](https://github.com/kedacore/keda/issues/6536))

pkg/scalers/github_runner_scaler.go

+13-6
Original file line numberDiff line numberDiff line change
@@ -602,7 +602,7 @@ func stripDeadRuns(allWfrs []WorkflowRuns) []WorkflowRun {
602602

603603
// getWorkflowRunJobs returns a list of jobs for a given workflow run
604604
func (s *githubRunnerScaler) getWorkflowRunJobs(ctx context.Context, workflowRunID int64, repoName string) ([]Job, error) {
605-
url := fmt.Sprintf("%s/repos/%s/%s/actions/runs/%d/jobs", s.metadata.githubAPIURL, s.metadata.owner, repoName, workflowRunID)
605+
url := fmt.Sprintf("%s/repos/%s/%s/actions/runs/%d/jobs?per_page=100", s.metadata.githubAPIURL, s.metadata.owner, repoName, workflowRunID)
606606
body, _, err := getGithubRequest(ctx, url, s.metadata, s.httpClient)
607607
if err != nil {
608608
return nil, err
@@ -618,8 +618,8 @@ func (s *githubRunnerScaler) getWorkflowRunJobs(ctx context.Context, workflowRun
618618
}
619619

620620
// getWorkflowRuns returns a list of workflow runs for a given repository
621-
func (s *githubRunnerScaler) getWorkflowRuns(ctx context.Context, repoName string) (*WorkflowRuns, error) {
622-
url := fmt.Sprintf("%s/repos/%s/%s/actions/runs", s.metadata.githubAPIURL, s.metadata.owner, repoName)
621+
func (s *githubRunnerScaler) getWorkflowRuns(ctx context.Context, repoName string, status string) (*WorkflowRuns, error) {
622+
url := fmt.Sprintf("%s/repos/%s/%s/actions/runs?status=%s&per_page=100", s.metadata.githubAPIURL, s.metadata.owner, repoName, status)
623623
body, statusCode, err := getGithubRequest(ctx, url, s.metadata, s.httpClient)
624624
if err != nil && statusCode == 404 {
625625
return nil, nil
@@ -672,12 +672,19 @@ func (s *githubRunnerScaler) GetWorkflowQueueLength(ctx context.Context) (int64,
672672
var allWfrs []WorkflowRuns
673673

674674
for _, repo := range repos {
675-
wfrs, err := s.getWorkflowRuns(ctx, repo)
675+
wfrsQueued, err := s.getWorkflowRuns(ctx, repo, "queued")
676676
if err != nil {
677677
return -1, err
678678
}
679-
if wfrs != nil {
680-
allWfrs = append(allWfrs, *wfrs)
679+
if wfrsQueued != nil {
680+
allWfrs = append(allWfrs, *wfrsQueued)
681+
}
682+
wfrsInProgress, err := s.getWorkflowRuns(ctx, repo, "in_progress")
683+
if err != nil {
684+
return -1, err
685+
}
686+
if wfrsInProgress != nil {
687+
allWfrs = append(allWfrs, *wfrsInProgress)
681688
}
682689
}
683690

0 commit comments

Comments
 (0)