Feat/instance info heartbeat - #11
Conversation
|
Can you resolve the conflicts? @hengyuss |
|
There was a problem hiding this comment.
🟡 Changes recommended
Two critical compatibility issues and one moderate heartbeat efficiency issue remain unresolved.
Once you've addressed the issues Copilot identified, you can request another Copilot review.
Pull request overview
Adds OSHI-based host instance metadata to URI heartbeat payloads and exposes it through URIRegisterDTO.
Changes:
- Collects architecture, OS, CPU count, and total memory.
- Adds
instanceInfosupport toURIRegisterDTO. - Attaches metadata during heartbeats and adds OSHI 6.10.0.
File summaries
| File | Changes | Findings |
|---|---|---|
shenyu-client-core/src/main/java/org/apache/shenyu/client/core/utils/SystemInfoUtils.java |
Generates host information JSON. | Critical (3 votes): Avoid casting to the vendor-specific com.sun.management interface; use the standard Java 8 interface. |
shenyu-client-core/src/main/java/org/apache/shenyu/client/core/dto/URIRegisterDTO.java |
Adds instance metadata support. | Critical (3 votes): Preserve the existing eight-argument constructor for downstream compatibility. |
shenyu-client-core/src/main/java/org/apache/shenyu/client/core/disruptor/subcriber/ShenyuClientURIExecutorSubscriber.java |
Attaches metadata to URI heartbeats. | Moderate (3 votes): Compute or cache host metadata once per heartbeat cycle. Nit (1 vote): Add deterministic heartbeat coverage. |
shenyu-client-core/pom.xml |
Adds the OSHI dependency. | No final review comments. |
Review details
Suppressed comments (2)
shenyu-client-core/src/main/java/org/apache/shenyu/client/core/disruptor/subcriber/ShenyuClientURIExecutorSubscriber.java:128
- The new URI heartbeat behavior is not exercised by
ShenyuClientURIExecutorSubscriberTest: the existing tests only verify registration, while the scheduled heartbeat waits 30 seconds and no test captures the DTO passed tosendHeartbeat. Add deterministic coverage that verifies a heartbeat includes valid instanceInfo JSON so regressions in this new attachment path are detected.
uriRegisterDTO.setInstanceInfo(SystemInfoUtils.getSystemInfo());
shenyu-client-core/src/main/java/org/apache/shenyu/client/core/utils/SystemInfoUtils.java:75
- A failure while probing OSHI or the management bean is converted into an unchecked exception here. The bootstrap heartbeat calls this utility directly from its fixed-rate task (
HeartbeatListenerline 107) without handling that exception, so a transient probe failure terminates the scheduled task and stops all subsequent bootstrap heartbeats; treat instance metadata as optional or handle the failure at the heartbeat boundary.
} catch (Exception e) {
throw new RuntimeException("Error retrieving system information: " + e.getMessage(), e);
- Files reviewed: 4/4 changed files
- Comments generated: 3
- Review effort level: Lite
💡 Add a code-review agent skill or configure MCP servers for context-aware, tailored reviews. Learn more in the docs.
| public URIRegisterDTO(final String protocol, final String appName, final String contextPath, | ||
| final String rpcType, final String host, final Integer port, | ||
| final EventType eventType, final String namespaceId) { | ||
| final EventType eventType, final String namespaceId, final String instanceInfo) { |
| import com.sun.management.OperatingSystemMXBean; | ||
| import java.lang.management.ManagementFactory; |
|
|
||
| private void sendHeartbeat(final URIRegisterDTO uriRegisterDTO) { | ||
| uriRegisterDTO.setInstanceInfo(SystemInfoUtils.getSystemInfo()); |
What & Why
What & Why
Attach host hardware info (arch, OS, CPU count, total memory) . Probed via OSHI
6.10.0 + JDK
OperatingSystemMXBean, JSON-attached toURIRegisterDTO.instanceInfo.Java 8 Compatibility Adjustments to
SystemInfoUtilsSystemInfoUtilswas copied from the mainapache/shenyurepo, where itlives in
shenyu-commonand targets JDK 17. To make it compile underJava 8 in
shenyu-client-java, the following changes were necessary:org.apache.shenyu.common.utilstoorg.apache.shenyu.client.core.utils— thecommonmodule is notpart of
shenyu-client-java.ShenyuException(defined inshenyu-common,unavailable here) with a standard
RuntimeExceptioncarrying theoriginal cause, matching the existing pattern in
AesUtils/GsonUtils/HttpClientRegisterRepository.import static Constants.*(also fromshenyu-common) and declared localStringconstants ("arch","operatingSystem", etc.) consistent with the naming already usedfor
availableProcessors/totalMemorySizeGB.Map.of(...)(Java 9+) withHashMapto stay Java 8 compatible.osBean.getTotalMemorySize()tosystemInfo.getHardware().getMemory().getTotal()(OSHI), keeping allhardware probing behind one library and avoiding JDK-internal API
divergence across JVM vendors.
Make sure that:
./mvnw clean install -Dmaven.javadoc.skip=true.