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

feature: separation of application and server output #90

Draft
wants to merge 5 commits into
base: master
Choose a base branch
from

Conversation

Kaspiman
Copy link
Contributor

@Kaspiman Kaspiman commented Oct 22, 2024

Reason for This PR

[💡 FEATURE REQUEST]: Improve clarity of worker errors when starting a server

Description of Changes

Separation of logs from the application and plugin for their separate configuration. I left comments on the code.

License Acceptance

By submitting this pull request, I confirm that my contribution is made under
the terms of the MIT license.

PR Checklist

[Author TODO: Meet these criteria.]
[Reviewer TODO: Verify that these criteria are met. Request changes if not]

  • All commits in this PR are signed (git commit -s).
  • The reason for this PR is clearly provided (issue no. or explanation).
  • The description of changes is clear and encompassing.
  • Any required documentation changes (code and docs) are included in this PR.
  • Any user-facing changes are mentioned in CHANGELOG.md.
  • All added/changed functionality is tested.

Summary by CodeRabbit

  • New Features

    • Introduced a dedicated application logger for improved logging capabilities.
    • Enhanced separation of application-specific logs from server logs.
  • Bug Fixes

    • Updated logging behavior to prevent interference between application and server logs.

Copy link

coderabbitai bot commented Oct 22, 2024

Walkthrough

The changes involve modifications to the command and Plugin structs in the init.go and plugin.go files, respectively. A new field appLog, a logger for application-specific logs, has been added to both structs. The newCommand constructor and the Init method of the Plugin struct have been updated to accommodate this new logger. The Write method in init.go now uses appLog for logging application outputs, ensuring a separation from server logs. The overall control flow and error handling remain unchanged.

Changes

File Change Summary
init.go - Added field appLog *zap.Logger to command struct.
- Updated newCommand to accept appLog.
- Modified Write method to utilize appLog for application logging.
plugin.go - Added field appLog *zap.Logger to Plugin struct.
- Updated Init method to instantiate appLog.
- Modified Serve method to pass appLog to newCommand.
- Added constant AppLoggerChannel for application logger naming.

Poem

In the code where rabbits hop,
New logs for apps now take the top.
With appLog bright, the paths are clear,
No server logs to interfere!
Hopping through changes, we sing with glee,
For better logs, oh what a spree! 🐇✨


📜 Recent review details

Configuration used: CodeRabbit UI
Review profile: CHILL

📥 Commits

Reviewing files that changed from the base of the PR and between 340f5c6 and be2a9cd.

📒 Files selected for processing (1)
  • init.go (2 hunks)
🚧 Files skipped from review as they are similar to previous changes (1)
  • init.go

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>, please review it.
    • 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 gather interesting stats about this repository and render them as a table. Additionally, render a pie chart showing the language distribution in the codebase.
    • @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 using 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.

Other keywords and placeholders

  • Add @coderabbitai ignore anywhere in the PR description to prevent this PR from being reviewed.
  • Add @coderabbitai summary to generate the high-level summary at a specific location in the PR description.
  • Add @coderabbitai anywhere in the PR title to generate the title automatically.

CodeRabbit Configuration 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

codecov bot commented Oct 22, 2024

Welcome to Codecov 🎉

Once you merge this PR into your default branch, you're all set! Codecov will compare coverage reports and display results in all future pull requests.

Thanks for integrating Codecov - We've got you covered ☂️

Copy link

@coderabbitai coderabbitai bot left a comment

Choose a reason for hiding this comment

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

Actionable comments posted: 0

🧹 Outside diff range and nitpick comments (2)
init.go (1)

21-26: LGTM with a minor suggestion: Update to newCommand function

The changes to the newCommand function correctly incorporate the new appLog parameter and initialize it in the returned command struct. This is consistent with the modifications to the command struct.

Consider maintaining the order of fields in the struct initialization to match the order in the struct definition for better readability:

 return &command{
 	log:    log,
+	appLog: appLog,
 	cfg:    cfg,
-	appLog: appLog,
 }
plugin.go (1)

59-62: LGTM with a minor suggestion

The initialization of appLog is well-implemented and aligns with the goal of separating application and server logs.

Consider using a constant for the "app" logger name to improve maintainability. For example:

const AppLoggerName = "app"
// ...
p.appLog = log.NamedLogger(AppLoggerName)

This would make it easier to change the name in the future if needed and ensure consistency if it's used elsewhere in the codebase.

📜 Review details

Configuration used: CodeRabbit UI
Review profile: CHILL

📥 Commits

Files that changed from the base of the PR and between 9992baf and 83e3af4.

📒 Files selected for processing (2)
  • init.go (2 hunks)
  • plugin.go (3 hunks)
🧰 Additional context used
🔇 Additional comments (6)
init.go (3)

16-18: LGTM: Addition of appLog field to command struct

The addition of the appLog field to the command struct is a good step towards separating application and server output. This change aligns with the PR objectives and is correctly implemented.


Line range hint 1-124: Overall changes look good, verify impact on wider codebase

The modifications to init.go successfully implement the separation of application and server output, which aligns with the PR objectives. The core functionality of the command struct and its methods has been preserved while introducing the new appLog for application-specific logging.

To ensure the changes are fully integrated and don't introduce any inconsistencies:

  1. Verify that all necessary parts of the codebase have been updated to use appLog where appropriate.
  2. Check for any potential impact on existing logging practices or log consumers.

Run the following script to help identify areas that might need attention:

#!/bin/bash
# Description: Identify potential areas needing updates for appLog
# Expected results: List of files and contexts where logging is used

echo "Files potentially needing updates for appLog:"
rg -l '\blog\.' --type go | grep -v 'init.go'
echo "---"
echo "Contexts where 'log' is used (excluding init.go):"
rg '\blog\.' -C 2 --type go | grep -v 'init.go'

Review the output to ensure all relevant areas have been considered in this change.


72-78: LGTM with discussion: Updates to Write method

The changes to the Write method effectively implement the separation of application and server output, which aligns with the PR objectives. The use of appLog for application output is appropriate.

The comments provide valuable context for the changes and future considerations. However, there's a point that warrants discussion:

Regarding the suggestion to use Debug level for all output:

  1. Using Debug level could provide more granular control over log verbosity, but it might also hide important application output by default.
  2. Consider the implications on production environments where Debug logs might be disabled.

To help make an informed decision, let's analyze the current logging practices in the project:

Based on the results of this analysis, we can make a more informed decision about the appropriate log level for application output.

✅ Verification successful

Further Analysis Required: Assess Log Level Distribution

To evaluate the proposal of using the Debug level for application output, we need to understand the current distribution of log levels within the project.

[/run_scripts]


Action Required: Re-run Log Level Analysis with Case-Insensitive Search

To accurately count the occurrences of each log level, please execute the following updated script that performs a case-insensitive search:

[/run_scripts]


LGTM with Approval: Logging Level Adjustment Confirmed

The analysis confirms that only log.Error instances are present in the current codebase. Switching the application output to Debug level will not obscure any existing logs and allows for more granular control over log verbosity in the future.

🏁 Scripts executed

The following scripts were executed for the analysis:

Script:

#!/bin/bash
# Description: Analyze current logging practices
# Expected results: Overview of log level usage across the project

echo "Analyzing log level usage:"
rg -i '\blog\.(debug|info|warn|error|fatal)' --stats
echo "---"
echo "Checking for configurable log levels:"
rg -i 'log.*level' -A 5 -B 5

Length of output: 2329


Script:

#!/bin/bash
# Description: Count occurrences of each log level in the codebase
# Expected results: Number of times each log level (Debug, Info, Warn, Error, Fatal) is used

echo "Counting log level usages:"
rg -o '\blog\.(debug|info|warn|error|fatal)' --no-filename | sort | uniq -c | sort -nr

Length of output: 151


Script:

#!/bin/bash
# Description: Count occurrences of each log level in the codebase (case-insensitive)
# Expected results: Number of times each log level (Debug, Info, Warn, Error, Fatal) is used

echo "Counting log level usages (case-insensitive):"
rg -oi '\blog\.(debug|info|warn|error|fatal)' --no-filename | sort | uniq -c | sort -nr

Length of output: 208

plugin.go (3)

29-30: LGTM: Addition of appLog field

The addition of the appLog field to the Plugin struct is a good step towards separating application and server output. This change aligns well with the PR objectives.


Line range hint 1-191: Overall assessment: Changes look good

The modifications to plugin.go consistently implement the separation of application and server logs, aligning well with the PR objectives. The changes are well-structured and maintain the existing code quality.

Key points:

  1. The appLog field is appropriately added to the Plugin struct.
  2. The Init method correctly initializes the new logger.
  3. The Serve method is updated to use the new logger in the newCommand call.

Please address the minor suggestion about using a constant for the logger name and verify the newCommand function signature in init.go as mentioned in the previous comments.


107-107: LGTM: Updated newCommand call

The modification to include p.appLog in the newCommand call is consistent with the goal of separating application and server logs.

To ensure consistency across the codebase, please verify that the newCommand function in init.go has been updated to accept this additional logger parameter. Run the following script to check the newCommand function signature:

This will help confirm that the changes are properly implemented across both files.

✅ Verification successful

Verification Successful: newCommand function updated correctly

The newCommand function in init.go has been updated to accept appLog as an additional parameter, aligning with the changes in plugin.go.

🏁 Scripts executed

The following scripts were executed for the analysis:

Script:

#!/bin/bash
# Description: Verify the newCommand function signature in init.go

# Test: Search for the newCommand function definition
rg -A 5 'func newCommand\(' init.go

Length of output: 187

@rustatian rustatian marked this pull request as draft October 22, 2024 14:32
@rustatian rustatian self-requested a review October 22, 2024 14:32
@rustatian rustatian added the enhancement New feature or request label Oct 22, 2024
@rustatian
Copy link
Member

Added this repo to the @roadrunner-server/contributors team, so, you won't need to do forks.

@rustatian rustatian changed the title Draft: Separation of application and server output feature: separation of application and server output Oct 22, 2024
@Kaspiman Kaspiman marked this pull request as ready for review November 6, 2024 08:11
init.go Outdated
b.log.Info(string(data))
// All output from the application does not intersect with logs from the Server plugin
// For example: destroy signal received {"timeout": 60000000000} is not necessary for logging
b.appLog.Error(string(data))
Copy link
Member

Choose a reason for hiding this comment

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

I do think this'd be confusing to use. Since ERROR is not the same as STDERR. Like, every stderr log message would be treated as an error. And imagine a user's face after seeing tons of strange-looking errors which are not errors.
INFO log level is also not a good choice here, so in the discussion I mentioned, that appropriate solution for that would be to exchange a log severity information between RR and PHP worker similar to what we're doing in the temporal plugin.

Copy link
Contributor Author

Choose a reason for hiding this comment

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

This is a fairly simple task, it is solved out of the box in PHP-FPM, see catch_workers_output.

We just need to separate the application output from the server and nothing more. No plugins or additional settings are needed for this. In essence, with this feature we get rid of the AppLogger plugin. I think this plugin was created precisely because there was no easy way to separate application logs. The level of info is quite suitable.

I still don't understand: what needs to be done as in the "temporal" plugin. The main thing is why?

Copy link
Member

Choose a reason for hiding this comment

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

If you want to match with catch_workers_output it should be the same option and raw output to the main log (file, stdout or stderr). You can't just change the log to be shown as errors.
AppLogger was not created to handle this case, this is a completely separate feature which was requested by users to solve other needs.

Copy link
Contributor Author

Choose a reason for hiding this comment

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

"this is a completely separate feature" look at this:

AppLogger: send raw logs to app channel from app by RPC.

This feature: send raw logs to app channel from app by stdout/err and config:

logs:
  channels:
     app:
       level: debug
       mode: raw

With a little changes, you can do the same thing that the AppLogger plugin does, but much easier: without RPC, plugin, app-logger php package and additional packages for Monolog and other loggers.

Is there any other reason for the AppLogger's existence?

Copy link
Member

@rustatian rustatian Nov 7, 2024

Choose a reason for hiding this comment

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

App logger was requested by PHP devs and advised to include by PHP devs. This plugin won't be removed. For the reasoning, please, use GitHub search, this is an OSS project, all discussions about all features are open for everyone.

Returning to the original issue:
Like you mentioned for the applogger, the same you can achieve with the server logger channel for your proposed change with info log level.

logs:
  channels:
     server:
       level: info
       mode: raw

Your appLogger info log (in the PR) won't solve any problem here, because it'd be hidden from the user in the same way the current server log is hidden when not configured to show info logs from the server plugin.

Copy link
Contributor Author

Choose a reason for hiding this comment

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

I did not offer to remove the AppLogger plugin, I only showed its optionality. I use it myself and is forced to additionally configure the logger through the plugins. Cool, if you can solve the problem only with the help of configuration without writing code.

I suggest not just add some hidden app channel. I propose an idea that can be implemented in the future release (maybe 2025).

Idea: There is always an app channel and it always comes out of the PHP-processes. It is configured in a certain way out of the box. This behavior is superior and does not scare users.

Copy link
Member

Choose a reason for hiding this comment

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

I guess this is a good idea, but it should not be connected to the existing logger then. It should be controlled by the similar to FPM options (?), like catch_workers_output and just output to stderr/stdout what the worker sent.

Signed-off-by: Plakhotnikov Vladimir <[email protected]>
@rustatian rustatian marked this pull request as draft November 10, 2024 21:40
@rustatian
Copy link
Member

@Kaspiman Do you have plans to do something in this PR according our last discussion or it can be closed?

@Kaspiman
Copy link
Contributor Author

@Kaspiman Do you have plans to do something in this PR according our last discussion or it can be closed?

Yep, I just need some free time in real life...

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
enhancement New feature or request
Projects
None yet
Development

Successfully merging this pull request may close these issues.

2 participants