Pearl1594 commented on issue #4982:
URL: https://github.com/apache/cloudstack/issues/4982#issuecomment-836491292
@olivierlemasle @rhtyd Did some tests on VM instance usage to compare its
behavior against the way backup usage currently works and observed the
following:
**Note:** The usage aggregation time interval (
`usage.stats.job.aggregation.range`) is set to 5 minutes
#### Case 1: When VM is destroyed before the aggregation time interval:
Usage record is generated for only the time period the VM was present: For
example:
```
mysql> select * from usage_vm_instance where usage_type = 1;
+------------+---------+------------+----------------+---------+---------------------+-------------+-----------------+---------------------+---------------------+-----------+-----------+--------+
| usage_type | zone_id | account_id | vm_instance_id | vm_name |
service_offering_id | template_id | hypervisor_type | start_date |
end_date | cpu_speed | cpu_cores | memory |
+------------+---------+------------+----------------+---------+---------------------+-------------+-----------------+---------------------+---------------------+-----------+-----------+--------+
| 1 | 1 | 2 | 3 | test |
1 | 111 | Simulator | 2021-05-10 04:35:23 | 2021-05-10
07:40:34 | NULL | NULL | NULL |
+------------+---------+------------+----------------+---------+---------------------+-------------+-----------------+---------------------+---------------------+-----------+-----------+--------+
Corresponding usage record for that time period:
mysql> select
id,zone_id,account_id,usage_display,usage_type,raw_usage,start_date,end_date
from cloud_usage where usage_type = 1;
| 219 | 1 | 2 | 0.083334 Hrs | 1 |
0.08333361148834229 | 2021-05-10 07:33:13 | 2021-05-10 07:38:13 | <-- 0.083334
Hrs corresponds to 5mins
| 225 | 1 | 2 | 0.038991 Hrs | 1 |
0.03899139165878296 | 2021-05-10 07:38:13 | 2021-05-10 07:43:13 | <-- VM
instance deleted at 7:40:34 ; 0.038992 corresponds to approx. 2mins
+-----+---------+------------+---------------+------------+---------------------+---------------------+---------------------+
```
Same holds true for backups as well, when a backup offering is removed,
usage record is generated only for the specific duration of the time-interval
(aggregation interval) - https://github.com/apache/cloudstack/pull/5005 handles
displaying duration of usage in the raw_usage / usage_display fields of the
cloud_usage table as opposed to size
#### Case 2: When the VM is scaled i.e., service offering is changed, 2
records are generated
2 records are generated for the time interval when the compute offering was
changed
```
mysql> select vm_name,service_offering_id,start_date,end_date from
usage_vm_instance where usage_type = 1 and vm_instance_id = 6;
+---------+---------------------+---------------------+---------------------+
| vm_name | service_offering_id | start_date | end_date |
+---------+---------------------+---------------------+---------------------+
| iso1 | 1 | 2021-05-10 08:00:54 | 2021-05-10 08:06:12 |
| iso1 | 2 | 2021-05-10 08:06:12 | NULL |
+---------+---------------------+---------------------+---------------------+
Corresponding usage record when service offering was changed
mysql> select
usage_display,raw_usage,start_date,end_date,vm_name,offering_id from
cloud_usage where usage_type = 1;
| 0.038787 Hrs | 0.03878694400191307 | 2021-05-10 07:58:13 | 2021-05-10
08:03:13 | iso1 | 1 |
| 0.033787 Hrs | 0.033786945044994354 | 2021-05-10 08:03:13 | 2021-05-10
08:08:13 | iso1 | 2 | <--- 0.033787 Hrs corresponds to 2mins ; @
8:06 the Service offering was changed hence 2 records generated within the time
interval of 8:03 - 8:08
| 0.049547 Hrs | 0.04954666644334793 | 2021-05-10 08:03:13 | 2021-05-10
08:08:13 | iso1 | 1 | <---- 0.049547 Hrs corresponds to 3 mins
```
Case 2 holds true for backups as well, i.e., if the backup offering is
changed to another one within the stipulated aggregation interval, 2 records
are generated for that time period.
At `8:45` the backup offering was unassigned from a VM and a **new** backup
offering was assigned to it:
```
mysql> select vm_id,backup_offering_id,created,removed from usage_backup
where vm_id =6;
+-------+--------------------+---------------------+---------------------+
| vm_id | backup_offering_id | created | removed |
+-------+--------------------+---------------------+---------------------+
| 6 | 1 | 2021-05-10 08:34:05 | 2021-05-10 08:45:27 |
<-- Backup Offering removed
| 6 | 2 | 2021-05-10 08:45:38 | NULL |
<-- New Backup offering assigned to the VM
+-------+--------------------+---------------------+---------------------+
mysql> select
id,offering_id,usage_display,raw_usage,size,start_date,end_date from
cloud_usage where usage_type = 28 and vm_instance_id = 6;
+-----+-------------+---------------+----------------------+------+---------------------+---------------------+
| id | offering_id | usage_display | raw_usage | size |
start_date | end_date |
+-----+-------------+---------------+----------------------+------+---------------------+---------------------+
| 296 | 1 | 0.069064 Hrs | 0.06906416267156601 | 0 |
2021-05-10 08:33:13 | 2021-05-10 08:38:13 |
| 303 | 1 | 0.083329 Hrs | 0.08332943916320801 | 1000 |
2021-05-10 08:38:13 | 2021-05-10 08:43:13 |
| 310 | 1 | 0.037051 Hrs | 0.037051115185022354 | 1000 |
2021-05-10 08:43:13 | 2021-05-10 08:48:13 | <--- usage record for backup with
offering ID = 1
| 311 | 2 | 0.043229 Hrs | 0.04322861135005951 | 0 |
2021-05-10 08:43:13 | 2021-05-10 08:48:13 | <--- usage record for backup with
offering ID = 2
| 318 | 2 | 0.083334 Hrs | 0.08333417028188705 | 1000 |
2021-05-10 08:48:13 | 2021-05-10 08:53:13 |
```
However, when the backup offering is removed from the VM and the VM is then
re-assigned to the **SAME** backup offering, the usage gets aggregated, which
in my opinion is the way it should behave.
--
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.
For queries about this service, please contact Infrastructure at:
[email protected]