winterhazel commented on PR #10712:
URL: https://github.com/apache/cloudstack/pull/10712#issuecomment-2864940630

   @rajujith thanks for testing. These usage records are not duplicated. I 
think you just misinterpreted the `start_date` and `end_date` values. 
   
   When Usage runs, it splits the total time it has to generate records for 
into periods defined by the global setting `usage.stats.job.aggregation.range` 
(by default, this period is of 24 hours). The `start_date` and `end_date` 
values represent this period.
   
   To interpret the usage records, you also need to check the other columns. I 
will show some records I got in my environment as an example.
   
   1. First, I performed the same procedure as you of creating a network, 
implementing it, stopping it and deleting it.
   
   ```sql
   MariaDB [cloud_usage]> select * from usage_event where resource_id=205 and 
type in ('NETWORK.CREATE','NETWORK.DELETE','NETWORK.UPDATE');
   
+----+----------------+------------+---------------------+---------+-------------+---------------+-------------+-------------+------+---------------+-----------+--------------+
   | id | type           | account_id | created             | zone_id | 
resource_id | resource_name | offering_id | template_id | size | resource_type 
| processed | virtual_size |
   
+----+----------------+------------+---------------------+---------+-------------+---------------+-------------+-------------+------+---------------+-----------+--------------+
   | 18 | NETWORK.CREATE |          2 | 2025-05-09 02:01:40 |       1 |         
205 | test-net      |          10 |        NULL | NULL | NULL          |        
 1 |         NULL |
   | 23 | NETWORK.UPDATE |          2 | 2025-05-09 02:02:49 |       1 |         
205 | test-net      |          10 |        NULL | NULL | Implemented   |        
 1 |         NULL |
   | 28 | NETWORK.UPDATE |          2 | 2025-05-09 02:05:40 |       1 |         
205 | test-net      |          10 |        NULL | NULL | Allocated     |        
 1 |         NULL |
   | 32 | NETWORK.DELETE |          2 | 2025-05-09 02:06:24 |       1 |         
205 | test-net      |          10 |        NULL | NULL | NULL          |        
 1 |         NULL |
   
+----+----------------+------------+---------------------+---------+-------------+---------------+-------------+-------------+------+---------------+-----------+--------------+
   4 rows in set (0.000 sec)
   ```
   
   2. Then, I ran the Usage job and got the following usage records for that 
network. Please see the `raw_usage`, `state`, `start_date` and `end_date` 
values.
   
   ```sql
   MariaDB [cloud_usage]> select 
id,usage_type,usage_id,description,raw_usage,state,start_date,end_date from 
cloud_usage where usage_id = 205;
   
+------+------------+----------+---------------------------------------------------------+----------------------+-------------+---------------------+---------------------+
   | id   | usage_type | usage_id | description                                 
            | raw_usage            | state       | start_date          | 
end_date            |
   
+------+------------+----------+---------------------------------------------------------+----------------------+-------------+---------------------+---------------------+
   | 1293 |         30 |      205 | Network usage for network ID: 205, network 
offering: 10 | 0.019166944548487663 | Allocated   | 2025-05-09 00:00:00 | 
2025-05-09 23:59:59 |
   | 1295 |         30 |      205 | Network usage for network ID: 205, network 
offering: 10 |  0.04750027880072594 | Implemented | 2025-05-09 00:00:00 | 
2025-05-09 23:59:59 |
   | 1296 |         30 |      205 | Network usage for network ID: 205, network 
offering: 10 | 0.012222499586641788 | Allocated   | 2025-05-09 00:00:00 | 
2025-05-09 23:59:59 |
   
+------+------------+----------+---------------------------------------------------------+----------------------+-------------+---------------------+---------------------+
   ```
   
   So, the first record does not represent that the network's state was 
`Allocated` for the full period between `2025-05-09 00:00:00` and `2025-05-09 
23:59:59`. Instead, it represents that the network's state was `Allocated` for 
`0.019166944548487663` hours between `2025-05-09 00:00:00` and `2025-05-09 
23:59:59`. We do not know when it transitioned into and out of `Allocated` in 
the usage record.
   
   Likewise, the second record represents that the network's state was 
`Implemented` for `0.04750027880072594` hours between `2025-05-09 00:00:00` and 
`2025-05-09 23:59:59`; the third represents that it was `Allocated` for 
`0.012222499586641788` more hours during that period.


-- 
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.

To unsubscribe, e-mail: [email protected]

For queries about this service, please contact Infrastructure at:
[email protected]

Reply via email to