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

   > @winterhazel , will you review?
   
   @DaanHoogland yes, I should be able to review and test this one by the end 
of the week.
   
   > @hsato03 , I feel a bit out of my depth on these preset variables and they 
only appear once in the documentation when it comes to storage; i.e. 
https://docs.cloudstack.apache.org/en/4.22.0.0/adminguide/storage.html#direct-resources-to-a-specific-secondary-storage.
 Is there some wiki page I can read to be able to concoct sensible tests for 
this?
   
   The Quota documentation needs some updating on how to use the activation 
rules and preset variables. There is no wiki on how to use them at the moment. 
We hope to address it in version 23/24 along with the pending code changes.
   
   Here's a basic guide on how to test the changes in this PR:
   
   1. Install Usage and ensure it is running. Also, have a look at the 
configured execution time, which is defined through the global settings 
`usage.stats.job.exec.time` and `usage.execution.timezone`.
   
   2. Enable Quota and JS interpretation. This can be done by toggling 
`quota.enable.service` and `js.interpretation.enabled` on and restarting the 
Management Server.
   
   3. Create different network and VPC offerings to be used for the tests.
   
   4. Create some tariffs (through `quotaTariffCreate`) using the preset 
variables in the activation rule.
   
      For the network usage type tariff, you can use the following activation 
rule:
      
      ```js
      if (value.networkOffering.id === '<uuid-of-network-offering-X>') {
      200
      } else {
      100
      }
      ```
      
      This tariff will charge users 200 credits in a month for each network 
using network offering X, and 100 for all other offerings. As this rule already 
returns a value, the tariff value can be left as 0 (it will be ignored). 
Another option is returning a true/false instead in the rule to inform whether 
or not the tariff value should be applied. The other non-required fields may be 
left as blank to use default values.
      
      ```sh
      (localcloud) 🐱 quota tariffcreate name="network tariff" usagetype=30 
activationrule="if (value.networkOffering.id === 
'<uuid-of-network-offering-X>') { 200 } else { 100 }" value=0
      ```
      
      For the VPC usage type tariff, the following activation rule can be used:
      
      ```js
      if (value.vpcOffering.id === '<uuid-of-VPC-offering-Y>') {
      300
      } else {
      200
      }
      ```
      
      This one will charge users 300 credits in a month for each VPC using the 
VPC offering Y, and 200 for all others.
   
      ```sh
      (localcloud) 🐱 quota tariffcreate name="vpc tariff" usagetype=31 
activationrule="if (value.vpcOffering.id === '<uuid-of-VPC-offering-Y>') { 300 
} else { 200 }" value=0
      ```
   
   5. Create and implement some networks and VPCs with the different offerings 
for this so that usage records are later generated.
   
   6. Run the Usage job. I usually do this by manually setting the date of the 
VM running the Usage server to some minutes before the execution of the next 
day and restarting the service.
   
   After the Usage job finishes generating all usage records, Quota will 
process them and charge credits from users based on the tariffs. You can follow 
Usage's logs during the job's execution to see which values are being charged 
for that execution, debug it to see which values are being injected as preset 
variables (I usually place my breakpoint in 
org.apache.cloudstack.quota.QuotaManagerImpl#injectPresetVariablesIntoJsInterpreter),
 and see the new balances in the Quota summary page.
   
   The idea for debugging other PRs that add preset variables is the same.


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