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

Move event filters into the database. #3636

Merged
merged 8 commits into from
Aug 14, 2015

Conversation

lfu
Copy link
Member

@lfu lfu commented Jul 28, 2015

Changes for phase 1 in #3273.

default_value_for :enabled, true
after_save :queue_sync_filtered_events
after_destroy :queue_sync_filtered_events
after_destroy { |r| _log.info("Event filter [#{r.event_name}] for provider #{r.provider_model} with ID [#{r.ems_id}] has been deleted by user [#{self.class.current_userid}]") }
Copy link
Member

Choose a reason for hiding this comment

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

Do we need this? If so, perhaps it should go into the AuditLog instead of evm log?

@Fryguy
Copy link
Member

Fryguy commented Jul 28, 2015

@lfu Looking good!

after_destroy :queue_sync_filtered_events
after_destroy { |r| $audit_log.success("Event filter [#{r.event_name}] for provider #{r.provider_model} with ID [#{r.ems_id}] has been deleted by user [#{self.class.current_userid}]") }

YAML_FILE ||= Rails.root.join("db", "fixtures", "#{self.to_s.pluralize.underscore}.yml")
Copy link
Member

Choose a reason for hiding this comment

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

You do not need 'self' here and the to_s should be name: name.pluralize.underscore

@lfu lfu force-pushed the filtered_provider_events_3273 branch from b57c7f1 to 8152bea Compare July 29, 2015 21:49
@@ -0,0 +1,76 @@
class EventBlacklisting < ActiveRecord::Base
Copy link
Member

Choose a reason for hiding this comment

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

There was probably a discussion I missed on the naming of EventBlacklisting. Looking up the meaning of a listing shows a printed list as the main definition. To avoid ambiguity I would change this name to EventBlacklistEntry

Copy link
Member

Choose a reason for hiding this comment

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

@gmcculloug
Copy link
Member

@Fryguy @matthewd Sounds like it would be better to move the default filters into each provider model as an array constant (instead of a single file with all providers) and for seeding we could process the descendants of the ExtManagementSystem model and process any that define the blacklist constant.

Something like:

  def self.seed
    MiqRegion.my_region.lock do
      ExtManagementSystem.descendants.each do |ems| 
        if ems.const_defined?(:DEFAULT_BLACKLISTED_EVENTS, false)
          ...

The seeding code will create any records that do not exist. By using the enabled flag a user can decide if they want to process one of the default events without removing it from the list.

Thoughts?

@matthewd
Copy link
Contributor

You probably want a , false in there, but otherwise 👍

@gmcculloug
Copy link
Member

Thanks, I updated the code snippet with that.

@Fryguy
Copy link
Member

Fryguy commented Jul 30, 2015

Yeah, I like that idea. Alternately it could be a class method. This would give the provider plugin author the flexibility to use a constant or a yaml file or whatever they want. Thoughts?

@matthewd
Copy link
Contributor

I lean toward the constant, because it "feels" more right: if you make your method clever enough that its value might change at some point, you're likely in for a surprise.

If the author happens to be particularly keen on YAML, they can just read it while setting the constant 😄

@chessbyte
Copy link
Member

I lean more toward a method that can be subclassed, overridden and memo-ized at will.

To me, if ems.const_defined?(:DEFAULT_BLACKLISTED_EVENTS, false) is a code smell. It should just read ems.blacklisted_events and the ExtManagementSystem class will have a base method that returns an empty array.

@matthewd
Copy link
Contributor

¯_(ツ)_/¯ that level of dynamism seems like overkill for something we were about to put in a static text file, but as long as each provider owns its part of the list in some way, I'm happy.

I was assuming we specifically wouldn't want it to be inherited by children automatically... otherwise it could skip the if even with the constant.

@chessbyte
Copy link
Member

@matthewd I think I am reacting to whether DEFAULT_BLACKLISTED_EVENTS is defined per EMS/Provider. Perhaps the constant should always be defined and set to [] to signify that there are no default blacklisted events.

@matthewd
Copy link
Contributor

Yeah, I think my imagined scenario where a class halfway up the inheritance hierarchy might define values, and that we would not want to automatically inflict those upon its subclasses, is actually pretty unlikely. So, either a method or a constant, defined as [] on ExtManagementSystem and inherited/overridden by subclasses, sounds good to me. I like the constant for the "set this once, at boot; no second chances" taste... but then, I can't really speak to what precedent we have for similar notions elsewhere.

However, it now occurs to me that blacklist + disabled is an unfortunate / possibly confusing double-negative. In order to receive the X event, I must ensure its blacklisting is disabled; if I don't want the event, it must be enabled. No exciting new names are leaping to mind, though, so perhaps that's just a problem for another day.

@gmcculloug
Copy link
Member

We started off calling the items filters and the filter could be enabled/disabled. Does it make sense to keep the word "filter" in the name: EventBlacklistFilter?

@matthewd
Copy link
Contributor

EventFilter + blacklist?

@chessbyte
Copy link
Member

@matthewd can you elaborate on your suggestion of EventFilter + blacklist?

@lfu lfu force-pushed the filtered_provider_events_3273 branch from 2126640 to 5e6b90f Compare August 3, 2015 16:23
@gmcculloug
Copy link
Member

Marking as WIP while we work on a migration to handle user added filters.

@gmcculloug gmcculloug changed the title Move event filters into the database. [WIP] Move event filters into the database. Aug 3, 2015
@gmcculloug gmcculloug added the wip label Aug 3, 2015
@miq-bot
Copy link
Member

miq-bot commented Aug 4, 2015

<pr_mergeability_checker />This pull request is not mergeable. Please rebase and repush.

@lfu lfu force-pushed the filtered_provider_events_3273 branch 5 times, most recently from e80b0e3 to 2ddd6ed Compare August 10, 2015 19:03
@lfu lfu force-pushed the filtered_provider_events_3273 branch from 2ddd6ed to de7aa4e Compare August 12, 2015 18:55
@miq-bot
Copy link
Member

miq-bot commented Aug 12, 2015

Checked commits lfu@c32d39d .. lfu@de7aa4e with rubocop 0.32.1 and haml-lint 0.13.0
14 files checked, 22 offenses detected

app/models/blacklisted_event.rb

db/migrate/20150806194147_migrate_filtered_events_to_blacklisted_events.rb

spec/migrations/20150806194147_migrate_filtered_events_to_blacklisted_events_spec.rb

spec/models/blacklisted_event_spec.rb

@gmcculloug gmcculloug removed the wip label Aug 13, 2015
@gmcculloug gmcculloug changed the title [WIP] Move event filters into the database. Move event filters into the database. Aug 13, 2015
@gmcculloug
Copy link
Member

👍

gmcculloug added a commit that referenced this pull request Aug 14, 2015
Move event filters into the database.
@gmcculloug gmcculloug merged commit 645dc9d into ManageIQ:master Aug 14, 2015
@gmcculloug gmcculloug added this to the Sprint 28 Ending August 24, 2015 milestone Aug 14, 2015
@lfu lfu deleted the filtered_provider_events_3273 branch August 19, 2015 18:54
t.bigint :ems_id
t.boolean :system
t.boolean :enabled
t.timestamps
Copy link
Contributor

Choose a reason for hiding this comment

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

This has added a bunch of noise to the migration specs...

DEPRECATION WARNING: #timestamps was called without specifying an option for null. In Rails 5, this behavior will change to null: false. You should manually specify null: true to prevent the behavior of your existing migrations from changing. (called from block in change at db/migrate/20150804194147_create_blacklisted_events.rb:9)

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