winterhazel opened a new pull request, #8243:
URL: https://github.com/apache/cloudstack/pull/8243
### Description
Dates are always stored in GMT in the database. However, when using the
Usage and Quota APIs, dates are manipulated according to the configuration
`usage.aggregation.timezone`. Therefore, when informing a date, the user must
consider the timezone defined in the configuration and the timezone of the
server in order to specify a value. Furthermore, if the configuration and the
server are not in the same timezone, ACS will not retrieve the data the user
requested.
This PR changes the behavior of Usage and Quota APIs to consider dates as
they were informed. Some examples showing how the current date manipulation may
yield unexpected results and how this change fixes them can be found in the
tests section.
The APIs affected by this change are:
- `listUsageRecords`: the return of this API was also changed to always
return the data in GMT, instead of depending on the timezone of the
configuration. This way, it complies with the other APIs and allows users to
handle the timezone in the frontend;
- `quotaCredits`: when adding credits to an account, the deposit date is now
stored in GMT;
- `quotaBalance`: in addition, it is now possible to inform an `enddate` in
the future;
- `quotaStatement`: it is also now possible to inform an `enddate` in the
future;
- `quotaTariffCreate`;
- `quotaTariffDelete`:
- `quotaTariffList`;
- `quotaTariffUpdate`.
With the extension that allows users to inform timezones on APIs that have
the date parameter (#7032), it is recommended to inform dates in the format
`yyyy-MM-dd'T'HH:mm:ssz`. When a date is informed in `yyyy-MM-dd HH:mm:ss` or
`yyyy-MM-dd`, it will be considered that the date was informed in the timezone
of the server.
### Types of changes
- [ ] Breaking change (fix or feature that would cause existing
functionality to change)
- [ ] New feature (non-breaking change which adds functionality)
- [X] 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)
### Feature/Enhancement Scale or Bug Severity
#### Bug Severity
- [ ] BLOCKER
- [ ] Critical
- [ ] Major
- [X] Minor
- [ ] Trivial
### Screenshots (if appropriate):
### How Has This Been Tested?
In a local lab, I defined `usage.aggregation.timezone` as GMT-3. Then,
through CloudMonkey, I verified the behavior of the affected APIs:
<details>
<summary>
`listUsageRecords`
</summary>
```
(admin) 🐱 > list usagerecords startdate='2023-07-20T20:41:22+0200'
enddate='2023-07-20T18:41:22-0150'
```
In this command, `startdate` is `2023-07-20 18:41:22` in GMT, and the
`enddate` is `2023-07-20 20:31:22`.
**Current behavior:**
```
2023-09-26 16:30:00,823 DEBUG [c.c.u.UsageServiceImpl]
(qtp1955920234-21:ctx-8cc949c0 ctx-b22a8082) (logid:486992ba) getting usage
records for account: 2, domainId: null, between Thu Jul 20 21:41:22 UTC 2023
and Thu Jul 20 23:31:22 UTC 2023, using pageSize: 500 and startIndex: 0
```
The dates get manipulated to `2023-07-20 21:41:22` GMT and `2023-07-20
23:31:22` GMT.
**After applying the changes:**
```
2023-09-26 16:26:20,172 DEBUG [c.c.u.UsageServiceImpl]
(qtp1955920234-21:ctx-52f71b4c ctx-04cac325) (logid:a95c7352) Getting usage
records for account [2] in domain [null], between [Thu Jul 20 18:41:22 UTC
2023] and [Thu Jul 20 20:31:22 UTC 2023], using pageSize [500] and startIndex
[0].
```
The command uses the provided dates converted to GMT.
The full response of this command after applying the patch will be posted as
a comment, because including it here made the description exceed the maximum
amount of characters.
</details>
<details>
<summary>
`quotaStatement`
</summary>
```
(admin) 🐱 > quota statement account=admin
domainid=52d83793-26de-11ec-8dcf-5254005dcdac enddate='2023-07-24'
startdate='2023-07-24T20:00:00-0300'
```
The `startdate` parameter is `2023-07-24 23:00:00` in GMT.
**Current behavior:**
```
2023-09-25 20:20:32,008 DEBUG [o.a.c.q.QuotaServiceImpl]
(qtp1955920234-21:ctx-a9ea777b ctx-fb4ee927) (logid:359e3d33) Getting quota
records for account: 2, domainId: 1, between Tue Jul 25 02:00:00 UTC 2023 and
Tue Jul 25 03:00:00 UTC 2023
```
`startdate` gets manipulated to `2023-07-25 02:00:00` GMT.
**After applying the changes:**
```
2023-09-25 20:17:36,499 DEBUG [o.a.c.q.QuotaServiceImpl]
(qtp1955920234-19:ctx-98fcebb7 ctx-d2a8f37f) (logid:6ec97910) Getting quota
records of type [null] for account [2] in domain [1], between [Mon Jul 24
23:00:00 UTC 2023] and [Tue Jul 25 00:00:00 UTC 2023].
```
The command uses the provided `startdate` in GMT.
Below there is the full response:
```
(admin) 🐱 > quota statement account=admin
domainid=52d83793-26de-11ec-8dcf-5254005dcdac enddate=2023-08-23
startdate=2023-08-21
{
"statement": {
"currency": "$",
"enddate": "2023-08-23T23:59:59+0000",
"quotausage": [
{
"accountid": 2,
"domain": 1,
"name": "RUNNING_VM",
"quota": 0,
"type": 1,
"unit": "Compute*Month"
},
{
"accountid": 2,
"domain": 1,
"name": "ALLOCATED_VM",
"quota": 0,
"type": 2,
"unit": "Compute*Month"
},
{
"accountid": 2,
"domain": 1,
"name": "IP_ADDRESS",
"quota": 0,
"type": 3,
"unit": "IP*Month"
},
{
"accountid": 2,
"domain": 1,
"name": "NETWORK_BYTES_SENT",
"quota": 0,
"type": 4,
"unit": "GB"
},
{
"accountid": 2,
"domain": 1,
"name": "NETWORK_BYTES_RECEIVED",
"quota": 0,
"type": 5,
"unit": "GB"
},
{
"accountid": 2,
"domain": 1,
"name": "VOLUME",
"quota": 0,
"type": 6,
"unit": "GB*Month"
},
{
"accountid": 2,
"domain": 1,
"name": "TEMPLATE",
"quota": 0,
"type": 7,
"unit": "GB*Month"
},
{
"accountid": 2,
"domain": 1,
"name": "ISO",
"quota": 0,
"type": 8,
"unit": "GB*Month"
},
{
"accountid": 2,
"domain": 1,
"name": "SNAPSHOT",
"quota": 0,
"type": 9,
"unit": "GB*Month"
},
{
"accountid": 2,
"domain": 1,
"name": "SECURITY_GROUP",
"quota": 0,
"type": 10,
"unit": "Policy*Month"
},
{
"accountid": 2,
"domain": 1,
"name": "LOAD_BALANCER_POLICY",
"quota": 0,
"type": 11,
"unit": "Policy*Month"
},
{
"accountid": 2,
"domain": 1,
"name": "PORT_FORWARDING_RULE",
"quota": 0,
"type": 12,
"unit": "Policy*Month"
},
{
"accountid": 2,
"domain": 1,
"name": "NETWORK_OFFERING",
"quota": 0,
"type": 13,
"unit": "Policy*Month"
},
{
"accountid": 2,
"domain": 1,
"name": "VPN_USERS",
"quota": 0,
"type": 14,
"unit": "Policy*Month"
},
{
"accountid": 2,
"domain": 1,
"name": "VM_DISK_IO_READ",
"quota": 0,
"type": 21,
"unit": "IOPS"
},
{
"accountid": 2,
"domain": 1,
"name": "VM_DISK_IO_WRITE",
"quota": 0,
"type": 22,
"unit": "IOPS"
},
{
"accountid": 2,
"domain": 1,
"name": "VM_DISK_BYTES_READ",
"quota": 0,
"type": 23,
"unit": "Bytes"
},
{
"accountid": 2,
"domain": 1,
"name": "VM_DISK_BYTES_WRITE",
"quota": 0,
"type": 24,
"unit": "Bytes"
},
{
"accountid": 2,
"domain": 1,
"name": "VM_SNAPSHOT",
"quota": 0,
"type": 25,
"unit": "GB*Month"
},
{
"accountid": 2,
"domain": 1,
"name": "VOLUME_SECONDARY",
"quota": 0,
"type": 26,
"unit": "GB*Month"
},
{
"accountid": 2,
"domain": 1,
"name": "VM_SNAPSHOT_ON_PRIMARY",
"quota": 0,
"type": 27,
"unit": "GB*Month"
},
{
"accountid": 2,
"domain": 1,
"name": "BACKUP",
"quota": 0,
"type": 28,
"unit": "GB*Month"
}
],
"startdate": "2023-08-21T00:00:00+0000",
"totalquota": 0
}
}
```
</details>
<details>
<summary>
`quotaCredits` and `quotaBalance`
</summary>
**Current behavior:**
```
(admin) 🐱 > quota credits account=admin
domainid=52d83793-26de-11ec-8dcf-5254005dcdac value=5
{
"quotacredits": {
"credits": 5,
"currency": "$",
"updated_by": "admin",
"updated_on": "2023-09-25T19:33:33+0000"
}
}
(admin) 🐱 > quota balance account=admin
domainid=52d83793-26de-11ec-8dcf-5254005dcdac startdate=2023-09-23
enddate=2023-09-25
{
"balance": {
"credits": [
{
"credits": 5,
"updated_on": "2023-09-25T22:33:32+0000"
}
],
"currency": "$",
"enddate": "2023-09-25T23:59:59+0000",
"endquota": 5,
"startdate": "2023-09-23T00:00:00+0000",
"startquota": 0
}
}
```
The time in GMT was `2023-09-25 19:33:33`, but `updated_on` was stored as
`2023-09-25 22:33:32` in the database.
**After applying the changes:**
```
(admin) 🐱 > quota credits account=admin
domainid=52d83793-26de-11ec-8dcf-5254005dcdac value=5
{
"quotacredits": {
"credits": 5,
"currency": "$",
"updated_by": "admin",
"updated_on": "2023-09-26T16:15:35+0000"
}
}
(admin) 🐱 > quota balance account=admin
domainid=52d83793-26de-11ec-8dcf-5254005dcdac startdate=2023-09-25
enddate=2023-09-26
{
"balance": {
"credits": [
{
"credits": 5,
"updated_on": "2023-09-26T16:15:35+0000"
}
],
"currency": "$",
"enddate": "2023-09-26T23:59:59+0000",
"endquota": 5,
"startdate": "2023-09-25T00:00:00+0000",
"startquota": 0
}
}
```
The time in GMT was `2023-09-26 16:15:35`, and the correct value of
`2023-09-26 16:15:35` was stored in the database.
</details>
<details>
<summary>
`quotaTariffCreate`
</summary>
**After applying the changes**:
```
(admin) 🐱 > quota tariffcreate name="teste" value=2 usagetype=1
startdate="2023-09-27T23:00:00-0300"
{
"quotatariff": {
"currency": "$",
"effectiveDate": "2023-09-28T02:00:00+0000",
"id": "327f84d1-1506-4366-8755-c4042057a93f",
"name": "teste",
"tariffValue": 2,
"usageDiscriminator": "None",
"usageName": "RUNNING_VM",
"usageType": 1,
"usageTypeDescription": "Running Vm Usage",
"usageUnit": "Compute*Month"
}
}
(admin) 🐱 > quota tariffcreate name="teste2" value=2 usagetype=1
startdate="2023-09-30T23:00:00+0000" enddate="2023-10-02T14:00:00+0000"
{
"quotatariff": {
"currency": "$",
"effectiveDate": "2023-09-30T23:00:00+0000",
"endDate": "2023-10-02T14:00:00+0000",
"id": "962feae6-7947-45bb-8d55-ca9e90dcf6e2",
"name": "teste2",
"tariffValue": 2,
"usageDiscriminator": "None",
"usageName": "RUNNING_VM",
"usageType": 1,
"usageTypeDescription": "Running Vm Usage",
"usageUnit": "Compute*Month"
}
}
```
</details>
<details>
<summary>
`quotaTariffUpdate`
</summary>
**After applying the changes**:
```
(admin) 🐱 > quota tariffupdate name=teste enddate=2023-09-29
{
"quotatariff": {
"currency": "$",
"effectiveDate": "2023-09-28T02:00:00+0000",
"endDate": "2023-09-29T23:59:59+0000",
"id": "c2788963-26ae-4a2a-b955-8123c353b517",
"name": "teste",
"tariffValue": 2,
"usageDiscriminator": "None",
"usageName": "RUNNING_VM",
"usageType": 1,
"usageTypeDescription": "Running Vm Usage",
"usageUnit": "Compute*Month"
}
}
```
</details>
<details>
<summary>
`quotaTariffList`
</summary>
**After applying the changes**:
```
(admin) 🐱 > quota tarifflist startdate='2023-09-24T01:00:00+0000'
enddate=2023-10-03
{
"count": 2,
"quotatariff": [
{
"currency": "$",
"effectiveDate": "2023-09-30T23:00:00+0000",
"endDate": "2023-10-02T14:00:00+0000",
"id": "962feae6-7947-45bb-8d55-ca9e90dcf6e2",
"name": "teste2",
"tariffValue": 2,
"usageDiscriminator": "None",
"usageName": "RUNNING_VM",
"usageType": 1,
"usageTypeDescription": "Running Vm Usage",
"usageUnit": "Compute*Month"
},
{
"currency": "$",
"effectiveDate": "2023-09-28T02:00:00+0000",
"endDate": "2023-09-29T23:59:59+0000",
"id": "c2788963-26ae-4a2a-b955-8123c353b517",
"name": "teste",
"tariffValue": 2,
"usageDiscriminator": "None",
"usageName": "RUNNING_VM",
"usageType": 1,
"usageTypeDescription": "Running Vm Usage",
"usageUnit": "Compute*Month"
}
]
}
(admin) 🐱 > quota tarifflist startdate='2023-09-29T01:00:00-0300'
enddate=2023-10-03
{
"count": 1,
"quotatariff": [
{
"currency": "$",
"effectiveDate": "2023-09-30T23:00:00+0000",
"endDate": "2023-10-02T14:00:00+0000",
"id": "962feae6-7947-45bb-8d55-ca9e90dcf6e2",
"name": "teste2",
"tariffValue": 2,
"usageDiscriminator": "None",
"usageName": "RUNNING_VM",
"usageType": 1,
"usageTypeDescription": "Running Vm Usage",
"usageUnit": "Compute*Month"
}
]
}
```
</details>
<details>
<summary>
`quotaTariffDelete`
</summary>
**After applying the changes**:
```
(admin) 🐱 > quota tariffdelete id=962feae6-7947-45bb-8d55-ca9e90dcf6e2
{
"success": true
}
```
</details>
--
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]