Skip to content

Commit ca78f5b

Browse files
Enhance log messages with host name (#4575)
* Enhance log messages with hostName * Use host.toString() on most of host logs. * Remove redundant "Host" in logs and enhance logs * duplicated "for" * Adopt String.format, and enhance code * Address reviews enhancing log messages Update server/src/main/java/com/cloud/resource/ResourceManagerImpl.java -- server/src/main/java/com/cloud/vm/UserVmManagerImpl.java -- server/src/main/java/com/cloud/resource/RollingMaintenanceManagerImpl.java Co-authored-by: Daniel Augusto Veronezi Salvador <38945620+GutoVeronezi@users.noreply.github.com> * Fix String.format issue and change log message from debug to warn * Fix checkstyle issue * Fix string.format log * Address review: enhance logs * Enhance log of hosts in maintenance avoid list * Remove "VM" on logs as vm.toString() already appends VM-<details> * Add more details of the VM when postStateTransitionEvent * Address reviewer and enhance VMInstanceVO.toString() Co-authored-by: Daniel Augusto Veronezi Salvador <38945620+GutoVeronezi@users.noreply.github.com>
1 parent b5d7535 commit ca78f5b

11 files changed

Lines changed: 100 additions & 77 deletions

File tree

engine/orchestration/src/main/java/com/cloud/agent/manager/ClusteredAgentManagerImpl.java

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -286,7 +286,7 @@ protected AgentAttache createAttacheForConnect(final HostVO host, final Link lin
286286

287287
@Override
288288
protected AgentAttache createAttacheForDirectConnect(final Host host, final ServerResource resource) {
289-
s_logger.debug("create ClusteredDirectAgentAttache for " + host.getId());
289+
s_logger.debug(String.format("Create ClusteredDirectAgentAttache for %s.", host));
290290
final DirectAgentAttache attache = new ClusteredDirectAgentAttache(this, host.getId(), host.getName(), _nodeId, resource, host.isInMaintenanceStates());
291291
AgentAttache old = null;
292292
synchronized (_agents) {

engine/orchestration/src/main/java/com/cloud/vm/VirtualMachineManagerImpl.java

Lines changed: 21 additions & 12 deletions
Original file line numberDiff line numberDiff line change
@@ -4346,19 +4346,25 @@ private void orchestrateMigrateForScale(final String vmUuid, final long srcHostI
43464346
throws ResourceUnavailableException, ConcurrentOperationException {
43474347

43484348
VMInstanceVO vm = _vmDao.findByUuid(vmUuid);
4349-
s_logger.info("Migrating " + vm + " to " + dest);
4349+
s_logger.info(String.format("Migrating %s to %s", vm, dest));
43504350

43514351
vm.getServiceOfferingId();
43524352
final long dstHostId = dest.getHost().getId();
43534353
final Host fromHost = _hostDao.findById(srcHostId);
4354+
Host srcHost = _hostDao.findById(srcHostId);
43544355
if (fromHost == null) {
4355-
s_logger.info("Unable to find the host to migrate from: " + srcHostId);
4356-
throw new CloudRuntimeException("Unable to find the host to migrate from: " + srcHostId);
4356+
String logMessageUnableToFindHost = String.format("Unable to find host to migrate from %s.", srcHost);
4357+
s_logger.info(logMessageUnableToFindHost);
4358+
throw new CloudRuntimeException(logMessageUnableToFindHost);
43574359
}
43584360

4359-
if (fromHost.getClusterId().longValue() != dest.getCluster().getId()) {
4360-
s_logger.info("Source and destination host are not in same cluster, unable to migrate to host: " + dstHostId);
4361-
throw new CloudRuntimeException("Source and destination host are not in same cluster, unable to migrate to host: " + dest.getHost().getId());
4361+
Host dstHost = _hostDao.findById(dstHostId);
4362+
long destHostClusterId = dest.getCluster().getId();
4363+
long fromHostClusterId = fromHost.getClusterId();
4364+
if (fromHostClusterId != destHostClusterId) {
4365+
String logMessageHostsOnDifferentCluster = String.format("Source and destination host are not in same cluster, unable to migrate to %s", srcHost);
4366+
s_logger.info(logMessageHostsOnDifferentCluster);
4367+
throw new CloudRuntimeException(logMessageHostsOnDifferentCluster);
43624368
}
43634369

43644370
final VirtualMachineGuru vmGuru = getVmGuru(vm);
@@ -4475,23 +4481,24 @@ private void orchestrateMigrateForScale(final String vmUuid, final long srcHostI
44754481
try {
44764482
_agentMgr.send(srcHostId, new Commands(cleanup(vm.getInstanceName())), null);
44774483
} catch (final AgentUnavailableException e) {
4478-
s_logger.error("AgentUnavailableException while cleanup on source host: " + srcHostId);
4484+
s_logger.error(String.format("Unable to cleanup source %s. ", srcHost), e);
44794485
}
44804486
cleanup(vmGuru, new VirtualMachineProfileImpl(vm), work, Event.AgentReportStopped, true);
44814487
throw new CloudRuntimeException("Unable to complete migration for " + vm);
44824488
}
44834489
} catch (final OperationTimedoutException e) {
4484-
s_logger.debug("Error while checking the vm " + vm + " on host " + dstHostId, e);
4490+
s_logger.debug(String.format("Error while checking the %s on %s", vm, dstHost), e);
44854491
}
44864492

44874493
migrated = true;
44884494
} finally {
44894495
if (!migrated) {
44904496
s_logger.info("Migration was unsuccessful. Cleaning up: " + vm);
44914497

4492-
_alertMgr.sendAlert(alertType, fromHost.getDataCenterId(), fromHost.getPodId(),
4493-
"Unable to migrate vm " + vm.getInstanceName() + " from host " + fromHost.getName() + " in zone " + dest.getDataCenter().getName() + " and pod " +
4494-
dest.getPod().getName(), "Migrate Command failed. Please check logs.");
4498+
String alertSubject = String.format("Unable to migrate %s from %s in Zone [%s] and Pod [%s].",
4499+
vm.getInstanceName(), fromHost, dest.getDataCenter().getName(), dest.getPod().getName());
4500+
String alertBody = "Migrate Command failed. Please check logs.";
4501+
_alertMgr.sendAlert(alertType, fromHost.getDataCenterId(), fromHost.getPodId(), alertSubject, alertBody);
44954502
try {
44964503
_agentMgr.send(dstHostId, new Commands(cleanup(vm.getInstanceName())), null);
44974504
} catch (final AgentUnavailableException ae) {
@@ -4841,6 +4848,8 @@ private void handlePowerOnReportWithNoPendingJobsOnVM(final VMInstanceVO vm) {
48414848
// 3) handle out of sync stationary states, marking VM from Stopped to Running with
48424849
// alert messages
48434850
//
4851+
Host host = _hostDao.findById(vm.getHostId());
4852+
Host poweredHost = _hostDao.findById(vm.getPowerHostId());
48444853
switch (vm.getState()) {
48454854
case Starting:
48464855
s_logger.info("VM " + vm.getInstanceName() + " is at " + vm.getState() + " and we received a power-on report while there is no pending jobs on it");
@@ -4862,7 +4871,7 @@ private void handlePowerOnReportWithNoPendingJobsOnVM(final VMInstanceVO vm) {
48624871
case Running:
48634872
try {
48644873
if (vm.getHostId() != null && vm.getHostId().longValue() != vm.getPowerHostId().longValue()) {
4865-
s_logger.info("Detected out of band VM migration from host " + vm.getHostId() + " to host " + vm.getPowerHostId());
4874+
s_logger.info(String.format("Detected out of band VM migration from %s to %s", host, poweredHost));
48664875
}
48674876
stateTransitTo(vm, VirtualMachine.Event.FollowAgentPowerOnReport, vm.getPowerHostId());
48684877
} catch (final NoTransitionException e) {

engine/schema/src/main/java/com/cloud/dc/ClusterVO.java

Lines changed: 5 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -196,4 +196,9 @@ public void setUuid(String uuid) {
196196
public PartitionType partitionType() {
197197
return PartitionType.Cluster;
198198
}
199+
200+
@Override
201+
public String toString() {
202+
return String.format("Cluster {id: \"%s\", name: \"%s\", uuid: \"%s\"}", id, name, uuid);
203+
}
199204
}

engine/schema/src/main/java/com/cloud/vm/VMInstanceVO.java

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -506,7 +506,7 @@ public void setRemoved(Date removed) {
506506

507507
@Override
508508
public String toString() {
509-
return String.format("VM instance {\"id\": \"%s\", \"name\": \"%s\", \"uuid\": \"%s\", \"type\"=\"%s\"}", id, getInstanceName(), uuid, type);
509+
return String.format("VM instance {id: \"%s\", name: \"%s\", uuid: \"%s\", type=\"%s\"}", id, getInstanceName(), uuid, type);
510510
}
511511

512512
@Override

server/src/main/java/com/cloud/capacity/CapacityManagerImpl.java

Lines changed: 5 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -926,8 +926,11 @@ public boolean postStateTransitionEvent(StateMachine2.Transition<State, Event> t
926926
State oldState = transition.getCurrentState();
927927
State newState = transition.getToState();
928928
Event event = transition.getEvent();
929-
s_logger.debug("VM state transitted from :" + oldState + " to " + newState + " with event: " + event + "vm's original host id: " + vm.getLastHostId() +
930-
" new host id: " + vm.getHostId() + " host id before state transition: " + oldHostId);
929+
Host lastHost = _hostDao.findById(vm.getLastHostId());
930+
Host oldHost = _hostDao.findById(oldHostId);
931+
Host newHost = _hostDao.findById(vm.getHostId());
932+
s_logger.debug(String.format("%s state transited from [%s] to [%s] with event [%s]. VM's original host: %s, new host: %s, host before state transition: %s", vm, oldState,
933+
newState, event, lastHost, newHost, oldHost));
931934

932935
if (oldState == State.Starting) {
933936
if (newState != State.Running) {

server/src/main/java/com/cloud/network/element/VirtualRouterElement.java

Lines changed: 3 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -411,12 +411,13 @@ public boolean stopVpn(final RemoteAccessVpn vpn) throws ResourceUnavailableExce
411411
if (canHandle(network, Service.Vpn)) {
412412
final List<DomainRouterVO> routers = _routerDao.listByNetworkAndRole(network.getId(), Role.VIRTUAL_ROUTER);
413413
if (routers == null || routers.isEmpty()) {
414-
s_logger.debug("Virtual router elemnt doesn't need stop vpn on the backend; virtual router doesn't " + "exist in the network " + network.getId());
414+
s_logger.debug(String.format("There is no virtual router in network [uuid: %s, name: %s], it is not necessary to stop the VPN on backend.",
415+
network.getUuid(), network.getName()));
415416
return true;
416417
}
417418
return _routerMgr.deleteRemoteAccessVpn(network, vpn, routers);
418419
} else {
419-
s_logger.debug("Element " + getName() + " doesn't handle removeVpn command");
420+
s_logger.debug(String.format("Element %s doesn't handle removeVpn command", getName()));
420421
return false;
421422
}
422423
}

0 commit comments

Comments
 (0)