Skip to content

Commit 2b38e60

Browse files
engine: alert when a host reports instances CloudStack does not know about
A warn line only helps someone already reading the log. Raise an ALERT_TYPE_SYNC alert as well, so the condition reaches whoever watches alerts. The alert follows the same rule as the log: raised when the set of unknown instances on a host changes, not on every report. Nothing is stopped automatically. An unknown instance may be a domain an operator put on the host deliberately. Signed-off-by: Brad House <bhouse@nexthop.ai>
1 parent 4748bab commit 2b38e60

1 file changed

Lines changed: 14 additions & 1 deletion

File tree

‎engine/orchestration/src/main/java/com/cloud/vm/VirtualMachinePowerStateSyncImpl.java‎

Lines changed: 14 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -36,6 +36,7 @@
3636
import org.apache.logging.log4j.Logger;
3737

3838
import com.cloud.agent.api.HostVmStateReportEntry;
39+
import com.cloud.alert.AlertManager;
3940
import com.cloud.configuration.ManagementServiceConfiguration;
4041
import com.cloud.host.Host;
4142
import com.cloud.host.HostVO;
@@ -50,6 +51,9 @@ public class VirtualMachinePowerStateSyncImpl implements VirtualMachinePowerStat
5051
@Inject VMInstanceDao _instanceDao;
5152
@Inject HostDao hostDao;
5253
@Inject ManagementServiceConfiguration mgmtServiceConf;
54+
@Inject AlertManager _alertMgr;
55+
56+
protected static final String UNKNOWN_INSTANCES_ALERT_SUBJECT = "Instances running on a host that CloudStack has no record of";
5357

5458
private final Map<Long, Set<String>> unknownInstancesByHost = new ConcurrentHashMap<>();
5559

@@ -245,9 +249,18 @@ protected boolean reportUnknownInstances(long hostId, Set<String> unknownInstanc
245249
return true;
246250
}
247251
unknownInstancesByHost.put(hostId, unknownInstanceNames);
252+
HostVO host = hostCache.get(hostId);
253+
String names = String.join(", ", unknownInstanceNames);
248254
logger.warn("Host reports {} instance(s) that do not exist in CloudStack DB, they are running unmanaged. " +
249255
"host: {}, instances: [{}]",
250-
unknownInstanceNames.size(), hostCache.get(hostId), String.join(", ", unknownInstanceNames));
256+
unknownInstanceNames.size(), host, names);
257+
if (host != null) {
258+
_alertMgr.sendAlert(AlertManager.AlertType.ALERT_TYPE_SYNC, host.getDataCenterId(), host.getPodId(),
259+
UNKNOWN_INSTANCES_ALERT_SUBJECT,
260+
String.format("Host %s reports %d instance(s) that do not exist in CloudStack: %s. They are "
261+
+ "running unmanaged and may still be holding addresses and storage.",
262+
host.getName(), unknownInstanceNames.size(), names));
263+
}
251264
return true;
252265
}
253266

0 commit comments

Comments
 (0)