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 (#6519)

Signed-off-by: Silviu Dinu <silviudn@gmail.com>
  • Loading branch information
silviu-dinu authored Feb 12, 2025
1 parent 3d47f70 commit 0060862
Show file tree
Hide file tree
Showing 3 changed files with 22 additions and 8 deletions.
1 change: 1 addition & 0 deletions CHANGELOG.md
Original file line number Diff line number Diff line change
Expand Up @@ -77,6 +77,7 @@ Here is an overview of all new **experimental** features:
### Improvements

- **General**: Add SecretKey to AWS SecretsManager TriggerAuthentication to allow parsing JSON / Key/Value Pairs in secrets ([#5940](https://github.com/kedacore/keda/issues/5940))
- **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))
- **RabbitMQ Scaler**: Support use of the ‘vhostName’ parameter in the ‘TriggerAuthentication’ resource ([#6369](https://github.com/kedacore/keda/issues/6369))
- **Selenium Grid**: Add trigger param to set custom capabilities for matching specific Nodes ([#6536](https://github.com/kedacore/keda/issues/6536))
Expand Down
19 changes: 13 additions & 6 deletions pkg/scalers/github_runner_scaler.go
Original file line number Diff line number Diff line change
Expand Up @@ -602,7 +602,7 @@ func stripDeadRuns(allWfrs []WorkflowRuns) []WorkflowRun {

// getWorkflowRunJobs returns a list of jobs for a given workflow run
func (s *githubRunnerScaler) getWorkflowRunJobs(ctx context.Context, workflowRunID int64, repoName string) ([]Job, error) {
url := fmt.Sprintf("%s/repos/%s/%s/actions/runs/%d/jobs", s.metadata.githubAPIURL, s.metadata.owner, repoName, workflowRunID)
url := fmt.Sprintf("%s/repos/%s/%s/actions/runs/%d/jobs?per_page=100", s.metadata.githubAPIURL, s.metadata.owner, repoName, workflowRunID)
body, _, err := getGithubRequest(ctx, url, s.metadata, s.httpClient)
if err != nil {
return nil, err
Expand All @@ -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&per_page=100", 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 0060862

Please sign in to comment.