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

Use table name when generating SQL to filter tasks on Tasks screen #344

Conversation

yrudman
Copy link
Contributor

@yrudman yrudman commented Feb 10, 2017

This PR depends and should be merged together with ManageIQ/manageiq#13452

There would be task created for each job after changes in ManageIQ/manageiq#13452 and those new tasks associated with jobs should be filtered out on UI Tasks screen.
Since there are columns in jobs and miq_tasks tables with same name (like state, status,...) we need to use table name when generating SQL on joined tables.

@miq-bot add-label enhancement

local AFTER UI and model changes:
after

\cc @Fryguy @gtanzillo @dclarizio

…rm always correctly defined.

Only task queries requier adding table name when accessing filed (after creating association between Job and MiqTask sql is joining 2 tables with the same column names), Job queries still the same.
@yrudman yrudman changed the title Use table name when generating SQL to filter jobs or tasks on Tasks screen Use table name when generating SQL to filter tasks on Tasks screen Feb 10, 2017
@yrudman yrudman force-pushed the keep-same-ui-after-making-job-belongs-to-task branch from 9110973 to deda7d7 Compare February 10, 2017 17:36
@yrudman yrudman force-pushed the keep-same-ui-after-making-job-belongs-to-task branch from deda7d7 to 36af099 Compare February 10, 2017 17:44
@yrudman yrudman force-pushed the keep-same-ui-after-making-job-belongs-to-task branch from 7e305ae to ee1f3a9 Compare February 10, 2017 21:21
@yrudman yrudman force-pushed the keep-same-ui-after-making-job-belongs-to-task branch from ee1f3a9 to 5b0118a Compare February 10, 2017 21:27
@dclarizio dclarizio requested a review from mzazrivec February 10, 2017 22:27
@gtanzillo
Copy link
Member

@yrudman Is there a "before" screen shot that goes with the "after" one? IIRC, there should not be any visible UI changes with this PR. I should just ensure the UI still works with you backend changes.

@yrudman
Copy link
Contributor Author

yrudman commented Feb 11, 2017

@gtanzillo
BEFORE: Screenshot below is on master branches from both repo but DB is after migration - each job has corresponding task. You can see that after filtering 3 records with name starting with "Scan" the rest would be the same as in "after" screenshot:
screen shot 2017-02-10 at 10 06 50 pm

Deleting 3 records linked to jobs from miq_tasks table will produce the same view as in "after"

@yrudman
Copy link
Contributor Author

yrudman commented Feb 16, 2017

@mzazrivec could you review

end

@user_names = db_class.distinct("userid").pluck("userid").delete_if(&:blank?) if @active_tab.to_i > 2
Copy link
Contributor

Choose a reason for hiding this comment

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

I know this has been there before, but is there perhaps a better way to do this? (select non-null user names
that have ever queued a job or a task). Esp. since miq_task.userid is a varchar and isn't indexed.

@kbrock ?

Copy link
Contributor Author

Choose a reason for hiding this comment

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

@mzazrivec This is good point!
Should that improvement belong to another PR ?

I was not aware that we keep history of users accessing specific screens/performing action. If we do, that table should be pretty big (vs users table) and which way is faster - need some benchmarking

Copy link
Member

@kbrock kbrock Feb 17, 2017

Choose a reason for hiding this comment

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

This is getting the list of every user who has ever created a job or task?
Yea, I'd imagine the tasks table is much bigger than the users table.

All the queries I imagine depend upon having an index on userid. do we want to add that?

Copy link
Contributor Author

@yrudman yrudman Feb 17, 2017

Choose a reason for hiding this comment

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

Ohh, I've misunderstood Milan's comment, user table is not involved here. @kbrock it may make sense to add index on userid in jobs and miq_tasks tables. I am not sure since there is trade-off on creating index...

Copy link
Member

Choose a reason for hiding this comment

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

yea, there is a tradeoff on creating tasks vs searching this screen.
And since we create a bunch of tasks that are not in the ui, this may be a hit we don't want.

Do we have another mechanism to pick users?
Since this is just moving code (not creating it), I think fixing this is for another PR

trivial change, loose the parameter to distinct - it is not necessary due to the pluck

-@user_names = db_class.distinct("userid").pluck("userid").delete_if(&:blank?) if @active_tab.to_i > 2
+@user_names = db_class.distinct.pluck("userid").delete_if(&:blank?) if @active_tab.to_i > 2

Copy link
Contributor Author

Choose a reason for hiding this comment

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

thank you Keenan for suggestion! Done

@gtanzillo, @dclarizio result of this query supposed to populate Users filter but at this time this filter not visible. I will create separate PR to make User filter visible on appropriate tabs

if vm_analysis_task?
[sql, %w(finished waiting_to_start queued)]
else
[sql, %w(Finished waiting_to_start Queued)]
Copy link
Contributor

Choose a reason for hiding this comment

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

I don't understand the backend part, so I need to ask: why the upper case / lower case difference?

Copy link
Contributor Author

@yrudman yrudman Feb 17, 2017

Choose a reason for hiding this comment

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

dynamic SQL generated against 2 different tables: jobs table (for tabs tasks_1 and tasks_3, when vm_analysis_task?=true) and miq_tasks table (for tabs task_2 and tasks_4)
state column present in both tables, but values are different: in jobs table there are starting with low case and in miq_tasks with with upper case. List of values to populate state filter for jobs table: https://github.com/ManageIQ/manageiq-ui-classic/blob/master/app/helpers/ui_constants.rb#L410
and for miq_tasks table: https://github.com/ManageIQ/manageiq-ui-classic/blob/master/app/helpers/ui_constants.rb#L415

There is waiting_to_start value in downcase which should not be there (https://github.com/ManageIQ/manageiq-ui-classic/blob/master/app/controllers/miq_task_controller.rb#L403), and may be we should delete it, however it is there from the beginning and I am not sure if it is some legitimate exception or old bug.

Copy link
Member

@gtanzillo gtanzillo left a comment

Choose a reason for hiding this comment

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

👍 LGTM

Copy link
Member

@kbrock kbrock left a comment

Choose a reason for hiding this comment

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

This is pruning the code down.

Do we have general style suggestions on using @variables or munging sql?

good call Milan on the distinct users column. That will bite us.

"(miq_tasks.state!=? AND miq_tasks.state!=? AND miq_tasks.state!=?)) AND "\
"miq_tasks.updated_on>=? AND "\
"miq_tasks.updated_on<=? AND "\
"miq_tasks.state=?"
Copy link
Member

Choose a reason for hiding this comment

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

I know you didn't write this.

but miq_tasks.state is confusing here (in these specs in general)

end
end

def get_jobs(conditions)
def list_jobs
Copy link
Member

Choose a reason for hiding this comment

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

something is nice about having the conditions explicitly passed into this method.

but it is duplicated in many places, so this will do

@@ -334,6 +322,9 @@ def tasks_set_default_options
# Create a condition from the passed in options
def tasks_condition(opts, use_times = true)
cond = [[]]

cond = add_to_condition(cond, "jobs.guid IS NULL", nil) unless vm_analysis_task?
Copy link
Member

Choose a reason for hiding this comment

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

not for today (or possibly ever) but...
active record's where() already builds queries for us. seems odd we are reinventing this wheel

@@ -394,32 +385,40 @@ def build_query_for_warn
end

def build_query_for_status_completed(status)
return ["(state=? AND status=?)", ["finished", status]] if vm_analysis_task?
["(state=? AND status=?)", ["Finished", status.capitalize]]
return ["(#{db_table}state=? AND #{db_table}status=?)", ["finished", status]] if vm_analysis_task?
Copy link
Member

@kbrock kbrock Feb 17, 2017

Choose a reason for hiding this comment

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

I like the way you formatted the sql code in build_query_for_running and other places with a common sql block up top.

Would it make sense to do that change here as well?

Copy link
Contributor Author

Choose a reason for hiding this comment

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

yea, it does make sense to format in the same way, will do. Btw, reason for formatting was to make miq-bot happy and remove long lines and since that line was not long it wasn't touched

Copy link
Contributor Author

Choose a reason for hiding this comment

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

@kbrock sql formating looks nicer now

@@ -851,6 +854,17 @@
end
end

describe "#list_jobs" do
it 'sets the active tab' do
controller.instance_variable_set(:@tabform, "ui_2")
Copy link
Member

Choose a reason for hiding this comment

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

yea, this is a side effect of all of those @ variables vs passing in the variables into list_jobs

Copy link
Contributor Author

@yrudman yrudman Feb 17, 2017

Choose a reason for hiding this comment

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

I was trying to minimize changes in this PR and did not remove global variables as aproach to pass parameter into methods.

end

@user_names = db_class.distinct("userid").pluck("userid").delete_if(&:blank?) if @active_tab.to_i > 2
Copy link
Member

@kbrock kbrock Feb 17, 2017

Choose a reason for hiding this comment

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

This is getting the list of every user who has ever created a job or task?
Yea, I'd imagine the tasks table is much bigger than the users table.

All the queries I imagine depend upon having an index on userid. do we want to add that?

@miq-bot
Copy link
Member

miq-bot commented Feb 20, 2017

Checked commits yrudman/manageiq-ui-classic@3dd0a2a~...171d44c with ruby 2.2.6, rubocop 0.47.1, and haml-lint 0.20.0
2 files checked, 0 offenses detected
Everything looks good. 👍

@yrudman yrudman closed this Feb 20, 2017
@yrudman yrudman reopened this Feb 20, 2017
Copy link
Member

@kbrock kbrock left a comment

Choose a reason for hiding this comment

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

This makes some nice changes.
Also nicely cleans it up in prep for merging those 2 models

👍

@yrudman
Copy link
Contributor Author

yrudman commented Feb 27, 2017

@miq-bot remove-label pending core

@yrudman
Copy link
Contributor Author

yrudman commented Feb 27, 2017

@mzazrivec @dclarizio back-end PR has been merged - ManageIQ/manageiq#13452

@dclarizio dclarizio self-assigned this Feb 27, 2017
@dclarizio dclarizio merged commit 5a6599d into ManageIQ:master Feb 27, 2017
@dclarizio dclarizio added this to the Sprint 55 Ending Feb 27, 2017 milestone Feb 27, 2017
@yrudman yrudman deleted the keep-same-ui-after-making-job-belongs-to-task branch February 28, 2017 12:56
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