-
Notifications
You must be signed in to change notification settings - Fork 897
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 duplicate metric_rollups not dealing with active relation #16166
Conversation
@miq-bot add_label wip, bug |
This change would fix the issue. it’s a wip coz not sure why we had that check in first place, i guess it’s for performance consideration, wanna to hold back hitting db til last. |
app/models/metric/helper.rb
Outdated
if recs.respond_to?(:klass) # active record relation | ||
return recs unless recs.klass.kind_of?(Metric) || recs.klass.kind_of?(MetricRollup) | ||
elsif recs.empty? || !recs.all? { |r| r.kind_of?(Metric) || r.kind_of?(MetricRollup) } | ||
if recs.empty? || !recs.all? { |r| r.kind_of?(Metric) || r.kind_of?(MetricRollup) } |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
I think we can still use previous code and only change
this condition:
https://github.com/ManageIQ/manageiq/blob/master/app/models/metric/helper.rb#L124
to
return recs unless recs.klass <= Metric || recs.klass <=MetricRollup
because kind_of?
is for instances and not for classes.
I think that with this change we can fix the bug and keep @kbrock's intention in #14224.
it should work also with VmPerformance
because it is inherited from MetricRollup
.
It would be also nice to add specs when the method has AR scope as input (MetricRollup.where(..)
)
thanks!
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
Yep! Done
cad295a
to
9b508f9
Compare
Checked commit jameswnl@d338c6f with ruby 2.3.3, rubocop 0.47.1, and haml-lint 0.20.0 |
@miq-bot remove_label wip |
cc @gtanzillo - just letting you know - it could affect chargeback (not sure how much when we are using max or avg) |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
Looks good 👍 thanks!
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
Awesome
@lpichler can you elaborate on your comment? What's the overlap of max/avg and this dedup code? Are you expecting the max/avg results to change, but now be correct? |
@miq-bot add_labels fine/yes, euwe/yes |
@@ -121,7 +121,7 @@ def self.sanitize_start_end_time(interval, interval_name, start_time, end_time) | |||
|
|||
def self.remove_duplicate_timestamps(recs) | |||
if recs.respond_to?(:klass) # active record relation | |||
return recs unless recs.klass.kind_of?(Metric) || recs.klass.kind_of?(MetricRollup) | |||
return recs unless recs.klass <= Metric || recs.klass <= MetricRollup | |||
elsif recs.empty? || !recs.all? { |r| r.kind_of?(Metric) || r.kind_of?(MetricRollup) } | |||
return recs |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
@lpichler @gtanzillo it looks to me that this would make chargeback "more correct" but I understand any change in chargeback isn't good. Is this something that we should do more planning on or do you think this is okay? |
yes we are now more correct but how much it is affected - it is based on how much duplicated records have been in the system for specific date range ( range the related to report whether it is monthly, weekly, daily ) Chargeback rating calculations are not related to counts of metric rollups. so it can affect AVG then MAX - because for AVG we are summing up metric values and we are diving it by hours in the date range. But previously(year before) when I was facing this issue(#11017) duplicated records mean that (duplicate records are records with same resource and timestamp) No sure how looks data where were we found the issue - if they have duplicated records with non-empty metric values. So it depends how duplication is frequentant (especially for AVGs). |
I agree that this change should make any calculations based on a range of metrics more accurate. However, it's not apparent what the cause of the dups is and whether they are truly dups - all values are the same or whether they are dups based on timestamp and resource but with different metric values. If it's the latter, is there a risk of throwing away valid metrics? I guess my question is somewhat beyond the scope of this PR since we were already doing this. And if this make the process more accurate, I'm good with it. |
@gtanzillo so we believe the cause of the dups is because we have >1 metrics_processor_workers and we have overlapping date ranges queued so they both process the same rollup range at the same time and without unique indexes on the table or some external locking it will be difficult to prevent this. This is something we're planning on addressing in rearch. @Ladas @jameswnl please correct anything I got wrong in ^^ :D |
the method is doing 'merging' values. It means that if any value is missing(is nil) it is populated from other duplicate record with any value. So if duplicated records have values, the winner is the first record with any value. (For chargeback query is ordered by 'resource_id, timestamp' which are same, so I don't know how to determine what is first record in the set of duplicates.) |
Remove duplicate metric_rollups not dealing with active relation
Nice find @jameswnl ! |
@gtanzillo yes what @agrare said, we will be adding unique indexes for 5.0, so any duplicates will not be possible. Until then, we need to live with it, since it's pretty hard to avoid duplication. |
Remove duplicate metric_rollups not dealing with active relation (cherry picked from commit 15e48b8) https://bugzilla.redhat.com/show_bug.cgi?id=1505417
Euwe backport details:
|
Remove duplicate metric_rollups not dealing with active relation (cherry picked from commit 15e48b8) https://bugzilla.redhat.com/show_bug.cgi?id=1505415
Fine backport details:
|
Remove duplicate metric_rollups not dealing with active relation (cherry picked from commit 15e48b8) https://bugzilla.redhat.com/show_bug.cgi?id=1505415
https://bugzilla.redhat.com/show_bug.cgi?id=1463165
Duplicated rollup records are still there in reports.