Skip to content
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

Structured events in place of comment strings #3771

Merged
merged 12 commits into from
Apr 14, 2024
Merged

Structured events in place of comment strings #3771

merged 12 commits into from
Apr 14, 2024

Conversation

simonwo
Copy link
Contributor

@simonwo simonwo commented Apr 10, 2024

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

  • Add more documentation
  • Sort execution histories by time DESC so that most relevant execution is first
  • Do some more examples of using structured errors from compute node components

@simonwo simonwo added the type/enhancement Type: New features or enhancements to existing features label Apr 10, 2024
@simonwo simonwo self-assigned this Apr 10, 2024
Copy link

coderabbitai bot commented Apr 10, 2024

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:

  • Review comments: Directly reply to a review comment made by CodeRabbit. Example:
    • I pushed a fix in commit <commit_id>.
    • 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 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 for detailed information on how to use CodeRabbit.
  • Join our Discord Community to get help, request features, and share feedback.
  • Follow us on X/Twitter for updates and announcements.

@simonwo
Copy link
Contributor Author

simonwo commented Apr 10, 2024

@coderabbitai review

@simonwo simonwo force-pushed the simonwo/events branch 2 times, most recently from fc39cb6 to 4cdc5b8 Compare April 11, 2024 00:53
Copy link
Contributor

@rossjones rossjones left a comment

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

LGTM, although I have added a couple of minor comments about impl/structure of the event struct.

pkg/models/error.go Outdated Show resolved Hide resolved
pkg/models/error.go Outdated Show resolved Hide resolved
pkg/models/job_history.go Outdated Show resolved Hide resolved
@simonwo simonwo marked this pull request as ready for review April 12, 2024 02:00
@simonwo simonwo force-pushed the simonwo/events branch 2 times, most recently from 1c0ec43 to 9998bc1 Compare April 12, 2024 04:54
pkg/compute/events.go Outdated Show resolved Hide resolved
pkg/compute/executor_buffer.go Show resolved Hide resolved
cmd/cli/job/describe.go Outdated Show resolved Hide resolved
cmd/cli/job/describe.go Outdated Show resolved Hide resolved
@wdbaruni wdbaruni merged commit f453e32 into main Apr 14, 2024
12 checks passed
@wdbaruni wdbaruni deleted the simonwo/events branch April 14, 2024 22:40
aronchick pushed a commit that referenced this pull request Apr 27, 2024
This PR implements the structure proposed in [Improve Error
Reporting](https://www.notion.so/expanso/Improve-Error-Reporting-c19f5516822b47de980d76ff43ff4bbe)
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](https://github.com/bacalhau-project/bacalhau/assets/4951176/04e63f09-4f7e-44ed-883a-85fb4b9a7f2d)

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
bacalhau-project/expanso-planning#693.
Resolves
bacalhau-project/expanso-planning#694.

### TODO in this PR
- [x] Add more documentation
- [x] Sort execution histories by time DESC so that most relevant
execution is first
- [x] Do some more examples of using structured errors from compute node
components

---------

Co-authored-by: Ross Jones <ross@register-dynamics.co.uk>
Co-authored-by: Walid Baruni <wdbaruni@gmail.com>
This was referenced Jun 30, 2024
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
type/enhancement Type: New features or enhancements to existing features
Projects
None yet
Development

Successfully merging this pull request may close these issues.

None yet

3 participants