Skip to content

Conversation

@Pearl1594
Copy link
Contributor

Description

listUsageRecords returns the count equal to the number of objects returned in the page, rather than the total count
Addresses: #4191

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)

@Pearl1594
Copy link
Contributor Author

@blueorangutan package

@blueorangutan
Copy link

@Pearl1594 a Jenkins job has been kicked to build packages. I'll keep you posted as I make progress.

Copy link
Member

@rohityadavcloud rohityadavcloud left a comment

Choose a reason for hiding this comment

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

Lgtm

@Pearl1594 Pearl1594 changed the title Fix usage record count fix Fix usage record count Jul 1, 2020
@blueorangutan
Copy link

Packaging result: ✔centos7 ✔debian. JID-1499

@olivierlemasle
Copy link
Contributor

Hi @Pearl1594 @rhtyd ,

Thank you for the quick fix.
If I'm not wrong, this will return the size of the unfiltered list. If there's some usage records for IP addresses on shared networks with "Hide IP address usage", the displayed "count" will be greater than the real number of returned usage records. Would that not break pagination in tools like Primate (if Primate displayed usage records)?

The best would probably be to move the filtering from the ApiResponseHelper to the actual search in UsageServiceImpl, but that could be difficult and/or inefficient.

@rohityadavcloud rohityadavcloud added this to the 4.13.2.0 milestone Jul 2, 2020
@Pearl1594
Copy link
Contributor Author

@blueorangutan package

@blueorangutan
Copy link

@Pearl1594 a Jenkins job has been kicked to build packages. I'll keep you posted as I make progress.

@blueorangutan
Copy link

Packaging result: ✔centos7 ✔debian. JID-1511

networkId = ip.getSourceNetworkId();
}
NetworkDetailVO networkDetail = _networkDetailsDao.findDetail(networkId, Network.hideIpAddressUsage);
if (networkDetail != null && networkDetail.getValue() != null && networkDetail.getValue().equals("true")) {
Copy link
Contributor

Choose a reason for hiding this comment

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

As this code is in a test if (usageId != null), it will remove IP address usage only if the API command listUsageRecords was called with a specific usageId parameter.
For API calls like command=listUsageRecords&startdate=xxx&enddate=xxx, it will include all usage records, including for IP addresses on networks with "Hide usage".

@Pearl1594
Copy link
Contributor Author

@blueorangutan package

1 similar comment
@Pearl1594
Copy link
Contributor Author

@blueorangutan package

@blueorangutan
Copy link

@Pearl1594 a Jenkins job has been kicked to build packages. I'll keep you posted as I make progress.

@blueorangutan
Copy link

Packaging result: ✔centos7 ✔debian. JID-1517

@Pearl1594
Copy link
Contributor Author

@blueorangutan test

@blueorangutan
Copy link

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

@blueorangutan
Copy link

Trillian test result (tid-1964)
Environment: kvm-centos7 (x2), Advanced Networking with Mgmt server 7
Total time taken: 35174 seconds
Marvin logs: https://github.com/blueorangutan/acs-prs/releases/download/trillian/pr4193-t1964-kvm-centos7.zip
Intermittent failure detected: /marvin/tests/smoke/test_internal_lb.py
Intermittent failure detected: /marvin/tests/smoke/test_outofbandmanagement.py
Intermittent failure detected: /marvin/tests/smoke/test_privategw_acl.py
Smoke tests completed. 76 look OK, 1 have error(s)
Only failed tests results shown below:

Test Result Time (s) Test File
test_02_vpc_privategw_static_routes Failure 226.32 test_privategw_acl.py
test_03_vpc_privategw_restart_vpc_cleanup Failure 217.54 test_privategw_acl.py
test_04_rvpc_privategw_static_routes Failure 331.09 test_privategw_acl.py

@rohityadavcloud
Copy link
Member

Can you @davidjumani review this? Thanx

Copy link
Contributor

@olivierlemasle olivierlemasle left a comment

Choose a reason for hiding this comment

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

Thanks, LGTM (not tested).
I hope this will not have a bad impact on performances.

Copy link
Member

@rohityadavcloud rohityadavcloud left a comment

Choose a reason for hiding this comment

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

This is still not a full fix for this without impacting the performance; the fix is not fully right as it does not count whether or not the IPs being listed/found existed if the list API was called with a start/end date. The simplest solution would be to simply return the actual total count; the edge case of hiding shared network IP usages could be handled in a separate PR.

@Pearl1594
Copy link
Contributor Author

@rhtyd since startdate and enddate are mandatory fields in the API , the usageRecords fetched from the database will be within the (date) range provided and further processing is then done on that list obtained

@rohityadavcloud
Copy link
Member

Thanks for checking the mandatory params @Pearl1594, you're right with the argument I hadn't considered start/end date as mandatory parameters.

In that case, perhaps we can spend some time in future to optimise it, for example, get all the IPs given a list of IPs (unique usage IDs) and then join against the details table to check how many IPs need to be hidden, and run a quick loop to find number of counts we've to reduce if any; the current code may significantly impact the list API response which would require many DB calls.

@rohityadavcloud rohityadavcloud marked this pull request as ready for review July 8, 2020 05:50
@olivierlemasle
Copy link
Contributor

Hi @Pearl1594 @rhtyd What are the required steps before merging this?

@Pearl1594
Copy link
Contributor Author

@olivierlemasle It will probably require another round of testing before it can be merged.

Copy link
Contributor

@olivierlemasle olivierlemasle left a comment

Choose a reason for hiding this comment

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

I've done some manual tests on this PR (actually, on this PR rebased on master). Sadly, it does not work as expected.

These jq filters display the value of "count", then the number of records in the page. They show that this works when there's no pagination:

➜ ~ cmk list usagerecords startdate=2020-07-21 enddate=2020-07-21 | jq ".count, .usagerecord | length"
76
76
➜ ~ cmk list usagerecords startdate=2020-07-21 enddate=2020-07-21 pagesize=100 page=1 | jq ".count, .usagerecord | length"
76
76

But with pagination, here are the results:

➜ ~ cmk list usagerecords startdate=2020-07-21 enddate=2020-07-21 pagesize=20 page=1 | jq ".count, .usagerecord | length"
82
18
➜ ~ cmk list usagerecords startdate=2020-07-21 enddate=2020-07-21 pagesize=20 page=2 | jq ".count, .usagerecord | length"
82
18
➜ ~ cmk list usagerecords startdate=2020-07-21 enddate=2020-07-21 pagesize=20 page=3 | jq ".count, .usagerecord | length"
82
18
➜ ~ cmk list usagerecords startdate=2020-07-21 enddate=2020-07-21 pagesize=20 page=4 | jq ".count, .usagerecord | length"
82
18
➜ ~ cmk list usagerecords startdate=2020-07-21 enddate=2020-07-21 pagesize=20 page=5 | jq ".count, .usagerecord | length"
84
4

As we can see, there is still 76 records (18*4 + 4), which is right. The difference between 18 (usage records in a page) and 20 (pagesize) is the IP addresses on networks with hideIpAddressUsage.
However, "count" is 82 or 84 (depending on the page), instead of 76.

Actually, 84 is the total amount of unfiltered usage records (the original count value). count is decremented to remove the number of usage records for IP addresses on networks with hideIpAddressUsage, but only for the current page...

@blueorangutan
Copy link

@Pearl1594 a Jenkins job has been kicked to build packages. I'll keep you posted as I make progress.

@blueorangutan
Copy link

Packaging result: ✔centos7 ✖centos8 ✔debian. JID-2021

@rohityadavcloud
Copy link
Member

@blueorangutan package

@blueorangutan
Copy link

@rhtyd a Jenkins job has been kicked to build packages. I'll keep you posted as I make progress.

@blueorangutan
Copy link

Packaging result: ✔centos7 ✖centos8 ✔debian. JID-2023

@Pearl1594
Copy link
Contributor Author

@blueorangutan package

@blueorangutan
Copy link

@Pearl1594 a Jenkins job has been kicked to build packages. I'll keep you posted as I make progress.

@blueorangutan
Copy link

Packaging result: ✔centos7 ✖centos8 ✔debian. JID-2036

@olivierlemasle
Copy link
Contributor

@Pearl1594 Any chance merging this PR?

@DaanHoogland
Copy link
Contributor

this is a 4.13 based change @rhtyd do we need to push this towards 4.16?

@olivierlemasle
Copy link
Contributor

IMHO, this should be backported in 4.13, 4.14 and recent releases, as it fixes a regression in 4.13.
The "long-term fix" #4327 should be included in the next release.

@olivierlemasle
Copy link
Contributor

@Pearl1594 Any new on this?

@Pearl1594
Copy link
Contributor Author

It's good to go @olivierlemasle

@Pearl1594
Copy link
Contributor Author

@blueorangutan test

@blueorangutan
Copy link

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

@blueorangutan
Copy link

Trillian test result (tid-3016)
Environment: kvm-centos7 (x2), Advanced Networking with Mgmt server 7
Total time taken: 59364 seconds
Marvin logs: https://github.com/blueorangutan/acs-prs/releases/download/trillian/pr4193-t3016-kvm-centos7.zip
Intermittent failure detected: /marvin/tests/smoke/test_privategw_acl.py
Intermittent failure detected: /marvin/tests/smoke/test_public_ip_range.py
Intermittent failure detected: /marvin/tests/smoke/test_reset_vm_on_reboot.py
Intermittent failure detected: /marvin/tests/smoke/test_resource_accounting.py
Intermittent failure detected: /marvin/tests/smoke/test_router_dhcphosts.py
Intermittent failure detected: /marvin/tests/smoke/test_router_dns.py
Intermittent failure detected: /marvin/tests/smoke/test_router_dnsservice.py
Intermittent failure detected: /marvin/tests/smoke/test_routers_iptables_default_policy.py
Intermittent failure detected: /marvin/tests/smoke/test_routers_network_ops.py
Intermittent failure detected: /marvin/tests/smoke/test_routers.py
Intermittent failure detected: /marvin/tests/smoke/test_secondary_storage.py
Intermittent failure detected: /marvin/tests/smoke/test_service_offerings.py
Intermittent failure detected: /marvin/tests/smoke/test_snapshots.py
Intermittent failure detected: /marvin/tests/smoke/test_ssvm.py
Intermittent failure detected: /marvin/tests/smoke/test_templates.py
Intermittent failure detected: /marvin/tests/smoke/test_usage.py
Intermittent failure detected: /marvin/tests/smoke/test_vm_life_cycle.py
Intermittent failure detected: /marvin/tests/smoke/test_vm_snapshots.py
Intermittent failure detected: /marvin/tests/smoke/test_volumes.py
Intermittent failure detected: /marvin/tests/smoke/test_vpc_redundant.py
Intermittent failure detected: /marvin/tests/smoke/test_vpc_router_nics.py
Intermittent failure detected: /marvin/tests/smoke/test_vpc_vpn.py
Intermittent failure detected: /marvin/tests/smoke/test_hostha_kvm.py
Smoke tests completed. 55 look OK, 22 have error(s)
Only failed tests results shown below:

Test Result Time (s) Test File
test_02_vpc_privategw_static_routes Failure 220.63 test_privategw_acl.py
test_03_vpc_privategw_restart_vpc_cleanup Failure 165.52 test_privategw_acl.py
test_04_rvpc_privategw_static_routes Failure 228.18 test_privategw_acl.py
ContextSuite context=TestResetVmOnReboot>:setup Error 0.00 test_reset_vm_on_reboot.py
ContextSuite context=TestRAMCPUResourceAccounting>:setup Error 0.00 test_resource_accounting.py
ContextSuite context=TestRouterDHCPHosts>:setup Error 0.00 test_router_dhcphosts.py
ContextSuite context=TestRouterDHCPOpts>:setup Error 0.00 test_router_dhcphosts.py
ContextSuite context=TestRouterDns>:setup Error 0.00 test_router_dns.py
test_01_sys_vm_start Failure 0.14 test_secondary_storage.py
ContextSuite context=TestRouterDnsService>:setup Error 0.00 test_router_dnsservice.py
ContextSuite context=TestRouterIpTablesPolicies>:setup Error 0.00 test_routers_iptables_default_policy.py
ContextSuite context=TestVPCIpTablesPolicies>:setup Error 0.00 test_routers_iptables_default_policy.py
ContextSuite context=TestIsolatedNetworks>:setup Error 0.00 test_routers_network_ops.py
ContextSuite context=TestRedundantIsolateNetworks>:setup Error 0.00 test_routers_network_ops.py
ContextSuite context=TestRouterServices>:setup Error 0.00 test_routers.py
ContextSuite context=TestCpuCapServiceOfferings>:setup Error 0.00 test_service_offerings.py
ContextSuite context=TestServiceOfferings>:setup Error 0.29 test_service_offerings.py
ContextSuite context=TestSnapshotRootDisk>:setup Error 0.00 test_snapshots.py
test_01_list_sec_storage_vm Failure 0.06 test_ssvm.py
test_02_list_cpvm_vm Failure 0.05 test_ssvm.py
test_03_ssvm_internals Failure 0.06 test_ssvm.py
test_04_cpvm_internals Failure 0.05 test_ssvm.py
test_05_stop_ssvm Failure 0.06 test_ssvm.py
test_06_stop_cpvm Failure 0.05 test_ssvm.py
test_07_reboot_ssvm Failure 0.06 test_ssvm.py
test_08_reboot_cpvm Failure 0.05 test_ssvm.py
test_09_destroy_ssvm Failure 0.06 test_ssvm.py
test_10_destroy_cpvm Failure 0.05 test_ssvm.py
test_02_create_template_with_checksum_sha1 Error 65.60 test_templates.py
test_03_create_template_with_checksum_sha256 Error 65.70 test_templates.py
test_04_create_template_with_checksum_md5 Error 65.61 test_templates.py
test_05_create_template_with_no_checksum Error 65.59 test_templates.py
test_02_deploy_vm_from_direct_download_template Error 1.39 test_templates.py
test_03_deploy_vm_wrong_checksum Error 1.40 test_templates.py
ContextSuite context=TestTemplates>:setup Error 19.05 test_templates.py
ContextSuite context=TestISOUsage>:setup Error 0.00 test_usage.py
ContextSuite context=TestLBRuleUsage>:setup Error 0.00 test_usage.py
ContextSuite context=TestNatRuleUsage>:setup Error 0.00 test_usage.py
ContextSuite context=TestPublicIPUsage>:setup Error 0.00 test_usage.py
ContextSuite context=TestSnapshotUsage>:setup Error 0.00 test_usage.py
ContextSuite context=TestVmUsage>:setup Error 0.00 test_usage.py
ContextSuite context=TestVolumeUsage>:setup Error 0.00 test_usage.py
ContextSuite context=TestVpnUsage>:setup Error 0.00 test_usage.py
ContextSuite context=Test01DeployVM>:setup Error 0.00 test_vm_life_cycle.py
ContextSuite context=Test02VMLifeCycle>:setup Error 0.00 test_vm_life_cycle.py
test_14_secure_to_secure_vm_migration Error 11.53 test_vm_life_cycle.py
test_15_secured_to_nonsecured_vm_migration Error 94.28 test_vm_life_cycle.py
test_16_nonsecured_to_secured_vm_migration Error 1.32 test_vm_life_cycle.py
ContextSuite context=TestVmSnapshot>:setup Error 2.18 test_vm_snapshots.py
ContextSuite context=TestCreateVolume>:setup Error 0.00 test_volumes.py
ContextSuite context=TestVolumes>:setup Error 0.00 test_volumes.py
ContextSuite context=TestVPCRedundancy>:setup Error 0.00 test_vpc_redundant.py
ContextSuite context=TestVPCNics>:setup Error 0.00 test_vpc_router_nics.py
ContextSuite context=TestRVPCSite2SiteVpn>:setup Error 0.00 test_vpc_vpn.py
ContextSuite context=TestVPCSite2SiteVPNMultipleOptions>:setup Error 0.00 test_vpc_vpn.py
ContextSuite context=TestVpcRemoteAccessVpn>:setup Error 0.00 test_vpc_vpn.py
ContextSuite context=TestVpcSite2SiteVpn>:setup Error 0.00 test_vpc_vpn.py
test_disable_oobm_ha_state_ineligible Error 1515.63 test_hostha_kvm.py

@Pearl1594
Copy link
Contributor Author

@blueorangutan test

@blueorangutan
Copy link

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

@blueorangutan
Copy link

Trillian test result (tid-3029)
Environment: kvm-centos7 (x2), Advanced Networking with Mgmt server 7
Total time taken: 33021 seconds
Marvin logs: https://github.com/blueorangutan/acs-prs/releases/download/trillian/pr4193-t3029-kvm-centos7.zip
Intermittent failure detected: /marvin/tests/smoke/test_privategw_acl.py
Intermittent failure detected: /marvin/tests/smoke/test_vpc_redundant.py
Intermittent failure detected: /marvin/tests/smoke/test_vpc_vpn.py
Smoke tests completed. 75 look OK, 2 have error(s)
Only failed tests results shown below:

Test Result Time (s) Test File
test_02_vpc_privategw_static_routes Failure 170.50 test_privategw_acl.py
test_03_vpc_privategw_restart_vpc_cleanup Failure 170.77 test_privategw_acl.py
test_04_rvpc_privategw_static_routes Failure 224.14 test_privategw_acl.py
test_01_vpc_site2site_vpn_multiple_options Failure 286.82 test_vpc_vpn.py

@DaanHoogland DaanHoogland merged commit 963d603 into apache:4.13 Oct 21, 2020
@DaanHoogland DaanHoogland deleted the usage_record_cnt_fix branch October 21, 2020 17:15
@olivierlemasle
Copy link
Contributor

olivierlemasle commented Oct 21, 2020

Thanks @DaanHoogland @Pearl1594

Pearl1594 added a commit to shapeblue/cloudstack that referenced this pull request Nov 4, 2020
Pearl1594 added a commit to shapeblue/cloudstack that referenced this pull request Nov 4, 2020
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