Skip to content
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
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
6 changes: 3 additions & 3 deletions lib/ldclient-rb/impl/data_source.rb
Original file line number Diff line number Diff line change
Expand Up @@ -89,7 +89,7 @@ def init(all_data)
monitor_store_update do
if @flag_change_broadcaster.has_listeners?
old_data = {}
Impl::DataStore::ALL_KINDS.each do |kind|
LaunchDarkly::Interfaces::DataStore::ALL_KINDS.each do |kind|
old_data[kind] = @data_store.all(kind)
end
end
Expand Down Expand Up @@ -193,7 +193,7 @@ def update_status(new_state, new_error)
private def compute_changed_items_for_full_data_set(old_data, new_data)
affected_items = Set.new

Impl::DataStore::ALL_KINDS.each do |kind|
LaunchDarkly::Interfaces::DataStore::ALL_KINDS.each do |kind|
old_items = old_data[kind] || {}
new_items = new_data[kind] || {}

Expand All @@ -217,7 +217,7 @@ def update_status(new_state, new_error)
#
private def send_change_events(affected_items)
affected_items.each do |item|
if item[:kind] == Impl::DataStore::FEATURES
if item[:kind] == LaunchDarkly::Interfaces::DataStore::FEATURES
@flag_change_broadcaster.broadcast(LaunchDarkly::Interfaces::FlagChange.new(item[:key].to_s))
end
end
Expand Down
8 changes: 4 additions & 4 deletions lib/ldclient-rb/impl/data_source/stream.rb
Original file line number Diff line number Diff line change
Expand Up @@ -17,8 +17,8 @@ module DataSource
READ_TIMEOUT_SECONDS = 300 # 5 minutes; the stream should send a ping every 3 minutes

KEY_PATHS = {
Impl::DataStore::FEATURES => "/flags/",
Impl::DataStore::SEGMENTS => "/segments/",
LaunchDarkly::Interfaces::DataStore::FEATURES => "/flags/",
LaunchDarkly::Interfaces::DataStore::SEGMENTS => "/segments/",
}

class StreamProcessor
Expand Down Expand Up @@ -182,7 +182,7 @@ def process_message(message)
@ready.set
elsif method == PATCH
data = JSON.parse(message.data, symbolize_names: true)
for kind in [Impl::DataStore::FEATURES, Impl::DataStore::SEGMENTS]
for kind in [LaunchDarkly::Interfaces::DataStore::FEATURES, LaunchDarkly::Interfaces::DataStore::SEGMENTS]
key = key_for_path(kind, data[:path])
if key
item = Impl::Model.deserialize(kind, data[:data], @config.logger)
Expand All @@ -192,7 +192,7 @@ def process_message(message)
end
elsif method == DELETE
data = JSON.parse(message.data, symbolize_names: true)
for kind in [Impl::DataStore::FEATURES, Impl::DataStore::SEGMENTS]
for kind in [LaunchDarkly::Interfaces::DataStore::FEATURES, LaunchDarkly::Interfaces::DataStore::SEGMENTS]
key = key_for_path(kind, data[:path])
if key
update_sink_or_data_store.delete(kind, key, data[:version])
Expand Down
23 changes: 0 additions & 23 deletions lib/ldclient-rb/impl/data_store.rb

This file was deleted.

10 changes: 5 additions & 5 deletions lib/ldclient-rb/impl/data_store/in_memory_feature_store.rb
Original file line number Diff line number Diff line change
Expand Up @@ -2,7 +2,7 @@

require "concurrent"
require "concurrent/atomics"
require "ldclient-rb/impl/data_store"
require "ldclient-rb/impl/data_store/status"
require "ldclient-rb/interfaces/data_system"

module LaunchDarkly
Expand Down Expand Up @@ -58,7 +58,7 @@ def initialized?
#
# Initializes the store with a full set of data, replacing any existing data.
#
# @param collections [Hash<LaunchDarkly::Impl::DataStore::DataKind, Hash<Symbol, Hash>>] Hash of data kinds to collections of items
# @param collections [Hash<LaunchDarkly::Interfaces::DataStore::DataKind, Hash<Symbol, Hash>>] Hash of data kinds to collections of items
# @return [Boolean] true if successful, false otherwise
#
def set_basis(collections)
Expand All @@ -80,7 +80,7 @@ def set_basis(collections)
#
# Applies a delta update to the store.
#
# @param collections [Hash<LaunchDarkly::Impl::DataStore::DataKind, Hash<Symbol, Hash>>] Hash of data kinds to collections with updates
# @param collections [Hash<LaunchDarkly::Interfaces::DataStore::DataKind, Hash<Symbol, Hash>>] Hash of data kinds to collections with updates
# @return [Boolean] true if successful, false otherwise
#
def apply_delta(collections)
Expand All @@ -105,8 +105,8 @@ def apply_delta(collections)
#
# Decodes a collection of items.
#
# @param collections [Hash<LaunchDarkly::Impl::DataStore::DataKind, Hash<Symbol, Hash>>] Hash of data kinds to collections
# @return [Hash<LaunchDarkly::Impl::DataStore::DataKind, Hash<Symbol, Hash>>, nil] Decoded collection with symbol keys, or nil on error
# @param collections [Hash<LaunchDarkly::Interfaces::DataStore::DataKind, Hash<Symbol, Hash>>] Hash of data kinds to collections
# @return [Hash<LaunchDarkly::Interfaces::DataStore::DataKind, Hash<Symbol, Hash>>, nil] Decoded collection with symbol keys, or nil on error
#
private def decode_collection(collections)
all_decoded = {}
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -4,55 +4,6 @@
module LaunchDarkly
module Impl
module DataStore
class DataKind
FEATURES = "features".freeze
SEGMENTS = "segments".freeze

FEATURE_PREREQ_FN = lambda { |flag| (flag[:prerequisites] || []).map { |p| p[:key] } }.freeze

attr_reader :namespace
attr_reader :priority

#
# @param namespace [String]
# @param priority [Integer]
#
def initialize(namespace:, priority:)
@namespace = namespace
@priority = priority
end

#
# Maintain the same behavior when these data kinds were standard ruby hashes.
#
# @param key [Symbol]
# @return [Object]
#
def [](key)
return priority if key == :priority
return namespace if key == :namespace
return get_dependency_keys_fn() if key == :get_dependency_keys
nil
end

#
# Retrieve the dependency keys for a particular data kind. Right now, this is only defined for flags.
#
def get_dependency_keys_fn()
return nil unless @namespace == FEATURES

FEATURE_PREREQ_FN
end

def eql?(other)
other.is_a?(DataKind) && namespace == other.namespace && priority == other.priority
end

def hash
[namespace, priority].hash
end
end

class StatusProvider
include LaunchDarkly::Interfaces::DataStore::StatusProvider

Expand Down
16 changes: 8 additions & 8 deletions lib/ldclient-rb/impl/data_store/store.rb
Original file line number Diff line number Diff line change
Expand Up @@ -2,7 +2,7 @@

require "concurrent"
require "set"
require "ldclient-rb/impl/data_store"
require "ldclient-rb/impl/data_store/status"
require "ldclient-rb/impl/data_store/in_memory_feature_store"
require "ldclient-rb/impl/dependency_tracker"
require "ldclient-rb/interfaces/data_system"
Expand Down Expand Up @@ -148,7 +148,7 @@ def commit
begin
# Get all data from memory store and write to persistent store
all_data = {}
[FEATURES, SEGMENTS].each do |kind|
[LaunchDarkly::Interfaces::DataStore::FEATURES, LaunchDarkly::Interfaces::DataStore::SEGMENTS].each do |kind|
all_data[kind] = @memory_store.all(kind)
end
@persistent_store.init(all_data)
Expand Down Expand Up @@ -204,7 +204,7 @@ def get_data_store_status_provider
old_data = nil
if @flag_change_broadcaster.has_listeners?
old_data = {}
[FEATURES, SEGMENTS].each do |kind|
[LaunchDarkly::Interfaces::DataStore::FEATURES, LaunchDarkly::Interfaces::DataStore::SEGMENTS].each do |kind|
old_data[kind] = @memory_store.all(kind)
end
end
Expand Down Expand Up @@ -313,12 +313,12 @@ def get_data_store_status_provider
#
private def changes_to_store_data(changes)
all_data = {
FEATURES => {},
SEGMENTS => {},
LaunchDarkly::Interfaces::DataStore::FEATURES => {},
LaunchDarkly::Interfaces::DataStore::SEGMENTS => {},
}

changes.each do |change|
kind = change.kind == LaunchDarkly::Interfaces::DataSystem::ObjectKind::FLAG ? FEATURES : SEGMENTS
kind = change.kind == LaunchDarkly::Interfaces::DataSystem::ObjectKind::FLAG ? LaunchDarkly::Interfaces::DataStore::FEATURES : LaunchDarkly::Interfaces::DataStore::SEGMENTS
if change.action == LaunchDarkly::Interfaces::DataSystem::ChangeType::PUT && !change.object.nil?
all_data[kind][change.key] = change.object
elsif change.action == LaunchDarkly::Interfaces::DataSystem::ChangeType::DELETE
Expand Down Expand Up @@ -352,7 +352,7 @@ def get_data_store_status_provider
#
private def send_change_events(affected_items)
affected_items.each do |item|
if item[:kind] == FEATURES
if item[:kind] == LaunchDarkly::Interfaces::DataStore::FEATURES
@flag_change_broadcaster.broadcast(LaunchDarkly::Interfaces::FlagChange.new(item[:key].to_s))
end
end
Expand All @@ -368,7 +368,7 @@ def get_data_store_status_provider
private def compute_changed_items_for_full_data_set(old_data, new_data)
affected_items = Set.new

[FEATURES, SEGMENTS].each do |kind|
[LaunchDarkly::Interfaces::DataStore::FEATURES, LaunchDarkly::Interfaces::DataStore::SEGMENTS].each do |kind|
old_items = old_data[kind] || {}
new_items = new_data[kind] || {}

Expand Down
2 changes: 1 addition & 1 deletion lib/ldclient-rb/impl/data_system/fdv1.rb
Original file line number Diff line number Diff line change
Expand Up @@ -5,7 +5,7 @@
require 'ldclient-rb/impl/data_source/polling'
require 'ldclient-rb/impl/data_source/requestor'
require 'ldclient-rb/impl/data_source/stream'
require 'ldclient-rb/impl/data_store'
require 'ldclient-rb/impl/data_store/status'
require 'ldclient-rb/impl/data_system'
require 'ldclient-rb/impl/store_client_wrapper'

Expand Down
6 changes: 3 additions & 3 deletions lib/ldclient-rb/impl/dependency_tracker.rb
Original file line number Diff line number Diff line change
Expand Up @@ -42,7 +42,7 @@ def update_dependencies_from(from_kind, from_key, from_item)
def self.segment_keys_from_clauses(clauses)
clauses.flat_map do |clause|
if clause.op == :segmentMatch
clause.values.map { |value| {kind: DataStore::SEGMENTS, key: value }}
clause.values.map { |value| {kind: LaunchDarkly::Interfaces::DataStore::SEGMENTS, key: value }}
else
[]
end
Expand All @@ -66,13 +66,13 @@ def self.compute_dependencies_from(from_kind, from_item, logger = nil)
from_item
end

if from_kind == DataStore::FEATURES && from_item.is_a?(LaunchDarkly::Impl::Model::FeatureFlag)
if from_kind == LaunchDarkly::Interfaces::DataStore::FEATURES && from_item.is_a?(LaunchDarkly::Impl::Model::FeatureFlag)
prereq_keys = from_item.prerequisites.map { |prereq| {kind: from_kind, key: prereq.key} }
segment_keys = from_item.rules.flat_map { |rule| DependencyTracker.segment_keys_from_clauses(rule.clauses) }

results = Set.new(prereq_keys)
results.merge(segment_keys)
elsif from_kind == DataStore::SEGMENTS && from_item.is_a?(LaunchDarkly::Impl::Model::Segment)
elsif from_kind == LaunchDarkly::Interfaces::DataStore::SEGMENTS && from_item.is_a?(LaunchDarkly::Impl::Model::Segment)
kind_and_keys = from_item.rules.flat_map do |rule|
DependencyTracker.segment_keys_from_clauses(rule.clauses)
end
Expand Down
10 changes: 5 additions & 5 deletions lib/ldclient-rb/impl/integrations/file_data_source.rb
Original file line number Diff line number Diff line change
Expand Up @@ -75,8 +75,8 @@ def stop

def load_all
all_data = {
Impl::DataStore::FEATURES => {},
Impl::DataStore::SEGMENTS => {},
LaunchDarkly::Interfaces::DataStore::FEATURES => {},
LaunchDarkly::Interfaces::DataStore::SEGMENTS => {},
}
@paths.each do |path|
begin
Expand Down Expand Up @@ -105,14 +105,14 @@ def load_file(path, all_data)
parsed = parse_content(File.read(path))
(parsed[:flags] || {}).each do |key, flag|
flag[:version] = version
add_item(all_data, Impl::DataStore::FEATURES, flag)
add_item(all_data, LaunchDarkly::Interfaces::DataStore::FEATURES, flag)
end
(parsed[:flagValues] || {}).each do |key, value|
add_item(all_data, Impl::DataStore::FEATURES, make_flag_with_value(key.to_s, value, version))
add_item(all_data, LaunchDarkly::Interfaces::DataStore::FEATURES, make_flag_with_value(key.to_s, value, version))
end
(parsed[:segments] || {}).each do |key, segment|
segment[:version] = version
add_item(all_data, Impl::DataStore::SEGMENTS, segment)
add_item(all_data, LaunchDarkly::Interfaces::DataStore::SEGMENTS, segment)
end
end

Expand Down
1 change: 1 addition & 0 deletions lib/ldclient-rb/impl/model/feature_flag.rb
Original file line number Diff line number Diff line change
@@ -1,5 +1,6 @@
require "ldclient-rb/impl/evaluator_helpers"
require "ldclient-rb/impl/model/clause"
require "ldclient-rb/context"
require "set"

# See serialization.rb for implementation notes on the data model classes.
Expand Down
1 change: 1 addition & 0 deletions lib/ldclient-rb/impl/model/segment.rb
Original file line number Diff line number Diff line change
@@ -1,5 +1,6 @@
require "ldclient-rb/impl/model/clause"
require "ldclient-rb/impl/model/preprocessed_data"
require "ldclient-rb/context"
require "set"

# See serialization.rb for implementation notes on the data model classes.
Expand Down
12 changes: 7 additions & 5 deletions lib/ldclient-rb/impl/model/serialization.rb
Original file line number Diff line number Diff line change
@@ -1,3 +1,5 @@
require "json"

require "ldclient-rb/impl/model/feature_flag"
require "ldclient-rb/impl/model/preprocessed_data"
require "ldclient-rb/impl/model/segment"
Expand Down Expand Up @@ -34,7 +36,7 @@ module Model
# SDK code outside of Impl::Model should use this method instead of calling the model class
# constructors directly, so as not to rely on implementation details.
#
# @param kind [Hash] normally either Impl::DataStore::FEATURES or Impl::DataStore::SEGMENTS
# @param kind [Hash] normally either LaunchDarkly::Interfaces::DataStore::FEATURES or LaunchDarkly::Interfaces::DataStore::SEGMENTS
# @param input [object] a JSON string or a parsed hash (or a data model object, in which case
# we'll just return the original object)
# @param logger [Logger|nil] logs errors if there are any data validation problems
Expand All @@ -44,9 +46,9 @@ def self.deserialize(kind, input, logger = nil)
return input unless input.is_a?(String) || input.is_a?(Hash)
data = input.is_a?(Hash) ? input : JSON.parse(input, symbolize_names: true)
case kind
when Impl::DataStore::FEATURES
when LaunchDarkly::Interfaces::DataStore::FEATURES
FeatureFlag.new(data, logger)
when Impl::DataStore::SEGMENTS
when LaunchDarkly::Interfaces::DataStore::SEGMENTS
Segment.new(data, logger)
else
data
Expand All @@ -63,8 +65,8 @@ def self.serialize(kind, item)
# Translates a { flags: ..., segments: ... } object received from LaunchDarkly to the data store format.
def self.make_all_store_data(received_data, logger = nil)
{
Impl::DataStore::FEATURES => (received_data[:flags] || {}).transform_values { |data| FeatureFlag.new(data, logger) },
Impl::DataStore::SEGMENTS => (received_data[:segments] || {}).transform_values { |data| Segment.new(data, logger) },
LaunchDarkly::Interfaces::DataStore::FEATURES => (received_data[:flags] || {}).transform_values { |data| FeatureFlag.new(data, logger) },
LaunchDarkly::Interfaces::DataStore::SEGMENTS => (received_data[:segments] || {}).transform_values { |data| Segment.new(data, logger) },
}
end
end
Expand Down
2 changes: 1 addition & 1 deletion lib/ldclient-rb/in_memory_store.rb
Original file line number Diff line number Diff line change
@@ -1,5 +1,5 @@
require "concurrent/atomics"
require "ldclient-rb/impl/data_store"
require "ldclient-rb/impl/data_store/status"

module LaunchDarkly
#
Expand Down
12 changes: 6 additions & 6 deletions lib/ldclient-rb/integrations/test_data.rb
Original file line number Diff line number Diff line change
Expand Up @@ -121,10 +121,10 @@ def update(flag_builder)
if @current_flags[flag_key]
version = @current_flags[flag_key][:version]
end
new_flag = LaunchDarkly::Impl::Model.deserialize(LaunchDarkly::Impl::DataStore::FEATURES, flag_builder.build(version+1))
new_flag = LaunchDarkly::Impl::Model.deserialize(LaunchDarkly::Interfaces::DataStore::FEATURES, flag_builder.build(version+1))
@current_flags[flag_key] = new_flag
end
update_item(LaunchDarkly::Impl::DataStore::FEATURES, new_flag)
update_item(LaunchDarkly::Interfaces::DataStore::FEATURES, new_flag)
self
end

Expand All @@ -147,7 +147,7 @@ def update(flag_builder)
# @return [TestData] the TestData instance
#
def use_preconfigured_flag(flag)
use_preconfigured_item(LaunchDarkly::Impl::DataStore::FEATURES, flag, @current_flags)
use_preconfigured_item(LaunchDarkly::Interfaces::DataStore::FEATURES, flag, @current_flags)
end

#
Expand All @@ -167,7 +167,7 @@ def use_preconfigured_flag(flag)
# @return [TestData] the TestData instance
#
def use_preconfigured_segment(segment)
use_preconfigured_item(LaunchDarkly::Impl::DataStore::SEGMENTS, segment, @current_segments)
use_preconfigured_item(LaunchDarkly::Interfaces::DataStore::SEGMENTS, segment, @current_segments)
end

private def use_preconfigured_item(kind, item, current)
Expand Down Expand Up @@ -198,8 +198,8 @@ def use_preconfigured_segment(segment)
def make_init_data
@lock.with_read_lock do
{
LaunchDarkly::Impl::DataStore::FEATURES => @current_flags.clone,
LaunchDarkly::Impl::DataStore::SEGMENTS => @current_segments.clone,
LaunchDarkly::Interfaces::DataStore::FEATURES => @current_flags.clone,
LaunchDarkly::Interfaces::DataStore::SEGMENTS => @current_segments.clone,
}
end
end
Expand Down
Loading
Loading