bacalhau-project / bacalhau

Compute over Data framework for public, transparent, and optionally verifiable computation
https://docs.bacalhau.org
Apache License 2.0
675 stars 88 forks source link

Structured events in place of comment strings #3771

Closed simonwo closed 5 months ago

simonwo commented 5 months ago

This PR implements the structure proposed in Improve Error Reporting as a first step towards providing richer progress reporting during job execution.

The "tl;dr;" is that we will move to using an event stream for reporting progress on jobs. The event stream will help users understand the progress of their job and give them extra context about any failures that occur. This will allow us to show a richer view in the UI, e.g. the user will be able to see "downloading Docker image" instead of just "job running".

To achieve this vision, we need to build this infrastructure for generating events, recording them in the job history, and displaying them (done), replace the orchestrator/compute callbacks mechanism (later PR), and then give lower level components the ability to push events (later PR).

This PR also includes some facility for structured error reporting. This allows low-level components to throw structured errors that provide a richer event than the ones generated automatically. This is used in e.g. the ErrNotEnoughNodes case and docker ImageUnavailable case so far.

This gives us the ability to output hints as part of our messages back to the user:

carbon

The output of describe now shows a split history between the overall job and its executions:

% ./bin/darwin/arm64/bacalhau job describe j-66081fef-8dd2-48de-9997-bbe23a62f0be

ID            = j-66081fef-8dd2-48de-9997-bbe23a62f0be
Name          = Docker Job
Namespace     = default
Type          = batch
State         = Completed
Count         = 1
Created Time  = 2024-04-10 06:56:26
Modified Time = 2024-04-10 06:56:29
Version       = 0

Summary
Completed = 1

Job History
 TIME       REV.  STATE      TOPIC       EVENT          DETAILS 
 0s         1     Pending    Submission  Job submitted          
 2.618376s  2     Running                                       
 2.840423s  3     Completed                                     

Executions
 ID          NODE ID     STATE      DESIRED  REV.  CREATED  MODIFIED  COMMENT      
 e-5886e01f  n-ffc3e455  Completed  Stopped  6     8s ago   5s ago    Accepted job 

Execution e-5886e01f History
 TIME       REV.  STATE              TOPIC            EVENT         DETAILS               
 0s         1     New                                                                     
 8.165ms    2     AskForBid                                                               
 2.569966s  3     AskForBidAccepted  Requesting node  Accepted job  FailsExecution: false 
                                                                    IsError: false        
                                                                    Retryable: false      
 2.590902s  4     AskForBidAccepted                                                       
 2.613668s  5     BidAccepted                                                             
 2.803923s  6     Completed                                                               

Standard Output
15

Resolves https://github.com/bacalhau-project/expanso-planning/issues/693. Resolves https://github.com/bacalhau-project/expanso-planning/issues/694.

TODO in this PR

coderabbitai[bot] commented 5 months ago

[!IMPORTANT]

Auto Review Skipped

Auto reviews are disabled on this repository.

Please check the settings in the CodeRabbit UI or the .coderabbit.yaml file in this repository.

To trigger a single review, invoke the @coderabbitai review command.

Walkthrough

The modifications introduce a comprehensive overhaul to error handling and event logging across various components, with a focus on structured errors, enhanced job and execution history tracking, and refined event management. The changes aim to improve debugging, monitoring, and the user interface experience by providing more detailed and structured information on job executions and errors.

Changes

File Pattern Change Summary
cmd/cli/job/* Enhanced job and execution history display, added structured error handling.
pkg/compute/* Updated logging, error handling, and event management with structured errors and detailed events.
pkg/jobstore/, pkg/models/ Incorporated events in job and execution creation, and updated structures to include event details.
pkg/orchestrator/* Improved error handling, event creation, and job state updates with structured errors and events.
pkg/requester/endpoint.go, pkg/test/* Adjusted to new event handling approach and structured errors.

Assessment against linked issues

Objective Addressed Explanation
Return structured errors from the API (#693) βœ…
Hide extraneous error output but show it with job describe (#694) βœ…
Implement a status update mechanism for compute nodes... (#407) ❌ The changes do not address status updates or the synchronization of state between requesters and compute nodes.

Possibly related issues

Poem

In the land of code and binary streams,
A rabbit hopped, chasing its dreams.
🐰 "To errors and logs, let's bring some light,
Structure and clarity, make them bright!"
Through files and functions, it danced with glee,
Crafting a world where errors are easy to see.
"With every hop, let's make it clear,
Debugging's no longer something to fear!" 🌟


Tips ### Chat There are 3 ways to chat with [CodeRabbit](https://coderabbit.ai): - Review comments: Directly reply to a review comment made by CodeRabbit. Example: - `I pushed a fix in commit .` - `Generate unit testing code for this file.` - `Open a follow-up GitHub issue for this discussion.` - Files and specific lines of code (under the "Files changed" tab): Tag `@coderabbitai` in a new review comment at the desired location with your query. Examples: - `@coderabbitai generate unit testing code for this file.` - `@coderabbitai modularize this function.` - PR comments: Tag `@coderabbitai` in a new PR comment to ask questions about the PR branch. For the best results, please provide a very specific query, as very limited context is provided in this mode. Examples: - `@coderabbitai generate interesting stats about this repository and render them as a table.` - `@coderabbitai show all the console.log statements in this repository.` - `@coderabbitai read src/utils.ts and generate unit testing code.` - `@coderabbitai read the files in the src/scheduler package and generate a class diagram using mermaid and a README in the markdown format.` Note: Be mindful of the bot's finite context window. It's strongly recommended to break down tasks such as reading entire modules into smaller chunks. For a focused discussion, use review comments to chat about specific files and their changes, instead of using the PR comments. ### CodeRabbit Commands (invoked as PR comments) - `@coderabbitai pause` to pause the reviews on a PR. - `@coderabbitai resume` to resume the paused reviews. - `@coderabbitai review` to trigger a review. This is useful when automatic reviews are disabled for the repository. - `@coderabbitai resolve` resolve all the CodeRabbit review comments. - `@coderabbitai help` to get help. Additionally, you can add `@coderabbitai ignore` anywhere in the PR description to prevent this PR from being reviewed. ### CodeRabbit Configration File (`.coderabbit.yaml`) - You can programmatically configure CodeRabbit by adding a `.coderabbit.yaml` file to the root of your repository. - Please see the [configuration documentation](https://docs.coderabbit.ai/guides/configure-coderabbit) for more information. - If your editor has YAML language server enabled, you can add the path at the top of this file to enable auto-completion and validation: `# yaml-language-server: $schema=https://coderabbit.ai/integrations/schema.v2.json` ### Documentation and Community - Visit our [Documentation](https://coderabbit.ai/docs) for detailed information on how to use CodeRabbit. - Join our [Discord Community](https://discord.com/invite/GsXnASn26c) to get help, request features, and share feedback. - Follow us on [X/Twitter](https://twitter.com/coderabbitai) for updates and announcements.
simonwo commented 5 months ago

@coderabbitai review