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

fix:Optimize the default log path configuration #5251

Merged

Conversation

youngzil
Copy link
Contributor

@youngzil youngzil commented Oct 17, 2024

What's the purpose of this PR

  1. Optimize the default log path configuration

Which issue(s) this PR fixes:

Fixes #

Brief changelog

XXXXX

Follow this checklist to help us incorporate your contribution quickly and easily:

  • Read the Contributing Guide before making this pull request.
  • Write a pull request description that is detailed enough to understand what the pull request does, how, and why.
  • Write necessary unit tests to verify the code.
  • Run mvn clean test to make sure this pull request doesn't break anything.
  • Update the CHANGES log.

Summary by CodeRabbit

Summary by CodeRabbit

  • New Features

    • Enhanced logging configuration for improved flexibility in log management.
  • Documentation

    • Updated Apollo development guides for clearer local setup instructions, including database requirements and running configurations.
    • Corrected default log output path and clarified service health verification steps.

1. Optimize the default log path configuration
2. Fixed the error that the log file does not exist when starting locally
@dosubot dosubot bot added the size:S This PR changes 10-29 lines, ignoring generated files. label Oct 17, 2024
Copy link
Contributor

coderabbitai bot commented Oct 17, 2024

Walkthrough

The pull request updates the documentation for local development in both English and Chinese, enhancing clarity regarding the setup requirements, particularly emphasizing the necessity of MySQL for database creation. Instructions for running configurations and verifying service health have been detailed. Additionally, the logging file paths in application.yml and configservice.properties have been simplified by removing a numeric directory component. No alterations were made to exported or public entity declarations.

Changes

File Path Change Summary
apollo-assembly/src/main/resources/application.yml Updated logging file path: /opt/logs/100003171/apollo-assembly.log/opt/logs/apollo-assembly.log.
apollo-configservice/src/main/resources/configservice.properties Updated logging file path: /opt/logs/100003171/apollo-configservice.log/opt/logs/apollo-configservice.log.
docs/en/contribution/apollo-development-guide.md Enhanced clarity on local development setup, updated requirements, and detailed instructions.
docs/zh/contribution/apollo-development-guide.md Enhanced clarity on local development setup, updated requirements, and detailed instructions.

Possibly related PRs

  • feat: ConfigService cache record stats #5247: The changes in the main PR regarding the documentation of MySQL requirements and local development setup are related to the enhancements made in the ConfigService to monitor cache statistics, as both involve improving the configuration and operational aspects of the Apollo system.

Suggested labels

size:L, lgtm

Suggested reviewers

  • nobodyiam

Poem

In the burrow where logs do flow,
Paths and names now clearly show.
With guides in hand, we leap and bound,
In Apollo's world, new joys abound! 🐇✨
MySQL or H2, we choose with glee,
Configurations set, oh what a spree!


📜 Recent review details

Configuration used: CodeRabbit UI
Review profile: CHILL

📥 Commits

Files that changed from the base of the PR and between 6857deb and 3262f28.

📒 Files selected for processing (1)
  • apollo-configservice/src/main/resources/configservice.properties (1 hunks)
🧰 Additional context used
🔇 Additional comments (1)
apollo-configservice/src/main/resources/configservice.properties (1)

19-19: ⚠️ Potential issue

Consider using environment-specific log paths

While simplifying the log path is good, using /opt/logs directly may cause permission issues in local development environments. Consider:

  1. Using a relative path for local development
  2. Leveraging Spring profiles to handle different environments
  3. Using system properties or environment variables for flexibility

Example configuration approach:

# Default fallback for local development
logging.file.name=./logs/apollo-configservice.log

# Can be overridden via environment-specific properties files
# configservice-{profile}.properties

Let's check if there are any environment-specific configurations already in place:


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
Contributor

@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: 1

🧹 Outside diff range and nitpick comments (4)
apollo-configservice/src/main/resources/application.yml (1)

36-37: Approve changes with suggestions for improvement

The changes to the logging configuration align well with the PR objectives. Splitting logging.file.name into logging.file.path and logging.file.name leverages Spring Boot 2.3+ features to automatically create log files, addressing the local startup issue.

Suggestions for improvement:

  1. Consider using environment-specific configurations for the log path. The hard-coded /opt/logs might not be suitable for all environments, especially for local development.
  2. Verify that similar changes have been made in other application.yml files (e.g., for apollo-adminservice and apollo-assembly) to maintain consistency across the project.
  3. Add a comment explaining the reason for this configuration change, to provide context for future developers.

Example implementation:

logging:
  file:
    # Split logging configuration to leverage Spring Boot 2.3+ automatic log file creation
    path: ${APOLLO_LOG_DIR:/opt/logs}
    name: apollo-configservice.log

This uses an environment variable APOLLO_LOG_DIR with a default fallback to /opt/logs, allowing for more flexible configuration across different environments.

docs/zh/contribution/apollo-development-guide.md (1)

69-69: LGTM! Consider adding a note about directory creation.

The added information about modifying the log file path is accurate and helpful. It aligns well with the PR objective of optimizing the default log path configuration.

Consider adding a note that the specified directory should exist or be created by the user before starting the application. This can help prevent potential issues for users who might specify a non-existent directory.

docs/en/contribution/apollo-development-guide.md (2)

78-80: Clarify log file configuration

The note about the default log output path has been updated, but there's a small issue with the wording. Consider revising it for clarity:

- >Note 3: The default log output of the program is /opt/logs/apollo-assembly.log, if you need to modify the log file path, you can add the `logging.file.name` parameter, as follows.
+ >Note 3: The default log output path of the program is /opt/logs/apollo-assembly.log. If you need to modify the log file path, you can add the `logging.file.name` parameter, as follows:

This change improves readability and corrects the grammar issue flagged by the static analysis tool.

🧰 Tools
🪛 LanguageTool

[grammar] ~78-~78: “Default” is a singular noun. It appears that the verb form is incorrect.
Context: ...olloportaldb.sql) >Note 3: The default log output of the program is /opt/logs/apol...

(PCT_SINGULAR_NOUN_PLURAL_VERB_AGREEMENT)


[style] ~78-~78: You have already used this phrasing in nearby sentences. Consider replacing it to add variety to your writing.
Context: ...s /opt/logs/apollo-assembly.log, if you need to modify the log file path, you can add t...

(REP_NEED_TO_VB)


Line range hint 113-117: Improved sample client setup instructions

The updates to both Java and .Net sample client setup instructions are excellent. They provide clearer guidance on configuring the project AppId and explain its importance in the Apollo ecosystem. This will help developers better understand how Apollo works with different applications.

For consistency, consider adding a note about the importance of AppId in the .Net section similar to the one in the Java section:

> Note: AppId is the unique identity of the application, which is used by Apollo clients to get the application's own private Namespace configuration.

> For public Namespace configurations, you can get the configuration without the AppId, but then you lose the ability for the application to override the public Namespace configuration.

This addition would ensure that .Net developers have the same level of understanding as Java developers regarding the significance of AppId.

Also applies to: 149-153, 176-180

🧰 Tools
🪛 LanguageTool

[grammar] ~78-~78: “Default” is a singular noun. It appears that the verb form is incorrect.
Context: ...olloportaldb.sql) >Note 3: The default log output of the program is /opt/logs/apol...

(PCT_SINGULAR_NOUN_PLURAL_VERB_AGREEMENT)


[style] ~78-~78: You have already used this phrasing in nearby sentences. Consider replacing it to add variety to your writing.
Context: ...s /opt/logs/apollo-assembly.log, if you need to modify the log file path, you can add t...

(REP_NEED_TO_VB)

📜 Review details

Configuration used: CodeRabbit UI
Review profile: CHILL

📥 Commits

Files that changed from the base of the PR and between 4bdf66a and 2c27d0f.

📒 Files selected for processing (5)
  • apollo-adminservice/src/main/resources/application.yml (1 hunks)
  • apollo-assembly/src/main/resources/application.yml (1 hunks)
  • apollo-configservice/src/main/resources/application.yml (1 hunks)
  • docs/en/contribution/apollo-development-guide.md (1 hunks)
  • docs/zh/contribution/apollo-development-guide.md (1 hunks)
🧰 Additional context used
🪛 LanguageTool
docs/en/contribution/apollo-development-guide.md

[grammar] ~78-~78: “Default” is a singular noun. It appears that the verb form is incorrect.
Context: ...olloportaldb.sql) >Note 3: The default log output of the program is /opt/logs/apol...

(PCT_SINGULAR_NOUN_PLURAL_VERB_AGREEMENT)


[style] ~78-~78: You have already used this phrasing in nearby sentences. Consider replacing it to add variety to your writing.
Context: ...s /opt/logs/apollo-assembly.log, if you need to modify the log file path, you can add t...

(REP_NEED_TO_VB)

🔇 Additional comments (5)
apollo-adminservice/src/main/resources/application.yml (1)

36-37: Approved: Improved logging configuration

This change optimizes the default log path configuration by separating the log file path and name. It aligns with Spring Boot best practices (version 2.3+) and addresses the issue mentioned in the PR description where log files weren't automatically created.

Benefits:

  1. Increased flexibility in managing log locations.
  2. Maintains consistency with the previous log file path and name.
  3. Allows Spring Boot to automatically create the log file, preventing startup errors due to missing log files.
apollo-assembly/src/main/resources/application.yml (1)

33-34: Approve: Improved logging configuration

The changes to the logging configuration are well-implemented and align with Spring Boot best practices. By separating the path and name properties, this configuration:

  1. Allows Spring Boot to automatically create the log directory if it doesn't exist, preventing startup errors.
  2. Maintains the same effective log file path (/opt/logs/apollo-assembly.log).
  3. Improves flexibility for future changes to either the log directory or file name.

This change successfully addresses the PR objective of optimizing the default log path configuration and resolves the issue of log files not being created automatically when starting the application locally.

docs/en/contribution/apollo-development-guide.md (3)

Line range hint 12-14: Improved clarity on database requirements

The changes in this section provide better guidance on the local runtime environment requirements. The addition of the H2 database option offers more flexibility for developers, which is particularly useful for those who prefer not to set up MySQL for local development.

🧰 Tools
🪛 LanguageTool

[grammar] ~78-~78: “Default” is a singular noun. It appears that the verb form is incorrect.
Context: ...olloportaldb.sql) >Note 3: The default log output of the program is /opt/logs/apol...

(PCT_SINGULAR_NOUN_PLURAL_VERB_AGREEMENT)


[style] ~78-~78: You have already used this phrasing in nearby sentences. Consider replacing it to add variety to your writing.
Context: ...s /opt/logs/apollo-assembly.log, if you need to modify the log file path, you can add t...

(REP_NEED_TO_VB)


Line range hint 60-73: Improved MySQL configuration instructions

The added details for MySQL database configuration are very helpful. They provide clear instructions on how to set up the necessary VM options for both the Config and Portal databases, which will make it easier for developers to get started with a MySQL setup.

🧰 Tools
🪛 LanguageTool

[grammar] ~78-~78: “Default” is a singular noun. It appears that the verb form is incorrect.
Context: ...olloportaldb.sql) >Note 3: The default log output of the program is /opt/logs/apol...

(PCT_SINGULAR_NOUN_PLURAL_VERB_AGREEMENT)


[style] ~78-~78: You have already used this phrasing in nearby sentences. Consider replacing it to add variety to your writing.
Context: ...s /opt/logs/apollo-assembly.log, if you need to modify the log file path, you can add t...

(REP_NEED_TO_VB)


Line range hint 91-103: Valuable addition of health check instructions

The new instructions for verifying service health through the Eureka interface and health check endpoints are excellent additions. They provide developers with clear steps to confirm that their services are running correctly, which is crucial for local development and troubleshooting.

🧰 Tools
🪛 LanguageTool

[grammar] ~78-~78: “Default” is a singular noun. It appears that the verb form is incorrect.
Context: ...olloportaldb.sql) >Note 3: The default log output of the program is /opt/logs/apol...

(PCT_SINGULAR_NOUN_PLURAL_VERB_AGREEMENT)


[style] ~78-~78: You have already used this phrasing in nearby sentences. Consider replacing it to add variety to your writing.
Context: ...s /opt/logs/apollo-assembly.log, if you need to modify the log file path, you can add t...

(REP_NEED_TO_VB)

Comment on lines 33 to 34
path: /opt/logs
name: apollo-assembly.log
Copy link
Contributor

Choose a reason for hiding this comment

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

💡 Codebase verification

Issues Detected with Logging Configuration

  • The log directory /opt/logs does not exist.
  • The log file apollo-assembly.log is missing.

These issues may prevent the application from logging correctly, which can hinder troubleshooting and monitoring. Please address the missing log directory and file to ensure proper logging functionality.

🔗 Analysis chain

Verify the new logging configuration

While the changes look good, it's important to verify that they work as expected in different environments. Please ensure:

  1. The log file is created at /opt/logs/apollo-assembly.log when the application starts.
  2. The application starts without any logging-related errors.
  3. Log entries are correctly written to the new file.
  4. The changes work consistently across all environments (development, staging, production).

To assist with verification, you can run the following script:

This script will help verify the existence and permissions of the log directory and file, check for any logging-related errors, and ensure the application is logging correctly.

🏁 Scripts executed

The following scripts were executed for the analysis:

Script:

#!/bin/bash
# Description: Verify the new logging configuration

# Check if the log directory exists
if [ -d "/opt/logs" ]; then
  echo "Log directory exists: /opt/logs"
else
  echo "Error: Log directory does not exist: /opt/logs"
fi

# Check if the log file exists
if [ -f "/opt/logs/apollo-assembly.log" ]; then
  echo "Log file exists: /opt/logs/apollo-assembly.log"
  
  # Check if the log file is writable
  if [ -w "/opt/logs/apollo-assembly.log" ]; then
    echo "Log file is writable"
  else
    echo "Error: Log file is not writable"
  fi
  
  # Check for any error messages related to logging in the log file
  if grep -i "error" "/opt/logs/apollo-assembly.log"; then
    echo "Warning: Found error messages in the log file"
  else
    echo "No error messages found in the log file"
  fi
else
  echo "Error: Log file does not exist: /opt/logs/apollo-assembly.log"
fi

# Check for any logging-related error messages in the application output
if journalctl -u apollo-assembly | grep -i "error.*logging"; then
  echo "Warning: Found logging-related error messages in the application output"
else
  echo "No logging-related error messages found in the application output"
fi

Length of output: 580

@nobodyiam
Copy link
Member

Is it only for local development? As there are logics to create the log folders in the startup.sh

## Create log directory if not existed because JDK 8+ won't do that
mkdir -p $LOG_DIR
# Create directory of -XX:HeapDumpPath
mkdir -p $LOG_DIR/HeapDumpOnOutOfMemoryError/

@youngzil
Copy link
Contributor Author

Is it only for local development? As there are logics to create the log folders in the startup.sh

## Create log directory if not existed because JDK 8+ won't do that
mkdir -p $LOG_DIR
# Create directory of -XX:HeapDumpPath
mkdir -p $LOG_DIR/HeapDumpOnOutOfMemoryError/

Yes, it is currently a problem in local development

@nobodyiam
Copy link
Member

It doesn't work for me. The apollo-assembly.log was created in the current folder, likely because the /opt directory requires root access for creation. Additionally, I don't think this's an essential feature so I would prefer leaving it as is.
However, it's nice to change the assembly log file to /opt/logs/apollo-assembly.log.

@youngzil
Copy link
Contributor Author

It doesn't work for me. The apollo-assembly.log was created in the current folder, likely because the /opt directory requires root access for creation. Additionally, I don't think this's an essential feature so I would prefer leaving it as is. However, it's nice to change the assembly log file to /opt/logs/apollo-assembly.log.

Hi, you are right. I did a test and changed the path to a non-existent path under $HOME and found that it can start normally.
So I'm going to revert this change

@dosubot dosubot bot added size:XS This PR changes 0-9 lines, ignoring generated files. and removed size:S This PR changes 10-29 lines, ignoring generated files. labels Oct 21, 2024
Copy link
Member

@nobodyiam nobodyiam left a comment

Choose a reason for hiding this comment

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

LGTM

@dosubot dosubot bot added the lgtm This PR has been approved by a maintainer label Oct 26, 2024
@nobodyiam nobodyiam merged commit ced6383 into apolloconfig:master Oct 26, 2024
7 checks passed
@github-actions github-actions bot locked and limited conversation to collaborators Oct 26, 2024
@youngzil youngzil deleted the fix/optimize-default-log-path-config branch October 27, 2024 03:50
Sign up for free to subscribe to this conversation on GitHub. Already have an account? Sign in.
Labels
lgtm This PR has been approved by a maintainer size:XS This PR changes 0-9 lines, ignoring generated files.
Projects
None yet
Development

Successfully merging this pull request may close these issues.

2 participants