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

Fixes #26226 - Filter Module Streams on CV #8295

Merged
merged 11 commits into from
Sep 14, 2019

Conversation

parthaa
Copy link
Contributor

@parthaa parthaa commented Aug 23, 2019

This commit adds UI, API and publish bindings for filtering module
streams in a content view.
Check out https://partha.fedorapeople.org/CVModuleFilters/ for the screen shots

@theforeman-bot
Copy link

Issues: #26226

@omkarkhatavkar
Copy link

@parthaa I tried quick glance today for UI, found some issues mentioned below.

Module Stream Link with not shown here.
Repositories for Filter  animal_repo_module_stream_filter

Module Stream Count shown wrong after all modules are applied in exclude filter with having Solve Dependencies is 'Yes'. This is not reproducible if Solve Dependencies is 'No'.
Versions for Content View  Content_view_2

We can get rid of this message as we have module stream filters
Package Filter  package filter

Currently, Publishing content views is failing with the below steps

  1. Add all module streams in the filter and publish the content view
  2. Now remove all modules from the filter and publish the filter
    Versions for Content View  Content_view_3
    centos7 katello devel okhatavk example com foreman_tasks tasks 002b9cba fa87 45ca 98dc 8a2bf3a5b116

Minor UI Issue, while removing module stream list we are showing multiple success message not similar while adding. we should stick only UI success message?
Content Views_1

I will be testing this further in detailed.

@parthaa parthaa force-pushed the module-stream-filters branch 6 times, most recently from 0f1b053 to 63649e3 Compare August 24, 2019 04:21
@omkarkhatavkar
Copy link

Module Stream Filter Create hangs in UI, not happens with other filters

New Filter for Content View  New_Testing_Content_View_1

@omkarkhatavkar
Copy link

@parthaa One More thing, I was not able to create the content view filter rule. tried some options, can you please that as well.

Option details:
  Following parameters accept format defined by its schema (bold are required):

  --module-streams    "name=string\,stream=string, ... "
hammer> 

hammer> content-view filter rule create --name "exclude duck module stream" --content-view-id 9 --content-view-filter-id 24 --module-streams "name='duck', stream='0'"
Could not create the filter rule:
  Missing arguments for 'module_streams[0][stream]', 'module_streams[1][name]'
hammer> content-view filter rule create --name "exclude duck module stream" --content-view-id 9 --content-view-filter-id 24 --module-streams "name=duck, stream=0"
Could not create the filter rule:
  Missing arguments for 'module_streams[0][stream]', 'module_streams[1][name]'

@parthaa
Copy link
Contributor Author

parthaa commented Aug 26, 2019

Option details:
  Following parameters accept format defined by its schema (bold are required):

  --module-streams    "name=string\,stream=string, ... "
hammer> 

hammer> content-view filter rule create --name "exclude duck module stream" --content-view-id 9 --content-view-filter-id 24 --module-streams "name='duck', stream='0'"
Could not create the filter rule:
  Missing arguments for 'module_streams[0][stream]', 'module_streams[1][name]'
hammer> content-view filter rule create --name "exclude duck module stream" --content-view-id 9 --content-view-filter-id 24 --module-streams "name=duck, stream=0"
Could not create the filter rule:
  Missing arguments for 'module_

@omkarkhatavkar I think this should be a separate hammer bug. The --module-streams parameter in the api creates "multiple" rules - one for each module-stream.
We should probably tweak the hammer call to have flags for module name and stream. Something like

hammer> content-view filter rule create --name "exclude duck module stream" --content-view-id 9 --content-view-filter-id 24 --module-name='duck'  --module-stream "0" 

@theforeman-bot
Copy link

There were the following issues with the commit message:

  • 2816e87 must be in the format fixes #redmine_number - brief description

If you don't have a ticket number, please create an issue in Redmine.

More guidelines are available in Coding Standards or on the Foreman wiki.


This message was auto-generated by Foreman's prprocessor

@coveralls
Copy link

coveralls commented Aug 26, 2019

Coverage Status

Coverage remained the same at 58.011% when pulling 770a327 on parthaa:module-stream-filters into 14a8471 on Katello:master.

@omkarkhatavkar
Copy link

omkarkhatavkar commented Aug 26, 2019

@omkarkhatavkar I think this should be a separate hammer bug. The --module-streams parameter in the api creates "multiple" rules - one for each module-stream.
We should probably tweak the hammer call to have flags for module name and stream. Something like

hammer> content-view filter rule create --name "exclude duck module stream" --content-view-id 9 --content-view-filter-id 24 --module-name='duck'  --module-stream "0" 

Make Sense, Bug raised here https://projects.theforeman.org/issues/27712

@theforeman-bot
Copy link

There were the following issues with the commit message:

  • 8380fe9 must be in the format fixes #redmine_number - brief description

If you don't have a ticket number, please create an issue in Redmine.

More guidelines are available in Coding Standards or on the Foreman wiki.


This message was auto-generated by Foreman's prprocessor

@parthaa
Copy link
Contributor Author

parthaa commented Aug 26, 2019

Module Stream Filter Create hangs in UI, not happens with other filters

addressed

@parthaa
Copy link
Contributor Author

parthaa commented Aug 26, 2019

[test katello]

@omkarkhatavkar
Copy link

omkarkhatavkar commented Aug 27, 2019

@parthaa I saw today another issue really weird one
Steps :

  1. added all module streams in the filter -> publish the filter
  2. remove all module streams from the filter -> publish
  3. Change the Content view Depedancy => Solve 'Yes'
  4. Now try to update module stream filter click on these two tabs
    ezgif com-video-to-gif (3)

@omkarkhatavkar
Copy link

Module Stream Link with not shown here.

PASS

Module Stream Count shown wrong after all modules are applied in exclude filter with having Solve Dependencies is 'Yes'. This is not reproducible if Solve Dependencies is 'No'.

Still Failing

We can get rid of this message as we have module stream filters

PASS

Currently, Publishing content views is failing with the below steps

  1. Add all module streams in the filter and publish the content view
  2. Now remove all modules from the filter and publish the filter

Module Stream Filter Create hangs in UI, not happens with other filters

PASS

Minor UI Issue, while removing module stream list we are showing multiple success message not similar while adding. we should stick only UI success message?

Can be Ignored

@omkarkhatavkar
Copy link

@partha: One change may be required here to make sure that API docs get updated

param :type, String, :desc => N_("type of filter (e.g. rpm, package_group, erratum, docker)"), :required => true

query
end

def self.uniquify_by_name_streams(name_streams)
Copy link
Contributor

Choose a reason for hiding this comment

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

where is this used?

Copy link
Contributor Author

Choose a reason for hiding this comment

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

Good call. Going to remove it (left over stray method from the name/stream implementation).

@omkarkhatavkar
Copy link

@parthaa please take a look on added automated tests for this PR here SatelliteQE/robottelo#7339 (whenever you get a chance)

@johnpmitsch
Copy link
Contributor

@parthaa I wonder if we need the description in the table of module streams in the filter? They can be lengthy and make the list very long and busy:

here

@johnpmitsch
Copy link
Contributor

@parthaa it looks like dependency solving does actually affect module streams?
here

I'm guessing this is intended, if so, I think we should change some of the dep solving help text in the content view details page, new CV page, and settings page. It currently says:
This will solve RPM dependencies on every publish of this Content View. , we should mention module streams or rephrase this

private

def module_stream_arel
::Katello::ModuleStream.arel_table
Copy link
Contributor

Choose a reason for hiding this comment

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

Why use arel in this file, does AR not provide the capability to do what you need?

Copy link
Contributor Author

Choose a reason for hiding this comment

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

So this query is only generating the where clause, instead of hard coding "(item in 111,24,5)" as string I feel arel table is a better approach

Copy link
Contributor

Choose a reason for hiding this comment

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

can't you do ::Katello::ModuleStream.find(module_stream_ids)?

Copy link
Contributor

@johnpmitsch johnpmitsch left a comment

Choose a reason for hiding this comment

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

Code and functionality looks good, just a few comments and open questions!

@parthaa
Copy link
Contributor Author

parthaa commented Sep 11, 2019

[test katlelo]

@parthaa
Copy link
Contributor Author

parthaa commented Sep 11, 2019

[test katello]

@parthaa
Copy link
Contributor Author

parthaa commented Sep 11, 2019

Code and functionality looks good, just a few comments and open questions!

updated

@parthaa
Copy link
Contributor Author

parthaa commented Sep 11, 2019

[test katello]

@@ -82,7 +82,7 @@ <h2 translate>Create Content View</h2>
</label>
</div>
<p class="help-block" translate>
This will solve RPM dependencies on every publish of this Content View. Dependency solving significantly increases
This will solve RPM and Module Stream dependencies on every publish of this Content View. Dependency solving significantly increases
Copy link
Contributor

Choose a reason for hiding this comment

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

This text is also in engines/bastion_katello/app/assets/javascripts/bastion_katello/content-views/details/views/content-view-info.html, can you update there 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.

updated

def generate_clauses(_repo)
return if module_stream_rules.blank?

module_stream_ids = module_stream_rules.map(&:module_stream_id)
Copy link
Contributor

Choose a reason for hiding this comment

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

Suggested change
module_stream_ids = module_stream_rules.map(&:module_stream_id)
module_stream_ids = module_stream_rules.map(&:module_stream_id)
::Katello::ModuleStream.find(module_stream_ids) unless module_stream_ids.empty?

This is what I am thinking, but maybe I'm missing something

Copy link
Contributor Author

@parthaa parthaa Sep 12, 2019

Choose a reason for hiding this comment

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

Ok I can see why this is confusing. Check the following output on rails console

irb(main):005:0> ::Katello::ModuleStream.arel_table[:id].in([1,2,3]).to_sql
=> "\"katello_module_streams\".\"id\" IN (1, 2, 3)"

The contract for generate_clauses is to return a sub clause like a where condition. Some thing like katello_module_streams in (...) . This method returns the arel version. Some where down the line in ModuleClauseGenerator it actually does a to_sql and aggregates various clauses with "or". Check out https://github.com/Katello/katello/pull/8295/files#diff-bba4518369114a7121b8027dac527bb1R56-R64

The main intent of generate clauses is to return \"katello_module_streams\".\"id\" IN (1, 2, 3)
" (a sub condition if you wll)

Copy link
Contributor

Choose a reason for hiding this comment

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

@parthaa I get what you are doing here, but I'm still failing to see why all this logic is necessary. It's very possible that I'm overlooking some scenarios, I only poked around with basic examples.

Currently, it seems like a lot of hoops to jump through just to get a list of pulp ids from a list of module stream ids.

I tried something like this:

diff --git a/app/lib/katello/util/module_stream_clause_generator.rb b/app/lib/katello/util/module_stream_clause_generator.rb
index e67cc35..8a7d9f8 100644
--- a/app/lib/katello/util/module_stream_clause_generator.rb
+++ b/app/lib/katello/util/module_stream_clause_generator.rb
@@ -54,13 +54,11 @@ module Katello
       end
 
       def clauses_for_module_streams(module_stream_clauses = [])
-        query_clauses = module_stream_clauses.map do |clause|
-          "(#{clause.to_sql})"
-        end
-        return unless query_clauses.any?
+        ids = module_stream_clauses
+        return unless ids.any?
+        ids.flatten!
 
-        statement = query_clauses.join(" OR ")
-        {'_id' => { "$in" => ModuleStream.where(statement).pluck(:pulp_id)}}
+        {'_id' => { "$in" => ModuleStream.where(id: ids).pluck(:pulp_id)}}
       end
     end
   end
diff --git a/app/models/katello/content_view_module_stream_filter.rb b/app/models/katello/content_view_module_stream_filter.rb
index f7803a2..ceca720 100644
--- a/app/models/katello/content_view_module_stream_filter.rb
+++ b/app/models/katello/content_view_module_stream_filter.rb
@@ -9,18 +9,7 @@ module Katello
     def generate_clauses(_repo)
       return if module_stream_rules.blank?
 
-      module_stream_ids = module_stream_rules.map(&:module_stream_id)
-      module_streams_in(module_stream_ids) unless module_stream_ids.empty?
-    end
-
-    private
-
-    def module_stream_arel
-      ::Katello::ModuleStream.arel_table
-    end
-
-    def module_streams_in(ids)
-      module_stream_arel[:id].in(ids)
+      module_stream_rules.map(&:module_stream_id)
     end
   end
 end

What is a basic example like the one above missing?

My main concern with using arel is I'm not sure how well Rails will support its API in upgrades and I would hate to see us cause headaches for ourselves down the road. Is there a way to do this without arel?

Copy link
Contributor Author

Choose a reason for hiding this comment

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

addressed

@johnpmitsch
Copy link
Contributor

I still want to continue the discussion about the arel clauses before approving, but otherwise, things look good and my other concerns are addressed 💯

Copy link
Contributor

@johnpmitsch johnpmitsch left a comment

Choose a reason for hiding this comment

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

Works well!

@parthaa parthaa merged commit 84bb258 into Katello:master Sep 14, 2019
@parthaa parthaa deleted the module-stream-filters branch September 14, 2019 04:01
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.

5 participants