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

feat: stream workflow logs #379

Merged
merged 2 commits into from
Jun 22, 2024
Merged

feat: stream workflow logs #379

merged 2 commits into from
Jun 22, 2024

Conversation

morgante
Copy link
Contributor

@morgante morgante commented Jun 22, 2024

Expose hooks for emitting logs from workflows to Grit Cloud.

Greptile Summary

This is an auto-generated summary

  • Added workflow_server dependency to server feature in Cargo.toml
  • Introduced emit_log method to JSONLineMessenger in jsonl.rs
  • Added emit_log method to MessengerVariant in messenger_variant.rs
  • Enhanced FormattedMessager and TransformedMessenger with new log levels and emit_log in result_formatting.rs
  • Implemented emit_log method in Messager trait in emit.rs

Summary by CodeRabbit

  • New Features

    • Added logging functionality with various log levels (debug, info, warn, error) to the messaging system.
    • Introduced SimpleLogMessage for structured logging with metadata support.
    • Enhanced testing capabilities with new log count tracking in TestingMessenger.
  • Improvements

    • Expanded AnalysisLogLevel to include more traits for better serialization and copying.
    • Updated logging methods across different messenger variants to support the new log levels.

@morgante morgante marked this pull request as ready for review June 22, 2024 03:32
@morgante morgante requested a review from a team as a code owner June 22, 2024 03:32
Copy link
Contributor

coderabbitai bot commented Jun 22, 2024

Walkthrough

Walkthrough

The changes introduce enhanced logging capabilities across multiple crates, including new methods for emitting logs, updates to handle different log levels, and a new SimpleLogMessage structure for consistent log message formatting. Dependencies have been updated to support these changes, and enhancements have been made to ensure modules can log messages effectively, including testing infrastructure to account for log-related metrics.

Changes

File Change Summary
crates/cli/Cargo.toml Updated the server dependency list to include "workflow_server".
crates/cli/src/jsonl.rs Added emit_log function to JSONLineMessenger for logging messages.
crates/cli/src/messenger_variant.rs Added emit_log method to MessengerVariant that dispatches log messages based on variants.
crates/cli/src/result_formatting.rs Added logging support for different log levels in FormattedMessager and TransformedMessenger.
crates/core/src/api.rs Enhanced AnalysisLogLevel enum to implement Deserialize, Copy, and Clone traits.
crates/marzano_messenger/src/emit.rs Added emit_log method to Messager trait for writing log messages.
crates/marzano_messenger/src/lib.rs Added and exported logs module and SimpleLogMessage struct.
crates/marzano_messenger/src/logs.rs Introduced SimpleLogMessage struct for consistent log message formatting.
crates/marzano_messenger/src/testing.rs Enhanced TestingMessenger to include a log_count field, replace message_count, and added emit_log method.

Sequence Diagram(s)

sequenceDiagram
    participant CLI_User as CLI User
    participant CLI as CLI Application
    participant JSONLMessenger as JSONLine Messenger
    participant FormattedMessenger as Formatted Messenger
    participant TransformedMessenger as Transformed Messenger
    participant LogSystem as Log System

    Note over CLI_User, LogSystem: Logging a Message Flow

    CLI_User->>CLI: Trigger Log Event
    CLI->>JSONLMessenger: emit_log(SimpleLogMessage)
    JSONLMessenger->>LogSystem: debug(SimpleLogMessage)
    
    CLI_User->>CLI: Trigger Log Event
    CLI->>FormattedMessenger: emit_log(SimpleLogMessage)
    FormattedMessenger->>LogSystem: Log based on LogLevel
    
    CLI_User->>CLI: Trigger Log Event
    CLI->>TransformedMessenger: emit_log(SimpleLogMessage)
    TransformedMessenger->>LogSystem: Log based on LogLevel
Loading

Recent review details

Configuration used: .coderabbit.yaml
Review profile: CHILL

Commits

Files that changed from the base of the PR and between b012f71 and 2b71d3c.

Files selected for processing (9)
  • crates/cli/Cargo.toml (1 hunks)
  • crates/cli/src/jsonl.rs (1 hunks)
  • crates/cli/src/messenger_variant.rs (1 hunks)
  • crates/cli/src/result_formatting.rs (3 hunks)
  • crates/core/src/api.rs (1 hunks)
  • crates/marzano_messenger/src/emit.rs (2 hunks)
  • crates/marzano_messenger/src/lib.rs (1 hunks)
  • crates/marzano_messenger/src/logs.rs (1 hunks)
  • crates/marzano_messenger/src/testing.rs (2 hunks)
Files not reviewed due to errors (1)
  • crates/cli/src/result_formatting.rs (no review received)
Additional context used
Learnings (1)
Common learnings
User: morgante
URL: https://github.com/getgrit/gritql/pull/231

Timestamp: 2024-04-15T05:47:47.743Z
Learning: User morgante prefers not to be asked for documentation.
Additional comments not posted (12)
crates/marzano_messenger/src/lib.rs (2)

3-3: Modularization of logging functionality.

Adding a separate logs module helps in organizing logging-related functionalities, which is a good practice for maintainability and scalability.


8-8: Exporting SimpleLogMessage.

Exporting SimpleLogMessage from logs module makes it accessible to other modules, aligning with the encapsulation and reusability principles.

crates/marzano_messenger/src/logs.rs (2)

1-2: Import statements for dependencies.

The import of AnalysisLogLevel and serialization libraries (Deserialize, Serialize) are essential for the functionality of SimpleLogMessage. This is correctly implemented.


4-9: Definition of SimpleLogMessage.

The struct SimpleLogMessage is well-defined with necessary fields for message content, log level, and optional metadata. Using Option for metadata is a good choice for flexibility.

crates/marzano_messenger/src/testing.rs (3)

11-19: Initialization of TestingMessenger.

The initialization of log_count along with message_count in the constructor is a necessary update to support the new logging functionality.


22-23: Method to calculate total interactions.

The method total_count which sums up log_count and message_count provides a comprehensive count of all interactions, useful for testing and debugging.


39-42: Implementation of emit_log in TestingMessenger.

The method emit_log correctly increments log_count and handles the result appropriately. This aligns with the added logging functionality.

crates/cli/src/jsonl.rs (1)

48-51: Implementation of emit_log method.

The emit_log method correctly logs messages at the debug level, which is consistent with the purpose of the function. The use of structured logging ({:?} for log) is appropriate for debugging.

crates/cli/Cargo.toml (1)

123-124: Approved addition of the workflow_server feature.

The addition is correctly placed and matches the project's architectural requirements for enhancing workflow functionalities.

crates/cli/src/messenger_variant.rs (1)

52-64: Well-implemented logging dispatch in MessengerVariant.

The emit_log method correctly handles log dispatching across different messengers, utilizing feature flags effectively to manage conditional compilation. This is crucial for maintaining modular and clean code in feature-rich applications.

crates/marzano_messenger/src/emit.rs (1)

248-250: Approved implementation of the emit_log method in Messager trait.

The method provides a default implementation that can be overridden by specific messengers, adhering to Rust's design patterns for extensible traits.

crates/core/src/api.rs (1)

671-671: Enhanced AnalysisLogLevel Enum

The AnalysisLogLevel enum has been updated to include the Debug level and the traits Deserialize, Copy, and Clone have been added. This change aligns with the PR's objective to enhance logging capabilities by providing more granular control over log levels.

Warning

Review ran into problems

Problems (1)
  • Git: Failed to clone repository. Please contact CodeRabbit support.

Thank you for using CodeRabbit. We offer it for free to the OSS community and would appreciate your support in helping us grow. If you find it useful, would you consider giving us a shout-out on your favorite social media?

Share
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.
    • @coderabbitai help me debug CodeRabbit configuration file.

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 an incremental review. This is useful when automatic reviews are disabled for the repository.
  • @coderabbitai full review to do a full review from scratch and review all the files again.
  • @coderabbitai summary to regenerate the summary of the PR.
  • @coderabbitai resolve resolve all the CodeRabbit review comments.
  • @coderabbitai configuration to show the current CodeRabbit configuration for the repository.
  • @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.

Copy link

@greptile-apps greptile-apps bot left a comment

Choose a reason for hiding this comment

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

LGTM

8 file(s) reviewed, no comment(s)

@morgante morgante merged commit 3fcba75 into main Jun 22, 2024
10 checks passed
@morgante morgante deleted the stream-workflow-logs branch June 22, 2024 03:44
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
None yet
Projects
None yet
Development

Successfully merging this pull request may close these issues.

None yet

1 participant