Versions Compared

Key

  • This line was added.
  • This line was removed.
  • Formatting was changed.
Comment: Migrated to Confluence 5.3

...

https://issues.apache.org/jira/browse/CLOUDSTACK-6256

Branch

4.4

Introduction

Various actions on resources(for example, creating a resource or deleting of a resource) are logged as events into Cloudstack. These events could An event in cloudstack can be change in state (like create, edit, delete etc) of the resources, an action performed by the user (like login, logout etc ) or policy based events aka alerts. These events hold success or failure details related to that resourceof an event. Events for synchronous or asynchronous jobs are logged into cloud database in the following tablesasynchronous jobs log when a job is scheduled, when it starts, and when it completes. While events for long running synchronous jobs log when it starts and when it completes.

Purpose

Currently the events logged in CloudStack doesn't give detailed information about the event that has occurred. The information provided in each event shown on the cloudstack ui doesn't provide specifics, particularly in case of errors. For example, the message shown on the cloudstack ui is just "Error while starting Vm. Vm Id: <id>" in case of failure to start a vm , which doesn't help much. Hence, the events should be enhanced to include more information to be descriptive enough.

Proposal

I would like to propose some changes to enhance the events to be more informative. Like:

  1. Instead of just showing resource database id in the event details it should display resource UUID. Since all the cloudstack apis take input as resource uuid it would be helpful to see the same on the ui as well.
  2. Enhance the events and listEvents API to include the resource UUID so that it can be queried by the resource UUID as well.
  3. Currently, the event description messages are specified in the *Cmd.java file instead, all of them should be externalize to a resource file. This would be helpful even for internationalization.
  4. Provide more detailed messages in case of error events. Messages such as "Error while starting VM" are generic to take any action.

Design description and changes

Currently all the cloudstack events are persisted into the cloud database in the event and event_view table.

 

Code Block
mysql> desc event_view;
Code Block
mysql> desc event;
+-------------+---------------------+------+-----+-----------+----------------+
| Field       | Type                | Null | Key | Default   | Extra          |
+-------------+---------------------+------+-----+-----------+----------------+
| id          | bigint(20) unsigned | NO   | PRI | NULL      | auto_increment |
| uuid        | varchar(40)         | YES  | UNI | NULL mysql> desc event;
+--------------+---------------------+------+-----+-----------+-------+   |     +-------------+---------------------+------+-----+-----------+----------------+
| Field             |
| typeType        | varchar(32)         | NONull   | MULKey | NULLDefault   |  Extra |     |    Field       |
| stateType       | varchar(32)         | NONull | Key | Default    | Completed |     Extra           |
| description | varchar(1024)       | NO   |     | NULL|
+--------------+---------------------+------+-----+-----------+-------+     +-------------+---------------------+------+-----+-----------+----------------+
| id      |     | bigint(20) unsigned |    NO    |
| user_id    | |0 bigint(20) unsigned | NO   | MUL | NULL      |     |   id        |
| account_id  | bigint(20) unsigned | NO   | MULPRI | NULL      | auto_increment |
| uuid         | varchar(40)   |
| domain_id   | bigint(20) unsigned | NOYES   |     | NULL      |       |     | uuid   |
| created     | datetimevarchar(40)         | YES  | NO   | MUL UNI | NULL      |                |
| leveltype         | varchar(1632)         | NO   | MUL    | NULL      |       |     | type   |
| start_id    | bigintvarchar(2032)    unsigned | NO   |  NO   | 0MUL | NULL       |                |
| parameters state        | varchar(102432)       | YES  |  NO   | NULL    | Completed |       |     | state   |
| archived    | tinyintvarchar(132) unsigned | NO   |     | 0NO   |     | Completed |                |
+-------------+---------------------+------+-----+-----------+----------------+

mysql> desc event_view;
+--------------+---------------------+------+-----+-----------+-------+
| Field        | Type    | description  | varchar(1024)       | NO   |     | NULL      |       |     | description | varchar(1024)       | NO   |     | NULL      |      | Null | Key | Default   | Extra |
+--------------+---------------------+------+-----+-----------+-------+
| id| created      | datetime    | bigint(20) unsigned       | NO   |     | 0NULL         |       |
|  uuid   | user_id     | varcharbigint(4020) unsigned | NO   | MUL | |NULL YES  |   |  | NULL      |       |
| typelevel         | varchar(3216)         | NO   |     | NULL      |       |
| state    | account_id   | varcharbigint(3220) unsigned | NO   | MUL | NULL  | NO   |       | Completed |       |
| parameters description  | varchar(1024)       | NO YES  |     | NULL      |       |
| created      | datetimedomain_id   | bigint(20) unsigned       | NO   |     | NULL      |       |
| level        | varchar(16)
| start_id     | bigint(20)  unsigned | NO   |     | NULL0      |   |    |
| parameters   | varchar(1024)       | YES  |created     | NULLdatetime      |       |
| start_idNO   | MUL | bigint(20)NULL unsigned | NO   |     |  0         |       |
| start_uuid   | varchar(40)         | YES  |     | NULL      |       |
     | user_idlevel       | bigintvarchar(2016) unsigned         | NO   | MUL | NULL      | NULL        |       |
| archiveduser_id      | tinyintbigint(120) unsigned | NO   |     | NULL 0     |    |   |     |
| userstart_nameid    | varcharbigint(25520) unsigned | NO   |     | 0 NO   |     | NULL       |        |
| archived  account_id   | biginttinyint(201) unsigned | NO   |     | 0         |       |
     | account_uuidparameters  | varchar(401024)         | YES  |     | NULL      |                |
| accountuser_name    | varchar(100255)        | YESNO   |     | NULL      |       |
| account_type     | archived    | inttinyint(1) unsigned | NO   | NO    | 0         |   NULL      |       |
| domainaccount_id    | bigint(20) unsigned | NO   |     | 0         |       |
|  domain_uuid  | varchar(40)         | YES  |     | NULL      |       |
| domain_name  | varchar(255) +-------------+---------------------+------+-----+-----------+----------------+
| account_uuid | varchar(40)         | YES  |     | NULL      |       |
| domainaccount_path name | varchar(255100)        | NO YES  |     | NULL      |       |
| projectaccount_id  type | bigintint(201) unsigned  | YES  | NO   |  | 0  | NULL      |       |
| projectdomain_id    | bigint(20) unsigned | NO   |     | 0         |       |
| domain_uuid  | varchar(40)         | YES  |     | NULL      |       |
| projectdomain_name  | varchar(255)        | YES  |     | NULL      |       |
+--------------+---------------------+------+-----+-----------+-------+
24 rows in set (0.00 sec)

 

Currently the events logged in CloudStack doesn't give detailed information about the event that has occurred. The information provided in each event shown on the cloudstack ui doesn't provide specifics, particularly in case of errors. For example, the message shown on the cloudstack ui is just "Error while starting Vm. Vm Id: <id>" in case of failure to start a vm , which doesn't help much. Hence, the events should be enhanced to include more information to be descriptive enough.

Purpose

I would like to propose some changes to enhance the events to be more informative. Like:

  1. Instead of just showing resource database id in the event details it should display resource UUID. Since all the cloudstack apis take input as resource uuid it would be helpful to see the same on the ui as well.
  2. Enhance the events and listEvents API to include the resource UUID so that it can be queried by the resource UUID as well.
  3. Currently, the event description messages are specified in the *Cmd.java file instead, all of them should be externalize to a resource file. This would be helpful even for internationalization.
  4. Provide more detailed messages in case of error events. Messages such as "Error while starting VM" are generic to take any action.

Design description

Introduce resource UUID

Currently, all async commands required parameter resource database ids are displayed in the event descriptions. Change the resource ids with the resource UUIDs. As per current implementation event description is described in the following commands

...

| domain_path  | varchar(255)        | NO   |     | NULL      |       |
| project_id   | bigint(20) unsigned | YES  |     | 0         |       |
| project_uuid | varchar(40)         | YES  |     | NULL      |       |
| project_name | varchar(255)        | YES  |     | NULL      |       |
+--------------+---------------------+------+-----+-----------+-------+

Enhance the events

In order to enhance the events logged in cloudstack

  1. Add a new field error_message and error_type in the event_view table 

    Code Block
    +---------------+---------------------+------+-----+-----------+-------+
    | Field         | Type                | Null | Key | Default   | Extra |
    +---------------+---------------------+------+-----+-----------+-------+
    | error_message | varchar(1024)       | YES  |     | NULL      |       |
    | error_type    | varchar(255)        | YES  |     | NULL      |       |
    +---------------+---------------------+------+-----+-----------+-------+
  2. Use the existing parameters field (in the event and event_view table) to hold the event parameters. For example, the parameters required for deployVirtualMachine command like the zoneId, serviceOfferingId, templateId would be stored in the parameters field to be queried later.
  3. Add a new field resource_uuid, error_message and error_type in usage_event table

    Code Block
    +---------------+---------------------+------+-----+-----------+-------+
    | Field         | Type                | Null | Key | Default   | Extra |
    +---------------+---------------------+------+-----+-----------+-------+
    | resource_uuid | varchar(40)         | YES  |     | NULL      |       |
    | error_message | varchar(1024)       | YES  |     | NULL      |       |
    | error_type    | varchar(255)        | YES  |     | NULL      |       |
    +---------------+---------------------+------+-----+-----------+-------+


    error_message – detailed message describing the cause of failure
    error_type – type of errors like resource allocation errors, errors with the physical resource etc.
    resource_uuid – uuid of the resources like virtual machine, zone etc.

Enhance the listEvents api

Add the following request parameters to the listEvents api to list all the events by resource uuids

Parameter NameDescriptionRequired
resourceuuidlist all events by resource uuid. To be used with resourcetype parameter.false
resourcetypelist all events by resource type.false

 

Introduce resource UUID in event description

Currently, the resource uuid passed as parameter is translated into internal id while processing the parameters. In order to display the resource uuid's in the event description the uuid need not be translated to internal id.

Code Block
                     while (st.hasMoreTokens()) {
                        ...
                        switch (listType) {
                            case INTEGER:
                                listParam.add(Integer.valueOf(token));
                                break;
                            case UUID:
                                if (token.isEmpty())
                                    break;
                                final Long internalId = translateUuidToInternalId(token, annotation);
                                listParam.add(internalId);
                                break;
                            ...
                        }
                    }
                    ...

Detailed error messages in events

In case of events logged due to an error occurred while processing a job or change of state of a resource , a detailed error message describing the reason of failure would be logged into the error_message field of the event. Based on who the user is an admin or a normal user relevant error message would be shown to the end user.

How would error_message data be filled?

Currently, the error messages are ignored in case of any exceptions while a job is performed. The event interceptors in case of error log error events with the hard coded description provided in the event files.

Code Block
public class ActionEventInterceptor implements ComponentMethodInterceptor, MethodInterceptor {
...
 
@Override
public Object invoke(MethodInvocation invocation) throws Throwable {
    ...
    try {
        interceptorData = interceptStart(m, target);
        Object result = invocation.proceed();
        success = true;
        return result;
    } finally {
        if (success) {
            interceptComplete(m, target, interceptorData);
        } else {
            interceptException(m, target, interceptorData);
        }
    }
...

A catch block would help to have descriptive error messages, instead of displaying short un-descriptive event descriptions in case of error events.

Externalize the event descriptions strings

The event descriptions are currently hard coded in the java files. These strings could be externalize to a resource bundle like in a message.properties file, and can be processed in the event interceptors before an event is logged.