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(elk-stack-setup): add ecs logging for elastic setup #21

Merged
merged 2 commits into from
Nov 14, 2024

Conversation

ivor11
Copy link
Contributor

@ivor11 ivor11 commented Oct 27, 2024

πŸ“‹ Description

JIRA ID: PSMRI/AMRIT#4

Add ECS logging for elastic stack setup


βœ… Type of Change

  • 🐞 Bug fix (non-breaking change which resolves an issue)
  • ✨ New feature (non-breaking change which adds functionality)
  • πŸ”₯ Breaking change (fix or feature that would cause existing functionality to not work as expected)
  • πŸ›  Refactor (change that is neither a fix nor a new feature)
  • βš™οΈ Config change (configuration file or build script updates)
  • πŸ“š Documentation (updates to docs or readme)
  • πŸ§ͺ Tests (adding new or updating existing tests)
  • 🎨 UI/UX (changes that affect the user interface)
  • πŸš€ Performance (improves performance)
  • 🧹 Chore (miscellaneous changes that don't modify src or test files)

ℹ️ Additional Information

  • Enabled springboot logback logging
  • added conf for ECS logging to logback-spring.xml
  • suppressed conflicting logging lib in jboss

Summary by CodeRabbit

Summary by CodeRabbit

  • New Features

    • Enhanced logging capabilities with the addition of new logging configuration properties, including log file path and name.
    • Introduced a new Logback configuration for improved log management, including JSON formatting and rolling policies.
    • Updated project name to "BeneficiaryID-Generation-API."
  • Bug Fixes

    • Adjustments made to existing dependencies to refine application performance.
  • Documentation

    • Updated configuration files for better management and clarity, including a new XML structure for deployment configuration.

Copy link

coderabbitai bot commented Oct 27, 2024

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 @coderabbitai review command as a PR comment. Alternatively, push new commits to this PR.

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.

πŸ“₯ Commits

Reviewing files that changed from the base of the PR and between 07c8609 and a4f459f.

Walkthrough

The changes in this pull request involve updates to the logging configuration of the project. Modifications include the addition of a new logging dependency (logback-ecs-encoder), the introduction of a new Logback configuration file (logback-spring.xml), and the removal of the old Logback configuration file (logback.xml). Additionally, new properties related to logging paths and file names have been added to the application.properties file. A new XML structure has also been introduced in the jboss-deployment-structure.xml file to exclude certain logging modules.

Changes

File Path Change Summary
pom.xml - Added dependency: logback-ecs-encoder (version 0.4.0)
- Removed exclusion of spring-boot-starter-logging
src/main/resources/application.properties - Added properties: logging.path=logs/
logging.file.name=logs/helpline1097-api.log
src/main/resources/logback-spring.xml - New configuration file added for Logback logging with JSON format and rolling policies.
src/main/resources/logback.xml - Deleted old Logback configuration file.
src/main/webapp/WEB-INF/jboss-deployment-structure.xml - New structure added to exclude org.slf4j and org.slf4j.impl modules.

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
Loading

🐰 "In the logs, we now find,
A path and name, so well-defined.
With JSON rolling, neat and bright,
Our logging's now a pure delight!
So hop along, let’s log away,
With every log, a brighter day!" πŸ‡


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

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

πŸ“œ Review details

Configuration used: CodeRabbit UI
Review profile: CHILL

πŸ“₯ Commits

Files that changed from the base of the PR and between 66dc99d and 07c8609.

πŸ“’ 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:

  1. The fallback to /tmp directory might not be suitable for production as it's typically cleared on system restart.
  2. The log file name "my-api" is generic and should reflect the actual application name (Helpline1097-API).

Consider:

  1. Using a more production-appropriate default path
  2. 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.

Comment on lines 17 to 20
<root level="INFO">
<appender-ref ref="CONSOLE"/>
<appender-ref ref="ECS_JSON_FILE"/>
</root>
Copy link

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:

  1. Add async wrapper for file appender
  2. 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>

Comment on lines 5 to 15
<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>
Copy link

Choose a reason for hiding this comment

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

⚠️ Potential issue

Adjust log rotation strategy for production use.

The current file appender configuration has several issues that need attention:

  1. maxHistory=0 disables log retention completely
  2. totalSizeCap=10MB is too restrictive for a production API
  3. maxFileSize=10MB might lead to frequent rotations
  4. 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.

Suggested change
<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
Comment on lines 60 to 63
<dependency>
<groupId>co.elastic.logging</groupId>
<artifactId>logback-ecs-encoder</artifactId>
<version>0.4.0</version>
Copy link

Choose a reason for hiding this comment

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

πŸ’‘ Codebase verification

⚠️ Potential issue

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

Copy link

sonarcloud bot commented Oct 31, 2024

@drtechie drtechie merged commit 67a836a into PSMRI:develop Nov 14, 2024
1 check passed
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.

2 participants