Repository navigation
Indirect agent connection improvements - #13345
sureshanaparti wants to merge 16 commits into
Conversation
|
@blueorangutan package |
|
@sureshanaparti a [SL] Jenkins job has been kicked to build packages. It will be bundled with no SystemVM templates. I'll keep you posted as I make progress. |
Codecov Report❌ Patch coverage is Additional details and impacted files@@ Coverage Diff @@
## main #13345 +/- ##
============================================
+ Coverage 20.67% 20.75% +0.07%
- Complexity 21727 21884 +157
============================================
Files 6492 6505 +13
Lines 590737 592595 +1858
Branches 72448 72665 +217
============================================
+ Hits 122129 122976 +847
- Misses 455335 456259 +924
- Partials 13273 13360 +87
Flags with carried forward coverage won't be shown. Click here to find out more. ☔ View full report in Codecov by Harness. 🚀 New features to boost your workflow:
|
There was a problem hiding this comment.
Pull request overview
This PR is a broad refactor/enhancement of indirect agent connection handling across both Management Server and Agent sides. It introduces a host-side connect/status-check process, adds configurable backoff and host-status heuristics, and expands logging/lock-check mechanisms to reduce reconnect storms and improve observability.
Changes:
- Adds agent-side connection orchestration (status polling + startup submission) and a server-side
AgentConnectStatus*command/answer pair to coordinate connect progress. - Introduces configurable backoff (factory + exponential-with-jitter implementation) and propagates configuration from Management Server to Agent during startup.
- Refactors NIO connection lifecycle and adds supporting utilities/logging, plus DB lock availability checks and DB indexes for performance.
Reviewed changes
Copilot reviewed 47 out of 47 changed files in this pull request and generated 13 comments.
Show a summary per file
| File | Description |
|---|---|
| utils/src/test/java/com/cloud/utils/testcase/NioTest.java | Test logging cleanup (exception logging). |
| utils/src/test/java/com/cloud/utils/backoff/impl/ConstantTimeBackoffTest.java | Updates config key name for constant backoff. |
| utils/src/main/java/com/cloud/utils/nio/NioServer.java | NIO server init tweaks and docstring. |
| utils/src/main/java/com/cloud/utils/nio/NioConnection.java | Connection lifecycle refactor, selector loop/logging, reject logic. |
| utils/src/main/java/com/cloud/utils/nio/NioClient.java | Client connect/handshake logging and expanded cleanup. |
| utils/src/main/java/com/cloud/utils/nio/Link.java | Adds local-port tracking, richer toString, termination helpers/logging changes. |
| utils/src/main/java/com/cloud/utils/nio/HandlerFactory.java | Changes new-connection registration API to InetSocketAddress. |
| utils/src/main/java/com/cloud/utils/net/NetUtils.java | Null guard in hostname-to-IP resolution helper. |
| utils/src/main/java/com/cloud/utils/LogUtils.java | Adds host logging helper with optional reverse lookup. |
| utils/src/main/java/com/cloud/utils/exception/CSExceptionErrorCode.java | Adds error-code mapping for ConnectionException. |
| utils/src/main/java/com/cloud/utils/DateUtil.java | Adds formatMillis duration formatter. |
| utils/src/main/java/com/cloud/utils/backoff/impl/ExponentialWithJitterBackoffMBean.java | New MBean interface for exponential-jitter backoff. |
| utils/src/main/java/com/cloud/utils/backoff/impl/ExponentialWithJitterBackoff.java | New exponential-with-jitter backoff implementation. |
| utils/src/main/java/com/cloud/utils/backoff/impl/ConstantTimeBackoff.java | Migrates to namespaced config keys + exposes configuration. |
| utils/src/main/java/com/cloud/utils/backoff/BackoffFactory.java | New backoff factory for selecting/configuring algorithms. |
| utils/src/main/java/com/cloud/utils/backoff/BackoffAlgorithm.java | Adds getConfiguration() API for propagating settings. |
| server/src/main/java/org/apache/cloudstack/agent/lb/IndirectAgentLBServiceImpl.java | Adds notes/timeout tweaks around agent migration command dispatch. |
| framework/db/src/main/java/com/cloud/utils/db/GlobalLock.java | Refactors lock bookkeeping/logging and adds lock-availability query. |
| framework/db/src/main/java/com/cloud/utils/db/DbUtil.java | Adds IS_FREE_LOCK helper and improves logging around lock DB connections. |
| framework/config/src/main/java/org/apache/cloudstack/framework/config/ConfigKeyUtil.java | New utility to parse key=value;... configuration strings. |
| framework/cluster/src/main/java/com/cloud/cluster/dao/ManagementServerHostDaoImpl.java | Adds DAO method to list all MS hosts including removed. |
| framework/cluster/src/main/java/com/cloud/cluster/dao/ManagementServerHostDao.java | Adds DAO API for “including removed” listing. |
| framework/cluster/src/main/java/com/cloud/cluster/ClusterServiceServletImpl.java | Adds request logging and more detailed RemoteException messages. |
| framework/cluster/src/main/java/com/cloud/cluster/ClusterServiceServletHttpHandler.java | Adds debug logging of inbound request line/body. |
| engine/schema/src/main/resources/META-INF/db/schema-42210to42300.sql | Adds indexes via idempotent add-index procedure calls. |
| engine/schema/src/main/resources/META-INF/db/procedures/cloud.idempotent_add_index.sql | Adds/defines IDEMPOTENT_ADD_INDEX procedure. |
| engine/orchestration/src/test/java/com/cloud/agent/manager/ClusteredAgentManagerImplTest.java | Expands tests for disconnect broadcast behavior and lock usage. |
| engine/orchestration/src/test/java/com/cloud/agent/manager/AgentManagerImplTest.java | Adds tests for config keys and deregister/disconnect behaviors. |
| engine/orchestration/src/main/java/com/cloud/agent/manager/ClusteredAgentManagerImpl.java | Refactors attache creation/removal and event handling behavior. |
| engine/orchestration/src/main/java/com/cloud/agent/manager/AgentManagerImpl.java | Major connect/disconnect refactor, new config keys, status checks, backoff propagation. |
| engine/orchestration/src/main/java/com/cloud/agent/manager/AgentAttache.java | Cancels listener alarm futures on unregister/cancel paths. |
| core/src/main/java/org/apache/cloudstack/threadcontext/ThreadContextUtil.java | New helper for propagating Log4j ThreadContext across threads. |
| core/src/main/java/com/cloud/resource/ServerResource.java | Changes default isExitOnFailures() behavior. |
| core/src/main/java/com/cloud/agent/transport/Request.java | Improves JSON deserialization error logging. |
| core/src/main/java/com/cloud/agent/api/StartupAnswer.java | Adds params + agent-side status-check delay transport fields. |
| core/src/main/java/com/cloud/agent/api/AgentConnectStatusCommand.java | New command for host connect-status checks. |
| core/src/main/java/com/cloud/agent/api/AgentConnectStatusAnswer.java | New answer carrying lock availability and host status. |
| agent/src/test/java/com/cloud/agent/HostConnectProcessTest.java | New test around scheduling the agent connect process. |
| agent/src/test/java/com/cloud/agent/AgentTest.java | Updates tests for new link/logging and reconnect helpers. |
| agent/src/main/java/com/cloud/agent/SynchronousListener.java | New blocking listener for synchronous waits on answers. |
| agent/src/main/java/com/cloud/agent/ServerListener.java | New listener interface for agent-side ServerAttache callbacks. |
| agent/src/main/java/com/cloud/agent/ServerAttache.java | New agent-side counterpart to MS Attache for command/answer flow. |
| agent/src/main/java/com/cloud/agent/properties/AgentProperties.java | Adds new agent properties for async timeouts and status-check delay. |
| agent/src/main/java/com/cloud/agent/IAgentShell.java | Adds setter for dynamically updated backoff algorithm. |
| agent/src/main/java/com/cloud/agent/HostConnectProcess.java | New connect/status-check orchestration loop on the agent side. |
| agent/src/main/java/com/cloud/agent/AgentShell.java | Uses backoff factory + persists configuration; relaxes version handling. |
| agent/src/main/java/com/cloud/agent/Agent.java | Major reconnect/startup refactor; integrates HostConnectProcess and ServerAttache. |
💡 Add Copilot custom instructions for smarter, more guided reviews. Learn how to get started.
|
Packaging result [SF]: ✔️ el8 ✔️ el9 ✔️ el10 ✔️ debian ✔️ suse15. SL-JID 18146 |
|
@blueorangutan package |
|
@sureshanaparti a [SL] Jenkins job has been kicked to build packages. It will be bundled with no SystemVM templates. I'll keep you posted as I make progress. |
|
Packaging result [SF]: ✔️ el8 ✔️ el9 ✔️ el10 ✔️ debian ✔️ suse15. SL-JID 18149 |
|
@blueorangutan package |
|
@sureshanaparti a [SL] Jenkins job has been kicked to build packages. It will be bundled with no SystemVM templates. I'll keep you posted as I make progress. |
|
Packaging result [SF]: ✔️ el8 ✔️ el9 ✔️ el10 ✔️ debian ✔️ suse15. SL-JID 18154 |
| /** | ||
| * Command to check status of {@link StartupCommand} from the Agent. | ||
| * | ||
| * @author mprokopchuk | ||
| */ |
There was a problem hiding this comment.
These @author fields are not necessary, right?
| /** | |
| * Command to check status of {@link StartupCommand} from the Agent. | |
| * | |
| * @author mprokopchuk | |
| */ | |
| /** | |
| * Command to check status of {@link StartupCommand} from the Agent. | |
| * | |
| */ |
There was a problem hiding this comment.
@bernardodemarco I think, it's ok to have it. we've author mentioned in few other classes as well. (check with '@author' in the code base).
|
This pull request has merge conflicts. Dear author, please fix the conflicts and sync your branch with the base branch. |
d5a6d20 to
22e832c
Compare
|
@blueorangutan package |
|
@nvazquez a [SL] Jenkins job has been kicked to build packages. It will be bundled with no SystemVM templates. I'll keep you posted as I make progress. |
There was a problem hiding this comment.
🟡 Changes recommended
Unresolved critical and moderate issues remain in connection handling, concurrent backoff state, hostname resolution, and context propagation.
14 open issues
Skip unresolvable aliases before caching · New Synchronize shared backoff state transitions · New Prevent remote address lookup from stopping the selector · New Hostname-only self-check misses active duplicate nodes Cancelled task can cancel a replacement taskisTerminated()reads_keywithout synchronization, whilesetKey()andterminated()write it… This adds a new abstract method toAgentManager, but `engine/storage/integration-test/src/test/jav… This debug logging prints all agent properties including their values. Agent properties commonly… Reset attempt number when backoff reaches zero · New VM work serialization prevents UUID propagation MBean setter silently ignores time-to-wait updates Blank hostname creates invalid cluster service URLcreateDefaultcurrently usesnew Properties(properties), which sets the passedpropertiesas… The migration command timeout is hard-coded to 60 seconds and marked as aFIXME. This contradicts…
Review effort: Lite
| } catch (UnknownHostException e) { | ||
| logger.debug("Unable to resolve configured management server address {}", hostname); | ||
| } | ||
| resolutionCache.put(hostname, new ResolvedAddress(ip, now)); |
|
Packaging result [SF]: ✔️ el8 ✔️ el9 ✔️ el10 ✔️ debian ✔️ suse15. SL-JID 19714 |
|
@blueorangutan test |
|
@nvazquez a [SL] Trillian-Jenkins test job (ol8 mgmt + kvm-ol8) has been kicked to run smoke tests |
|
@blueorangutan package |
|
@sureshanaparti a [SL] Jenkins job has been kicked to build packages. It will be bundled with no SystemVM templates. I'll keep you posted as I make progress. |
There was a problem hiding this comment.
🟡 Changes recommended
Several active correctness issues remain, including stale trace-context propagation, removal of the wrong agent during replacement, clustered peer failures for IP-configured deployments, and incomplete failure tracking for null responses.
13 open issues
Respect configured address format for host identification · New Skip unresolvable aliases before caching Hostname-only self-check misses active duplicate nodesisTerminated()reads_keywithout synchronization, whilesetKey()andterminated()write it… This adds a new abstract method toAgentManager, but `engine/storage/integration-test/src/test/jav… This debug logging prints all agent properties including their values. Agent properties commonly… Clear stale command trace context from MDC · New VM work serialization prevents UUID propagation MBean setter silently ignores time-to-wait updates Blank hostname creates invalid cluster service URLcreateDefaultcurrently usesnew Properties(properties), which sets the passedpropertiesas… The migration command timeout is hard-coded to 60 seconds and marked as aFIXME. This contradicts… Track null-answer migrations as failures · New
4 resolved since last review
Review effort: Lite
debdd10 to
64df4e3
Compare
There was a problem hiding this comment.
🟡 Changes recommended
Unresolved critical lifecycle, forwarding-registration, and public-interface compatibility defects, along with an unsafe empty-response dereference, can cause resource leaks, failed lookups, runtime incompatibility, and exceptions.
13 open issues
Agent shutdown leaves host connection process running · New New abstract method breaks custom backoff implementations · New Skip unresolvable aliases before caching Hostname-only self-check misses active duplicate nodesisTerminated()reads_keywithout synchronization, whilesetKey()andterminated()write it… This adds a new abstract method toAgentManager, but `engine/storage/integration-test/src/test/jav… This debug logging prints all agent properties including their values. Agent properties commonly… Empty answer array crashes response logging · New VM work serialization prevents UUID propagation MBean setter silently ignores time-to-wait updates Blank hostname creates invalid cluster service URLcreateDefaultcurrently usesnew Properties(properties), which sets the passedpropertiesas… The migration command timeout is hard-coded to 60 seconds and marked as aFIXME. This contradicts…
3 resolved since last review
Review effort: Lite
| private ScheduledExecutorService hostStatusExecutor; | ||
|
|
||
| public HostConnectProcess(Agent agent) { | ||
| this.agent = agent; | ||
| initExecutors(); | ||
| } | ||
|
|
||
| private void initExecutors() { | ||
| stop(); | ||
| var threadFactory = new NamedThreadFactory("Agent-" + HostStatusTask.class.getSimpleName()); | ||
| hostStatusExecutor = Executors.newScheduledThreadPool(1, threadFactory); |
64df4e3 to
5a5b922
Compare
There was a problem hiding this comment.
🟡 Changes recommended
Critical concurrency and agent-replacement defects remain that can trigger duplicate startup commands and remove the newly connected host from the agent map.
12 open issues
Prevent concurrent startup scheduling and stale future replacement · New Agent shutdown leaves host connection process running Skip unresolvable aliases before caching Hostname-only self-check misses active duplicate nodesisTerminated()reads_keywithout synchronization, whilesetKey()andterminated()write it… This adds a new abstract method toAgentManager, but `engine/storage/integration-test/src/test/jav… This debug logging prints all agent properties including their values. Agent properties commonly… VM work serialization prevents UUID propagation MBean setter silently ignores time-to-wait updates Blank hostname creates invalid cluster service URLcreateDefaultcurrently usesnew Properties(properties), which sets the passedpropertiesas… The migration command timeout is hard-coded to 60 seconds and marked as aFIXME. This contradicts…
2 resolved since last review
Review effort: Lite
| public void scheduleConnectProcess(Link link, boolean connectionTransfer) { | ||
| logger.debug("Scheduling connect process for {}", link); | ||
| initExecutors(); | ||
|
|
||
| var task = new HostStatusTask(link, connectionTransfer, agent); | ||
| var future = hostStatusExecutor.scheduleWithFixedDelay(ThreadContextUtil.wrapThreadContext(task), | ||
| HOST_STATUS_CHECK_INITIAL_DELAY_SEC, | ||
| hostStatusCheckDelaySec, TimeUnit.SECONDS); | ||
| task.setFuture(future); | ||
| hostStatusFutureRef.set(future); |
5a5b922 to
92a0c48
Compare
|
@blueorangutan package |
|
@sureshanaparti a [SL] Jenkins job has been kicked to build packages. It will be bundled with no SystemVM templates. I'll keep you posted as I make progress. |
|
Packaging result [SF]: ✔️ el8 ✔️ el9 ✔️ el10 ✔️ debian ✔️ suse15. SL-JID 19798 |
|
@blueorangutan test keepEnv |
|
@sureshanaparti a [SL] Trillian-Jenkins test job (ol8 mgmt + kvm-ol8) has been kicked to run smoke tests |
|
[SF] Trillian test result (tid-17310)
|



Description
Continued from #13028
This PR improves the Indirect agent connection handling, has the following improvements.
Types of changes
Feature/Enhancement Scale or Bug Severity
Feature/Enhancement Scale
Bug Severity
Screenshots (if appropriate):
How Has This Been Tested?
Checked the indirect agents connections (and re-connections) with KVM hosts, SSVM & CPVM.
How did you try to break this feature and the system with this change?