Skip to content

Commit

Permalink
Add some logging
Browse files Browse the repository at this point in the history
Signed-off-by: Gabriel Adrian Samfira <[email protected]>
  • Loading branch information
gabriel-samfira committed Jan 30, 2024
1 parent 8e0456c commit 43b96c5
Showing 1 changed file with 17 additions and 4 deletions.
21 changes: 17 additions & 4 deletions runner/pool/pool.go
Original file line number Diff line number Diff line change
Expand Up @@ -1249,6 +1249,8 @@ func (r *basePoolManager) retryFailedInstancesForOnePool(ctx context.Context, po

g, errCtx := errgroup.WithContext(ctx)
for _, instance := range existingInstances {
instance := instance

if instance.Status != commonParams.InstanceError {
continue
}
Expand All @@ -1267,9 +1269,11 @@ func (r *basePoolManager) retryFailedInstancesForOnePool(ctx context.Context, po
continue
}

instance := instance
g.Go(func() error {
defer r.keyMux.Unlock(instance.Name, false)
slog.DebugContext(
ctx, "attempting to clean up any previous instance",
"runner_name", instance.Name)
// NOTE(gabriel-samfira): this is done in parallel. If there are many failed instances
// this has the potential to create many API requests to the target provider.
// TODO(gabriel-samfira): implement request throttling.
Expand All @@ -1286,7 +1290,9 @@ func (r *basePoolManager) retryFailedInstancesForOnePool(ctx context.Context, po
// which we would rather avoid.
return err
}

slog.DebugContext(
ctx, "cleanup of previously failed instance complete",
"runner_name", instance.Name)
// TODO(gabriel-samfira): Incrementing CreateAttempt should be done within a transaction.
// It's fairly safe to do here (for now), as there should be no other code path that updates
// an instance in this state.
Expand Down Expand Up @@ -1397,6 +1403,11 @@ func (r *basePoolManager) deleteInstanceFromProvider(ctx context.Context, instan
identifier = instance.Name
}

slog.DebugContext(
ctx, "calling delete instance on provider",
"runner_name", instance.Name,
"provider_id", identifier)

if err := provider.DeleteInstance(ctx, identifier); err != nil {
return errors.Wrap(err, "removing instance")
}
Expand Down Expand Up @@ -1534,15 +1545,17 @@ func (r *basePoolManager) addPendingInstances() error {
"pool_id", instance.PoolID)
if err := r.addInstanceToProvider(instance); err != nil {
slog.With(slog.Any("error", err)).ErrorContext(
r.ctx, "failed to add instance to provider")
r.ctx, "failed to add instance to provider",
"runner_name", instance.Name)
errAsBytes := []byte(err.Error())
if _, statusErr := r.setInstanceStatus(instance.Name, commonParams.InstanceError, errAsBytes); statusErr != nil {
slog.With(slog.Any("error", statusErr)).ErrorContext(
r.ctx, "failed to update runner status",
"runner_name", instance.Name)
}
slog.With(slog.Any("error", err)).ErrorContext(
r.ctx, "failed to create instance in provider")
r.ctx, "failed to create instance in provider",
"runner_name", instance.Name)
}
}(instance)
}
Expand Down

0 comments on commit 43b96c5

Please sign in to comment.