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: Email notification when releasing by OpenAPI #5324

Merged
merged 4 commits into from
Jan 26, 2025

Conversation

spaceluke
Copy link
Member

@spaceluke spaceluke commented Jan 24, 2025

What's the purpose of this PR

  1. Support email notification when releasing by OpenAPI

  2. Fix wrong code style of openapi.v1.controller.ReleaseController

Which issue(s) this PR fixes:

https://github.com/orgs/apolloconfig/projects/2/views/1?pane=issue&itemId=77891785

Brief changelog

see commits

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

  • New Features

    • Added a new method for creating gray deletion releases.
    • Enhanced event publishing for release management actions.
    • Introduced user management authority assignment by cluster for modification and publishing.
    • Added email notifications for releases made via OpenAPI.
    • Added support for a portal RestTemplate client connection pool configuration.
    • Enabled global search for values by administrators.
    • Implemented an observe status access-key for pre-check and logging purposes.
  • Improvements

    • Introduced more robust event tracking for configuration changes.
    • Added support for publishing events during release operations like creation, merging, and rollback.
    • Updated the server configuration link on the system info page.

@dosubot dosubot bot added the size:L This PR changes 100-499 lines, ignoring generated files. label Jan 24, 2025
Copy link
Contributor

coderabbitai bot commented Jan 24, 2025

Walkthrough

The changes in the ReleaseController class focus on enhancing the event-driven architecture of release management. The controller now integrates ApplicationEventPublisher to publish configuration change events for various release operations, including creating releases, merging namespaces, creating gray releases, and performing rollbacks. A new method for creating gray deletion releases is introduced, further expanding the event publishing capabilities. Additionally, the release notes and changes documentation have been updated to reflect new features and improvements in Apollo version 2.4.0.

Changes

File Change Summary
apollo-portal/.../ReleaseController.java - Added ApplicationEventPublisher as a new field and constructor parameter
- Enhanced methods to publish ConfigPublishEvent for release operations
- Added new createGrayDelRelease method with event publishing
changes/changes-2.4.0.md - Added feature for user management authority assignment by cluster
- Added feature for email notifications on releases via OpenAPI
changes/changes-2.4.0.md - Added support for portal RestTemplate client connection pool config
- Added ability for administrators to globally search for values
- Added support for observe status access-key for pre-check and logging
- Updated server config link in system info page

Possibly related PRs

Suggested labels

lgtm

Suggested reviewers

  • nobodyiam

Poem

🐰 Hop, hop, release the code with glee,
Events now dance, so wild and free!
Gray releases, merges, and more,
Publishing changes down to the core.
Apollo's portal, now event-wise and bright! 🚀


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 generate docstrings to generate docstrings for this PR. (Beta)
  • @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.

@spaceluke spaceluke changed the title [Issue] Email notification when releasing by OpenAPI [Feat] Email notification when releasing by OpenAPI Jan 24, 2025
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

🧹 Nitpick comments (2)
apollo-portal/src/main/java/com/ctrip/framework/apollo/openapi/v1/controller/ReleaseController.java (2)

113-138: Duplication of event-publishing code
The same logic for creating and configuring ConfigPublishEvent is repeated. Consider extracting this into a helper method or utility class to enforce DRY (Don’t Repeat Yourself) and promote maintainability.


140-169: createGrayRelease event logic
Again, the event-publishing code is effectively duplicated. Centralizing this logic will reduce the risk of inconsistent event configurations across methods.

📜 Review details

Configuration used: CodeRabbit UI
Review profile: CHILL
Plan: Pro

📥 Commits

Reviewing files that changed from the base of the PR and between 6c41ef0 and 9c8ed0f.

📒 Files selected for processing (1)
  • apollo-portal/src/main/java/com/ctrip/framework/apollo/openapi/v1/controller/ReleaseController.java (5 hunks)
⏰ Context from checks skipped due to timeout of 90000ms (1)
  • GitHub Check: build (8)
🔇 Additional comments (7)
apollo-portal/src/main/java/com/ctrip/framework/apollo/openapi/v1/controller/ReleaseController.java (7)

33-33: New import for ConfigPublishEvent looks correct
This import is required for the event-driven approach you have introduced.


38-38: Introducing ApplicationEventPublisher
Importing Spring’s ApplicationEventPublisher is a solid approach for decoupled event publishing.


59-59: New field for event publishing
Declaring a private final ApplicationEventPublisher publisher; ensures that all publish operations remain consistent throughout the controller.


73-73: Assigning the publisher
Using the constructor argument to set this.publisher adheres to best practices in immutability for final fields. Nice job.


218-226: Rollback event consistency
Publishing an event before rolling back aligns rollback operations with the rest of the event-driven design. This consistent approach ensures that release-related activities (including notifications) are traceable and maintainable.


91-103: Event publishing in createRelease
The creation and publication of the ConfigPublishEvent is consistent with the new event-driven architecture. Please verify that the mapped event listener actually sends the email notifications as intended.

✅ Verification successful

Email notifications are properly implemented
The ConfigPublishListener correctly handles email notifications with a robust implementation that:

  • Builds appropriate email content based on the release operation type (normal/gray/rollback/merge)
  • Sends notifications through EmailService with proper error handling
  • Respects environment-specific email configurations
🏁 Scripts executed

The following scripts were executed for the analysis:

Script:

#!/bin/bash
# Description: Search any event listener or handler for ConfigPublishEvent that triggers the email notification.

rg -A 10 "implements.*ApplicationListener|@EventListener"

Length of output: 13688


Script:

#!/bin/bash
# Get the complete implementation of ConfigPublishListener
echo "=== ConfigPublishListener Implementation ==="
rg -l "class ConfigPublishListener" | xargs cat

echo -e "\n=== Email Service Usage ==="
# Search for email-related services and their usage
rg -A 5 "EmailService|sendEmail|notify.*email"

Length of output: 21293


66-67: Constructor injection
The constructor injection for the publisher is correctly added and follows Spring’s recommended pattern. Confirm that the Spring bean wiring is properly configured at runtime.

✅ Verification successful

Constructor injection verified
The ApplicationEventPublisher injection follows Spring's standard constructor injection pattern and will be properly autowired at runtime. The class is correctly annotated with @RestController, ensuring it's picked up by Spring's component scanning.

🏁 Scripts executed

The following scripts were executed for the analysis:

Script:

#!/bin/bash
# Description: Verify the bean wiring for ApplicationEventPublisher injection in ReleaseController.

# Here we look for ReleaseController references to confirm that it's picked up by Spring.
rg -A 5 $'@RestController(\"openapiReleaseController\")\\npublic class ReleaseController|ApplicationEventPublisher' 

Length of output: 305


Script:

#!/bin/bash
# Search for ReleaseController definition and ApplicationEventPublisher usage
rg -U --multiline '@RestController.*?\npublic class ReleaseController' -A 10

# Look for ApplicationEventPublisher usage within ReleaseController
ast-grep --pattern 'class ReleaseController {
  $$$
  publisher.$_($$$)
  $$$
}'

# Check for any custom configuration that might affect bean wiring
fd -e xml -e java -e properties -e yaml -e yml | xargs rg -l "ApplicationEventPublisher|ReleaseController"

Length of output: 4730

Comment on lines +171 to +197
@PreAuthorize(value = "@consumerPermissionValidator.hasReleaseNamespacePermission(#request, #appId, #namespaceName, #env)")
@PostMapping(value = "/apps/{appId}/clusters/{clusterName}/namespaces/{namespaceName}/branches/{branchName}/gray-del-releases")
public OpenReleaseDTO createGrayDelRelease(@PathVariable String appId, @PathVariable String env,
@PathVariable String clusterName, @PathVariable String namespaceName,
@PathVariable String branchName, @RequestBody NamespaceGrayDelReleaseDTO model,
HttpServletRequest request) {
RequestPrecondition.checkArguments(
!StringUtils.isContainEmpty(model.getReleasedBy(), model.getReleaseTitle()),
"Params(releaseTitle and releasedBy) can not be empty");
RequestPrecondition.checkArguments(model.getGrayDelKeys() != null,
"Params(grayDelKeys) can not be null");

if (userService.findByUserId(model.getReleasedBy()) == null) {
throw BadRequestException.userNotExists(model.getReleasedBy());
}

NamespaceGrayDelReleaseModel releaseModel = BeanUtils.transform(
NamespaceGrayDelReleaseModel.class, model);
releaseModel.setAppId(appId);
releaseModel.setEnv(env.toUpperCase());
releaseModel.setClusterName(branchName);
releaseModel.setNamespaceName(namespaceName);

return OpenApiBeanUtils.transformFromReleaseDTO(
releaseService.publish(releaseModel, releaseModel.getReleasedBy()));
}

Copy link
Contributor

@coderabbitai coderabbitai bot Jan 24, 2025

Choose a reason for hiding this comment

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

⚠️ Potential issue

Missing event publishing in createGrayDelRelease
Unlike the other methods (createRelease, merge, createGrayRelease), this method does not publish a ConfigPublishEvent. If the intent is to maintain consistent event-driven behavior (including email notifications), you may need to publish an event here as well.

@@ -193,6 +193,16 @@ public OpenReleaseDTO createGrayDelRelease(...) {
     return OpenApiBeanUtils.transformFromReleaseDTO(
         releaseService.publish(releaseModel, releaseModel.getReleasedBy()));
+    
+    // Potential fix: Publish event similarly
+    // ConfigPublishEvent event = ConfigPublishEvent.instance();
+    // event.withAppId(appId)
+    //      .withCluster(clusterName)
+    //      .withNamespace(namespaceName)
+    //      .withReleaseId(<INSERT RELEASE ID>)
+    //      .setEnv(Env.valueOf(env))
+    //      .setGrayPublishEvent(true);
+    // publisher.publishEvent(event);
 }

Committable suggestion skipped: line range outside the PR's diff.

Copy link
Member Author

Choose a reason for hiding this comment

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

There was no event emit when createGrayDelRelease in Portal

Copy link
Contributor

Choose a reason for hiding this comment

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

@BlackBear2003 Yes, that's correct. The event emission is missing in the createGrayDelRelease method, while other release-related methods (createRelease, merge, createGrayRelease) do emit events. This inconsistency should be addressed to maintain uniform behavior across all release operations.


✏️ Learnings added
Learnt from: BlackBear2003
PR: apolloconfig/apollo#5324
File: apollo-portal/src/main/java/com/ctrip/framework/apollo/openapi/v1/controller/ReleaseController.java:171-197
Timestamp: 2025-01-24T14:43:58.530Z
Learning: The `createGrayDelRelease` method in Portal's ReleaseController should emit a ConfigPublishEvent, similar to other release-related methods (`createRelease`, `merge`, `createGrayRelease`), to maintain consistent event-driven behavior.

Note: Learnings are effective only in the context of similar code segments. To apply general coding guidelines, please configure review instructions. You can manage existing learnings in the app.


If you found this review helpful, would you consider giving us a shout-out on X?
Thank you for using CodeRabbit!

@spaceluke spaceluke assigned spaceluke and unassigned spaceluke Jan 24, 2025
@spaceluke spaceluke changed the title [Feat] Email notification when releasing by OpenAPI feat: Email notification when releasing by OpenAPI Jan 24, 2025
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.

Please also update the CHANGES.md.

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: 0

🧹 Nitpick comments (1)
changes/changes-2.4.0.md (1)

13-13: Improve the grammar in the changelog entry.

The current wording could be clearer. Consider this revision:

-* [Feature support to notification by email when releasing by OpenApi also](https://github.com/apolloconfig/apollo/pull/5324)
+* [Feature: Add email notification support for OpenAPI releases](https://github.com/apolloconfig/apollo/pull/5324)
📜 Review details

Configuration used: CodeRabbit UI
Review profile: CHILL
Plan: Pro

📥 Commits

Reviewing files that changed from the base of the PR and between 9c8ed0f and 8dd5122.

📒 Files selected for processing (1)
  • changes/changes-2.4.0.md (1 hunks)
🧰 Additional context used
📓 Learnings (1)
📓 Common learnings
Learnt from: BlackBear2003
PR: apolloconfig/apollo#5324
File: apollo-portal/src/main/java/com/ctrip/framework/apollo/openapi/v1/controller/ReleaseController.java:171-197
Timestamp: 2025-01-24T14:43:58.631Z
Learning: The `createGrayDelRelease` method in Portal's ReleaseController should emit a ConfigPublishEvent, similar to other release-related methods (`createRelease`, `merge`, `createGrayRelease`), to maintain consistent event-driven behavior.
⏰ Context from checks skipped due to timeout of 90000ms (1)
  • GitHub Check: build (8)

@@ -9,6 +9,8 @@ Apollo 2.4.0
* [Feature support portal restTemplate Client connection pool config](https://github.com/apolloconfig/apollo/pull/5200)
* [Feature added the ability for administrators to globally search for Value](https://github.com/apolloconfig/apollo/pull/5182)
* [Feature support the observe status access-key for pre-check and logging only](https://github.com/apolloconfig/apollo/pull/5236)
* [Feature support to assign users management authority by the cluster (modify, publish)](https://github.com/apolloconfig/apollo/pull/5302)
Copy link
Member

Choose a reason for hiding this comment

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

The changes-2.4.0.md will be updated when 2.4.0 is released. So please update the CHANGES.md instead.

Copy link
Member Author

Choose a reason for hiding this comment

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

fixed~

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: 0

🧹 Nitpick comments (1)
CHANGES.md (1)

29-30: LGTM! Consider enhancing the feature descriptions.

The changelog entries follow the correct format and provide clear links to the corresponding PRs. However, the descriptions could be more detailed to better communicate the impact and scope of these features.

Consider expanding the descriptions:

-* [Feature: support to assign users management authority by the cluster (modify, publish)](https://github.com/apolloconfig/apollo/pull/5302)
-* [Feature: notification by email when releasing by OpenApi also](https://github.com/apolloconfig/apollo/pull/5324)
+* [Feature: Support fine-grained user management with cluster-level authority controls for modification and publishing](https://github.com/apolloconfig/apollo/pull/5302)
+* [Feature: Extend release notifications to include email alerts for OpenAPI-triggered releases](https://github.com/apolloconfig/apollo/pull/5324)
📜 Review details

Configuration used: CodeRabbit UI
Review profile: CHILL
Plan: Pro

📥 Commits

Reviewing files that changed from the base of the PR and between 8dd5122 and 35fd433.

📒 Files selected for processing (2)
  • CHANGES.md (1 hunks)
  • changes/changes-2.4.0.md (0 hunks)
💤 Files with no reviewable changes (1)
  • changes/changes-2.4.0.md
🧰 Additional context used
📓 Learnings (1)
📓 Common learnings
Learnt from: BlackBear2003
PR: apolloconfig/apollo#5324
File: apollo-portal/src/main/java/com/ctrip/framework/apollo/openapi/v1/controller/ReleaseController.java:171-197
Timestamp: 2025-01-24T14:43:58.631Z
Learning: The `createGrayDelRelease` method in Portal's ReleaseController should emit a ConfigPublishEvent, similar to other release-related methods (`createRelease`, `merge`, `createGrayRelease`), to maintain consistent event-driven behavior.
⏰ Context from checks skipped due to timeout of 90000ms (1)
  • GitHub Check: build (8)

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 Jan 26, 2025
@nobodyiam nobodyiam merged commit ba197ed into apolloconfig:master Jan 26, 2025
8 checks passed
@github-actions github-actions bot locked and limited conversation to collaborators Jan 26, 2025
@nobodyiam nobodyiam added this to the 2.4.0 milestone Jan 30, 2025
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:L This PR changes 100-499 lines, ignoring generated files.
Projects
None yet
Development

Successfully merging this pull request may close these issues.

2 participants