Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Remove conversion to UTC in Chargeback #17606

Conversation

lpichler
Copy link
Contributor

@lpichler lpichler commented Jun 19, 2018

pulled out from #13398
description is in ^

currently it is tricky to cover it by tests because of zone setting in CI.

cc @jrafanie @gtanzillo

Links

Fixes: https://bugzilla.redhat.com/show_bug.cgi?id=1587857

@jrafanie
Copy link
Member

@lpichler Can you write a test for this? Also, could you summarize the problem and why we're removing the UTC conversion in the PR description and commit message? It's unclear why this was done by just looking at the commit/PR.

From what I'm understanding, it's something like this: "Because we expect resources to be charged for their usage in their local time, we must remove UTC conversion for the report data range to ensure the range starts and ends in local time to avoid incorrect results such as double costs for one month and no charge for the next month"

@@ -62,14 +62,14 @@ def report_time_range
ts = Time.now.in_time_zone(tz)
case interval
when 'daily'
start_time = (ts - start_interval_offset.days).beginning_of_day.utc
Copy link
Member

Choose a reason for hiding this comment

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

We might want to put a comment above ts = Time.now.in_time_zone(tz) saying something like # Use local time for determining the start and end of the date range since we use and are charged for consumption in local time. Or something that clearly states why we're using local time here.

@lpichler
Copy link
Contributor Author

@jrafanie it is described here #13398 because we caught it in past time and there is just different time zone used. It is pretty edge case. Look on it and let me if it brings light to you. I did not finish it because it was never ending story to write test for in CI environment for me but there is test and it us briefly describing it in comment in code.

Briefly.
We have month(for example) report and we are splitting time interval for reporting. One interval is month. But in this case the start of month is not in the same month as it suppose to be because of time zone shift and superabundant converting to UTC.

Let me know if it is more understandable.

thanks

@gtanzillo
Copy link
Member

The effect of this is that the report is picking up the last day of April in addition to the entire month of May when the report should just be for May. This is what's happening in the code -

2.3.1 :043 > ts = Time.now.in_time_zone("Seoul")
 => Tue, 19 Jun 2018 21:49:31 KST +09:00 
2.3.1 :044 > start_time = (ts - 1.months).beginning_of_month.utc
 => 2018-04-30 15:00:00 UTC 
2.3.1 :045 > end_time   = (ts - 1.months).end_of_month.utc
 => 2018-05-31 14:59:59 UTC 

@JPrause
Copy link
Member

JPrause commented Jun 19, 2018

@miq-bot add_label blocker

@JPrause
Copy link
Member

JPrause commented Jun 19, 2018

@lpichler if this can be backported, can you add the gaprindashvili/yes label.

@lpichler
Copy link
Contributor Author

@miq-bot add_label gaprindashvili/yes

@jrafanie
Copy link
Member

@lpichler Document it once in the commit message for future everyone. Looking at this commit/change 6 months from now, I have no idea why we're using local time here. Make your commits clear as to why you're making a change. It's automatically used in the description of the PR (if single commit). The commit message(s) get auto-copied to the BZ on merge so there's no need for you to describe it any further.

Conversion to UTC is superfluous here.
We are splitting out time base according to
report interval - daily,weekly and monthly.
Reference date is Time.now (includes local time)
and we are converting this date to zone from
report definition and we are determining
beginning of report interval.

After this we were converting the beginning of
month to UTC which was considered as improper
step.

it is improper because it can end in previous month and
then interval is split out badly
Example:

Time.now:
2018-06-20 09:33:38 +0200

in report zone ("Seoul" +0900):
Wed, 20 Jun 2018 16:34:24 KST +09:00

beginning of month (we are consider 1 month back):
Tue, 01 May 2018 00:00:00 KST +09:00
^ this ok

but when we convert it to utc:
2018-04-30 15:00:00 UTC

as you can it ends in different month and this
date is user to querying on metric rollup and
then we are getting different set of metric rollups.
@lpichler lpichler force-pushed the remove_utc_conversion_from_report_interval_in_chargeback branch from d61ac8a to 9dc1e1c Compare June 20, 2018 07:40
@lpichler
Copy link
Contributor Author

@jrafanie @gtanzillo I described issue in commit message 👍

@miq-bot
Copy link
Member

miq-bot commented Jun 20, 2018

Checked commit lpichler@9dc1e1c with ruby 2.3.3, rubocop 0.52.1, haml-lint 0.20.0, and yamllint 1.10.0
1 file checked, 0 offenses detected
Everything looks fine. 🍪

@lpichler
Copy link
Contributor Author

I will add test in follow up PR.

@gtanzillo gtanzillo merged commit 9fe07d0 into ManageIQ:master Jun 20, 2018
@lpichler lpichler deleted the remove_utc_conversion_from_report_interval_in_chargeback branch June 20, 2018 08:59
@jrafanie
Copy link
Member

@lpichler next time, please put the bz link in the commit message so the commit message will be automatically copied to the BZ (and you don't have to explain what you did again in the bz)

@jrafanie jrafanie added this to the Sprint 89 Ending Jul 2, 2018 milestone Jun 20, 2018
simaishi pushed a commit that referenced this pull request Jun 21, 2018
…port_interval_in_chargeback

Remove conversion to UTC in Chargeback
(cherry picked from commit 9fe07d0)

Fixes https://bugzilla.redhat.com/show_bug.cgi?id=1593678
@simaishi
Copy link
Contributor

Fine backport details:

$ git log -1
commit 553db93f1aa65a2504c93cfdf23966ddf935da5f
Author: Gregg Tanzillo <gtanzill@redhat.com>
Date:   Wed Jun 20 10:54:38 2018 +0200

    Merge pull request #17606 from lpichler/remove_utc_conversion_from_report_interval_in_chargeback
    
    Remove conversion to UTC in Chargeback
    (cherry picked from commit 9fe07d02c8ee1367b84a0c80a42e25386662349a)
    
    Fixes https://bugzilla.redhat.com/show_bug.cgi?id=1593678

simaishi pushed a commit that referenced this pull request Jun 21, 2018
…port_interval_in_chargeback

Remove conversion to UTC in Chargeback
(cherry picked from commit 9fe07d0)

Fixes https://bugzilla.redhat.com/show_bug.cgi?id=1593677
@simaishi
Copy link
Contributor

Gaprindashvili backport details:

$ git log -1
commit e40b6fe1a8bed02504f463799b9263c50a094984
Author: Gregg Tanzillo <gtanzill@redhat.com>
Date:   Wed Jun 20 10:54:38 2018 +0200

    Merge pull request #17606 from lpichler/remove_utc_conversion_from_report_interval_in_chargeback
    
    Remove conversion to UTC in Chargeback
    (cherry picked from commit 9fe07d02c8ee1367b84a0c80a42e25386662349a)
    
    Fixes https://bugzilla.redhat.com/show_bug.cgi?id=1593677

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