-
Notifications
You must be signed in to change notification settings - Fork 11
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(elk-stack-setup): add ecs logging for elastic setup #21
Conversation
Warning Rate limit exceeded@ivor11 has exceeded the limit for the number of commits or files that can be reviewed per hour. Please wait 21 minutes and 31 seconds before requesting another review. β How to resolve this issue?After the wait time has elapsed, a review can be triggered using the We recommend that you space out your commits to avoid hitting the rate limit. π¦ How do rate limits work?CodeRabbit enforces hourly rate limits for each developer per organization. Our paid plans have higher rate limits than the trial, open-source and free plans. In all cases, we re-allow further reviews after a brief timeout. Please see our FAQ for further information. WalkthroughThe changes in this pull request involve updates to the logging configuration of the project. Modifications include the addition of a new logging dependency ( Changes
Sequence Diagram(s)sequenceDiagram
participant User
participant Application
participant Logger
participant LogFile
User->>Application: Start application
Application->>Logger: Initialize logging
Logger->>LogFile: Set log file path and name
Logger->>LogFile: Log messages
LogFile->>Logger: Store logs in JSON format
Logger->>Application: Logging complete
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? πͺ§ TipsChatThere are 3 ways to chat with CodeRabbit:
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)
Other keywords and placeholders
CodeRabbit Configuration File (
|
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
Actionable comments posted: 3
π Review details
Configuration used: CodeRabbit UI
Review profile: CHILL
π Files selected for processing (5)
- pom.xml (1 hunks)
- src/main/resources/application.properties (1 hunks)
- src/main/resources/logback-spring.xml (1 hunks)
- src/main/resources/logback.xml (0 hunks)
- src/main/webapp/WEB-INF/jboss-deployment-structure.xml (1 hunks)
π€ Files with no reviewable changes (1)
- src/main/resources/logback.xml
β Files skipped from review due to trivial changes (2)
- src/main/resources/application.properties
- src/main/webapp/WEB-INF/jboss-deployment-structure.xml
π Additional comments (2)
src/main/resources/logback-spring.xml (1)
1-4
: Review logging path configuration for production readiness.The logging path configuration has several concerns:
- The fallback to
/tmp
directory might not be suitable for production as it's typically cleared on system restart.- The log file name "my-api" is generic and should reflect the actual application name (Helpline1097-API).
Consider:
- Using a more production-appropriate default path
- Renaming the log file to be more specific
- <property name="LOG_FILE" value="${LOG_FILE:-${LOG_PATH:-${LOG_TEMP:-${java.io.tmpdir:-/tmp}}}/my-api}"/> + <property name="LOG_FILE" value="${LOG_FILE:-${LOG_PATH:-${LOG_TEMP:-${java.io.tmpdir:-/var/log/helpline1097}}}/helpline1097-api}"/>pom.xml (1)
58-58
: LGTM! Spring Boot logging configuration.Removing the logging exclusion is correct as it allows Spring Boot's default logging to work with the ECS encoder.
<root level="INFO"> | ||
<appender-ref ref="CONSOLE"/> | ||
<appender-ref ref="ECS_JSON_FILE"/> | ||
</root> |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
π οΈ Refactor suggestion
Consider performance optimization and granular logging.
While the basic setup is correct, consider these improvements for better logging control and performance:
- Add async wrapper for file appender
- Add package-specific logging levels
Add these configurations before the root logger:
<appender name="ASYNC_ECS" class="ch.qos.logback.classic.AsyncAppender">
<appender-ref ref="ECS_JSON_FILE" />
<queueSize>512</queueSize>
<discardingThreshold>0</discardingThreshold>
<includeCallerData>false</includeCallerData>
</appender>
<!-- Application-specific logging -->
<logger name="com.psmri.helpline1097" level="INFO"/>
<!-- Spring Framework logging -->
<logger name="org.springframework" level="WARN"/>
<!-- Hibernate logging -->
<logger name="org.hibernate" level="WARN"/>
Then update the root logger:
<root level="INFO">
<appender-ref ref="CONSOLE"/>
- <appender-ref ref="ECS_JSON_FILE"/>
+ <appender-ref ref="ASYNC_ECS"/>
</root>
<appender name="ECS_JSON_FILE" class="ch.qos.logback.core.rolling.RollingFileAppender"> | ||
<file>${LOG_FILE}.json</file> | ||
<rollingPolicy class="ch.qos.logback.core.rolling.TimeBasedRollingPolicy"> | ||
<fileNamePattern>${LOG_FILE}.json.%d{yyyy-MM-dd}.gz</fileNamePattern> | ||
<maxFileSize>10MB</maxFileSize> | ||
<maxHistory>0</maxHistory> | ||
<totalSizeCap>10MB</totalSizeCap> | ||
<cleanHistoryOnStart>true</cleanHistoryOnStart> | ||
</rollingPolicy> | ||
<encoder class="co.elastic.logging.logback.EcsEncoder"/> | ||
</appender> |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
Adjust log rotation strategy for production use.
The current file appender configuration has several issues that need attention:
maxHistory=0
disables log retention completelytotalSizeCap=10MB
is too restrictive for a production APImaxFileSize=10MB
might lead to frequent rotations- Missing error handling for file write failures
Apply these improvements:
<appender name="ECS_JSON_FILE" class="ch.qos.logback.core.rolling.RollingFileAppender">
<file>${LOG_FILE}.json</file>
+ <prudent>true</prudent>
+ <append>true</append>
<rollingPolicy class="ch.qos.logback.core.rolling.TimeBasedRollingPolicy">
<fileNamePattern>${LOG_FILE}.json.%d{yyyy-MM-dd}.gz</fileNamePattern>
- <maxFileSize>10MB</maxFileSize>
- <maxHistory>0</maxHistory>
- <totalSizeCap>10MB</totalSizeCap>
+ <maxFileSize>100MB</maxFileSize>
+ <maxHistory>30</maxHistory>
+ <totalSizeCap>5GB</totalSizeCap>
<cleanHistoryOnStart>true</cleanHistoryOnStart>
</rollingPolicy>
<encoder class="co.elastic.logging.logback.EcsEncoder"/>
+ <immediateFlush>true</immediateFlush>
</appender>
π Committable suggestion
βΌοΈ IMPORTANT
Carefully review the code before committing. Ensure that it accurately replaces the highlighted code, contains no missing lines, and has no issues with indentation. Thoroughly test & benchmark the code to ensure it meets the requirements.
<appender name="ECS_JSON_FILE" class="ch.qos.logback.core.rolling.RollingFileAppender"> | |
<file>${LOG_FILE}.json</file> | |
<rollingPolicy class="ch.qos.logback.core.rolling.TimeBasedRollingPolicy"> | |
<fileNamePattern>${LOG_FILE}.json.%d{yyyy-MM-dd}.gz</fileNamePattern> | |
<maxFileSize>10MB</maxFileSize> | |
<maxHistory>0</maxHistory> | |
<totalSizeCap>10MB</totalSizeCap> | |
<cleanHistoryOnStart>true</cleanHistoryOnStart> | |
</rollingPolicy> | |
<encoder class="co.elastic.logging.logback.EcsEncoder"/> | |
</appender> | |
<appender name="ECS_JSON_FILE" class="ch.qos.logback.core.rolling.RollingFileAppender"> | |
<file>${LOG_FILE}.json</file> | |
<prudent>true</prudent> | |
<append>true</append> | |
<rollingPolicy class="ch.qos.logback.core.rolling.TimeBasedRollingPolicy"> | |
<fileNamePattern>${LOG_FILE}.json.%d{yyyy-MM-dd}.gz</fileNamePattern> | |
<maxFileSize>100MB</maxFileSize> | |
<maxHistory>30</maxHistory> | |
<totalSizeCap>5GB</totalSizeCap> | |
<cleanHistoryOnStart>true</cleanHistoryOnStart> | |
</rollingPolicy> | |
<encoder class="co.elastic.logging.logback.EcsEncoder"/> | |
<immediateFlush>true</immediateFlush> | |
</appender> |
pom.xml
Outdated
<dependency> | ||
<groupId>co.elastic.logging</groupId> | ||
<artifactId>logback-ecs-encoder</artifactId> | ||
<version>0.4.0</version> |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
π‘ Codebase verification
Update logback-ecs-encoder to version 1.3.2 for Spring Boot 3.x compatibility
The current version (0.4.0) is not officially tested with Spring Boot 3.x. Based on the configuration and Spring Boot version (3.2.2), I recommend updating to version 1.3.2 which has been tested with Spring Boot 3.x:
<dependency>
<groupId>co.elastic.logging</groupId>
<artifactId>logback-ecs-encoder</artifactId>
- <version>0.4.0</version>
+ <version>1.3.2</version>
</dependency>
- The current logback configuration in
src/main/resources/logback-spring.xml
is correctly set up and will work with the updated version - Version 1.3.2 is recommended over 1.5.0 as it has been extensively tested with Spring Boot 3.x
π Analysis chain
Update logback-ecs-encoder to the latest version.
The current version (0.4.0) is quite old and might have compatibility issues with Spring Boot 3.x. The latest version (1.5.0) includes important updates and bug fixes.
Apply this diff to update the version:
<dependency>
<groupId>co.elastic.logging</groupId>
<artifactId>logback-ecs-encoder</artifactId>
- <version>0.4.0</version>
+ <version>1.5.0</version>
</dependency>
Let's verify the compatibility of the current version with Spring Boot 3.x:
The previous GitHub API call might have failed due to authentication. Let's try a different approach by checking the local configuration files and compatibility information directly from the repository's documentation and checking how the library is being used in the project.
Let's examine the actual Spring Boot version and the logback configuration to understand how the ECS encoder is being used and ensure compatibility.
π Scripts executed
The following scripts were executed for the analysis:
Script:
#!/bin/bash
# Check if there are any known compatibility issues or CVEs
gh api \
-H "Accept: application/vnd.github+json" \
-H "X-GitHub-Api-Version: 2022-11-28" \
/repos/elastic/ecs-logging-java/issues \
-q '.[] | select(.title | test("compatibility|spring boot 3|CVE"; "i")) | {title: .title, url: .html_url}'
Length of output: 233
Script:
#!/bin/bash
# Let's check the release notes and compatibility information from the repository
curl -s https://raw.githubusercontent.com/elastic/ecs-logging-java/main/README.md | grep -A 5 "Compatibility Matrix\|Spring Boot"
# Check if there are any existing logback configurations that might be affected
fd -e xml -e properties . | xargs grep -l "logback\|ecs-encoder" || true
# Let's also check the current Spring Boot version in use
grep -A 2 "<parent>" pom.xml
Length of output: 385
Script:
#!/bin/bash
# Let's check the Spring Boot version and examine the logback configuration
grep -A 1 "spring-boot-starter-parent" pom.xml
cat src/main/resources/logback-spring.xml
Length of output: 1191
Quality Gate passedIssues Measures |
π Description
JIRA ID: PSMRI/AMRIT#4
Add ECS logging for elastic stack setup
β Type of Change
βΉοΈ Additional Information
Summary by CodeRabbit
Summary by CodeRabbit
New Features
Bug Fixes
Documentation