flippercloud / flipper

🐬 Beautiful, performant feature flags for Ruby.
https://www.flippercloud.io/docs
MIT License
3.7k stars 413 forks source link

Getting enabled? => true for non-enabled actors #752

Closed UnderpantsGnome closed 1 year ago

UnderpantsGnome commented 1 year ago

I'm guessing I'm doing something incorrectly here, but I'm not sure what it is.

I would expect Flipper.enabled?(:test, not_enabled) to be false.

>> Flipper::VERSION
=> "0.28.3"

>> Rails.version
=> "6.1.7.4"

>> class User < Struct.new(:id)
  include Flipper::Identifier
end
=> User

>> Flipper.new(Flipper::Adapters::ActiveRecord.new).features.each do |feature|
  pp feature: feature.key, values: feature.gate_values
end
=> #<Set: {}>

>> enabled = User.new({id: "enabled"})
=> #<struct User id={:id=>"enabled"}>

>> not_enabled = User.new({id: "not_enabled"})
=> #<struct User id={:id=>"not_enabled"}>

>> Flipper.enable_actor(:test, enabled)
  Flipper feature(test) enable true (31.2ms)  [ thing=#<Flipper::Types::Actor:0x000000010d19fb28 @actor=#<struct User id={:id=>"enabled"}>, @value="User;{:id=>\"enabled\"}"> gate_name=actor ]
=> true

>> Flipper.enable_percentage_of_actors(:test, 100)
  Flipper feature(test) enable true (4.5ms)  [ thing=#<Flipper::Types::PercentageOfActors:0x000000010d367398 @value=100> gate_name=percentage_of_actors ]
=> true

>> Flipper.new(Flipper::Adapters::ActiveRecord.new).features.each do |feature|
  pp feature: feature.key, values: feature.gate_values
end

{:feature=>"test",
 :values=>
  #<Flipper::GateValues:0x000000010d3b7aa0
   @actors=#<Set: {"User;{:id=>\"enabled\"}"}>,
   @boolean=false,
   @groups=#<Set: {}>,
   @percentage_of_actors=100,
   @percentage_of_time=0>}
=> #<Set:
 {#<Flipper::Feature:14660 name="test", state=:conditional, enabled_gate_names=[:actor, :percentage_of_actors], adapter=:memoizable>}>

 >> Flipper.enabled?(:test, enabled)
  Flipper feature(test) enabled? true (1.2ms)  [ actors=[#<Flipper::Types::Actor:0x000000010d3e4898 @actor=#<struct User id={:id=>"enabled"}>, @value="User;{:id=>\"enabled\"}">] gate_name=actor ]
=> true

>> Flipper.enabled?(:test, not_enabled)
  Flipper feature(test) enabled? true (1.9ms)  [ actors=[#<Flipper::Types::Actor:0x000000010d4142f0 @actor=#<struct User id={:id=>"not_enabled"}>, @value="User;{:id=>\"not_enabled\"}">] gate_name=percentage_of_actors ]
=> true
jnunemaker commented 1 year ago

Hey! It's because you enabled percentage of actors to 100. If you leave that at 0 then only the enabled actor will return true.

jnunemaker commented 1 year ago

Let me know if you have any other questions.

UnderpantsGnome commented 1 year ago

Hey! At least I didn't make you type "UnderpantsGnome" this time 🤣

That's what I figured, but my brain was all "100% of the actors", apologies for the noise.

jnunemaker commented 1 year ago

Gotcha. Yeah each gate works independently. If any return true the feature is enabled.