Skip to content

Commit

Permalink
feat: filter GitHub workflows via query parameter for better queue co…
Browse files Browse the repository at this point in the history
…unt accuracy

Signed-off-by: silviu-dinu <silviudn@gmail.com>
  • Loading branch information
silviu-dinu committed Feb 6, 2025
1 parent d76aa17 commit a0709c2
Show file tree
Hide file tree
Showing 3 changed files with 20 additions and 6 deletions.
1 change: 1 addition & 0 deletions CHANGELOG.md
Original file line number Diff line number Diff line change
Expand Up @@ -71,6 +71,7 @@ Here is an overview of all new **experimental** features:

### Improvements

- **GitHub Scaler**: Filter workflows via query parameter for improved queue count accuracy ([#6519](https://github.com/kedacore/keda/pull/6519))
- **IBMMQ Scaler**: Handling StatusNotFound in IBMMQ scaler ([#6472](https://github.com/kedacore/keda/pull/6472))

### Fixes
Expand Down
17 changes: 12 additions & 5 deletions pkg/scalers/github_runner_scaler.go
Original file line number Diff line number Diff line change
Expand Up @@ -618,8 +618,8 @@ func (s *githubRunnerScaler) getWorkflowRunJobs(ctx context.Context, workflowRun
}

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

for _, repo := range repos {
wfrs, err := s.getWorkflowRuns(ctx, repo)
wfrsQueued, err := s.getWorkflowRuns(ctx, repo, "queued")
if err != nil {
return -1, err
}
if wfrs != nil {
allWfrs = append(allWfrs, *wfrs)
if wfrsQueued != nil {
allWfrs = append(allWfrs, *wfrsQueued)
}
wfrsInProgress, err := s.getWorkflowRuns(ctx, repo, "in_progress")
if err != nil {
return -1, err
}
if wfrsInProgress != nil {
allWfrs = append(allWfrs, *wfrsInProgress)
}
}

Expand Down
Loading

0 comments on commit a0709c2

Please sign in to comment.