-
Notifications
You must be signed in to change notification settings - Fork 125
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
[WIP] Add cache columns to operating_systems table #322
base: master
Are you sure you want to change the base?
[WIP] Add cache columns to operating_systems table #322
Conversation
67cb826
to
fb9ac4b
Compare
Regarding the remaining CodeClimate/
|
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.
Little screwed up by the active record N+1 to save
But all in all, this looks good.
I Realize these methods are probably the same as methods somewhere else - I'll find those in your PR and make a comment elsewhere
return a[0] unless findStr.index(n).nil? | ||
end | ||
end | ||
"unknown" |
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.
does it make sense to not return "unknown"
?
If you want unknown, you could use a || "unknown"
(or pass in a boolean for default_value
or allow_unknown
)
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 This is a complete clone of what exists in OperatingSystem already:
os = obj.operating_system | ||
if os | ||
# check the given field names for possible matching value | ||
osName = [:distribution, :product_type, :product_name].each do |field| # rubocop:disable Style/SymbolArray |
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.
if "unknown"
isn't in play, maybe you could just use detect?
osName = [:distribution, :product_type, :product_name].each do |field| # rubocop:disable Style/SymbolArray | |
osName = [:distribution, :product_type, :product_name].detect do |field| | |
os_field = os.send(field) | |
os_field if normalize_os_name(os_field) | |
end |
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.
end | ||
|
||
# If the OS Name is still blank check the 'user_assigned_os' | ||
if osName.nil? && obj.respond_to?(:user_assigned_os) && obj.user_assigned_os |
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.
This is probably a naive suggestion but...
if osName.nil? && obj.respond_to?(:user_assigned_os) && obj.user_assigned_os | |
osName ||= obj.try(:user_assigned_os) |
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.
say_batch_started(base_relation.size) | ||
|
||
base_relation.find_in_batches do |group| | ||
group.each(&:save) |
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.
love the simplicity here
before_save :update_platform_and_image_name | ||
|
||
def update_platform_and_image_name | ||
obj = case |
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.
obj = case | |
obj = host || vm_or_template || computer_system || StubOperatingSystemObj.new(self) |
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.
But is that under 80 characters?
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.
close? 84 (not counting the indentation)
end | ||
|
||
# If the normalized name comes back as unknown, nil out the value so we can get it from another field | ||
if osName.kind_of?(String) |
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.
(still selling my idea) I don't think this is necessary if "unknown"
wouldn't come back :)
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.
Still "selling my idea" of "I copy pasted of what is in the existing OperatingSystem
model" and not trying to refactor that in this PR. Just trying to replicate what would be done when saving normally and trying to calculate the value as it would be generated today.
I think the bigger question to ask is not "can this code be done better", but does the idea of "caching this value" make sense. Hence the [WIP]
and [POC]
labels, since I really want a this to be agreed on before moving forward.
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.
Also, see "Considerations" section in the PR description... which I even forgot about...
end | ||
|
||
@@os_map = [ # rubocop:disable Style/ClassVars | ||
["windows_generic", %w(winnetenterprise w2k3 win2k3 server2003 winnetstandard servernt)], |
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.
Is winnetenterprise
right? I'm guessing it's winntenterprise
, but thought I'd double check.
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 just copied-pased this from the class I think, but let me double check.
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.
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 guess that's correct: https://communities.vmware.com/thread/42204
I agree with @NickLaMuro that we should stick with "unknown" since that's the current behavior. |
Side note, I'm having difficulty telling what codeclimate is upset about. There's no analysis there atm. |
@djberg96 probably long methods that I am replicating from the |
@NickLaMuro Ok, try rebasing and see if it triggers another build. I tried to request one but it didn't seem to actually do anything. |
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
👍 |
yea, I'm still 👍 on this one |
cc @agrare moreso on the processing side of this column.
Thoughts? That is, should we do it at collector time, persister time, or even lower at model save time? I like the idea of caching the value and not calculating over and over (better for reporting too), but I'm not sure where/when is the best place to do it? |
fb9ac4b
to
1238c6a
Compare
Welp, looks like this is being looked at now again. I rebased since I said I was going to do that 4 months ago... oops... |
Son of a bisquick |
1238c6a
to
a84a87a
Compare
@Fryguy @agrare For what it is worth, I "started" doing some of that here: But I agree, some decisions should be made before we move forward with that one. |
a84a87a
to
1081ffe
Compare
Both platform and image_name are relatively stable values that get re-calculated every time they are accessed, and in the worst case, causes it to traverse through many different sources to try and find a proper `platform`/`image_name`. This is compounded when you are trying to fetch thousands of records at once. This adds the columns to be cache store for those values, and should be triggered on every update of those records, and related records (not addressed in this patch).
Checked commit NickLaMuro@1081ffe with ruby 2.5.5, rubocop 0.69.0, haml-lint 0.20.0, and yamllint 1.10.0 |
? |
This pull request has been automatically marked as stale because it has not been updated for at least 3 months. If these changes are still valid, please remove the Thank you for all your contributions! More information about the ManageIQ triage process can be found in the traige process documentation. |
@NickLaMuro What do you want to do with this one? |
@gtanzillo I covered a lot of my rational in the related PR here: ManageIQ/manageiq-automation_engine#446 (comment) And really, I am waiting on approval of this approach, or if this is something we instead don't want to support. The BZ that was originally associated with this fix became less relevant since AWS was being de-prioritized at the time, but if that has changed then perhaps this should be re-visited and re-reviewed. |
This pull request has been automatically marked as stale because it has not been updated for at least 3 months. If these changes are still valid, please remove the Thank you for all your contributions! More information about the ManageIQ triage process can be found in the triage process documentation. |
My thoughts were here and are the same #322 (comment) |
FWIW, I think this should be done at model save time (calculate during record save and update if necessary) and I'm ok with caching these as columns, but really want @agrare 's opinion. |
Saving this to the database instead of calculating it every time at display time makes a lot of sense. This sounds a lot like raw_power_state / power_state where |
This pull request has been automatically marked as stale because it has not been updated for at least 3 months. If these changes are still valid, please remove the Thank you for all your contributions! More information about the ManageIQ triage process can be found in the triage process documentation. |
This pull request has been automatically closed because it has not been updated for at least 3 months. Feel free to reopen this pull request if these changes are still valid. Thank you for all your contributions! More information about the ManageIQ triage process can be found in the triage process documentation. |
This pull request has been automatically marked as stale because it has not been updated for at least 3 months. If these changes are still valid, please remove the |
3 similar comments
This pull request has been automatically marked as stale because it has not been updated for at least 3 months. If these changes are still valid, please remove the |
This pull request has been automatically marked as stale because it has not been updated for at least 3 months. If these changes are still valid, please remove the |
This pull request has been automatically marked as stale because it has not been updated for at least 3 months. If these changes are still valid, please remove the |
Both
platform
andimage_name
are relatively stable values that get re-calculated every time they are accessed, and in the worst case, causes it to traverse through many different sources to try and find a properplatform
/image_name
. This is compounded when you are trying to fetch thousands of records at once.This patch adds the columns to be cache store for those values, and should be triggered on every update of those records, and related records (not addressed in this patch).
Links to associated
manageiq
implementation and BZ related PRs to come, but those are what will provide more context to the advantages to this change.Considerations
Example Output
This was done with a DB that had a single Amazon EMS with public images that have been included in a refresh: