Skip to content

Commit

Permalink
Merge branch 'main' into chore/update-release-process
Browse files Browse the repository at this point in the history
  • Loading branch information
thomasheartman authored Sep 30, 2024
2 parents 8e36bb7 + c6679d2 commit 90d995a
Show file tree
Hide file tree
Showing 55 changed files with 385 additions and 3,142 deletions.
2 changes: 0 additions & 2 deletions .github/workflows/pull_request.yml
Original file line number Diff line number Diff line change
Expand Up @@ -29,13 +29,11 @@ jobs:
- macos
ruby-version:
- jruby-9.4
- jruby-9.3
- 3.3
- 3.2
- 3.1
- '3.0'
- 2.7
- 2.6

needs:
- lint
Expand Down
2 changes: 1 addition & 1 deletion .rubocop.yml
Original file line number Diff line number Diff line change
@@ -1,7 +1,7 @@
# inherit_from: .rubocop_todo.yml

AllCops:
TargetRubyVersion: 2.6
TargetRubyVersion: 2.7

Naming/PredicateName:
AllowedMethods:
Expand Down
10 changes: 10 additions & 0 deletions CHANGELOG.md
Original file line number Diff line number Diff line change
Expand Up @@ -13,6 +13,16 @@ Note: These changes are not considered notable:

## [Unreleased]

## [6.0.0.pre] - 2024-09-25
#### Changed
- No longer possible to override built in strategies with custom strategies (#152)
- No longer possible to access built in strategy's objects, these are now native code (#152)
- Core of the SDK swapped for Yggdrasil engine (#152)

## [5.1.1] - 2024-09-23
### Fixed
- increased accuracy of rollout distribution (#200)

## [5.1.0] - 2024-09-18
### Added
- feature_enabled in variants (#197)
Expand Down
216 changes: 94 additions & 122 deletions README.md

Large diffs are not rendered by default.

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.

43 changes: 21 additions & 22 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,12 +117,12 @@ 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,
'platformVersion': RUBY_VERSION,
'yggdrasilVersion': nil,
'yggdrasilVersion': "0.13.2",
'specVersion': Unleash::CLIENT_SPECIFICATION_VERSION
}
end
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

0 comments on commit 90d995a

Please sign in to comment.