Copilot commented on code in PR #13105:
URL: https://github.com/apache/cloudstack/pull/13105#discussion_r3200701183
##########
server/src/main/java/com/cloud/server/StatsCollector.java:
##########
@@ -2139,6 +2147,27 @@ protected boolean
isCurrentVmDiskStatsDifferentFromPrevious(VmDiskStatisticsVO p
return true;
}
+ /**
+ * Returns {@code true} if the given network is eligible for VM network
statistics collection.
+ * Only Shared (DirectAttached) networks and Routed networks qualify.
+ *
+ * @param networkId the network id to evaluate
+ * @return {@code true} when the network is routed or direct-attached,
{@code false} otherwise
+ */
+ protected boolean isNetworkEligibleForNetworkStats(Long networkId) {
+ if (networkId == null) {
+ return false;
+ }
+ List<VlanVO> vlans = _vlanDao.listVlansByNetworkId(networkId);
+ boolean isDirectAttachedNetwork = CollectionUtils.isNotEmpty(vlans)
+ && vlans.get(0).getVlanType() == VlanType.DirectAttached;
+ if (isDirectAttachedNetwork) {
+ return true;
+ }
+ NetworkVO networkVO = networkDao.findById(networkId);
+ return networkVO != null &&
routedIpv4Manager.isRoutedNetwork(networkVO);
+ }
+
Review Comment:
This helper is called inside the innermost VM/NIC stats loop, but it
performs multiple DB lookups (`networkDao.findById` here and
`routedIpv4Manager.isRoutedNetwork(...)`, which in `RoutedIpv4ManagerImpl`
loads the network offering). This can create an N+1 query pattern on large
setups. Consider caching eligibility per `networkId` for the duration of the
task/transaction or otherwise batching/preloading the network/offering data to
avoid repeated queries.
--
This is an automated message from the Apache Git Service.
To respond to the message, please log on to GitHub and use the
URL above to go to the specific comment.
To unsubscribe, e-mail: [email protected]
For queries about this service, please contact Infrastructure at:
[email protected]