-
-
Notifications
You must be signed in to change notification settings - Fork 72
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/monitor #86
base: main
Are you sure you want to change the base?
Fix/monitor #86
Conversation
WalkthroughThe changes in this pull request involve modifications to several classes in the Changes
Assessment against linked issues
Suggested reviewers
Poem
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
🧹 Outside diff range and nitpick comments (6)
apollo-client/src/main/java/com/ctrip/framework/apollo/util/date/DateUtil.java (1)
22-26
: Enhance class-level Javadoc commentWhile the author and date information is provided, it would be beneficial to include a brief description of the class's purpose and functionality. This helps other developers understand the utility's role at a glance.
Consider adding a description like this:
/** * Utility class for date and time formatting operations. * Provides standardized formatting for LocalDateTime objects. * * @author Rawven * @date 2024/10/19 */ public class DateUtil { // ... existing code ... }apollo-client/src/main/java/com/ctrip/framework/apollo/monitor/internal/listener/impl/DefaultApolloClientBootstrapArgsApi.java (2)
94-97
: LGTM with suggestion: Add null check in putAttachmentValue method.The
putAttachmentValue
method improves code maintainability and ensures consistency betweenbootstrapArgs
andbootstrapArgsString
. However, consider adding a null check to prevent potential NullPointerExceptions.Consider modifying the method as follows:
private void putAttachmentValue(String argName, Object value) { bootstrapArgs.put(argName, value); - bootstrapArgsString.put(argName, value.toString()); + bootstrapArgsString.put(argName, value != null ? value.toString() : "null"); }
Line range hint
1-114
: Overall improvements with some objectives unaddressed.The changes to
DefaultApolloClientBootstrapArgsApi
improve code consistency and provide additional useful information (initialization timestamp). However, the modifications don't directly address the issues mentioned in the PR objectives:
- Redundant logging when MetricsExporter is not enabled.
- Default values for monitoring parameters to prevent null pointer exceptions.
Consider addressing these objectives in this or a follow-up PR to fully meet the goals outlined in issue #85.
apollo-client/src/main/java/com/ctrip/framework/apollo/internals/ConfigMonitorInitializer.java (1)
106-113
: LGTM: Early return for disabled metrics exporterThe addition of an early return when the metrics exporter is not enabled effectively addresses the issue of redundant logging mentioned in the PR objectives. This change enhances the Client-Monitor user experience by preventing unnecessary initialization and logging.
A minor suggestion for improvement:
Consider extracting the condition into a separate method for better readability and potential reuse. For example:
private boolean isMetricsExporterDisabled() { return StringUtils.isEmpty(m_configUtil.getMonitorExternalType()) || "NONE".equals(m_configUtil.getMonitorExternalType()); } private static void initializeMetricsExporter() { if (isMetricsExporterDisabled()) { return; } // ... rest of the method }This extraction would make the main method more concise and the condition more self-explanatory.
apollo-client/src/main/java/com/ctrip/framework/apollo/monitor/internal/tracer/ApolloClientMonitorMessageProducer.java (1)
129-129
: Improved date-time formatting.The change from
LocalDate.now().toString()
toDateUtil.formatLocalDateTime(LocalDateTime.now())
is a good improvement. It provides more precise and standardized date-time formatting, which aligns with the objective of maintaining consistent date handling across the application.Consider caching the current date-time value if it's used multiple times within the method to avoid repeated calls to
LocalDateTime.now()
.+ LocalDateTime now = LocalDateTime.now(); - .putAttachment(META_FRESH, DateUtil.formatLocalDateTime(LocalDateTime.now()))); + .putAttachment(META_FRESH, DateUtil.formatLocalDateTime(now)));apollo-client/src/main/java/com/ctrip/framework/apollo/monitor/internal/listener/impl/DefaultApolloClientNamespaceApi.java (1)
Line range hint
1-205
: Summary: Improved date formatting enhances consistency.The changes in this file are minimal but impactful. By standardizing the date formatting using
DateUtil.formatLocalDateTime()
, the code now provides a more consistent and potentially more readable output for namespace metrics. This aligns well with the PR objective of enhancing the user experience.These changes:
- Improve code maintainability by centralizing date formatting logic.
- Potentially enhance readability of the output for users and integrating systems.
Consider applying similar date formatting standardization across the entire project for consistency. This could be a good opportunity to create or update coding guidelines regarding date and time handling in the Apollo Client project.
📜 Review details
Configuration used: CodeRabbit UI
Review profile: CHILL
📒 Files selected for processing (5)
- apollo-client/src/main/java/com/ctrip/framework/apollo/internals/ConfigMonitorInitializer.java (2 hunks)
- apollo-client/src/main/java/com/ctrip/framework/apollo/monitor/internal/listener/impl/DefaultApolloClientBootstrapArgsApi.java (2 hunks)
- apollo-client/src/main/java/com/ctrip/framework/apollo/monitor/internal/listener/impl/DefaultApolloClientNamespaceApi.java (2 hunks)
- apollo-client/src/main/java/com/ctrip/framework/apollo/monitor/internal/tracer/ApolloClientMonitorMessageProducer.java (3 hunks)
- apollo-client/src/main/java/com/ctrip/framework/apollo/util/date/DateUtil.java (1 hunks)
🧰 Additional context used
🔇 Additional comments (11)
apollo-client/src/main/java/com/ctrip/framework/apollo/util/date/DateUtil.java (1)
1-32
: Overall assessment: Good implementation with room for minor improvementsThe
DateUtil
class is a well-structured utility for date formatting, which aligns with the PR objectives of enhancing user experience and maintaining consistent date formatting. The implementation is generally sound, but there are a few areas for improvement:
- Enhance the class-level Javadoc with a description of the class's purpose.
- Consider making the
MEDIUM_FORMATTER
fieldfinal
and possiblyprivate
for better encapsulation.- Add method-level Javadoc and null handling to the
formatLocalDateTime
method.These suggestions will improve the code's documentation, robustness, and maintainability. Once these minor adjustments are made, the class will be in excellent shape.
apollo-client/src/main/java/com/ctrip/framework/apollo/monitor/internal/listener/impl/DefaultApolloClientBootstrapArgsApi.java (3)
31-31
: LGTM: New imports are appropriate for the added functionality.The addition of
DateUtil
andLocalDateTime
imports aligns with the new date-related functionality in the constructor.Also applies to: 34-34
52-79
: LGTM: Improved code consistency and added initialization timestamp.The use of
putAttachmentValue
method improves code consistency and maintainability. The addition ofMETA_FRESH
provides a useful timestamp for when the bootstrap args were initialized.
88-88
: LGTM: Consistent use of putAttachmentValue method.The change to use
putAttachmentValue
in thecollect0
method is consistent with the modifications in the constructor and ensures that bothbootstrapArgs
andbootstrapArgsString
are updated.apollo-client/src/main/java/com/ctrip/framework/apollo/internals/ConfigMonitorInitializer.java (2)
23-23
: LGTM: New import for StringUtilsThe addition of the StringUtils import is appropriate for the new string checks in the
initializeMetricsExporter
method.
Line range hint
1-146
: Overall assessment: Changes effectively address the PR objectivesThe modifications to the
ConfigMonitorInitializer
class successfully address the issue of redundant logging when the metrics exporter is not enabled. This aligns well with the objectives outlined in the PR and the linked issue #85.The implementation is clean, focused, and doesn't introduce any apparent issues. It enhances the user experience of the Client-Monitor feature as intended.
apollo-client/src/main/java/com/ctrip/framework/apollo/monitor/internal/tracer/ApolloClientMonitorMessageProducer.java (3)
28-31
: LGTM: Import statements for improved date handling.The addition of
DateUtil
andLocalDateTime
imports is appropriate for enhancing date and time handling in the class. This change aligns with the objective of improving date formatting across the application.
102-102
: LGTM: Improved comment readability.The translation of the comment from Chinese to English ("// 不需要收集" to "// No need to collect") enhances code readability for a wider audience. This change aligns with best practices for maintaining English comments in international codebases.
Line range hint
1-205
: Overall assessment: Positive changes enhancing code quality.The modifications in this file contribute to improved date handling, code readability, and consistency. These changes align well with the PR objectives of enhancing the user experience and addressing issues related to the monitoring functionality. The use of
DateUtil
for standardized date formatting is particularly noteworthy.No major issues were identified during the review. The suggestions provided are minor and aimed at further optimizing the code.
apollo-client/src/main/java/com/ctrip/framework/apollo/monitor/internal/listener/impl/DefaultApolloClientNamespaceApi.java (2)
31-31
: LGTM: DateUtil import added correctly.The import for
DateUtil
is appropriately added, which is necessary for the change in thegetNamespaceMetricsString
method.
186-186
: LGTM: Improved date formatting.The change from
toString()
toDateUtil.formatLocalDateTime()
is a good improvement for standardizing date formatting across the application. This enhances consistency and maintainability.To ensure this change doesn't affect existing integrations, please run the following verification:
If the search returns any results, those occurrences may need to be updated to use the new
DateUtil.formatLocalDateTime()
method or to expect the new format.
apollo-client/src/main/java/com/ctrip/framework/apollo/util/date/DateUtil.java
Outdated
Show resolved
Hide resolved
apollo-client/src/main/java/com/ctrip/framework/apollo/util/date/DateUtil.java
Outdated
Show resolved
Hide resolved
...rip/framework/apollo/monitor/internal/listener/impl/DefaultApolloClientBootstrapArgsApi.java
Show resolved
Hide resolved
e935f4a
to
c35ae02
Compare
c35ae02
to
212238b
Compare
Codecov ReportAttention: Patch coverage is
Additional details and impacted files@@ Coverage Diff @@
## main #86 +/- ##
============================================
+ Coverage 69.06% 69.15% +0.08%
- Complexity 1228 1451 +223
============================================
Files 172 208 +36
Lines 5260 6063 +803
Branches 570 617 +47
============================================
+ Hits 3633 4193 +560
- Misses 1362 1569 +207
- Partials 265 301 +36 ☔ View full report in Codecov by Sentry. |
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: 1
🧹 Outside diff range and nitpick comments (1)
apollo-client/src/main/java/com/ctrip/framework/apollo/monitor/internal/listener/impl/DefaultApolloClientBootstrapArgsApi.java (1)
94-97
: Consider adding parameter validation.While the method correctly handles the updates, consider adding validation for the
argName
parameter to prevent potential NPEs.private void putAttachmentValue(String argName, Object value) { + if (argName == null) { + throw new IllegalArgumentException("argName cannot be null"); + } bootstrapArgs.put(argName, value); bootstrapArgsString.put(argName, value == null ? null : value.toString()); }
📜 Review details
Configuration used: CodeRabbit UI
Review profile: CHILL
📒 Files selected for processing (4)
- apollo-client/src/main/java/com/ctrip/framework/apollo/internals/ConfigMonitorInitializer.java (2 hunks)
- apollo-client/src/main/java/com/ctrip/framework/apollo/monitor/internal/listener/impl/DefaultApolloClientBootstrapArgsApi.java (2 hunks)
- apollo-client/src/main/java/com/ctrip/framework/apollo/util/date/DateUtil.java (1 hunks)
- apollo-plugin/apollo-plugin-client-prometheus/src/main/java/com/ctrip/framework/apollo/monitor/internal/exporter/impl/PrometheusApolloClientMetricsExporter.java (1 hunks)
🚧 Files skipped from review as they are similar to previous changes (2)
- apollo-client/src/main/java/com/ctrip/framework/apollo/internals/ConfigMonitorInitializer.java
- apollo-client/src/main/java/com/ctrip/framework/apollo/util/date/DateUtil.java
🔇 Additional comments (5)
apollo-plugin/apollo-plugin-client-prometheus/src/main/java/com/ctrip/framework/apollo/monitor/internal/exporter/impl/PrometheusApolloClientMetricsExporter.java (1)
43-43
: Good improvement to logger initialization!The change to use
PrometheusApolloClientMetricsExporter.class
instead ofDefaultApolloClientNamespaceApi.class
for logger initialization follows best practices. This ensures that log messages are correctly attributed to their source class, improving traceability and debugging capabilities.apollo-client/src/main/java/com/ctrip/framework/apollo/monitor/internal/listener/impl/DefaultApolloClientBootstrapArgsApi.java (4)
31-31
: LGTM! Appropriate imports added for date handling.The new imports support the META_FRESH functionality and follow the project's conventions.
Also applies to: 34-34
52-79
: LGTM! Improved initialization with consistent method usage and timestamp tracking.The changes enhance the code by:
- Using a consistent method for all value assignments
- Adding META_FRESH timestamp for tracking initialization time
88-88
: LGTM! Consistent usage of putAttachmentValue method.The change ensures atomic updates to both maps and maintains consistency with the rest of the code.
66-67
: Verify logging improvement for disabled MetricsExporter.The PR objectives mention reducing unnecessary logging when MetricsExporter is not enabled. While these lines set the monitor configuration, we should verify if the logging improvement is implemented elsewhere.
✅ Verification successful
Based on the gathered information, I can now generate the final response:
Logging improvement is properly implemented for disabled MetricsExporter
The codebase shows proper handling of disabled monitoring:
- When monitoring is disabled (
isClientMonitorEnabled() == false
), aNullApolloClientMetricsExporter
is used which only logs a single warning message- The monitoring state is checked early in the event publishing flow to prevent unnecessary processing
- The configuration is properly propagated through
ConfigUtil
and respected throughout the monitoring system🏁 Scripts executed
The following scripts were executed for the analysis:
Script:
#!/bin/bash # Search for logging related to MetricsExporter rg -A 5 "MetricsExporter.*not.*enabled" --type javaLength of output: 53
Script:
#!/bin/bash # Let's search for MetricsExporter class and its usage ast-grep --pattern 'class MetricsExporter { $$$ }' # Also search for any logging related to metrics or monitoring rg -A 3 "(?i)(log|logger).*(?:metric|monitor)" --type javaLength of output: 12839
Script:
#!/bin/bash # Let's search for the implementation of MetricsExporter initialization and configuration rg -A 5 "class.*MetricsExporter.*implements" --type java # Also search for where the MetricsExporter is created/configured rg -A 5 "new.*MetricsExporter" --type java # Search for configuration related to metrics enabling/disabling ast-grep --pattern 'isClientMonitorEnabled'Length of output: 10159
Script:
#!/bin/bash # Let's check the DefaultApolloClientMetricsExporterFactory implementation to see how it handles disabled state rg -A 10 "class DefaultApolloClientMetricsExporterFactory" --type java # Also check for any changes in the initialization of MetricsExporter rg -A 10 "getMetricsExporter" --type javaLength of output: 12321
...p/framework/apollo/monitor/internal/exporter/impl/PrometheusApolloClientMetricsExporter.java
Show resolved
Hide resolved
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: 1
🧹 Outside diff range and nitpick comments (1)
apollo-client/src/test/java/com/ctrip/framework/apollo/monitor/internal/DefaultConfigMonitorTest.java (1)
Line range hint
1-85
: Consider adding test cases for the issues mentioned in #85.The current test suite doesn't cover the specific scenarios mentioned in issue #85:
- MetricsExporter disabled state and logging behavior
- Default values for monitoring parameters to prevent NPEs
Consider adding these test cases:
@Test public void testMetricsExporterDisabled() { // Given when(monitorContext.getMetricsExporter()).thenReturn(null); DefaultConfigMonitor configMonitor = new DefaultConfigMonitor(); // When/Then assertNull(configMonitor.getExporterData()); } @Test public void testBootstrapArgsDefaultValues() { // Given DefaultConfigMonitor configMonitor = new DefaultConfigMonitor(); // When ApolloClientBootstrapArgsMonitorApi api = configMonitor.getBootstrapArgsMonitorApi(); // Then assertNotNull(api.getMetaFreshTime()); // Should return default value instead of null }
📜 Review details
Configuration used: CodeRabbit UI
Review profile: CHILL
📒 Files selected for processing (3)
- apollo-client/src/main/java/com/ctrip/framework/apollo/monitor/api/ConfigMonitor.java (1 hunks)
- apollo-client/src/main/java/com/ctrip/framework/apollo/monitor/internal/DefaultConfigMonitor.java (1 hunks)
- apollo-client/src/test/java/com/ctrip/framework/apollo/monitor/internal/DefaultConfigMonitorTest.java (1 hunks)
🔇 Additional comments (4)
apollo-client/src/main/java/com/ctrip/framework/apollo/monitor/api/ConfigMonitor.java (2)
42-42
: LGTM! The method rename improves clarity.The rename from
getRunningParamsMonitorApi
togetBootstrapArgsMonitorApi
better reflects the actual functionality of retrieving bootstrap arguments.Let's verify all implementations have been updated:
✅ Verification successful
Let me try a different search strategy to verify the implementations.
Method rename has been properly implemented across the codebase
The verification shows that:
- The old method name
getRunningParamsMonitorApi
has no remaining references in the codebase- The new method
getBootstrapArgsMonitorApi
is properly implemented inDefaultConfigMonitor
- All related test cases have been updated to use the new method name
- The change is consistently reflected across all relevant files
🏁 Scripts executed
The following scripts were executed for the analysis:
Script:
#!/bin/bash # Description: Check for any missed implementations or references to the old method name # Search for any remaining references to the old method name echo "Checking for any remaining references to getRunningParamsMonitorApi..." rg "getRunningParamsMonitorApi" # Search for implementations of ConfigMonitor to verify updates echo "Checking ConfigMonitor implementations..." ast-grep --pattern 'class $_ implements ConfigMonitor { $$$ }'Length of output: 342
Script:
#!/bin/bash # Search for implementations using different patterns # Find all files that might contain ConfigMonitor implementations echo "Files containing ConfigMonitor reference:" rg -l "ConfigMonitor" # Search for the new method name to verify implementations echo -e "\nChecking implementations of new method name:" rg "getBootstrapArgsMonitorApi" -A 2 # Search for files containing ApolloClientBootstrapArgsMonitorApi echo -e "\nFiles using ApolloClientBootstrapArgsMonitorApi:" rg -l "ApolloClientBootstrapArgsMonitorApi"Length of output: 3478
42-42
: Update documentation and CHANGES log for this breaking change.This is a breaking API change that requires:
- Documentation updates for the new method name
- Entry in the CHANGES log
- Migration guide for users updating from previous versions
Let's check for documentation that needs updating:
apollo-client/src/main/java/com/ctrip/framework/apollo/monitor/internal/DefaultConfigMonitor.java (1)
52-52
: LGTM! Method name change improves clarity.The renaming from
getRunningParamsMonitorApi
togetBootstrapArgsMonitorApi
better reflects the actual functionality of retrieving bootstrap arguments.apollo-client/src/test/java/com/ctrip/framework/apollo/monitor/internal/DefaultConfigMonitorTest.java (1)
67-67
: LGTM! Method rename is consistent with the API changes.The assertion update correctly reflects the method rename from
getRunningParamsMonitorApi
togetBootstrapArgsMonitorApi
.
...o-client/src/main/java/com/ctrip/framework/apollo/monitor/internal/DefaultConfigMonitor.java
Show resolved
Hide resolved
@Anilople would you please help to take a look? |
What's the purpose of this PR
修复当初合并PR #74 时未及时找出来的bug与问题
基于以下仓库持续测试中
apollo-ospp-test apollo-demo-java
Which issue(s) this PR fixes:
Fixes #85
Brief changelog
XXXXX
Follow this checklist to help us incorporate your contribution quickly and easily:
mvn clean test
to make sure this pull request doesn't break anything.CHANGES
log.Summary by CodeRabbit
Summary by CodeRabbit
New Features
DateUtil
class for standardized date and time formatting.Bug Fixes
DateUtil
class.Documentation
Refactor