Bug 1376210

Summary: Chargeback - Can't create a custom rate on anything else than an hourly basis
Product: Red Hat CloudForms Management Engine Reporter: Fabien CAMBI <fcambi>
Component: ReportingAssignee: Šimon Lukašík <slukasik>
Status: CLOSED DUPLICATE QA Contact: Nandini Chandra <nachandr>
Severity: low Docs Contact:
Priority: medium    
Version: 5.6.0CC: bascar, greartes, gtanzill, jhardy, kmorey, nstephan, obarenbo, slukasik
Target Milestone: GAFlags: dajohnso: needinfo? (jhardy)
Target Release: cfme-future   
Hardware: x86_64   
OS: Linux   
Whiteboard: chargeback
Fixed In Version: Doc Type: If docs needed, set a value
Doc Text:
Story Points: ---
Clone Of: Environment:
Last Closed: 2017-03-09 12:53:40 UTC Type: Bug
Regression: --- Mount Type: ---
Documentation: --- CRM:
Verified Versions: Category: ---
oVirt Team: --- RHEL 7.3 requirements from Atomic Host:
Cloudforms Team: --- Target Upstream Version:
Attachments:
Description Flags
Screenshot of the problem none

Description Fabien CAMBI 2016-09-14 21:20:23 UTC
Description of problem:
It seems 

Version-Release number of selected component (if applicable):
5.6.0.13

How reproducible:
Fressh install of CF

Steps to Reproduce:
1. Go to Cloud Intel -> Chargeback -> rates -> Compute
2. Click Configuration -> Add a new chargeback rate

Actual results:
You can't select any other option than "hourly" in the "per time" column.

Expected results:
You should be able to select at least "hourly" and "daily".

Comment 3 Fabien CAMBI 2016-10-12 18:53:27 UTC
Created attachment 1209708 [details]
Screenshot of the problem

I added the attachment for a better understanding. It shows exactly in which menu you can't choose anything else than "hourly" in the dropdown.

Comment 6 Reartes Guillermo 2016-11-05 23:54:33 UTC
Appliance Version: 5.6.2.2.20161017185613_7cee0a0

On the database i concluded that i am looking for the column "per_time" value source:

vmdb_production=# select * from chargeback_rate_details;
      id       | enabled |      description       |   group   |  source   |              metric               | per_time | per_unit  | friendly_rate | chargeback_rate_id |         created_on         |         updated_on         | chargeback_rate_detail_measure_id | charg
eback_rate_detail_currency_id 
---------------+---------+------------------------+-----------+-----------+-----------------------------------+----------+-----------
[...TRUNCATED...]
(13 rows)

Where are the values from "per_time" column from table "chargeback_rate_details"  come from?

File: /var/www/miq/vmdb/db/schema.yml

chargeback_rate_details:
- id
- enabled
- description
- group
- source
- metric
- per_time
- per_unit
- friendly_rate
- chargeback_rate_id
- created_on
- updated_on
- chargeback_rate_detail_measure_id
- chargeback_rate_detail_currency_id

Then i located the file "/var/www/miq/vmdb/app/controllers/chargeback_controller.rb"

[root@cfme1 controllers]# grep per_time ./chargeback_controller.rb 
      temp[:per_time] ||= "hourly"
    @edit[:new][:per_time_types] = {"hourly" => _("Hourly")}
      %i{per_time per_unit}.each do |measure|

I since i am testing this on my very own POC setup, i took a chance...
I assumed that there is code somewhere for at least a 'daily' rate...
If there is no code for it, i hope the report will end up in a traceback...

And changed:
ORIGINAL : @edit[:new][:per_time_types] = {"hourly" => _("Hourly")}
NEW      : @edit[:new][:per_time_types] = {"hourly" => _("Hourly"), "daily" => _("Daily")}


# grep -n ":per_time_types" /var/www/miq/vmdb/app/controllers/chargeback_controller.rb 
596:    @edit[:new][:per_time_types] = {"hourly" => _("Hourly"), "daily" => _("Daily")}

Then i ran a chargeback report with a new chargeback rate using "Daily" and to my surprise, it did not result in a traceback. 

Hourly: (default/default:hourly)

Date Range | VM Name Owner  | CPU Used | CPU Total Cost | Memory Used | Memory Total Cost *
Oct 2016   | cfme-prod_0004 | 0 MHz    | $8.00          | 0 Bytes     | $0.00             *

*| Storage Used | Storage Total Cost | Storage Allocated | Storage Allocated Cost
 |        24 GB | $51,539,607,560.00 | 120 GB            | $8.00

Daily: 

Date Range | VM Name Owner  | CPU Used | CPU Total Cost | Memory Used | Memory Total Cost *
Oct 2016   | cfme-prod_0004 | 0 MHz    | $0.33          | 0 Bytes     | $0.00             *

*| Storage Used | Storage Total Cost | Storage Allocated | Storage Allocated Cost
*|        24 GB | $2,147,483,648.33  | 120 GB            | $0.33


Is it enough to manually modify the hardcoded auxiliary table? 

I do assume that there is code to support 'daily', otherwise the report would have failed with a traceback?
I did not use the chargeback feature before.

Is there any hope for it to be fixed for 5.6.x?

Cheers.

Comment 7 Šimon Lukašík 2016-12-13 22:35:01 UTC
This is dupe bz for this in master: https://bugzilla.redhat.com/show_bug.cgi?id=1401498

Comment 8 Šimon Lukašík 2017-03-09 12:53:40 UTC
This was fixed in CFME 5.7.z (bug 1412283).
This is gonna be fixed in CFME 5.8 (bug 1401498)

In the first round this was not slated for 5.6.z. Please re-open if you need this in 5.6.z. Thanks!

*** This bug has been marked as a duplicate of bug 1412283 ***