Enable scoped_search for monitoring_proxy#99
Conversation
39e22bc to
63eb93a
Compare
63eb93a to
545f3ae
Compare
|
Hi @dgoetz , could you take a look at this PR? It is a feature we would like to have. |
|
Two questions on the implementation: Is it possible to limit the suggestions to only smart proxies which have the feature monitoring? Is it possible to have a test for this to prevent breaking it in the future? A note on the feature itself, for perhaps adding documentation in the future: I can search for hosts with a specific smart proxy set ( |
ekohl
left a comment
There was a problem hiding this comment.
As noted in Matrix: I don't see any relationship defined. Normally you include BelongsToProxies and then use belongs_to_proxy on the model. Foreman's subnet has examples.
|
@ekohl so you mean add |
|
Oh, I now see where it's added. I missed that at first: foreman_monitoring/lib/foreman_monitoring/engine.rb Lines 69 to 78 in d1c0bfa That may be sufficient.
See my above comments: I'd expect it to already respect what |
|
So the search for |
|
So it's not filtering on the feature. I suspect because that's added as a validation which scoped_search ignores: I wonder if you can somehow make belongs_to aware of the constraint. Looking at https://api.rubyonrails.org/v7.0.2/classes/ActiveRecord/Associations/ClassMethods.html#method-i-belongs_to you can pass where constraints. If you solve that in Foreman itself then all plugins should benefit from it. |
|
Hmm I build a sql query which allows filtering by feature |
We recently did something like this in Katello and it works well: https://github.com/Katello/katello/blob/df7ea596fc2b655c3c61a90293aac478d9804bb2/app/models/katello/content_view.rb#L45 |
|
I tried it like that def register_smart_proxy(name, options)
self.registered_smart_proxies = registered_smart_proxies.merge(name => options)
has_many :smart_proxy_features, :dependent => :destroy
has_many :features, :through => :smart_proxy_features
belongs_to name, -> { where( :features => { :name => options[:feature]}).joins(:features)}, :class_name => 'SmartProxy'
validates name, :proxy_features => { :feature => options[:feature], :required => options[:required] }
endbut got the same. So it suggests all Proxies. |
I don't think these should be needed.
This looks alright. My theory is that scoped_search doesn't look at the scope when searching. When digging into this I found that it's really the It may be tricky to apply the scope. I found you can call ekohl/scoped_search@9567990 is where I tried to reproduce this in tests. However, the However, this is where I need to end my research. If you want to solve this it's probably within scoped_search or how we call scoped_search. On a related note: I think can reuse the belongs_to name, -> { with_features(options[:feature]) }, :class_name => 'SmartProxy' |
|
@ekohl thanks for your help. I'm going to research a little bit after my vacation. Maybe I could try to use scoped_search with external_search_ method https://github.com/wvanbergen/scoped_search/wiki/Search-definition#external-search-methods. |
|
@ochnerd If you find out it is not fixable, I am not against merging the current state as it is already an improvement! So thanks already to everyone for investigating! |
|
I got to experiment a little bit with ext_method but haven't been successfull. But I found am PR which is Foreman releated in scoped_search wvanbergen/scoped_search#221 which is about enhanced_filtering theforeman/foreman#10197. @dgoetz I think we should merge this and when I have spare time i look into the scoping issues. |
|
Any other feature planned for inclusion or should I do a new release? |
|
We currently have no other features planned. Please create a new release. Thank you! |
We want to be able to easily search Hosts without any monitoring_proxy set