-
Notifications
You must be signed in to change notification settings - Fork 95
New issue
Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.
By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.
Already on GitHub? Sign in to your account
feat: improve error handling and logging in the compute package #4850
base: main
Are you sure you want to change the base?
Changes from all commits
a437f45
49d44cd
d522430
3232529
ae682ba
2d0e837
232c7b6
907aa46
fe293bc
c330854
1d8ddab
1aac4eb
File filter
Filter by extension
Conversations
Jump to
Diff view
Diff view
There are no files selected for viewing
Original file line number | Diff line number | Diff line change | ||||||||||||||||||||||||||||||||
---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|
|
@@ -4,9 +4,11 @@ | |||||||||||||||||||||||||||||||||
"context" | ||||||||||||||||||||||||||||||||||
"fmt" | ||||||||||||||||||||||||||||||||||
|
||||||||||||||||||||||||||||||||||
"github.com/bacalhau-project/bacalhau/pkg/bacerrors" | ||||||||||||||||||||||||||||||||||
"github.com/bacalhau-project/bacalhau/pkg/compute" | ||||||||||||||||||||||||||||||||||
"github.com/bacalhau-project/bacalhau/pkg/lib/watcher" | ||||||||||||||||||||||||||||||||||
"github.com/bacalhau-project/bacalhau/pkg/models" | ||||||||||||||||||||||||||||||||||
"github.com/rs/zerolog/log" | ||||||||||||||||||||||||||||||||||
) | ||||||||||||||||||||||||||||||||||
|
||||||||||||||||||||||||||||||||||
type ExecutionUpsertHandler struct { | ||||||||||||||||||||||||||||||||||
|
@@ -29,15 +31,42 @@ | |||||||||||||||||||||||||||||||||
} | ||||||||||||||||||||||||||||||||||
|
||||||||||||||||||||||||||||||||||
execution := upsert.Current | ||||||||||||||||||||||||||||||||||
logger := log.Ctx(ctx).With(). | ||||||||||||||||||||||||||||||||||
Str("executionID", execution.ID). | ||||||||||||||||||||||||||||||||||
Str("state", execution.ComputeState.StateType.String()). | ||||||||||||||||||||||||||||||||||
Logger() | ||||||||||||||||||||||||||||||||||
Comment on lines
+34
to
+37
There was a problem hiding this comment. Choose a reason for hiding this commentThe reason will be displayed to describe this comment to others. Learn more. nice |
||||||||||||||||||||||||||||||||||
|
||||||||||||||||||||||||||||||||||
var err error | ||||||||||||||||||||||||||||||||||
switch execution.ComputeState.StateType { | ||||||||||||||||||||||||||||||||||
case models.ExecutionStateNew: | ||||||||||||||||||||||||||||||||||
return h.bidder.RunBidding(ctx, execution) | ||||||||||||||||||||||||||||||||||
if err = h.bidder.RunBidding(ctx, execution); err != nil { | ||||||||||||||||||||||||||||||||||
compute.ExecutionBiddingErrors.Add(ctx, 1) | ||||||||||||||||||||||||||||||||||
logger.Error(). | ||||||||||||||||||||||||||||||||||
Err(err). | ||||||||||||||||||||||||||||||||||
Msg("failed to run bidding") | ||||||||||||||||||||||||||||||||||
} | ||||||||||||||||||||||||||||||||||
case models.ExecutionStateBidAccepted: | ||||||||||||||||||||||||||||||||||
return h.executor.Run(ctx, execution) | ||||||||||||||||||||||||||||||||||
err = h.executor.Run(ctx, execution) | ||||||||||||||||||||||||||||||||||
if err != nil { | ||||||||||||||||||||||||||||||||||
compute.ExecutionRunErrors.Add(ctx, 1) | ||||||||||||||||||||||||||||||||||
logger.Error(). | ||||||||||||||||||||||||||||||||||
Err(err). | ||||||||||||||||||||||||||||||||||
Msg("failed to run execution") | ||||||||||||||||||||||||||||||||||
} | ||||||||||||||||||||||||||||||||||
case models.ExecutionStateCancelled: | ||||||||||||||||||||||||||||||||||
Check failure on line 56 in pkg/compute/watchers/executor_watcher.go
|
||||||||||||||||||||||||||||||||||
return h.executor.Cancel(ctx, execution) | ||||||||||||||||||||||||||||||||||
case models.ExecutionStateCancelled: | ||||||||||||||||||||||||||||||||||
Check failure on line 57 in pkg/compute/watchers/executor_watcher.go
|
||||||||||||||||||||||||||||||||||
err = h.executor.Cancel(ctx, execution) | ||||||||||||||||||||||||||||||||||
if err != nil { | ||||||||||||||||||||||||||||||||||
+ logger.Error().Err(err).Msg("failed to cancel execution") | ||||||||||||||||||||||||||||||||||
Check failure on line 60 in pkg/compute/watchers/executor_watcher.go
|
||||||||||||||||||||||||||||||||||
compute.ExecutionCancelErrors.Add(ctx, 1) | ||||||||||||||||||||||||||||||||||
} | ||||||||||||||||||||||||||||||||||
Comment on lines
56
to
+62
There was a problem hiding this comment. Choose a reason for hiding this commentThe reason will be displayed to describe this comment to others. Learn more. Fix duplicate case statement and logger syntax. There are two critical issues in the cancelled state handling:
Apply this diff to fix the issues: - case models.ExecutionStateCancelled:
-case models.ExecutionStateCancelled:
+ case models.ExecutionStateCancelled:
err = h.executor.Cancel(ctx, execution)
if err != nil {
- logger.Error().Err(err).Msg("failed to cancel execution")
+ logger.Error().
+ Err(err).
+ Msg("failed to cancel execution")
compute.ExecutionCancelErrors.Add(ctx, 1)
} 📝 Committable suggestion
Suggested change
🧰 Tools🪛 GitHub Check: lint / go-lint (ubuntu-latest)[failure] 57-57: [failure] 56-56: [failure] 60-60: [failure] 57-57: [failure] 56-56: [failure] 60-60: [failure] 57-57: [failure] 56-56: |
||||||||||||||||||||||||||||||||||
default: | ||||||||||||||||||||||||||||||||||
// No action needed for other states | ||||||||||||||||||||||||||||||||||
return nil | ||||||||||||||||||||||||||||||||||
} | ||||||||||||||||||||||||||||||||||
|
||||||||||||||||||||||||||||||||||
if err != nil { | ||||||||||||||||||||||||||||||||||
return bacerrors.Wrap(err, "failed to handle execution state %s", execution.ComputeState.StateType) | ||||||||||||||||||||||||||||||||||
} | ||||||||||||||||||||||||||||||||||
return nil | ||||||||||||||||||||||||||||||||||
} |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
🧹 Nitpick (assertive)
Skips update if
ErrInvalidExecutionState
.Returning
nil
here is appropriate if you intentionally ignore an outdated or conflicting state. To enhance clarity, add a comment explaining the decision and how it aligns with the desired concurrency or state-management logic.if errors.As(err, &invalidStateErr) { + // The execution has likely advanced to a newer state. Skipping update is intentional. log.Ctx(ctx).Debug().
📝 Committable suggestion