Yuliia7-1 opened a new issue, #13555:
URL: https://github.com/apache/cloudstack/issues/13555

   ### problem
   
   When a volume is resized, CloudStack publishes a EVENT_VOLUME_RESIZE usage 
event that is later used for billing calculations and stored in cloud_usage.
   
   In VolumeApiServiceImpl.orchestrateResizeVolume(), the volume size is 
updated before the usage event is published:
   
   ```
   if (currentSize == volume.getSize() && currentSize != newSize) {
       volume.setSize(newSize);
   } else if (volume.getSize() != newSize) {
       newSize = volume.getSize();
   }
   
   _volsDao.update(volume.getId(), volume);
   ```
   
   The usage event is then published using:
   ```
   UsageEventUtils.publishUsageEvent(
       EventTypes.EVENT_VOLUME_RESIZE,
       volume.getAccountId(),
       volume.getDataCenterId(),
       volume.getId(),
       volume.getName(),
       volume.getDiskOfferingId(),
       volume.getTemplateId(),
       volume.getSize(),
       Volume.class.getName(),
       volume.getUuid()
   );
   ```
   **Observed Behaviour**
   
   The resize event uses `volume.getSize()` instead of the final resize target 
value (newSize).
   
   In environments where billing is calculated from cloud_usage, we have 
observed discrepancies between:
   the current volume size reported by CloudStack APIs/UI, and the size stored 
in cloud_usage following resize operations.
   
   As a result, billing records may not accurately reflect the expected volume 
size history after one or more resize operations.
   
   ### versions
   
   4.19.1
   
   ### The steps to reproduce the bug
   
   1.
   2.
   3.
   ...
   
   
   ### What to do about it?
   
   The resize usage event should be published using the actual final resized 
value (newSize) that was determined during the resize workflow.
   
   For example:
   
   ```
   UsageEventUtils.publishUsageEvent(
       EventTypes.EVENT_VOLUME_RESIZE,
       volume.getAccountId(),
       volume.getDataCenterId(),
       volume.getId(),
       volume.getName(),
       volume.getDiskOfferingId(),
       volume.getTemplateId(),
       newSize,
       Volume.class.getName(),
       volume.getUuid()
   );
   ```
   
   This would ensure that usage records and billing calculations are based on 
the intended resize value.
   
   Affected Code: 
`server/src/main/java/com/cloud/storage/VolumeApiServiceImpl.java`
   
   Method: `orchestrateResizeVolume(...)`


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