Copilot commented on code in PR #13775:
URL: https://github.com/apache/cloudstack/pull/13775#discussion_r4523923352


##########
engine/components-api/src/main/java/com/cloud/alert/AlertFormatUtils.java:
##########
@@ -0,0 +1,47 @@
+// Licensed to the Apache Software Foundation (ASF) under one
+// or more contributor license agreements.  See the NOTICE file
+// distributed with this work for additional information
+// regarding copyright ownership.  The ASF licenses this file
+// to you under the Apache License, Version 2.0 (the
+// "License"); you may not use this file except in compliance
+// with the License.  You may obtain a copy of the License at
+//
+//   http://www.apache.org/licenses/LICENSE-2.0
+//
+// Unless required by applicable law or agreed to in writing,
+// software distributed under the License is distributed on an
+// "AS IS" BASIS, WITHOUT WARRANTIES OR CONDITIONS OF ANY
+// KIND, either express or implied.  See the License for the
+// specific language governing permissions and limitations
+// under the License.
+package com.cloud.alert;
+
+import com.cloud.dc.DataCenter;
+import com.cloud.dc.Pod;
+import com.cloud.host.Host;
+
+/**
+ * Shared formatting for the host/zone/pod description that recurs, 
independently
+ * hand-rolled and inconsistently worded (and occasionally mislabelled), 
across the
+ * HA and agent-management alert call sites. See CLOUDSTACK-7297.
+ */

Review Comment:
   The PR description template is largely unfilled (no detailed behavior 
change, testing notes, or type/scale boxes checked), but the note indicates 
automation relies on it. Please update the PR description to clearly state what 
changed in alert formats, which subsystems are affected, and how it was tested.



##########
server/src/main/java/com/cloud/storage/snapshot/SnapshotManagerImpl.java:
##########
@@ -2139,7 +2139,7 @@ public Snapshot allocSnapshot(Long volumeId, Long 
policyId, String snapshotName,
             return snapshot;
         } catch (ResourceAllocationException e) {
             if (snapshotType != Type.MANUAL) {
-                String msg = String.format("Snapshot resource limit exceeded 
for account id : %s. Failed to create recurring snapshots", owner.getId());
+                String msg = String.format("Snapshot resource limit exceeded 
for account: %s. Failed to create recurring snapshots", owner);
                 logger.warn(msg);
                 
_alertMgr.sendAlert(AlertManager.AlertType.ALERT_TYPE_UPDATE_RESOURCE_COUNT, 
0L, 0L, msg, msg + ". Please, use updateResourceLimit to increase the limit");

Review Comment:
   Using `owner`’s `toString()` in an operational alert can reduce usefulness 
if it doesn’t include a stable identifier (e.g., numeric id/uuid) or if its 
formatting changes over time. Consider including both: a stable id/uuid and a 
human-readable name (similar to the new host-location formatting) to keep 
alerts actionable and consistent.



##########
server/src/main/java/org/apache/cloudstack/outofbandmanagement/OutOfBandManagementServiceImpl.java:
##########
@@ -260,7 +260,7 @@ private boolean isOutOfBandManagementEnabledForHost(Long 
hostId) {
         Host host = hostDao.findById(hostId);
         if (host == null || host.getResourceState() == ResourceState.Degraded) 
{
             String state = host != null ? 
String.valueOf(host.getResourceState()) : null;
-            logger.debug("Host [id={}, uuid={}, state={}] was removed or 
placed in Degraded state by the Admin.", hostId, host != null ? host.getUuid() 
: "", state);
+            logger.debug("Host [{}] was removed or placed in Degraded state 
(state={}) by the Admin.", host != null ? host : "id=" + hostId, state);

Review Comment:
   The logger call builds `"id=" + hostId` eagerly (and potentially calls 
`host.toString()` eagerly) even when debug logging is disabled. Prefer passing 
`hostId` as a separate argument (or guarding with `logger.isDebugEnabled()`) to 
avoid unnecessary string allocation in a likely hot path.



##########
server/src/main/java/org/apache/cloudstack/ha/provider/host/HAAbstractHostProvider.java:
##########
@@ -95,11 +95,11 @@ public void sendAlert(final Host host, final 
HAConfig.HAState nextState) {
         String subject = "HA operation performed for host";
         String body = subject;
         if (HAConfig.HAState.Fencing.equals(nextState)) {
-            subject = String.format("HA Fencing of host id=%d, in dc id=%d 
performed", host.getId(), host.getDataCenterId());
-            body = String.format("HA Fencing has been performed for host 
id=%d, uuid=%s in datacenter id=%d", host.getId(), host.getUuid(), 
host.getDataCenterId());
+            subject = String.format("HA Fencing of host %s performed", host);
+            body = String.format("HA Fencing has been performed for host %s", 
host);
         } else if (HAConfig.HAState.Recovering.equals(nextState)) {
-            subject = String.format("HA Recovery of host id=%d, in dc id=%d 
performed", host.getId(), host.getDataCenterId());
-            body = String.format("HA Recovery has been performed for host 
id=%d, uuid=%s in datacenter id=%d", host.getId(), host.getUuid(), 
host.getDataCenterId());
+            subject = String.format("HA Recovery of host %s performed", host);
+            body = String.format("HA Recovery has been performed for host %s", 
host);
         }
         alertManager.sendAlert(AlertService.AlertType.ALERT_TYPE_HA_ACTION, 
host.getDataCenterId(), host.getPodId(), subject, body);

Review Comment:
   Switching from explicit fields (id/uuid/dc) to `host.toString()` makes alert 
content dependent on the `toString()` implementation, which can change and may 
omit critical identifiers. Consider formatting the alert with stable, explicit 
identifiers (e.g., name/id/uuid) and/or reusing 
`AlertFormatUtils.describeHostLocation(...)` so operators consistently see 
dc/pod context and machine-parseable fields.



-- 
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]

Reply via email to