Skip to content

Feat/instance info heartbeat - #11

Open
hengyuss wants to merge 3 commits into
apache:mainfrom
hengyuss:feat/instance-info-heartbeat
Open

Feat/instance info heartbeat#11
hengyuss wants to merge 3 commits into
apache:mainfrom
hengyuss:feat/instance-info-heartbeat

Conversation

@hengyuss

Copy link
Copy Markdown
Contributor

What & Why

What & Why

Attach host hardware info (arch, OS, CPU count, total memory) . Probed via OSHI
6.10.0 + JDK OperatingSystemMXBean, JSON-attached to
URIRegisterDTO.instanceInfo.

Java 8 Compatibility Adjustments to SystemInfoUtils

SystemInfoUtils was copied from the main apache/shenyu repo, where it
lives in shenyu-common and targets JDK 17. To make it compile under
Java 8 in shenyu-client-java, the following changes were necessary:

  • Package: moved from org.apache.shenyu.common.utils to
    org.apache.shenyu.client.core.utils — the common module is not
    part of shenyu-client-java.
  • Exception: replaced ShenyuException (defined in shenyu-common,
    unavailable here) with a standard RuntimeException carrying the
    original cause, matching the existing pattern in AesUtils /
    GsonUtils / HttpClientRegisterRepository.
  • Constants: removed import static Constants.* (also from
    shenyu-common) and declared local String constants ("arch",
    "operatingSystem", etc.) consistent with the naming already used
    for availableProcessors / totalMemorySizeGB.
  • Map construction: replaced Map.of(...) (Java 9+) with
    HashMap to stay Java 8 compatible.
  • Memory source: switched from osBean.getTotalMemorySize() to
    systemInfo.getHardware().getMemory().getTotal() (OSHI), keeping all
    hardware probing behind one library and avoiding JDK-internal API
    divergence across JVM vendors.

Make sure that:

  • You have read the contribution guidelines.
  • You submit test cases (unit or integration tests) that back your changes.
  • Your local test passed ./mvnw clean install -Dmaven.javadoc.skip=true.

@dengliming

Copy link
Copy Markdown
Member

Can you resolve the conflicts? @hengyuss

@hengyuss

Copy link
Copy Markdown
Contributor Author

Can you resolve the conflicts? @hengyuss
i have resolved the conflicts

Copilot AI left a comment

Copy link
Copy Markdown

Choose a reason for hiding this comment

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

🟡 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 instanceInfo support to URIRegisterDTO.
  • 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 to sendHeartbeat. 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 (HeartbeatListener line 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) {
Comment on lines +20 to 21
import com.sun.management.OperatingSystemMXBean;
import java.lang.management.ManagementFactory;

private void sendHeartbeat(final URIRegisterDTO uriRegisterDTO) {
uriRegisterDTO.setInstanceInfo(SystemInfoUtils.getSystemInfo());
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.

3 participants