-
Notifications
You must be signed in to change notification settings - Fork 1.2k
Improve logging to include more identifiable information #9873
New issue
Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.
By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.
Already on GitHub? Sign in to your account
Changes from 11 commits
5bea350
e388764
bd59153
e1b9862
c4dcb2b
0bbc2cb
6b6ae03
7e0d848
d28ffab
2bf838b
20dbdaa
a639d3c
6557a3d
9146221
785c064
c197b83
b903796
7ba32df
499df2d
74124af
b47db16
1cb1962
f0ee884
8af0b13
File filter
Filter by extension
Conversations
Jump to
Diff view
Diff view
There are no files selected for viewing
| Original file line number | Diff line number | Diff line change | ||||
|---|---|---|---|---|---|---|
|
|
@@ -132,6 +132,8 @@ | |||||
| ServerResource _resource; | ||||||
| Link _link; | ||||||
| Long _id; | ||||||
| String _uuid; | ||||||
| String _name; | ||||||
|
|
||||||
| Timer _timer = new Timer("Agent Timer"); | ||||||
| Timer certTimer; | ||||||
|
|
@@ -182,8 +184,10 @@ | |||||
| resource.setAgentControl(this); | ||||||
|
|
||||||
| final String value = _shell.getPersistentProperty(getResourceName(), "id"); | ||||||
| _uuid = _shell.getPersistentProperty(getResourceName(), "uuid"); | ||||||
| _name = _shell.getPersistentProperty(getResourceName(), "name"); | ||||||
| _id = value != null ? Long.parseLong(value) : null; | ||||||
| logger.info("id is {}", ObjectUtils.defaultIfNull(_id, "")); | ||||||
| logger.info("Initialising agent [id: {}, uuid: {}, name: {}]", ObjectUtils.defaultIfNull(_id, ""), _uuid, _name); | ||||||
|
|
||||||
| final Map<String, Object> params = new HashMap<>(); | ||||||
|
|
||||||
|
|
@@ -212,8 +216,9 @@ | |||||
| new ThreadPoolExecutor(_shell.getWorkers(), 5 * _shell.getWorkers(), 1, TimeUnit.DAYS, new LinkedBlockingQueue<Runnable>(), new NamedThreadFactory( | ||||||
| "agentRequest-Handler")); | ||||||
|
|
||||||
| logger.info("Agent [id = {} : type = {} : zone = {} : pod = {} : workers = {} : host = {} : port = {}", ObjectUtils.defaultIfNull(_id, "new"), getResourceName(), | ||||||
| _shell.getZone(), _shell.getPod(), _shell.getWorkers(), host, _shell.getPort()); | ||||||
| logger.info("Agent [id = {}, uuid: {}, name: {}] : type = {} : zone = {} : pod = {} : workers = {} : host = {} : port = {}", | ||||||
|
Contributor
There was a problem hiding this comment. Choose a reason for hiding this commentThe reason will be displayed to describe this comment to others. Learn more.
Suggested change
|
||||||
| ObjectUtils.defaultIfNull(_id, "new"), _uuid, _name, getResourceName(), | ||||||
| _shell.getZone(), _shell.getPod(), _shell.getWorkers(), host, _shell.getPort()); | ||||||
| } | ||||||
|
|
||||||
| public String getVersion() { | ||||||
|
|
@@ -377,11 +382,28 @@ | |||||
| } | ||||||
|
|
||||||
| public void setId(final Long id) { | ||||||
| logger.debug("Set agent id {}", id); | ||||||
| _id = id; | ||||||
| _shell.setPersistentProperty(getResourceName(), "id", Long.toString(id)); | ||||||
| } | ||||||
|
|
||||||
| public String getUuid() { | ||||||
| return _uuid; | ||||||
| } | ||||||
|
|
||||||
| public void setUuid(String uuid) { | ||||||
| this._uuid = uuid; | ||||||
| _shell.setPersistentProperty(getResourceName(), "uuid", uuid); | ||||||
| } | ||||||
|
|
||||||
| public String getName() { | ||||||
| return _name; | ||||||
| } | ||||||
|
|
||||||
| public void setName(String name) { | ||||||
| this._name = name; | ||||||
| _shell.setPersistentProperty(getResourceName(), "name", name); | ||||||
| } | ||||||
|
|
||||||
| private synchronized void scheduleServicesRestartTask() { | ||||||
| if (certTimer != null) { | ||||||
| certTimer.cancel(); | ||||||
|
|
@@ -594,19 +616,21 @@ | |||||
| return; | ||||||
| } | ||||||
|
|
||||||
| logger.info("Process agent startup answer, agent [id: {}, name: {}] connected to the server", | ||||||
| startup.getHostId(), startup.getHostName()); | ||||||
| logger.info("Process agent startup answer, agent [id: {}, uuid: {}, name: {}] connected to the server", | ||||||
| startup.getHostId(), startup.getHostUuid(), startup.getHostName()); | ||||||
|
|
||||||
| setId(startup.getHostId()); | ||||||
| setUuid(startup.getHostUuid()); | ||||||
| setName(startup.getHostName()); | ||||||
| _pingInterval = (long)startup.getPingInterval() * 1000; // change to ms. | ||||||
|
|
||||||
| setLastPingResponseTime(); | ||||||
| scheduleWatch(link, response, _pingInterval, _pingInterval); | ||||||
|
|
||||||
| _ugentTaskPool.setKeepAliveTime(2 * _pingInterval, TimeUnit.MILLISECONDS); | ||||||
|
|
||||||
| logger.info("Startup Response Received: agent [id: {}, name: {}]", | ||||||
| getId(), startup.getHostName()); | ||||||
| logger.info("Startup Response Received: agent [id: {}, uuid: {}, name: {}]", | ||||||
| startup.getHostId(), startup.getHostUuid(), startup.getHostName()); | ||||||
| } | ||||||
|
|
||||||
| protected void processRequest(final Request request, final Link link) { | ||||||
|
|
@@ -862,15 +886,17 @@ | |||||
| NumbersUtil.enableHumanReadableSizes = humanReadable; | ||||||
| } | ||||||
|
|
||||||
| logger.info("Processing agent ready command, agent id = {}", ready.getHostId()); | ||||||
| logger.info("Processing agent ready command, agent id = {}, uuid = {}, name = {}", ready.getHostId(), ready.getHostUuid(), ready.getHostName()); | ||||||
| if (ready.getHostId() != null) { | ||||||
| setId(ready.getHostId()); | ||||||
| setUuid(ready.getHostUuid()); | ||||||
| setName(ready.getHostName()); | ||||||
| } | ||||||
|
|
||||||
| verifyAgentArch(ready.getArch()); | ||||||
| processManagementServerList(ready.getMsHostList(), ready.getLbAlgorithm(), ready.getLbCheckInterval()); | ||||||
|
|
||||||
| logger.info("Ready command is processed for agent id = {}", getId()); | ||||||
| logger.info("Ready command is processed for agent [id: {}, uuid: {}, name: {}]", getId(), getUuid(), getName()); | ||||||
| } | ||||||
|
|
||||||
| private void verifyAgentArch(String arch) { | ||||||
|
|
||||||
| Original file line number | Diff line number | Diff line change | ||||
|---|---|---|---|---|---|---|
|
|
@@ -125,8 +125,9 @@ | |||||
| hostResponse.setResponseName(getCommandName()); | ||||||
| this.setResponseObject(hostResponse); | ||||||
| } catch (Exception e) { | ||||||
| logger.debug("Failed to update host:" + getId(), e); | ||||||
| throw new ServerApiException(ApiErrorCode.INTERNAL_ERROR, "Failed to update host:" + getId() + "," + e.getMessage()); | ||||||
| Host host = _entityMgr.findById(Host.class, getId()); | ||||||
| logger.debug("Failed to update host: {} with id {}", host, getId(), e); | ||||||
|
Contributor
There was a problem hiding this comment. Choose a reason for hiding this commentThe reason will be displayed to describe this comment to others. Learn more.
Suggested change
|
||||||
| throw new ServerApiException(ApiErrorCode.INTERNAL_ERROR, String.format("Failed to update host: %s with id %d, %s", host, getId(), e.getMessage())); | ||||||
|
Check warning on line 130 in api/src/main/java/org/apache/cloudstack/api/command/admin/host/UpdateHostCmd.java
|
||||||
| } | ||||||
| } | ||||||
| } | ||||||
| Original file line number | Diff line number | Diff line change | ||||
|---|---|---|---|---|---|---|
|
|
@@ -124,10 +124,10 @@ | |||||
| if (account.getType() == Account.Type.PROJECT) { | ||||||
| Project project = _projectService.findByProjectAccountId(vmsnapshot.getAccountId()); | ||||||
| if (project == null) { | ||||||
| throw new InvalidParameterValueException("Unable to find project by account id=" + account.getUuid()); | ||||||
| throw new InvalidParameterValueException(String.format("Unable to find project by account %s", account)); | ||||||
|
Check warning on line 127 in api/src/main/java/org/apache/cloudstack/api/command/user/snapshot/CreateSnapshotFromVMSnapshotCmd.java
|
||||||
| } | ||||||
| if (project.getState() != Project.State.Active) { | ||||||
| throw new PermissionDeniedException("Can't add resources to the project id=" + project.getUuid() + " in state=" + project.getState() + " as it's no longer active"); | ||||||
| throw new PermissionDeniedException(String.format("Can't add resources to the project %s in state=%s as it's no longer active", project, project.getState())); | ||||||
|
Check warning on line 130 in api/src/main/java/org/apache/cloudstack/api/command/user/snapshot/CreateSnapshotFromVMSnapshotCmd.java
|
||||||
| } | ||||||
| } else if (account.getState() == Account.State.DISABLED) { | ||||||
| throw new PermissionDeniedException("The owner of template is disabled: " + account); | ||||||
|
|
@@ -164,8 +164,9 @@ | |||||
|
|
||||||
| @Override | ||||||
| public void execute() { | ||||||
| logger.info("CreateSnapshotFromVMSnapshotCmd with vm snapshot id:" + getVMSnapshotId() + " and snapshot id:" + getEntityId() + " starts:" + System.currentTimeMillis()); | ||||||
| CallContext.current().setEventDetails("Vm Snapshot Id: "+ this._uuidMgr.getUuid(VMSnapshot.class, getVMSnapshotId())); | ||||||
| VMSnapshot vmSnapshot = _vmSnapshotService.getVMSnapshotById(getVMSnapshotId()); | ||||||
| logger.info("CreateSnapshotFromVMSnapshotCmd with vm snapshot {} with id {} and snapshot [id: {}, uuid: {}]", vmSnapshot, getVMSnapshotId(), getEntityId(), getEntityUuid()); | ||||||
|
Contributor
There was a problem hiding this comment. Choose a reason for hiding this commentThe reason will be displayed to describe this comment to others. Learn more.
Suggested change
|
||||||
| CallContext.current().setEventDetails("Vm Snapshot Id: " + vmSnapshot.getUuid()); | ||||||
|
Check warning on line 169 in api/src/main/java/org/apache/cloudstack/api/command/user/snapshot/CreateSnapshotFromVMSnapshotCmd.java
|
||||||
| Snapshot snapshot = null; | ||||||
| try { | ||||||
| snapshot = _snapshotService.backupSnapshotFromVmSnapshot(getEntityId(), getVmId(), getVolumeId(), getVMSnapshotId()); | ||||||
|
|
@@ -174,19 +175,19 @@ | |||||
| response.setResponseName(getCommandName()); | ||||||
| this.setResponseObject(response); | ||||||
| } else { | ||||||
| throw new ServerApiException(ApiErrorCode.INTERNAL_ERROR, "Failed to create snapshot due to an internal error creating snapshot from vm snapshot " + getVMSnapshotId()); | ||||||
| throw new ServerApiException(ApiErrorCode.INTERNAL_ERROR, String.format("Failed to create snapshot due to an internal error creating snapshot from vm snapshot %s", vmSnapshot)); | ||||||
|
Check warning on line 178 in api/src/main/java/org/apache/cloudstack/api/command/user/snapshot/CreateSnapshotFromVMSnapshotCmd.java
|
||||||
| } | ||||||
| } catch (InvalidParameterValueException ex) { | ||||||
| throw ex; | ||||||
| } catch (Exception e) { | ||||||
| logger.debug("Failed to create snapshot", e); | ||||||
| throw new ServerApiException(ApiErrorCode.INTERNAL_ERROR, "Failed to create snapshot due to an internal error creating snapshot from vm snapshot " + getVMSnapshotId()); | ||||||
| throw new ServerApiException(ApiErrorCode.INTERNAL_ERROR, String.format("Failed to create snapshot due to an internal error creating snapshot from vm snapshot %s", vmSnapshot)); | ||||||
|
Check warning on line 184 in api/src/main/java/org/apache/cloudstack/api/command/user/snapshot/CreateSnapshotFromVMSnapshotCmd.java
|
||||||
| } finally { | ||||||
| if (snapshot == null) { | ||||||
| try { | ||||||
| _snapshotService.deleteSnapshot(getEntityId(), null); | ||||||
| } catch (Exception e) { | ||||||
| logger.debug("Failed to clean failed snapshot" + getEntityId()); | ||||||
| logger.debug("Failed to clean failed snapshot {} with id {}", () -> _entityMgr.findById(Snapshot.class, getEntityId()), this::getEntityId); | ||||||
|
Check warning on line 190 in api/src/main/java/org/apache/cloudstack/api/command/user/snapshot/CreateSnapshotFromVMSnapshotCmd.java
|
||||||
| } | ||||||
| } | ||||||
| } | ||||||
|
|
||||||
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.