Skip to content

Quota email configuration#8307

Merged
JoaoJandre merged 22 commits intoapache:mainfrom
scclouds:quota-email-configuration
Mar 18, 2024
Merged

Quota email configuration#8307
JoaoJandre merged 22 commits intoapache:mainfrom
scclouds:quota-email-configuration

Conversation

@JoaoJandre
Copy link
Copy Markdown
Contributor

@JoaoJandre JoaoJandre commented Dec 5, 2023

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

@codecov
Copy link
Copy Markdown

codecov bot commented Dec 5, 2023

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 ⚠️
...tack/quota/dao/QuotaEmailConfigurationDaoImpl.java 43.75% 18 Missing ⚠️
...apache/cloudstack/quota/QuotaAlertManagerImpl.java 67.34% 10 Missing and 6 partials ⚠️
...tack/api/response/QuotaConfigureEmailResponse.java 0.00% 15 Missing ⚠️
...cloudstack/api/command/QuotaConfigureEmailCmd.java 0.00% 11 Missing ⚠️
...rg/apache/cloudstack/quota/QuotaStatementImpl.java 33.33% 9 Missing and 1 partial ⚠️
...ck/api/command/QuotaListEmailConfigurationCmd.java 0.00% 7 Missing ⚠️
...cloudstack/quota/vo/QuotaEmailConfigurationVO.java 75.00% 4 Missing ⚠️
.../org/apache/cloudstack/quota/QuotaServiceImpl.java 0.00% 2 Missing ⚠️
...oudstack/quota/dao/QuotaEmailTemplatesDaoImpl.java 0.00% 1 Missing ⚠️
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%) ⬆️
uitests 4.34% <ø> (ø)
unit-tests 16.88% <34.00%> (+<0.01%) ⬆️

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

☔ View full report in Codecov by Sentry.
📢 Have feedback on the report? Share it here.

@github-actions
Copy link
Copy Markdown

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

@github-actions
Copy link
Copy Markdown

github-actions bot commented Jan 9, 2024

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

@JoaoJandre JoaoJandre requested review from BryanMLima, GutoVeronezi and shwstppr and removed request for BryanMLima and shwstppr February 6, 2024 13:12
@JoaoJandre JoaoJandre added this to the 4.20.0.0 milestone Feb 6, 2024
@github-actions
Copy link
Copy Markdown

github-actions bot commented Feb 8, 2024

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

Copy link
Copy Markdown
Member

@winterhazel winterhazel left a comment

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

CLGTM, just pointed out some minor adjustments. I'll try testing soon.

Comment thread engine/schema/src/main/resources/META-INF/db/schema-41900to42000.sql Outdated
@github-actions
Copy link
Copy Markdown

github-actions bot commented Mar 4, 2024

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

@winterhazel
Copy link
Copy Markdown
Member

winterhazel commented Mar 5, 2024

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.

@JoaoJandre JoaoJandre requested a review from BryanMLima March 6, 2024 13:15
@JoaoJandre
Copy link
Copy Markdown
Contributor Author

Thank you for testing @winterhazel

@github-actions
Copy link
Copy Markdown

github-actions bot commented Mar 8, 2024

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

Copy link
Copy Markdown
Contributor

@BryanMLima BryanMLima left a comment

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Approving as my comments were addressed.

@github-actions
Copy link
Copy Markdown

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

@JoaoJandre
Copy link
Copy Markdown
Contributor Author

@blueorangutan package

@blueorangutan
Copy link
Copy Markdown

@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
Copy link
Copy Markdown

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

@JoaoJandre
Copy link
Copy Markdown
Contributor Author

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

@shwstppr
Copy link
Copy Markdown
Contributor

@blueorangutan test

@blueorangutan
Copy link
Copy Markdown

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

@blueorangutan
Copy link
Copy Markdown

[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

@JoaoJandre
Copy link
Copy Markdown
Contributor Author

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

@JoaoJandre JoaoJandre merged commit f76c6f3 into apache:main Mar 18, 2024
dhslove pushed a commit to ablecloud-team/ablestack-cloud that referenced this pull request Mar 21, 2024
* Quota email configuration feature
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment

Projects

None yet

Development

Successfully merging this pull request may close these issues.

6 participants