Skip to content

Commit 08a1b97

Browse files
Remove unnecessary mock and fix logging
1 parent 9bf3a74 commit 08a1b97

File tree

3 files changed

+5
-56
lines changed

3 files changed

+5
-56
lines changed

internal/controller/agentpool_controller_autoscaling.go

Lines changed: 4 additions & 5 deletions
Original file line numberDiff line numberDiff line change
@@ -81,7 +81,6 @@ func (ap *agentPoolInstance) pendingWorkspaceRuns(ctx context.Context) (int32, e
8181
}
8282
planOnlyRunCount := 0
8383
for {
84-
ap.log.Info("Fetching runs for organization", "org", ap.instance.Spec.Organization, "page", listOpts.PageNumber)
8584
runsList, err := ap.tfClient.Client.Runs.ListForOrganization(ctx, ap.instance.Spec.Organization, listOpts)
8685
if err != nil {
8786
return 0, err
@@ -108,9 +107,9 @@ func (ap *agentPoolInstance) pendingWorkspaceRuns(ctx context.Context) (int32, e
108107

109108
// TODO:
110109
// Add metric(s) for runs awaiting user interaction
111-
agentsCount := len(runs) + planOnlyRunCount
112-
ap.log.Info("Workspaces and plan-only runs count", "msg", fmt.Sprintf("Workspaces: %+v Plan-only runs: %d Total agents: %d", runs, planOnlyRunCount, agentsCount))
113-
return int32(agentsCount), nil
110+
totalPendingRuns := len(runs) + planOnlyRunCount
111+
ap.log.Info("Runs", "msg", fmt.Sprintf("Workspaces: %+v Plan-only runs: %d Total pending runs: %d", runs, planOnlyRunCount, totalPendingRuns))
112+
return int32(totalPendingRuns), nil
114113
}
115114

116115
// computeRequiredAgents is a legacy algorithm that is used to compute the number of agents needed.
@@ -278,7 +277,7 @@ func (r *AgentPoolReconciler) reconcileAgentAutoscaling(ctx context.Context, ap
278277
r.Recorder.Eventf(&ap.instance, corev1.EventTypeWarning, "AutoscaleAgentPoolDeployment", "Autoscaling failed: %v", err.Error())
279278
return err
280279
}
281-
ap.log.Info("Reconcile Agent Autoscaling", "msg", fmt.Sprintf("%d workspaces have pending runs", requiredAgents))
280+
ap.log.Info("Reconcile Agent Autoscaling", "msg", fmt.Sprintf("%d agents are required", requiredAgents))
282281

283282
currentReplicas, err := r.getAgentDeploymentReplicas(ctx, ap)
284283
if err != nil {

internal/controller/agentpool_controller_autoscaling_test.go

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -263,7 +263,7 @@ func TestPendingWorkspaceRuns(t *testing.T) {
263263
mockRuns := mocks.NewMockRuns(ctrl)
264264
mockRuns.EXPECT().
265265
ListForOrganization(gomock.Any(), "test-org", gomock.Any()).
266-
Return(&tfc.RunList{Items: tt.mockRuns, Pagination: &tfc.Pagination{NextPage: 0}}, tt.mockErr)
266+
Return(&tfc.OrganizationRunList{Items: tt.mockRuns, PaginationNextPrev: &tfc.PaginationNextPrev{NextPage: 0}}, tt.mockErr)
267267

268268
ap := &agentPoolInstance{
269269
tfClient: HCPTerraformClient{Client: &tfc.Client{Runs: mockRuns}},

mocks/agentpool_controller_autoscaling_mocks.go

Lines changed: 0 additions & 50 deletions
This file was deleted.

0 commit comments

Comments
 (0)