-
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
Fix Containers dashboard heatmaps #14857
Conversation
6a8ebf3
to
7b9f2b6
Compare
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.
LGTM. @kbrock can you have a look? its the same as https://github.com/ManageIQ/manageiq/blob/master/app/models/metric_rollup.rb#L48
@kbrock Can you please take a look? |
app/models/metric/helper.rb
Outdated
metrics = Metric.where(:resource_type => resource_type) | ||
metrics = metrics.where(:resource_id => resource_ids) if resource_ids | ||
metrics = metrics.order(:resource_id, :timestamp => :desc) | ||
metrics = metrics.where('timestamp > ?', 10.minutes.ago.utc) |
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.
@zakiva why 10.minutes.ago.utc
? Is it dependent on any other value?
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.
@simon3z That is the time interval we agreed on for "realtime" metrics that we display in the dashboard. Same value is used here:
https://github.com/ManageIQ/manageiq-ui-classic/blob/master/app/services/container_dashboard_service.rb#L395
(we can change it easily of course)
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.
@zakiva then it seems to me that this should be a single constant in the code (or a setting?) instead that having 10.minutes.ago.utc
hard-coded, so in case we need to tweak it we change the value in a single place.
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.
Right, I will fix that.
app/models/metric/helper.rb
Outdated
@@ -198,4 +198,12 @@ def self.get_time_interval(obj, timestamp) | |||
|
|||
start_time..timestamp | |||
end | |||
|
|||
def self.latest_metrics(resource_type, resource_ids = nil) | |||
metrics = Metric.where(:resource_type => resource_type) |
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.
@kbrock any way to make the syntax of the whole query (these 5 lines) nicer? Any syntactic sugar?
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.
Yea, not perfect, but it will work.
@kbrock can you review this? |
@Fryguy can you take a look? Thanks. |
7b9f2b6
to
89867aa
Compare
@miq-bot assign kbrock |
app/models/metric/helper.rb
Outdated
@@ -198,4 +198,12 @@ def self.get_time_interval(obj, timestamp) | |||
|
|||
start_time..timestamp | |||
end | |||
|
|||
def self.latest_metrics(resource_type, timestamp, resource_ids = nil) |
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.
@zakiva is it more clear to use since_timestamp
instead of just timestamp
?
89867aa
to
12ad5b5
Compare
Checked commit zakiva@12ad5b5 with ruby 2.2.6, rubocop 0.47.1, and haml-lint 0.20.0 |
@kbrock can you review/approve/merge? |
metrics = metrics.where(:resource_id => resource_ids) if resource_ids | ||
metrics = metrics.order(:resource_id, :timestamp => :desc) | ||
metrics = metrics.where('timestamp > ?', since_timestamp) | ||
metrics.select('DISTINCT ON (metrics.resource_id) metrics.*') |
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.
think metrics.distinct(:resource_id)
is an alternative
Fix Containers dashboard heatmaps (cherry picked from commit 5d0ec5b) https://bugzilla.redhat.com/show_bug.cgi?id=1460357
Fine backport details:
|
Why the added 'helper' here? This module is already a bucket of random things. Seems like this could have been a few scopes on the Metric model with the helper in ui-classic utilizing them. |
@zakiva how hard is this refactoring? Is it just moving some code around? |
@chrisarcand I'm not sure I understand you right, can you please explain what change exactly would you like to see here? Back then a similar code was in the ui-classic repo and I was asked to move it here. |
@zakiva This code is basically just layers of scoping on the metrics model. I'm suggesting actually using ActiveRecord scopes instead of this class method. Forget about it, it's not really worth correcting at this point. I also understand if it's mostly just a code move that you were asked to do :) |
BZ: https://bugzilla.redhat.com/show_bug.cgi?id=1439671
UI side and tests in ManageIQ/manageiq-ui-classic#608
@simon3z @zeari @moolitayer Please review
@miq-bot add_label providers/containers, bug, fine/yes