Skip to content

Commit b71321d

Browse files
Fix issue with speculative runs not scaling agents
1 parent f4952ed commit b71321d

File tree

1 file changed

+9
-3
lines changed

1 file changed

+9
-3
lines changed

internal/controller/agentpool_controller_autoscaling.go

Lines changed: 9 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -74,7 +74,7 @@ func pendingWorkspaceRuns(ctx context.Context, ap *agentPoolInstance) (int32, er
7474
PageNumber: initPageNumber,
7575
},
7676
}
77-
77+
runCount := 0
7878
for {
7979
runsList, err := ap.tfClient.Client.Runs.ListForOrganization(ctx, ap.instance.Spec.Organization, listOpts)
8080
if err != nil {
@@ -87,6 +87,10 @@ func pendingWorkspaceRuns(ctx context.Context, ap *agentPoolInstance) (int32, er
8787
awaitingUserInteractionRuns[string(run.Status)]++
8888
continue
8989
}
90+
if _, exists := runs[run.Workspace.ID]; exists && run.PlanOnly {
91+
runCount++
92+
continue
93+
}
9094
runs[run.Workspace.ID] = struct{}{}
9195
}
9296
if runsList.NextPage == 0 {
@@ -97,8 +101,10 @@ func pendingWorkspaceRuns(ctx context.Context, ap *agentPoolInstance) (int32, er
97101

98102
// TODO:
99103
// Add metric(s) for runs awaiting user interaction
100-
101-
return int32(len(runs)), nil
104+
ap.log.Info("Runs", "msg", fmt.Sprintf("Runs: %+v", runs))
105+
ap.log.Info("Run count", "msg", fmt.Sprintf("RunCount: %+v", runCount))
106+
runCount = len(runs) + runCount
107+
return int32(runCount), nil
102108
}
103109

104110
// computeRequiredAgents is a legacy algorithm that is used to compute the number of agents needed.

0 commit comments

Comments
 (0)