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> add bizFailedEvent #881

Merged
merged 6 commits into from
Mar 25, 2024

Conversation

gaosaroma
Copy link
Collaborator

@gaosaroma gaosaroma commented Mar 21, 2024

Motivation

To record failed biz for health check

Modification

add bizFailedEvent

Summary by CodeRabbit

  • New Features
    • Introduced a new event AfterBizFailedEvent to handle scenarios after a business operation failure within the framework.
  • Tests
    • Added tests for the new AfterBizFailedEvent to ensure proper event registration and handling.

Copy link
Contributor

coderabbitai bot commented Mar 21, 2024

Walkthrough

The recent updates to the SOFAArk framework introduce a new event, AfterBizFailedEvent, aimed at handling scenarios where a business operation fails. This enhancement involves adding a new constant for the event topic, implementing the event class, and integrating event sending within the BizModel start method. Additionally, the framework's testing suite has been expanded to cover this new functionality, ensuring robustness and reliability in handling business operation failures.

Changes

Files Change Summary
.../spi/constant/Constants.java Added BIZ_EVENT_TOPIC_AFTER_BIZ_FAILED constant.
.../container/model/BizModel.java
.../container/src/test/.../EventTest.java
Integrated AfterBizFailedEvent sending and testing.
.../spi/event/biz/AfterBizFailedEvent.java Introduced AfterBizFailedEvent class.

"In the land of code where the SOFAArk lies,

A new event whispers as the business cries.

🌟 'AfterBizFailed', a beacon in the night,

Guiding through errors, towards the light.

🐰 Hops the coderabbit, with glee and might,

Crafting tales of resilience, byte by byte."

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-tests 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 tests 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 tests.
    • @coderabbitai read the files in the src/scheduler package and generate a class diagram using mermaid and a README in the markdown format.

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 a review. This is useful when automatic reviews are disabled for the repository.
  • @coderabbitai resolve resolve all the CodeRabbit review comments.
  • @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.
  • The JSON schema for the configuration file is available here.
  • 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/coderabbit-overrides.v2.json

CodeRabbit Discord Community

Join our Discord Community to get help, request features, and share feedback.

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.

Review Status

Actionable comments generated: 0

Configuration used: CodeRabbit UI

Commits Files that changed from the base of the PR and between e6ab184 and 50ae7a0.
Files selected for processing (4)
  • sofa-ark-parent/core-impl/container/src/main/java/com/alipay/sofa/ark/container/model/BizModel.java (2 hunks)
  • sofa-ark-parent/core-impl/container/src/test/java/com/alipay/sofa/ark/container/service/event/EventTest.java (4 hunks)
  • sofa-ark-parent/core/spi/src/main/java/com/alipay/sofa/ark/spi/constant/Constants.java (1 hunks)
  • sofa-ark-parent/core/spi/src/main/java/com/alipay/sofa/ark/spi/event/biz/BizFailedEvent.java (1 hunks)
Additional comments: 7
sofa-ark-parent/core/spi/src/main/java/com/alipay/sofa/ark/spi/event/biz/BizFailedEvent.java (1)
  • 11-18: Consider adding a getter method for the throwable field. This would allow event handlers to access the exception associated with the failed business operation, providing more context for debugging or logging purposes.
sofa-ark-parent/core-impl/container/src/test/java/com/alipay/sofa/ark/container/service/event/EventTest.java (3)
  • 83-83: The registration of BizFailedEventHandler is correctly implemented.
  • 143-145: The test case for sending and handling BizFailedEvent is correctly implemented and follows the established pattern for event testing in this class.
  • 338-348: The implementation of BizFailedEventHandler is consistent with the pattern used for other event handlers in this test class, correctly handling BizFailedEvent events.
sofa-ark-parent/core/spi/src/main/java/com/alipay/sofa/ark/spi/constant/Constants.java (1)
  • 188-188: The addition of the constant BIZ_EVENT_TOPIC_BIZ_FAILED is correctly implemented and follows the established naming conventions for event topic constants.
sofa-ark-parent/core-impl/container/src/main/java/com/alipay/sofa/ark/container/model/BizModel.java (2)
  • 39-39: The import of BizFailedEvent is correctly added for its usage in the start method.
  • 298-298: The addition of sending a BizFailedEvent in the start method upon catching an exception is a valuable enhancement for error handling and observability of business operation failures.

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.

Review Status

Actionable comments generated: 0

Configuration used: CodeRabbit UI

Commits Files that changed from the base of the PR and between 50ae7a0 and 14bf742.
Files selected for processing (2)
  • sofa-ark-parent/core-impl/container/src/test/java/com/alipay/sofa/ark/container/service/event/EventTest.java (4 hunks)
  • sofa-ark-parent/core/spi/src/main/java/com/alipay/sofa/ark/spi/event/biz/BizFailedEvent.java (1 hunks)
Files skipped from review as they are similar to previous changes (2)
  • sofa-ark-parent/core-impl/container/src/test/java/com/alipay/sofa/ark/container/service/event/EventTest.java
  • sofa-ark-parent/core/spi/src/main/java/com/alipay/sofa/ark/spi/event/biz/BizFailedEvent.java

Copy link

codecov bot commented Mar 21, 2024

Codecov Report

Attention: Patch coverage is 80.00000% with 1 lines in your changes are missing coverage. Please review.

Project coverage is 78.91%. Comparing base (e74c7ea) to head (133b423).

Files Patch % Lines
.../com/alipay/sofa/ark/container/model/BizModel.java 0.00% 1 Missing ⚠️
Additional details and impacted files
@@             Coverage Diff              @@
##             master     #881      +/-   ##
============================================
+ Coverage     78.76%   78.91%   +0.14%     
  Complexity      831      831              
============================================
  Files           162      163       +1     
  Lines          6767     6772       +5     
  Branches       1006     1006              
============================================
+ Hits           5330     5344      +14     
+ Misses          917      907      -10     
- Partials        520      521       +1     

☔ View full report in Codecov by Sentry.
📢 Have feedback on the report? Share it here.

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.

Review Status

Actionable comments generated: 0

Configuration used: CodeRabbit UI

Commits Files that changed from the base of the PR and between 14bf742 and 8ba0704.
Files selected for processing (1)
  • sofa-ark-parent/core/spi/src/main/java/com/alipay/sofa/ark/spi/event/biz/BizFailedEvent.java (1 hunks)
Files skipped from review as they are similar to previous changes (1)
  • sofa-ark-parent/core/spi/src/main/java/com/alipay/sofa/ark/spi/event/biz/BizFailedEvent.java

@@ -294,6 +295,7 @@ public void start(String[] args) throws Throwable {
}
} catch (Throwable e) {
bizState = BizState.BROKEN;
eventAdminService.sendEvent(new BizFailedEvent(this, e));
Copy link
Collaborator

Choose a reason for hiding this comment

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

改成这个名字 AfterBizFailedEvent

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.

Review Status

Actionable comments generated: 0

Configuration used: CodeRabbit UI

Commits Files that changed from the base of the PR and between 8ba0704 and 7100d78.
Files selected for processing (1)
  • sofa-ark-parent/core/spi/src/main/java/com/alipay/sofa/ark/spi/constant/Constants.java (1 hunks)
Files skipped from review as they are similar to previous changes (1)
  • sofa-ark-parent/core/spi/src/main/java/com/alipay/sofa/ark/spi/constant/Constants.java

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.

Review Status

Actionable comments generated: 1

Configuration used: CodeRabbit UI

Commits Files that changed from the base of the PR and between 7100d78 and d8b18d9.
Files selected for processing (4)
  • sofa-ark-parent/core-impl/container/src/main/java/com/alipay/sofa/ark/container/model/BizModel.java (2 hunks)
  • sofa-ark-parent/core-impl/container/src/test/java/com/alipay/sofa/ark/container/service/event/EventTest.java (4 hunks)
  • sofa-ark-parent/core/spi/src/main/java/com/alipay/sofa/ark/spi/constant/Constants.java (1 hunks)
  • sofa-ark-parent/core/spi/src/main/java/com/alipay/sofa/ark/spi/event/biz/AfterBizFailedEvent.java (1 hunks)
Files skipped from review as they are similar to previous changes (2)
  • sofa-ark-parent/core-impl/container/src/test/java/com/alipay/sofa/ark/container/service/event/EventTest.java
  • sofa-ark-parent/core/spi/src/main/java/com/alipay/sofa/ark/spi/constant/Constants.java
Additional comments: 2
sofa-ark-parent/core/spi/src/main/java/com/alipay/sofa/ark/spi/event/biz/AfterBizFailedEvent.java (1)
  • 27-34: The class AfterBizFailedEvent is well-defined and follows Java conventions. However, the throwable field lacks a visibility modifier, which could lead to encapsulation issues. Consider making the field private and providing a public getter method for it to adhere to encapsulation principles.
sofa-ark-parent/core-impl/container/src/main/java/com/alipay/sofa/ark/container/model/BizModel.java (1)
  • 39-39: The import of AfterBizFailedEvent is correctly added and follows Java conventions.

@@ -294,6 +295,7 @@
}
} catch (Throwable e) {
bizState = BizState.BROKEN;
eventAdminService.sendEvent(new AfterBizFailedEvent(this, e));
Copy link
Contributor

Choose a reason for hiding this comment

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

The addition of AfterBizFailedEvent in the start method is a good practice for capturing and signaling business operation failures. However, it's important to ensure this new functionality is covered by tests to verify its correctness and effectiveness.

Consider adding unit tests that simulate a failure during the startup process and verify that an AfterBizFailedEvent is correctly published.

Copy link
Collaborator

@lvjing2 lvjing2 left a comment

Choose a reason for hiding this comment

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

LGTM

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.

Review Status

Actionable comments generated: 0

Configuration used: CodeRabbit UI

Commits Files that changed from the base of the PR and between d8b18d9 and 133b423.
Files selected for processing (1)
  • sofa-ark-parent/core/spi/src/main/java/com/alipay/sofa/ark/spi/constant/Constants.java (1 hunks)
Files skipped from review as they are similar to previous changes (1)
  • sofa-ark-parent/core/spi/src/main/java/com/alipay/sofa/ark/spi/constant/Constants.java

@lvjing2 lvjing2 merged commit 1a30e63 into sofastack:master Mar 25, 2024
7 checks passed
lvjing2 pushed a commit that referenced this pull request Mar 30, 2024
* <feature> add bizFailedEvent

* format

* add notes

* rename BizFailedEvent to AfterBizFailedEvent

* refactor

---------

Co-authored-by: leo james <leojames.googol@gmail.com>
(cherry picked from commit 1a30e63)
lvjing2 added a commit that referenced this pull request Mar 31, 2024
* netty support 0.9.x (#843)

* modify test for zip fill to support jdk9+

* fix export import config

* support multi sdk

* format test

* support netty 0.9

(cherry picked from commit 92daff0)

* Update README.md (#846)

(cherry picked from commit 815ea32)

* support multi sdk

(cherry picked from commit 5f7fe98)

* format test

(cherry picked from commit 0f8c409)

* using 0.9 netty

(cherry picked from commit 233f6d7)

* no lib for netty ark plugin

(cherry picked from commit 68c3509)

* set scope = provided for netty

(cherry picked from commit 957f714)

* fix test error "No Ark Container Jar File Found"

(cherry picked from commit e6bfade)

* fix test error (#854)

(cherry picked from commit 917941c)

* fix test error (#855)

* fix test error

* just warn for stop tomcat

* fix test error

(cherry picked from commit c8c384c)

* fix test error (#856)

(cherry picked from commit a77b061)

* update guava version to aviod guava cache pin problem (#853)

* update guava version

* update guava version in container jar

* remove file

---------

Co-authored-by: leo james <leojames.googol@gmail.com>

(cherry picked from commit 51ba5e0)

* update version

* no maven tree when single bundle

* update version

* Update README.md (#869)

(cherry picked from commit 5971b2a)

* add log for file not found

(cherry picked from commit 0d7ca0c)

* simplify artifact id parser

(cherry picked from commit 1969cdb)

* Update sofa-ark-parent/core-impl/archive/src/test/java/com/alipay/sofa/ark/loader/test/jar/JarUtilsTest.java

Co-authored-by: coderabbitai[bot] <136622811+coderabbitai[bot]@users.noreply.github.com>
(cherry picked from commit 8134069)

* fix ark plugin  (#877)

* no export apache for web and netty ark plugin

* no lib in ark plugin

(cherry picked from commit af25776)

* parse artifact id with accuracy first (#878)

* no export apache for web and netty ark plugin

* no lib in ark plugin

* parse artifact id with accuracy first

* fix test error

(cherry picked from commit e6ab184)

* add start class in manifest (#883)

* no export apache for web and netty ark plugin

* no lib in ark plugin

* parse artifact id with accuracy first

* fix test error

* add start class in manifest

* fix test

* remove unused field

(cherry picked from commit e74c7ea)

* <feature> add bizFailedEvent (#881)

* <feature> add bizFailedEvent

* format

* add notes

* rename BizFailedEvent to AfterBizFailedEvent

* refactor

---------

Co-authored-by: leo james <leojames.googol@gmail.com>
(cherry picked from commit 1a30e63)

* add envs for biz starter (#885)

* no export apache for web and netty ark plugin

* no lib in ark plugin

* parse artifact id with accuracy first

* fix test error

* add start class in manifest

* fix test

* remove unused field

* add envs for biz start

(cherry picked from commit 12d4da4)

* add envs for install operation (#887)

* add envs for install operation

* fix format

* fix potential resource leaks when install biz

(cherry picked from commit 24bd60d)

* set args as empty array when args = null for startup (#888)

* add envs for install operation

* fix format

* fix potential resource leaks when install biz

* fix null args throw exception for springboot

(cherry picked from commit e4adbcb)

* add bizStateChangeLog (#889)

* add more info for biz.toString()

* format

* format

* update bizinfo

* format

* rename to bizStateRecord

* format

(cherry picked from commit 6659991)

* 1、增加zookeeper注册节点环境变量,新增配置参数com.alipay.sofa.ark.config.env。默认为sofa-ark (#890)

* 1、增加zookeeper注册节点环境变量,新增配置参数com.alipay.sofa.ark.config.env。默认为sofa-ark
2、升级curator版本,重构NodeCache已过时

* 1、增加zookeeper注册节点环境变量,新增配置参数com.alipay.sofa.ark.config.env。默认为sofa-ark
2、升级curator版本,重构NodeCache已过时

---------

Co-authored-by: leo james <leojames.googol@gmail.com>
(cherry picked from commit 5395cbf)

* fix no ark log in ark container (#891)

* update logback in ark container

* fix ark container log

(cherry picked from commit 75fa690)

* update biz state record name (#892)

* update logback in ark container

* fix ark container log

* modify biz state record name

(cherry picked from commit 6412923)

* rename typo (#893)

* update logback in ark container

* fix ark container log

* modify biz state record name

* format code

(cherry picked from commit 6602b96)

* update version

* code format

* remove springboot 1.x 2.x adapter

---------

Co-authored-by: g-stream <ylchen.changshu@gmail.com>
Co-authored-by: Lipeng <44571204+gaosaroma@users.noreply.github.com>
Co-authored-by: hadoop835 <chenjian835@163.com>
lvjing2 pushed a commit that referenced this pull request Mar 31, 2024
* <feature> add bizFailedEvent

* format

* add notes

* rename BizFailedEvent to AfterBizFailedEvent

* refactor

---------

Co-authored-by: leo james <leojames.googol@gmail.com>
(cherry picked from commit 1a30e63)
lvjing2 added a commit that referenced this pull request Apr 1, 2024
* Update README.md (#869)

(cherry picked from commit 5971b2a)

* add log for file not found

(cherry picked from commit 0d7ca0c)

* simplify artifact id parser

(cherry picked from commit 1969cdb)

* Update sofa-ark-parent/core-impl/archive/src/test/java/com/alipay/sofa/ark/loader/test/jar/JarUtilsTest.java

Co-authored-by: coderabbitai[bot] <136622811+coderabbitai[bot]@users.noreply.github.com>
(cherry picked from commit 8134069)

* fix ark plugin  (#877)

* no export apache for web and netty ark plugin

* no lib in ark plugin

(cherry picked from commit af25776)

* parse artifact id with accuracy first (#878)

* no export apache for web and netty ark plugin

* no lib in ark plugin

* parse artifact id with accuracy first

* fix test error

(cherry picked from commit e6ab184)

* add start class in manifest (#883)

* no export apache for web and netty ark plugin

* no lib in ark plugin

* parse artifact id with accuracy first

* fix test error

* add start class in manifest

* fix test

* remove unused field

(cherry picked from commit e74c7ea)

* <feature> add bizFailedEvent (#881)

* <feature> add bizFailedEvent

* format

* add notes

* rename BizFailedEvent to AfterBizFailedEvent

* refactor

---------

Co-authored-by: leo james <leojames.googol@gmail.com>
(cherry picked from commit 1a30e63)

* add envs for biz starter (#885)

* no export apache for web and netty ark plugin

* no lib in ark plugin

* parse artifact id with accuracy first

* fix test error

* add start class in manifest

* fix test

* remove unused field

* add envs for biz start

(cherry picked from commit 12d4da4)

* add envs for install operation (#887)

* add envs for install operation

* fix format

* fix potential resource leaks when install biz

(cherry picked from commit 24bd60d)

* set args as empty array when args = null for startup (#888)

* add envs for install operation

* fix format

* fix potential resource leaks when install biz

* fix null args throw exception for springboot

(cherry picked from commit e4adbcb)

* add bizStateChangeLog (#889)

* add more info for biz.toString()

* format

* format

* update bizinfo

* format

* rename to bizStateRecord

* format

(cherry picked from commit 6659991)

* 1、增加zookeeper注册节点环境变量,新增配置参数com.alipay.sofa.ark.config.env。默认为sofa-ark (#890)

* 1、增加zookeeper注册节点环境变量,新增配置参数com.alipay.sofa.ark.config.env。默认为sofa-ark
2、升级curator版本,重构NodeCache已过时

* 1、增加zookeeper注册节点环境变量,新增配置参数com.alipay.sofa.ark.config.env。默认为sofa-ark
2、升级curator版本,重构NodeCache已过时

---------

Co-authored-by: leo james <leojames.googol@gmail.com>
(cherry picked from commit 5395cbf)

* fix no ark log in ark container (#891)

* update logback in ark container

* fix ark container log

(cherry picked from commit 75fa690)

* update biz state record name (#892)

* update logback in ark container

* fix ark container log

* modify biz state record name

(cherry picked from commit 6412923)

* rename typo (#893)

* update logback in ark container

* fix ark container log

* modify biz state record name

* format code

(cherry picked from commit 6602b96)

* code format

* remove springboot 1.x 2.x adapter

* update version

---------

Co-authored-by: Lipeng <44571204+gaosaroma@users.noreply.github.com>
Co-authored-by: hadoop835 <chenjian835@163.com>
@gaosaroma gaosaroma deleted the lipeng_dev_healthcheck branch April 9, 2024 02:32
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Projects
None yet
Development

Successfully merging this pull request may close these issues.

None yet

2 participants