Skip to content
Closed
Show file tree
Hide file tree
Changes from all commits
Commits
Show all changes
44 commits
Select commit Hold shift + click to select a range
fb3bdf8
feat: splat apply patch from local work
sighphyre Sep 18, 2023
eec8121
chore: hack in local path for yggdrasil
sighphyre Sep 18, 2023
61ad46c
chore: trim out diff that shouldn't have been checked in
sighphyre Oct 23, 2023
5797508
wip: implement custom strategies, this definitely needs a rebase
sighphyre Nov 3, 2023
4b3a598
green tests!
sighphyre Nov 10, 2023
211fcdf
chore: use published package rather than a symlink
sighphyre Nov 15, 2023
6382a94
chore: merge main
sighphyre Nov 15, 2023
a0707de
wip: trim some unneeded strings and apply format
sighphyre Nov 15, 2023
c39fe95
wip: trim some unneeded nil checks
sighphyre Nov 15, 2023
5df5067
wip: move default_variant to Variant
sighphyre Nov 15, 2023
f6071b9
wip: more null checks removed
sighphyre Nov 15, 2023
88b46c7
wip: make internal public api for custom strategies match existing api
sighphyre Nov 15, 2023
7f55e6b
wip: remove class and references to FeatureToggle.default_variant
sighphyre Nov 15, 2023
5851724
wip: remove new log message
sighphyre Nov 15, 2023
49925d5
wip: bring custom strategies closer to existing api
sighphyre Nov 15, 2023
0116bef
wip: remove unused parameters and functions and take rubocop suggestion
sighphyre Nov 15, 2023
766d392
wip: remove :toggles, :toggle_metrics, and :segment_cache from Unleas…
sighphyre Nov 15, 2023
6530299
wip: refactor get_variant method and restore logging
sighphyre Nov 15, 2023
c367b0b
chore: apply some rubocop lints
sighphyre Nov 15, 2023
1cd34b2
wip: minor refactor to toggle fethcer
sighphyre Nov 16, 2023
5b5bb20
wip: bump yggdrasil
sighphyre Feb 16, 2024
aaa6b0f
wip: merge main
sighphyre Feb 16, 2024
8f0c038
chore: bump ygg version
sighphyre Feb 19, 2024
3122986
wip: include version of ygg that contains gem for jruby9.2
sighphyre Feb 20, 2024
3e44bc3
chore: bump ygg to a version that should include macos universal arti…
sighphyre Feb 20, 2024
05c83ce
chore: bump yggdrasil version
sighphyre Feb 20, 2024
e0d37af
chore: bump ygg again
sighphyre Feb 20, 2024
156356c
chore: exclude spec folder in coveralls
sighphyre Feb 21, 2024
9be1f29
chore: remove variant override, don't need it anymore
sighphyre Feb 21, 2024
8e64f84
chore: disable some coverage that I don't think makes sense
sighphyre Feb 21, 2024
cf89cc5
fix: make strategies report correct data shape during registration
sighphyre Feb 21, 2024
9dc382e
chore: clean up gem dependency
sighphyre Feb 21, 2024
950eb8a
chore: no longer save on shutdown, there's no point in doing that
sighphyre Jul 30, 2024
b7f1b7a
chore: merge main
sighphyre Sep 4, 2024
3fb4688
fix: convert all context values to strings prior to send to ygg
sighphyre Sep 5, 2024
0518b74
chore: bump ygg to test macos
sighphyre Sep 5, 2024
92642d6
chore: bump yggdrasil version
sighphyre Sep 20, 2024
f143ca2
chore: merge main
sighphyre Sep 20, 2024
d4d7a8b
chore: bump ygg version
sighphyre Sep 23, 2024
7a7e70a
chore: bump yggdrasil and use feature_enabled in variant calculation
sighphyre Sep 23, 2024
25ac942
chore: bump ygg version
sighphyre Sep 23, 2024
4ec0e17
chore: bump ygg version
sighphyre Sep 23, 2024
d75e0b3
chore: bump ygg version
sighphyre Sep 23, 2024
4cf3254
docs: migration guide to v6
sighphyre Sep 25, 2024
File filter

Filter by extension

Filter by extension


Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
39 changes: 39 additions & 0 deletions MigrationGuide.md
Original file line number Diff line number Diff line change
@@ -0,0 +1,39 @@
# Migrating to Unleash-Client-Ruby 6.0.0

The upgrade the v6.0.0 of the Unleash client should be mostly seamless. There are a few significant changes that may require some changes on the consumer side or that the consumer should be generally aware of.

## Custom strategy changes

There's a few changes to custom strategies that may affect you if you make heavy use of them.

Firstly, custom strategies are no longer allowed to override the built in strategies, namely custom strategies named 'applicationHostname', 'default', 'flexibleRollout', 'gradualRolloutRandom', 'gradualRolloutSessionId', 'gradualRolloutUserId', 'remoteAddress' or 'userWithId' will now raise an error on startup, whereas previously creating a custom strategy with one of these names would raise a warning in the logs.

Secondly, the deprecated `register_custom_strategies` method has now been removed. The only way to register a custom strategy is to use configuration, i.e.

```ruby
class MyCustomStrategy
def name
'myCustomStrategy'
end

def is_enabled?(params = {}, context = nil)
true
end
end

Unleash.configure do |config|
config.strategies.add(MyCustomStrategy.new)
end
```

If you're already using configuration to register your custom strategies and you're not overriding the default strategies, this section doesn't affect you.

## Direct access to strategy objects

The objects for base strategies are no longer directly accessible via the SDK, the `known_strategies` method will only return custom strategies registered by the user. If you need to know whether or not a custom strategy will override either a built in or custom strategy, the `includes?` method will return a false if the name is available.

Generally, it's strongly discouraged to access or alter any of the strategy properties other than the name for built in strategies. v.6.0.0 makes this a hard requirement.

## ARM requirements

v6.0.0 has a new dependency on a native binary; we currently only distribute ARM binaries for MacOS. If you need ARM support on Linux or Windows, please feel free to open an issue.
4 changes: 4 additions & 0 deletions README.md
Original file line number Diff line number Diff line change
Expand Up @@ -32,6 +32,10 @@ Ruby client for the [Unleash](https://github.com/Unleash/unleash) feature manage
- [Releasing](#releasing)
- [Contributing](#contributing)

# Migrating to v6

If you're using custom strategies or overriding built in strategies, please read the full [migration guide](./MigrationGuide.md) before upgrading to v6.

## Supported Ruby Interpreters

- MRI 3.3
Expand Down
2 changes: 1 addition & 1 deletion lib/unleash.rb
Original file line number Diff line number Diff line change
Expand Up @@ -10,7 +10,7 @@ module Unleash
TIME_RESOLUTION = 3

class << self
attr_accessor :configuration, :toggle_fetcher, :toggles, :toggle_metrics, :reporter, :segment_cache, :logger
attr_accessor :configuration, :toggle_fetcher, :reporter, :logger, :engine
end

self.configuration = Unleash::Configuration.new
Expand Down
44 changes: 0 additions & 44 deletions lib/unleash/activation_strategy.rb

This file was deleted.

41 changes: 20 additions & 21 deletions lib/unleash/client.rb
Original file line number Diff line number Diff line change
Expand Up @@ -2,7 +2,7 @@
require 'unleash/toggle_fetcher'
require 'unleash/metrics_reporter'
require 'unleash/scheduled_executor'
require 'unleash/feature_toggle'
require 'unleash/variant'
require 'unleash/util/http'
require 'logger'
require 'time'
Expand All @@ -11,14 +11,17 @@ module Unleash
class Client
attr_accessor :fetcher_scheduled_executor, :metrics_scheduled_executor

# rubocop:disable Metrics/AbcSize
def initialize(*opts)
Unleash.configuration = Unleash::Configuration.new(*opts) unless opts.empty?
Unleash.configuration.validate!

Unleash.logger = Unleash.configuration.logger.clone
Unleash.logger.level = Unleash.configuration.log_level
Unleash.engine = YggdrasilEngine.new
Unleash.engine.register_custom_strategies(Unleash.configuration.strategies.custom_strategies)

Unleash.toggle_fetcher = Unleash::ToggleFetcher.new
Unleash.toggle_fetcher = Unleash::ToggleFetcher.new Unleash.engine
if Unleash.configuration.disable_client
Unleash.logger.warn "Unleash::Client is disabled! Will only return default (or bootstrapped if available) results!"
Unleash.logger.warn "Unleash::Client is disabled! Metrics and MetricsReporter are also disabled!"
Expand All @@ -30,6 +33,7 @@ def initialize(*opts)
start_toggle_fetcher
start_metrics unless Unleash.configuration.disable_metrics
end
# rubocop:enable Metrics/AbcSize

def is_enabled?(feature, context = nil, default_value_param = false, &fallback_blk)
Unleash.logger.debug "Unleash::Client.is_enabled? feature: #{feature} with context #{context}"
Expand All @@ -40,15 +44,16 @@ def is_enabled?(feature, context = nil, default_value_param = false, &fallback_b
default_value_param
end

toggle_as_hash = Unleash&.toggles&.select{ |toggle| toggle['name'] == feature }&.first
if toggle_as_hash.nil?
toggle_enabled = Unleash.engine.enabled?(feature, context)
if toggle_enabled.nil?
Unleash.logger.debug "Unleash::Client.is_enabled? feature: #{feature} not found"
Unleash.engine.count_toggle(feature, false)
return default_value
end

toggle = Unleash::FeatureToggle.new(toggle_as_hash, Unleash&.segment_cache)
Unleash.engine.count_toggle(feature, toggle_enabled)

toggle.is_enabled?(context)
toggle_enabled
end

def is_disabled?(feature, context = nil, default_value_param = true, &fallback_blk)
Expand All @@ -71,23 +76,19 @@ def if_disabled(feature, context = nil, default_value = true, &blk)
end

def get_variant(feature, context = Unleash::Context.new, fallback_variant = disabled_variant)
Unleash.logger.debug "Unleash::Client.get_variant for feature: #{feature} with context #{context}"

toggle_as_hash = Unleash&.toggles&.select{ |toggle| toggle['name'] == feature }&.first

if toggle_as_hash.nil?
Unleash.logger.debug "Unleash::Client.get_variant feature: #{feature} not found"
return fallback_variant
end

toggle = Unleash::FeatureToggle.new(toggle_as_hash, Unleash&.segment_cache)
variant = toggle.get_variant(context, fallback_variant)
variant = Unleash.engine.get_variant(feature, context)

if variant.nil?
Unleash.logger.debug "Unleash::Client.get_variant variants for feature: #{feature} not found"
Unleash.engine.count_toggle(feature, false)
return fallback_variant
end

variant = Variant.new(variant)

Unleash.engine.count_variant(feature, variant.name)
Unleash.engine.count_toggle(feature, variant.feature_enabled)

# TODO: Add to README: name, payload, enabled (bool)

variant
Expand All @@ -96,7 +97,6 @@ def get_variant(feature, context = Unleash::Context.new, fallback_variant = disa
# safe shutdown: also flush metrics to server and toggles to disk
def shutdown
unless Unleash.configuration.disable_client
Unleash.toggle_fetcher.save!
Unleash.reporter.post unless Unleash.configuration.disable_metrics
shutdown!
end
Expand All @@ -117,7 +117,7 @@ def info
'appName': Unleash.configuration.app_name,
'instanceId': Unleash.configuration.instance_id,
'sdkVersion': "unleash-client-ruby:" + Unleash::VERSION,
'strategies': Unleash.strategies.keys,
'strategies': Unleash.strategies.known_strategies,
'started': Time.now.iso8601(Unleash::TIME_RESOLUTION),
'interval': Unleash.configuration.metrics_interval_in_millis,
'platformName': RUBY_ENGINE,
Expand All @@ -140,7 +140,6 @@ def start_toggle_fetcher
end

def start_metrics
Unleash.toggle_metrics = Unleash::Metrics.new
Unleash.reporter = Unleash::MetricsReporter.new
self.metrics_scheduled_executor = Unleash::ScheduledExecutor.new(
'MetricsReporter',
Expand All @@ -166,7 +165,7 @@ def register
end

def disabled_variant
@disabled_variant ||= Unleash::FeatureToggle.disabled_variant
@disabled_variant ||= Unleash::Variant.disabled_variant
end

def first_fetch_is_eager
Expand Down
4 changes: 2 additions & 2 deletions lib/unleash/configuration.rb
Original file line number Diff line number Diff line change
Expand Up @@ -40,9 +40,9 @@ def metrics_interval_in_millis
def validate!
return if self.disable_client

raise ArgumentError, "URL and app_name are required parameters." if self.app_name.nil? || self.url.nil?
raise ArgumentError, "app_name is a required parameter." if self.app_name.nil?

validate_custom_http_headers!(self.custom_http_headers)
validate_custom_http_headers!(self.custom_http_headers) unless self.url.nil?
end

def refresh_backup_file!
Expand Down
117 changes: 0 additions & 117 deletions lib/unleash/constraint.rb

This file was deleted.

Loading
Loading