cloudstack icon indicating copy to clipboard operation
cloudstack copied to clipboard

Quota email configuration

Open JoaoJandre opened this issue 1 year ago • 9 comments

Description

Currently, users have no control on whether they receive Quota emails or not. If the Quota plugin is enabled, they will receive all applicable emails.

Furthermore, there is currently no way to set the (min_balance) configuration without adding credits to the account. That value acts as a threshold for the QUOTA_LOW email template. However, there should be a way to easily configure it.

To address the described problems, this PR creates a new API (quotaConfigureEmail) which will has the following parameters: (accountid:String, emailTemplateName:String, enable:Boolean, minBalance:Integer).

  • Regarding the API parameters:
    • (accountid) is required, since all configurations will only be in the accounts scope.
    • (emailTemplateName) is not required, unless the (enable) parameter is informed.
    • (enable) is not required, unless the (emailTemplateName) parameter is informed.
    • (minBalance) is not required. When informed, it will set the (minBalance) attribute in the (quota_account) table.
  • Regarding the API functionality:
    • When the (accountid, emailTemplateName, enable) parameters are informed, the email referenced by (emailTemplateName) will be enabled/disabled based on (enable) for account referenced by (accountid).
    • When the (accountid, minBalance) parameters are informed, the (min_balance) of the account referenced by (accountid) will be set.
    • While a email template is not configured for a given account using this API, the default behavior will be maintained, that is, the email template will be considered as enabled.

Furthermore, a second API (quotaListEmailConfiguration) was created, which has a single parameter: (accountid:String).

  • Regarding the API functionality:
    • The API lists all the email template configurations for the given account.

To improve the user experience, the account-level setting quota.enable.emails was also created, which defines whether or not Quota emails will be sent to the account. By default, the setting has the value true. When the setting is enabled, it is possible to disable sending specific email types (QUOTA_EMPTY, QUOTA_LOW, QUOTA_STATEMENT and QUOTA_UNLOCK_ACCOUNT) to the account via the quotaConfigureEmail API.

Types of changes

  • [ ] Breaking change (fix or feature that would cause existing functionality to change)
  • [X] New feature (non-breaking change which adds functionality)
  • [ ] Bug fix (non-breaking change which fixes an issue)
  • [ ] Enhancement (improves an existing feature and functionality)
  • [ ] Cleanup (Code refactoring and cleanup, that may add test cases)
  • [ ] build/CI

Feature/Enhancement Scale or Bug Severity

Feature/Enhancement Scale

  • [ ] Major
  • [X] Minor

How Has This Been Tested?

Testing the quotaConfigureEmail API

No. Test Result Expected result?
1 Call the API passing accountid Exception thrown yes
2 Call the API passing accountid and templatename Exception thrown yes
3 Call the API passing accountid, templatename and enable for an account that does not have a Quota account Exception thrown yes
4 Call the API passing accountid, templatename, enable and minbalance for an account that does not have a Quota account Exception thrown yes
5 Call the API passing accountid, templatename and enable Configuration generated and persisted in the database yes
6 Call the API passing accountid and minbalance minbalance updated yes
7 Call the API passing accountid, templatename, enable and minbalance Configuration generated and persisted in the database, and minbalance updated yes

Testing the quotaListConfiguration API

No. Test Result Expected result?
1 Call the API passing accountid of an account that does not have email settings Empty Response yes
2 Call the API passing accountid of an account that has email settings Response with email settings yes

Feature tests:

  • Without configuring the emails, I tested reaching all alert email thresholds, all emails were sent correctly.
  • Enabling all emails, I tested reaching all alert email thresholds, all emails were sent correctly.
  • Disabling all emails, I tested reaching all alert email thresholds, none of the emails were sent.

JoaoJandre avatar Dec 05 '23 13:12 JoaoJandre

Codecov Report

Attention: Patch coverage is 42.00000% with 116 lines in your changes are missing coverage. Please review.

Project coverage is 31.12%. Comparing base (e87c6cf) to head (9200140).

Files Patch % Lines
...udstack/api/response/QuotaResponseBuilderImpl.java 37.25% 31 Missing and 1 partial :warning:
...tack/quota/dao/QuotaEmailConfigurationDaoImpl.java 43.75% 18 Missing :warning:
...apache/cloudstack/quota/QuotaAlertManagerImpl.java 67.34% 10 Missing and 6 partials :warning:
...tack/api/response/QuotaConfigureEmailResponse.java 0.00% 15 Missing :warning:
...cloudstack/api/command/QuotaConfigureEmailCmd.java 0.00% 11 Missing :warning:
...rg/apache/cloudstack/quota/QuotaStatementImpl.java 33.33% 9 Missing and 1 partial :warning:
...ck/api/command/QuotaListEmailConfigurationCmd.java 0.00% 7 Missing :warning:
...cloudstack/quota/vo/QuotaEmailConfigurationVO.java 75.00% 4 Missing :warning:
.../org/apache/cloudstack/quota/QuotaServiceImpl.java 0.00% 2 Missing :warning:
...oudstack/quota/dao/QuotaEmailTemplatesDaoImpl.java 0.00% 1 Missing :warning:
Additional details and impacted files
@@             Coverage Diff              @@
##               main    #8307      +/-   ##
============================================
+ Coverage     31.08%   31.12%   +0.04%     
- Complexity    33887    33953      +66     
============================================
  Files          5397     5402       +5     
  Lines        379499   379658     +159     
  Branches      55373    55381       +8     
============================================
+ Hits         117955   118170     +215     
+ Misses       245899   245825      -74     
- Partials      15645    15663      +18     
Flag Coverage Δ
simulator-marvin-tests 24.74% <9.00%> (+0.07%) :arrow_up:
uitests 4.34% <ø> (ø)
unit-tests 16.88% <34.00%> (+<0.01%) :arrow_up:

Flags with carried forward coverage won't be shown. Click here to find out more.

:umbrella: View full report in Codecov by Sentry.
:loudspeaker: Have feedback on the report? Share it here.

codecov[bot] avatar Dec 05 '23 14:12 codecov[bot]

This pull request has merge conflicts. Dear author, please fix the conflicts and sync your branch with the base branch.

github-actions[bot] avatar Dec 18 '23 08:12 github-actions[bot]

This pull request has merge conflicts. Dear author, please fix the conflicts and sync your branch with the base branch.

github-actions[bot] avatar Jan 09 '24 11:01 github-actions[bot]

This pull request has merge conflicts. Dear author, please fix the conflicts and sync your branch with the base branch.

github-actions[bot] avatar Feb 08 '24 13:02 github-actions[bot]

This pull request has merge conflicts. Dear author, please fix the conflicts and sync your branch with the base branch.

github-actions[bot] avatar Feb 19 '24 09:02 github-actions[bot]

@blueorangutan package

JoaoJandre avatar Feb 20 '24 19:02 JoaoJandre

@JoaoJandre a [SL] Jenkins job has been kicked to build packages. It will be bundled with KVM, XenServer and VMware SystemVM templates. I'll keep you posted as I make progress.

blueorangutan avatar Feb 20 '24 19:02 blueorangutan

Packaging result [SF]: ✔️ el7 ✔️ el8 ✔️ el9 ✔️ debian ✔️ suse15. SL-JID 8726

blueorangutan avatar Feb 20 '24 20:02 blueorangutan

This pull request has merge conflicts. Dear author, please fix the conflicts and sync your branch with the base branch.

github-actions[bot] avatar Feb 26 '24 14:02 github-actions[bot]

@GutoVeronezi @BryanMLima @winterhazel Could someone review this PR?

JoaoJandre avatar Feb 29 '24 19:02 JoaoJandre

This pull request has merge conflicts. Dear author, please fix the conflicts and sync your branch with the base branch.

github-actions[bot] avatar Mar 04 '24 12:03 github-actions[bot]

I tested the feature introduced in this PR. It seems to be working as intended.

First, I configured Quota to send e-mails. I also created an account with my e-mail, added 9 credits to it in order to enable Quota and configured its minimum balance to 10. To receive the e-mails at any time, I would set both cloud_usage.quota_account. quota_alert_date/quota_statement_date to NULL and execute quotaUpdate.

  1. I set quota.enable.emails to true for the account.

  2. I enabled all e-mails for the account through the API quotaConfigureEmail.

    API Response
    (admin) 🐱 > quota configureemail enable=true accountid=0ee4c6d5-f3b0-479b-8a16-40a57f22525f templatename=QUOTA_EMPTY
    {
      "quotaconfigureemail": {
        "account": "0ee4c6d5-f3b0-479b-8a16-40a57f22525f",
        "enabled": true,
        "templatename": "QUOTA_EMPTY"
      }
    }
    
    (admin) 🐱 > quota configureemail enable=true accountid=0ee4c6d5-f3b0-479b-8a16-40a57f22525f templatename=QUOTA_LOW
    {
      "quotaconfigureemail": {
        "account": "0ee4c6d5-f3b0-479b-8a16-40a57f22525f",
        "enabled": true,
        "templatename": "QUOTA_LOW"
      }
    }
    
    (admin) 🐱 > quota configureemail enable=true accountid=0ee4c6d5-f3b0-479b-8a16-40a57f22525f templatename=QUOTA_STATEMENT
    {
      "quotaconfigureemail": {
        "account": "0ee4c6d5-f3b0-479b-8a16-40a57f22525f",
        "enabled": true,
        "templatename": "QUOTA_STATEMENT"
      }
    }
    
    (admin) 🐱 > quota configureemail enable=true accountid=0ee4c6d5-f3b0-479b-8a16-40a57f22525f templatename=QUOTA_UNLOCK_ACCOUNT
    {
      "quotaconfigureemail": {
        "account": "0ee4c6d5-f3b0-479b-8a16-40a57f22525f",
        "enabled": true,
        "templatename": "QUOTA_UNLOCK_ACCOUNT"
      }
    }
    
  3. Using quotaListEmailConfiguration, I verified that the e-mails had been enabled for the account.

    API Response
    (admin) 🐱 > quota listemailconfiguration accountid=0ee4c6d5-f3b0-479b-8a16-40a57f22525f 
    {
      "count": 4,
      "quotaconfigureemail": [
        {
          "account": "0ee4c6d5-f3b0-479b-8a16-40a57f22525f",
          "enabled": true,
          "minbalance": 10,
          "templatename": "QUOTA_LOW"
        },
        {
          "account": "0ee4c6d5-f3b0-479b-8a16-40a57f22525f",
          "enabled": true,
          "minbalance": 10,
          "templatename": "QUOTA_EMPTY"
        },
        {
          "account": "0ee4c6d5-f3b0-479b-8a16-40a57f22525f",
          "enabled": true,
          "minbalance": 10,
          "templatename": "QUOTA_UNLOCK_ACCOUNT"
        },
        {
          "account": "0ee4c6d5-f3b0-479b-8a16-40a57f22525f",
          "enabled": true,
          "minbalance": 10,
          "templatename": "QUOTA_STATEMENT"
        }
      ]
    }
    
  4. I executed quotaUpdate and verified that I received QUOTA_LOW and QUOTA_STATEMENT e-mails.

  5. I emptied the account's credits (by adding -9 credits to it) and executed quotaUpdate. I verified that I received QUOTA_EMPTY and QUOTA_STATEMENT e-mails.

  6. I disabled the QUOTA_EMPTY e-mail through the API quotaConfigureEmail.

    API Response
    (admin) 🐱 > quota configureemail enable=false accountid=0ee4c6d5-f3b0-479b-8a16-40a57f22525f templatename=QUOTA_EMPTY
    {
      "quotaconfigureemail": {
        "account": "0ee4c6d5-f3b0-479b-8a16-40a57f22525f",
        "enabled": false,
        "templatename": "QUOTA_EMPTY"
      }
    }
    
  7. Using quotaListEmailConfiguration, I verified that QUOTA_EMPTY had been disabled.

    API Response
    (admin) 🐱 > quota listemailconfiguration accountid=0ee4c6d5-f3b0-479b-8a16-40a57f22525f 
    {
      "count": 4,
      "quotaconfigureemail": [
        {
          "account": "0ee4c6d5-f3b0-479b-8a16-40a57f22525f",
          "enabled": true,
          "minbalance": 10,
          "templatename": "QUOTA_LOW"
        },
        {
          "account": "0ee4c6d5-f3b0-479b-8a16-40a57f22525f",
          "enabled": false,
          "minbalance": 10,
          "templatename": "QUOTA_EMPTY"
        },
        {
          "account": "0ee4c6d5-f3b0-479b-8a16-40a57f22525f",
          "enabled": true,
          "minbalance": 10,
          "templatename": "QUOTA_UNLOCK_ACCOUNT"
        },
        {
          "account": "0ee4c6d5-f3b0-479b-8a16-40a57f22525f",
          "enabled": true,
          "minbalance": 10,
          "templatename": "QUOTA_STATEMENT"
        }
      ]
    }
    
  8. I executed quotaUpdate and verified that I only received the QUOTA_STATEMENT e-mail.

  9. I set quota.enable.emails to false for the account. Then, I executed quotaUpdate and verified that I did not receive any e-mails.

winterhazel avatar Mar 05 '24 20:03 winterhazel

Thank you for testing @winterhazel

JoaoJandre avatar Mar 06 '24 13:03 JoaoJandre

This pull request has merge conflicts. Dear author, please fix the conflicts and sync your branch with the base branch.

github-actions[bot] avatar Mar 08 '24 10:03 github-actions[bot]

This pull request has merge conflicts. Dear author, please fix the conflicts and sync your branch with the base branch.

github-actions[bot] avatar Mar 13 '24 13:03 github-actions[bot]

@blueorangutan package

JoaoJandre avatar Mar 14 '24 12:03 JoaoJandre

@JoaoJandre a [SL] Jenkins job has been kicked to build packages. It will be bundled with KVM, XenServer and VMware SystemVM templates. I'll keep you posted as I make progress.

blueorangutan avatar Mar 14 '24 12:03 blueorangutan

Packaging result [SF]: ✔️ el7 ✔️ el8 ✔️ el9 ✔️ debian ✔️ suse15. SL-JID 8937

blueorangutan avatar Mar 14 '24 14:03 blueorangutan

@DaanHoogland @rohityadavcloud @shwstppr could we run the CI on this one?

JoaoJandre avatar Mar 14 '24 16:03 JoaoJandre

@blueorangutan test

shwstppr avatar Mar 15 '24 04:03 shwstppr

@shwstppr a [SL] Trillian-Jenkins test job (centos7 mgmt + kvm-centos7) has been kicked to run smoke tests

blueorangutan avatar Mar 15 '24 04:03 blueorangutan

[SF] Trillian test result (tid-9489) Environment: kvm-centos7 (x2), Advanced Networking with Mgmt server 7 Total time taken: 53759 seconds Marvin logs: https://github.com/blueorangutan/acs-prs/releases/download/trillian/pr8307-t9489-kvm-centos7.zip Smoke tests completed. 129 look OK, 0 have errors, 0 did not run Only failed and skipped tests results shown below:

Test Result Time (s) Test File

blueorangutan avatar Mar 15 '24 19:03 blueorangutan

Merging based on approvals, manual test results and CI results.

JoaoJandre avatar Mar 18 '24 11:03 JoaoJandre