Skip to content

Commit

Permalink
Merge pull request #145 from launchdarkly/eb/ch98642/revert-intf-rename
Browse files Browse the repository at this point in the history
revert renames of feature_store & update_processor
  • Loading branch information
eli-darkly authored Jan 21, 2021
2 parents 3214f71 + 557d2c4 commit d2b5a3c
Show file tree
Hide file tree
Showing 27 changed files with 210 additions and 200 deletions.
36 changes: 23 additions & 13 deletions lib/ldclient-rb/config.rb
Original file line number Diff line number Diff line change
Expand Up @@ -23,7 +23,7 @@ class Config
# @option opts [Float] :read_timeout (10) See {#read_timeout}.
# @option opts [Float] :connect_timeout (2) See {#connect_timeout}.
# @option opts [Object] :cache_store See {#cache_store}.
# @option opts [Object] :data_store See {#data_store}.
# @option opts [Object] :feature_store See {#feature_store}.
# @option opts [Boolean] :use_ldd (false) See {#use_ldd?}.
# @option opts [Boolean] :offline (false) See {#offline?}.
# @option opts [Float] :poll_interval (30) See {#poll_interval}.
Expand All @@ -35,6 +35,8 @@ class Config
# @option opts [Float] :user_keys_flush_interval (300) See {#user_keys_flush_interval}.
# @option opts [Boolean] :inline_users_in_events (false) See {#inline_users_in_events}.
# @option opts [Object] :data_source See {#data_source}.
# @option opts [Object] :update_processor Obsolete synonym for `data_source`.
# @option opts [Object] :update_processor_factory Obsolete synonym for `data_source`.
# @option opts [Boolean] :diagnostic_opt_out (false) See {#diagnostic_opt_out?}.
# @option opts [Float] :diagnostic_recording_interval (900) See {#diagnostic_recording_interval}.
# @option opts [String] :wrapper_name See {#wrapper_name}.
Expand All @@ -50,7 +52,7 @@ def initialize(opts = {})
@flush_interval = opts[:flush_interval] || Config.default_flush_interval
@connect_timeout = opts[:connect_timeout] || Config.default_connect_timeout
@read_timeout = opts[:read_timeout] || Config.default_read_timeout
@data_store = opts[:data_store] || Config.default_data_store
@feature_store = opts[:feature_store] || Config.default_feature_store
@stream = opts.has_key?(:stream) ? opts[:stream] : Config.default_stream
@use_ldd = opts.has_key?(:use_ldd) ? opts[:use_ldd] : Config.default_use_ldd
@offline = opts.has_key?(:offline) ? opts[:offline] : Config.default_offline
Expand All @@ -61,7 +63,9 @@ def initialize(opts = {})
@user_keys_capacity = opts[:user_keys_capacity] || Config.default_user_keys_capacity
@user_keys_flush_interval = opts[:user_keys_flush_interval] || Config.default_user_keys_flush_interval
@inline_users_in_events = opts[:inline_users_in_events] || false
@data_source = opts[:data_source]
@data_source = opts[:data_source] || opts[:update_processor] || opts[:update_processor_factory]
@update_processor = opts[:update_processor]
@update_processor_factory = opts[:update_processor_factory]
@diagnostic_opt_out = opts.has_key?(:diagnostic_opt_out) && opts[:diagnostic_opt_out]
@diagnostic_recording_interval = opts.has_key?(:diagnostic_recording_interval) && opts[:diagnostic_recording_interval] > Config.minimum_diagnostic_recording_interval ?
opts[:diagnostic_recording_interval] : Config.default_diagnostic_recording_interval
Expand Down Expand Up @@ -103,9 +107,9 @@ def stream?
#
# Whether to use the LaunchDarkly relay proxy in daemon mode. In this mode, the client does not
# use polling or streaming to get feature flag updates from the server, but instead reads them
# from the {#data_store data store}, which is assumed to be a database that is populated by
# from the {#feature_store feature store}, which is assumed to be a database that is populated by
# a LaunchDarkly relay proxy. For more information, see ["The relay proxy"](https://docs.launchdarkly.com/v2.0/docs/the-relay-proxy)
# and ["Using a persistent data store"](https://docs.launchdarkly.com/v2.0/docs/using-a-persistent-feature-store).
# and ["Using a persistent feature store"](https://docs.launchdarkly.com/v2.0/docs/using-a-persistent-feature-store).
#
# All other properties related to streaming or polling are ignored if this option is set to true.
#
Expand Down Expand Up @@ -181,13 +185,13 @@ def offline?
#
# A store for feature flags and related data. The client uses it to store all data received
# from LaunchDarkly, and uses the last stored data when evaluating flags. Defaults to
# {InMemoryDataStore}; for other implementations, see {LaunchDarkly::Integrations}.
# {InMemoryFeatureStore}; for other implementations, see {LaunchDarkly::Integrations}.
#
# For more information, see ["Using a persistent data store"](https://docs.launchdarkly.com/v2.0/docs/using-a-persistent-feature-store).
# For more information, see ["Using a persistent feature store"](https://docs.launchdarkly.com/v2.0/docs/using-a-persistent-feature-store).
#
# @return [LaunchDarkly::Interfaces::DataStore]
# @return [LaunchDarkly::Interfaces::FeatureStore]
#
attr_reader :data_store
attr_reader :feature_store

#
# True if all user attributes (other than the key) should be considered private. This means
Expand Down Expand Up @@ -256,6 +260,12 @@ def offline?
#
attr_reader :data_source

# @deprecated This is replaced by {#data_source}.
attr_reader :update_processor

# @deprecated This is replaced by {#data_source}.
attr_reader :update_processor_factory

#
# Set to true to opt out of sending diagnostics data.
#
Expand Down Expand Up @@ -399,11 +409,11 @@ def self.default_use_ldd
end

#
# The default value for {#data_store}.
# @return [LaunchDarkly::Interfaces::DataStore] an {InMemoryDataStore}
# The default value for {#feature_store}.
# @return [LaunchDarkly::Interfaces::FeatureStore] an {InMemoryFeatureStore}
#
def self.default_data_store
InMemoryDataStore.new
def self.default_feature_store
InMemoryFeatureStore.new
end

#
Expand Down
8 changes: 4 additions & 4 deletions lib/ldclient-rb/file_data_source.rb
Original file line number Diff line number Diff line change
Expand Up @@ -118,14 +118,14 @@ class FileDataSource
# @return an object that can be stored in {Config#data_source}
#
def self.factory(options={})
return lambda { |sdk_key, config| FileDataSourceImpl.new(config.data_store, config.logger, options) }
return lambda { |sdk_key, config| FileDataSourceImpl.new(config.feature_store, config.logger, options) }
end
end

# @private
class FileDataSourceImpl
def initialize(data_store, logger, options={})
@data_store = data_store
def initialize(feature_store, logger, options={})
@feature_store = feature_store
@logger = logger
@paths = options[:paths] || []
if @paths.is_a? String
Expand Down Expand Up @@ -187,7 +187,7 @@ def load_all
return
end
end
@data_store.init(all_data)
@feature_store.init(all_data)
@initialized.make_true
end

Expand Down
10 changes: 5 additions & 5 deletions lib/ldclient-rb/impl/integrations/consul_impl.rb
Original file line number Diff line number Diff line change
Expand Up @@ -5,9 +5,9 @@ module Impl
module Integrations
module Consul
#
# Internal implementation of the Consul data store, intended to be used with CachingStoreWrapper.
# Internal implementation of the Consul feature store, intended to be used with CachingStoreWrapper.
#
class ConsulDataStoreCore
class ConsulFeatureStoreCore
begin
require "diplomat"
CONSUL_ENABLED = true
Expand All @@ -17,14 +17,14 @@ class ConsulDataStoreCore

def initialize(opts)
if !CONSUL_ENABLED
raise RuntimeError.new("can't use Consul data store without the 'diplomat' gem")
raise RuntimeError.new("can't use Consul feature store without the 'diplomat' gem")
end

@prefix = (opts[:prefix] || LaunchDarkly::Integrations::Consul.default_prefix) + '/'
@logger = opts[:logger] || Config.default_logger
Diplomat.configuration = opts[:consul_config] if !opts[:consul_config].nil?
Diplomat.configuration.url = opts[:url] if !opts[:url].nil?
@logger.info("ConsulDataStore: using Consul host at #{Diplomat.configuration.url}")
@logger.info("ConsulFeatureStore: using Consul host at #{Diplomat.configuration.url}")
end

def init_internal(all_data)
Expand Down Expand Up @@ -90,7 +90,7 @@ def upsert_internal(kind, new_item)
else
old_item = Model.deserialize(kind, old_value[0]["Value"])
# Check whether the item is stale. If so, don't do the update (and return the existing item to
# DataStoreWrapper so it can be cached)
# FeatureStoreWrapper so it can be cached)
if old_item[:version] >= new_item[:version]
return old_item
end
Expand Down
8 changes: 4 additions & 4 deletions lib/ldclient-rb/impl/integrations/dynamodb_impl.rb
Original file line number Diff line number Diff line change
Expand Up @@ -5,9 +5,9 @@ module Impl
module Integrations
module DynamoDB
#
# Internal implementation of the DynamoDB data store, intended to be used with CachingStoreWrapper.
# Internal implementation of the DynamoDB feature store, intended to be used with CachingStoreWrapper.
#
class DynamoDBDataStoreCore
class DynamoDBFeatureStoreCore
begin
require "aws-sdk-dynamodb"
AWS_SDK_ENABLED = true
Expand All @@ -28,7 +28,7 @@ class DynamoDBDataStoreCore

def initialize(table_name, opts)
if !AWS_SDK_ENABLED
raise RuntimeError.new("can't use DynamoDB data store without the aws-sdk or aws-sdk-dynamodb gem")
raise RuntimeError.new("can't use DynamoDB feature store without the aws-sdk or aws-sdk-dynamodb gem")
end

@table_name = table_name
Expand All @@ -41,7 +41,7 @@ def initialize(table_name, opts)
@client = Aws::DynamoDB::Client.new(opts[:dynamodb_opts] || {})
end

@logger.info("DynamoDBDataStore: using DynamoDB table \"#{table_name}\"")
@logger.info("DynamoDBFeatureStore: using DynamoDB table \"#{table_name}\"")
end

def init_internal(all_data)
Expand Down
14 changes: 7 additions & 7 deletions lib/ldclient-rb/impl/integrations/redis_impl.rb
Original file line number Diff line number Diff line change
Expand Up @@ -6,9 +6,9 @@ module Impl
module Integrations
module Redis
#
# Internal implementation of the Redis data store, intended to be used with CachingStoreWrapper.
# Internal implementation of the Redis feature store, intended to be used with CachingStoreWrapper.
#
class RedisDataStoreCore
class RedisFeatureStoreCore
begin
require "redis"
require "connection_pool"
Expand All @@ -19,7 +19,7 @@ class RedisDataStoreCore

def initialize(opts)
if !REDIS_ENABLED
raise RuntimeError.new("can't use Redis data store because one of these gems is missing: redis, connection_pool")
raise RuntimeError.new("can't use Redis feature store because one of these gems is missing: redis, connection_pool")
end

@redis_opts = opts[:redis_opts] || Hash.new
Expand All @@ -42,7 +42,7 @@ def initialize(opts)
@stopped = Concurrent::AtomicBoolean.new(false)

with_connection do |redis|
@logger.info("RedisDataStore: using Redis instance at #{redis.connection[:host]}:#{redis.connection[:port]} \
@logger.info("RedisFeatureStore: using Redis instance at #{redis.connection[:host]}:#{redis.connection[:port]} \
and prefix: #{@prefix}")
end
end
Expand All @@ -61,7 +61,7 @@ def init_internal(all_data)
multi.set(inited_key, inited_key)
end
end
@logger.info { "RedisDataStore: initialized with #{count} items" }
@logger.info { "RedisFeatureStore: initialized with #{count} items" }
end

def get_internal(kind, key)
Expand Down Expand Up @@ -97,13 +97,13 @@ def upsert_internal(kind, new_item)
multi.hset(base_key, key, Model.serialize(kind, new_item))
end
if result.nil?
@logger.debug { "RedisDataStore: concurrent modification detected, retrying" }
@logger.debug { "RedisFeatureStore: concurrent modification detected, retrying" }
try_again = true
end
else
final_item = old_item
action = new_item[:deleted] ? "delete" : "update"
@logger.warn { "RedisDataStore: attempted to #{action} #{key} version: #{old_item[:version]} \
@logger.warn { "RedisFeatureStore: attempted to #{action} #{key} version: #{old_item[:version]} \
in '#{kind[:namespace]}' with a version that is the same or older: #{new_item[:version]}" }
end
redis.unwatch
Expand Down
8 changes: 4 additions & 4 deletions lib/ldclient-rb/impl/store_client_wrapper.rb
Original file line number Diff line number Diff line change
Expand Up @@ -4,19 +4,19 @@
module LaunchDarkly
module Impl
#
# Provides additional behavior that the client requires before or after data store operations.
# Provides additional behavior that the client requires before or after feature store operations.
# Currently this just means sorting the data set for init(). In the future we may also use this
# to provide an update listener capability.
#
class DataStoreClientWrapper
include Interfaces::DataStore
class FeatureStoreClientWrapper
include Interfaces::FeatureStore

def initialize(store)
@store = store
end

def init(all_data)
@store.init(DataStoreDataSetSorter.sort_all_collections(all_data))
@store.init(FeatureStoreDataSetSorter.sort_all_collections(all_data))
end

def get(kind, key)
Expand Down
6 changes: 3 additions & 3 deletions lib/ldclient-rb/impl/store_data_set_sorter.rb
Original file line number Diff line number Diff line change
Expand Up @@ -2,10 +2,10 @@
module LaunchDarkly
module Impl
#
# Implements a dependency graph ordering for data to be stored in a data store. We must use this
# on every data set that will be passed to the data store's init() method.
# Implements a dependency graph ordering for data to be stored in a feature store. We must use this
# on every data set that will be passed to the feature store's init() method.
#
class DataStoreDataSetSorter
class FeatureStoreDataSetSorter
#
# Returns a copy of the input hash that has the following guarantees: the iteration order of the outer
# hash will be in ascending order by the VersionDataKind's :priority property (if any), and for each
Expand Down
10 changes: 5 additions & 5 deletions lib/ldclient-rb/in_memory_store.rb
Original file line number Diff line number Diff line change
Expand Up @@ -2,12 +2,12 @@

module LaunchDarkly

# These constants denote the types of data that can be stored in the data store. If
# These constants denote the types of data that can be stored in the feature store. If
# we add another storable data type in the future, as long as it follows the same pattern
# (having "key", "version", and "deleted" properties), we only need to add a corresponding
# constant here and the existing store should be able to handle it.
#
# The :priority and :get_dependency_keys properties are used by DataStoreDataSetSorter
# The :priority and :get_dependency_keys properties are used by FeatureStoreDataSetSorter
# to ensure data consistency during non-atomic updates.

# @private
Expand All @@ -24,12 +24,12 @@ module LaunchDarkly
}.freeze

#
# Default implementation of the LaunchDarkly client's data store, using an in-memory
# Default implementation of the LaunchDarkly client's feature store, using an in-memory
# cache. This object holds feature flags and related data received from LaunchDarkly.
# Database-backed implementations are available in {LaunchDarkly::Integrations}.
#
class InMemoryDataStore
include LaunchDarkly::Interfaces::DataStore
class InMemoryFeatureStore
include LaunchDarkly::Interfaces::FeatureStore

def initialize
@items = Hash.new
Expand Down
12 changes: 6 additions & 6 deletions lib/ldclient-rb/integrations/consul.rb
Original file line number Diff line number Diff line change
Expand Up @@ -5,7 +5,7 @@ module LaunchDarkly
module Integrations
module Consul
#
# Default value for the `prefix` option for {new_data_store}.
# Default value for the `prefix` option for {new_feature_store}.
#
# @return [String] the default key prefix
#
Expand All @@ -14,10 +14,10 @@ def self.default_prefix
end

#
# Creates a Consul-backed persistent data store.
# Creates a Consul-backed persistent feature store.
#
# To use this method, you must first install the gem `diplomat`. Then, put the object returned by
# this method into the `data_store` property of your client configuration ({LaunchDarkly::Config}).
# this method into the `feature_store` property of your client configuration ({LaunchDarkly::Config}).
#
# @param opts [Hash] the configuration options
# @option opts [Hash] :consul_config an instance of `Diplomat::Configuration` to replace the default
Expand All @@ -27,10 +27,10 @@ def self.default_prefix
# @option opts [Logger] :logger a `Logger` instance; defaults to `Config.default_logger`
# @option opts [Integer] :expiration (15) expiration time for the in-memory cache, in seconds; 0 for no local caching
# @option opts [Integer] :capacity (1000) maximum number of items in the cache
# @return [LaunchDarkly::Interfaces::DataStore] a data store object
# @return [LaunchDarkly::Interfaces::FeatureStore] a feature store object
#
def self.new_data_store(opts, &block)
core = LaunchDarkly::Impl::Integrations::Consul::ConsulDataStoreCore.new(opts)
def self.new_feature_store(opts, &block)
core = LaunchDarkly::Impl::Integrations::Consul::ConsulFeatureStoreCore.new(opts)
return LaunchDarkly::Integrations::Util::CachingStoreWrapper.new(core, opts)
end
end
Expand Down
20 changes: 10 additions & 10 deletions lib/ldclient-rb/integrations/dynamodb.rb
Original file line number Diff line number Diff line change
Expand Up @@ -5,17 +5,17 @@ module LaunchDarkly
module Integrations
module DynamoDB
#
# Creates a DynamoDB-backed persistent data store. For more details about how and why you can
# use a persistent data store, see the
# Creates a DynamoDB-backed persistent feature store. For more details about how and why you can
# use a persistent feature store, see the
# [SDK reference guide](https://docs.launchdarkly.com/v2.0/docs/using-a-persistent-feature-store).
#
# To use this method, you must first install one of the AWS SDK gems: either `aws-sdk-dynamodb`, or
# the full `aws-sdk`. Then, put the object returned by this method into the `data_store` property
# the full `aws-sdk`. Then, put the object returned by this method into the `feature_store` property
# of your client configuration ({LaunchDarkly::Config}).
#
# @example Configuring the data store
# store = LaunchDarkly::Integrations::DynamoDB::new_data_store("my-table-name")
# config = LaunchDarkly::Config.new(data_store: store)
# @example Configuring the feature store
# store = LaunchDarkly::Integrations::DynamoDB::new_feature_store("my-table-name")
# config = LaunchDarkly::Config.new(feature_store: store)
# client = LaunchDarkly::LDClient.new(my_sdk_key, config)
#
# Note that the specified table must already exist in DynamoDB. It must have a partition key called
Expand All @@ -31,15 +31,15 @@ module DynamoDB
# @param table_name [String] name of an existing DynamoDB table
# @param opts [Hash] the configuration options
# @option opts [Hash] :dynamodb_opts options to pass to the DynamoDB client constructor (ignored if you specify `:existing_client`)
# @option opts [Object] :existing_client an already-constructed DynamoDB client for the data store to use
# @option opts [Object] :existing_client an already-constructed DynamoDB client for the feature store to use
# @option opts [String] :prefix namespace prefix to add to all keys used by LaunchDarkly
# @option opts [Logger] :logger a `Logger` instance; defaults to `Config.default_logger`
# @option opts [Integer] :expiration (15) expiration time for the in-memory cache, in seconds; 0 for no local caching
# @option opts [Integer] :capacity (1000) maximum number of items in the cache
# @return [LaunchDarkly::Interfaces::DataStore] a data store object
# @return [LaunchDarkly::Interfaces::FeatureStore] a feature store object
#
def self.new_data_store(table_name, opts)
core = LaunchDarkly::Impl::Integrations::DynamoDB::DynamoDBDataStoreCore.new(table_name, opts)
def self.new_feature_store(table_name, opts)
core = LaunchDarkly::Impl::Integrations::DynamoDB::DynamoDBFeatureStoreCore.new(table_name, opts)
return LaunchDarkly::Integrations::Util::CachingStoreWrapper.new(core, opts)
end
end
Expand Down
Loading

0 comments on commit d2b5a3c

Please sign in to comment.