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: 触发懒加载时,需要同步更新notify内容,更新component监听变更的ns #302

Merged
merged 8 commits into from Mar 27, 2024

Conversation

qdsordinarydream
Copy link
Contributor

@qdsordinarydream qdsordinarydream commented Mar 8, 2024

触发懒加载时,需要同步更新notify内容,更新component监听变更的ns;因为sync也会触发component返回,所以component不需要重新 start,期间两秒的时间足够configComponent变更appconfig

component 依赖 appconfig 的内容更新
image
image
image

Summary by CodeRabbit

  • Bug Fixes
    • Improved the logic for configuration retrieval and caching in the application.
  • Tests
    • Enhanced testing for configuration updates and notifications.
  • Refactor
    • Code refactoring for better readability and efficiency in configuration management.

dongsheng.qi added 2 commits March 8, 2024 11:57
Copy link

coderabbitai bot commented Mar 8, 2024

Walkthrough

The recent updates focus on refining the configuration management and testing within a Go project. Modifications include variable name corrections, enhanced logic for configuration retrieval and caching, and updates to app configuration handling. Additionally, test coverage has been expanded to ensure the updated configuration logic functions as expected, particularly with regards to application notifications and cache coherence.

Changes

File(s) Summary
client.go Corrected variable names, updated configuration retrieval and caching logic, added string operations.
client_test.go Added assertion for appConfig notifications map update, included cache update comment, and updated imports.
.../notify/componet_notify_test.go Added a test for SetAppConfig method to ensure correct application configuration updates.

"In the realm of code, where logic is king,
🐰 A rabbit hopped in, making changes with a swing.
Renaming, testing, with a meticulous eye,
Ensuring configs are right, under the digital sky.
With every hop, a bug squashed, making the codebase sing,
This rabbit coder, with joy, does bring."
🌟🌈🐾

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

mergify bot commented Mar 8, 2024

感谢您提出Pull Request,我会尽快Review。我会在1-2日内进行查看或者回复,如果遇到节假日可能会处理较慢,敬请谅解。

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.

Review Status

Actionable comments generated: 1

Configuration used: CodeRabbit UI

Commits Files that changed from the base of the PR and between 9a87bea and aae4195.
Files selected for processing (3)
  • client.go (2 hunks)
  • client_test.go (2 hunks)
  • env/config/config.go (4 hunks)
Additional comments: 12
env/config/config.go (9)
  • 32-32: Renaming comma to Comma improves clarity and follows Go conventions for exported variables. Ensure that all references to this variable across the project have been updated to reflect this change.
  • 35-35: The comment for the File interface is concise but could be more descriptive regarding its purpose and the functions it provides. Consider expanding this comment to include details about the role of the File interface in configuration file handling.
  • 42-42: The AppConfig struct is well-documented, but it's important to ensure that all fields are necessary and used within the application. Unused fields can lead to confusion and unnecessary memory allocation.
Verification successful

The verification process has confirmed that all fields in the AppConfig struct are indeed utilized within the application across various functionalities, including configuration loading, network settings, security configurations, and runtime behavior control. This indicates that the fields are necessary and actively contribute to the application's operations.

Scripts Executed

The following scripts were executed for the analysis:


Script:

#!/bin/bash
# Verify the usage of all fields in AppConfig across the project
fields=("AppID" "Cluster" "NamespaceName" "IP" "IsBackupConfig" "BackupConfigPath" "Secret" "Label" "SyncServerTimeout" "MustStart" "notificationsMap" "currentConnApolloConfig")
for field in "${fields[@]}"; do
  echo "Checking usage of field: $field"
  rg --type go "\b$field\b"
done

Length of output: 21204

* 59-59: The `ServerInfo` struct is clearly documented. However, consider adding more context about how `ServerInfo` is used within the application, especially the significance of the `IsDown` field which is not immediately clear from the comment. * 67-69: The comments for `GetIsBackupConfig` effectively explain the return values. It's a good practice to include such explanatory comments for boolean getters to clarify the implications of true/false values. * 74-74: The comment for `GetBackupConfigPath` is redundant as it simply repeats the function name. Consider providing more details about when and why this path is used within the application. * 79-79: The `GetHost` function's comment could be enhanced by explaining the conditions under which the IP address is parsed and modified. This would help future maintainers understand the purpose of the URL parsing logic. * 111-111: The comment for `SplitNamespaces` is clear, but it would be beneficial to explain the expected format of `namespacesStr` and the role of the `callback` function in more detail. * 129-129: The comment for `GetServicesConfigURL` is missing. Adding a brief description of what this URL represents and how it's used within the application would improve code readability and maintainability.
client.go (1)
  • 160-160: Renaming config to cfg within the GetConfigAndInit function improves readability by avoiding confusion with the config package. Ensure that this renaming does not conflict with other local variables or package names.
client_test.go (2)
  • 23-23: The addition of the notify import statement is necessary for the new assignment within the createMockApolloConfig function. Ensure that this import is used elsewhere in the test file to justify its inclusion.
  • 69-69: Assigning client.configComponent = &notify.ConfigComponent{} within the createMockApolloConfig function is a crucial step for setting up the test environment. This ensures that the configComponent is initialized and can be used in tests that rely on its behavior. Verify that tests which depend on configComponent are updated to reflect this change.

client.go Outdated
Comment on lines 166 to 172
// update appConfig
c.appConfig.NamespaceName = c.appConfig.NamespaceName + config.Comma + namespace
c.appConfig.GetNotificationsMap().UpdateNotify(namespace, 0)
// update cache
c.cache.UpdateApolloConfig(apolloConfig, c.getAppConfig)
// update configComponent
c.configComponent.SetAppConfig(c.getAppConfig)
Copy link

Choose a reason for hiding this comment

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

The logic within this conditional block correctly updates the appConfig, notificationsMap, cache, and configComponent based on the newly fetched apolloConfig. However, consider extracting this logic into a separate method to improve readability and maintainability. This would also make unit testing easier by allowing you to test the update logic in isolation.

func (c *internalClient) updateConfigComponents(namespace string, apolloConfig *config.ApolloConfig) {
+   // update appConfig
+   c.appConfig.NamespaceName = c.appConfig.NamespaceName + config.Comma + namespace
+   c.appConfig.GetNotificationsMap().UpdateNotify(namespace, 0)
+   // update cache
+   c.cache.UpdateApolloConfig(apolloConfig, c.getAppConfig)
+   // update configComponent
+   c.configComponent.SetAppConfig(c.getAppConfig)
}

-   // update appConfig
-   c.appConfig.NamespaceName = c.appConfig.NamespaceName + config.Comma + namespace
-   c.appConfig.GetNotificationsMap().UpdateNotify(namespace, 0)
-   // update cache
-   c.cache.UpdateApolloConfig(apolloConfig, c.getAppConfig)
-   // update configComponent
-   c.configComponent.SetAppConfig(c.getAppConfig)

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.

Suggested change
// update appConfig
c.appConfig.NamespaceName = c.appConfig.NamespaceName + config.Comma + namespace
c.appConfig.GetNotificationsMap().UpdateNotify(namespace, 0)
// update cache
c.cache.UpdateApolloConfig(apolloConfig, c.getAppConfig)
// update configComponent
c.configComponent.SetAppConfig(c.getAppConfig)
func (c *internalClient) updateConfigComponents(namespace string, apolloConfig *config.ApolloConfig) {
// update appConfig
c.appConfig.NamespaceName = c.appConfig.NamespaceName + config.Comma + namespace
c.appConfig.GetNotificationsMap().UpdateNotify(namespace, 0)
// update cache
c.cache.UpdateApolloConfig(apolloConfig, c.getAppConfig)
// update configComponent
c.configComponent.SetAppConfig(c.getAppConfig)
}

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.

Review Status

Actionable comments generated: 0

Configuration used: CodeRabbit UI

Commits Files that changed from the base of the PR and between aae4195 and 7a344b4.
Files selected for processing (1)
  • client_test.go (2 hunks)
Files skipped from review as they are similar to previous changes (1)
  • client_test.go

@coveralls
Copy link

coveralls commented Mar 8, 2024

Pull Request Test Coverage Report for Build 8433294733

Details

  • 22 of 22 (100.0%) changed or added relevant lines in 2 files are covered.
  • No unchanged relevant lines lost coverage.
  • Overall coverage increased (+0.4%) to 74.857%

Totals Coverage Status
Change from base Build 8181144278: 0.4%
Covered Lines: 1313
Relevant Lines: 1754

💛 - Coveralls

@nobodyiam
Copy link
Member

Could you assist in including a test case that this pull request resolves?

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.

Review Status

Actionable comments generated: 1

Configuration used: CodeRabbit UI

Commits Files that changed from the base of the PR and between 7a344b4 and 5c0e640.
Files selected for processing (3)
  • client.go (2 hunks)
  • client_test.go (1 hunks)
  • component/notify/componet_notify_test.go (1 hunks)
Additional comments: 2
client.go (1)
  • 160-176: The changes in the GetConfigAndInit function, including the variable renaming and the logic update for handling configuration updates, are well-implemented. The refactor to extract the logic into a separate method has significantly improved readability and maintainability. Good job on addressing the previous feedback effectively.
client_test.go (1)
  • 376-379: The addition of the assertion to check if the appConfig notifications map is updated is a valuable improvement to the test. It ensures that the GetConfigAndInit function behaves as expected in updating the notifications map, which is crucial for the configuration update mechanism. Well done on enhancing the test coverage.

Comment on lines 106 to 123
func TestSetAppConfig(t *testing.T) {
var a *config.AppConfig = getTestAppConfig()
mockAppConfig := func() config.AppConfig {
return *a
}

c := &ConfigComponent{}
c.SetAppConfig(mockAppConfig)

// appConfig should be equal
Assert(t, c.appConfigFunc(), Equal(*a))

// appConfig value is be replaced
a.AppID = "test1"
a.NamespaceName = a.NamespaceName + config.Comma + "abc"
Assert(t, c.appConfigFunc().AppID, Equal("test1"))
Assert(t, c.appConfigFunc().NamespaceName, Equal("application,abc"))
}
Copy link

Choose a reason for hiding this comment

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

The test function TestSetAppConfig is logically correct and effectively tests the SetAppConfig method. However, there are a couple of points to consider for improvement:

  1. The filename contains a typo: componet_notify_test.go should be corrected to component_notify_test.go for consistency and clarity.
  2. Consider using a more descriptive naming for the mock function or directly initializing ConfigComponent with a test AppConfig instance for readability.
- func TestSetAppConfig(t *testing.T) {
+ func TestConfigComponent_SetAppConfig_UpdatesAppConfigCorrectly(t *testing.T) {

Consider simplifying the test setup for better readability. For example:

func TestConfigComponent_SetAppConfig_UpdatesAppConfigCorrectly(t *testing.T) {
    expectedAppConfig := getTestAppConfig()
    c := &ConfigComponent{}
    c.SetAppConfig(func() config.AppConfig {
        return *expectedAppConfig
    })

    // Assertions remain the same
}

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.

Review Status

Actionable comments generated: 0

Configuration used: CodeRabbit UI

Commits Files that changed from the base of the PR and between 5c0e640 and a79a21a.
Files selected for processing (1)
  • component/notify/componet_notify_test.go (1 hunks)
Files skipped from review as they are similar to previous changes (1)
  • component/notify/componet_notify_test.go

@qdsordinarydream
Copy link
Contributor Author

Could you assist in including a test case that this pull request resolves?

sure, completed

@nobodyiam
Copy link
Member

Could you assist in including a test case that this pull request resolves?

sure, completed

Thank you! Could you also assist in addressing the concerns mentioned by @coderabbitai?

Copy link

coderabbitai bot commented Mar 26, 2024

Tip

For best results, initiate chat on the files or code changes.

It appears there was a misunderstanding. The output provided does not contain specific concerns raised by @coderabbitai within the context of the PR comments. Instead, it outlines general instructions on how to interact with @coderabbitai in PR comments and the capabilities offered. Given this, there are no direct concerns from @coderabbitai to address based on the provided script output.

If there are specific areas of the code or aspects of the PR you would like feedback on, please provide more details or direct me to specific comments or code changes in the PR. I'm here to assist with code review, answer questions, or provide guidance on specific tasks as needed.

Analysis chain
Scripts executed

The following scripts were executed for the analysis:


Script:

#!/bin/bash
# Search for comments made by @coderabbitai in the PR to identify the concerns.
gh pr view 302 --repo apolloconfig/agollo --comments | grep -A 5 "@coderabbitai"

Length of output: 2113

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.

Review Status

Actionable comments generated: 0

Configuration used: CodeRabbit UI

Commits Files that changed from the base of the PR and between a79a21a and 1272a39.
Files selected for processing (3)
  • client.go (2 hunks)
  • client_test.go (1 hunks)
  • component/notify/componet_notify_test.go (1 hunks)
Files skipped from review as they are similar to previous changes (3)
  • client.go
  • client_test.go
  • component/notify/componet_notify_test.go

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.

Review Status

Actionable comments generated: 0

Configuration used: CodeRabbit UI

Commits Files that changed from the base of the PR and between 1272a39 and 6116cb4.
Files selected for processing (1)
  • client.go (2 hunks)
Files skipped from review as they are similar to previous changes (1)
  • client.go

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.

Review Status

Actionable comments generated: 0

Configuration used: CodeRabbit UI

Commits Files that changed from the base of the PR and between 6116cb4 and 2deb5ed.
Files selected for processing (2)
  • client.go (2 hunks)
  • client_test.go (1 hunks)
Files skipped from review as they are similar to previous changes (2)
  • client.go
  • client_test.go

@zouyx zouyx changed the base branch from master to develop March 27, 2024 12:53
@zouyx zouyx changed the base branch from develop to master March 27, 2024 12:54
@zouyx zouyx changed the base branch from master to develop March 27, 2024 12:59
@mergify mergify bot merged commit a288a91 into apolloconfig:develop Mar 27, 2024
5 checks passed
@zouyx
Copy link
Member

zouyx commented Mar 27, 2024

I need more time to test this feature before release.

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.

None yet

4 participants