From 027b3f66b2bf5f0e4e863c66b6cf767bf3a9989f Mon Sep 17 00:00:00 2001 From: Joe Cieslik <5600929+torchhound@users.noreply.github.com> Date: Thu, 20 Feb 2020 15:32:24 -0800 Subject: [PATCH] Prepare beta2 release (#19) * [ch65671] Mass rename from eld to ldclient (#49) * Alpha => beta (#50) * Changed package name and description (#51) * Added CHANGELOG for beta2, updated version to beta2 Co-authored-by: zurab-darkly <56062336+zurab-darkly@users.noreply.github.com> Co-authored-by: Ben Woskow <48036130+bwoskow-ld@users.noreply.github.com> --- .circleci/config.yml | 14 +- .gitignore | 2 +- .ldrelease/update-version.sh | 4 +- CHANGELOG.md | 7 + Makefile | 2 + README.md | 2 +- rebar.config | 2 +- src/eld_update_processor_state.hrl | 2 - src/{eld.app.src => ldclient.app.src} | 9 +- src/{eld.erl => ldclient.erl} | 68 ++++---- src/{eld_app.erl => ldclient_app.erl} | 8 +- src/{eld_clause.erl => ldclient_clause.erl} | 18 +- src/{eld_eval.erl => ldclient_eval.erl} | 62 +++---- src/{eld_event.erl => ldclient_event.erl} | 86 +++++----- ...spatch.erl => ldclient_event_dispatch.erl} | 4 +- ....erl => ldclient_event_dispatch_httpc.erl} | 8 +- ....erl => ldclient_event_process_server.erl} | 47 +++--- ...t_server.erl => ldclient_event_server.erl} | 64 +++---- ...d_event_sup.erl => ldclient_event_sup.erl} | 10 +- src/{eld_flag.erl => ldclient_flag.erl} | 16 +- ...eld_instance.erl => ldclient_instance.erl} | 40 ++--- ...ance_sup.erl => ldclient_instance_sup.erl} | 6 +- src/{eld_rollout.erl => ldclient_rollout.erl} | 20 +-- src/{eld_rule.erl => ldclient_rule.erl} | 20 +-- src/{eld_segment.erl => ldclient_segment.erl} | 20 +-- ...eld_settings.erl => ldclient_settings.erl} | 26 +-- ...engine.erl => ldclient_storage_engine.erl} | 4 +- ...orage_ets.erl => ldclient_storage_ets.erl} | 24 +-- ...er.erl => ldclient_storage_ets_server.erl} | 4 +- ...s_sup.erl => ldclient_storage_ets_sup.erl} | 6 +- ...orage_map.erl => ldclient_storage_map.erl} | 24 +-- ...er.erl => ldclient_storage_map_server.erl} | 4 +- ...p_sup.erl => ldclient_storage_map_sup.erl} | 6 +- src/{eld_sup.erl => ldclient_sup.erl} | 8 +- ...er.erl => ldclient_update_null_server.erl} | 4 +- ...er.erl => ldclient_update_poll_server.erl} | 18 +- ...rl => ldclient_update_processor_state.erl} | 8 +- src/ldclient_update_processor_state.hrl | 2 + ...stor.erl => ldclient_update_requestor.erl} | 4 +- ...rl => ldclient_update_requestor_httpc.erl} | 12 +- ..._server.erl => ldclient_update_server.erl} | 4 +- ....erl => ldclient_update_stream_server.erl} | 20 +-- ...update_sup.erl => ldclient_update_sup.erl} | 2 +- src/{eld_updater.erl => ldclient_updater.erl} | 4 +- src/{eld_user.erl => ldclient_user.erl} | 4 +- ...user_cache.erl => ldclient_user_cache.erl} | 6 +- test/eld_clause_SUITE.erl | 81 --------- test/eld_storage_map_SUITE.erl | 159 ------------------ test/ldclient_clause_SUITE.erl | 81 +++++++++ ...eval_SUITE.erl => ldclient_eval_SUITE.erl} | 118 ++++++------- ...t.erl => ldclient_event_dispatch_test.erl} | 6 +- ...ts_SUITE.erl => ldclient_events_SUITE.erl} | 86 +++++----- ...rse_SUITE.erl => ldclient_parse_SUITE.erl} | 20 +-- ...poll_SUITE.erl => ldclient_poll_SUITE.erl} | 54 +++--- ...ITE.erl => ldclient_storage_ets_SUITE.erl} | 76 ++++----- test/ldclient_storage_map_SUITE.erl | 159 ++++++++++++++++++ ...am_SUITE.erl => ldclient_stream_SUITE.erl} | 68 ++++---- ...ldclient_update_requestor_httpc_SUITE.erl} | 24 +-- ...erl => ldclient_update_requestor_test.erl} | 6 +- ...user_SUITE.erl => ldclient_user_SUITE.erl} | 80 ++++----- 60 files changed, 882 insertions(+), 871 deletions(-) delete mode 100644 src/eld_update_processor_state.hrl rename src/{eld.app.src => ldclient.app.src} (63%) rename src/{eld.erl => ldclient.erl} (75%) rename src/{eld_app.erl => ldclient_app.erl} (79%) rename src/{eld_clause.erl => ldclient_clause.erl} (94%) rename src/{eld_eval.erl => ldclient_eval.erl} (86%) rename src/{eld_event.erl => ldclient_event.erl} (74%) rename src/{eld_event_dispatch.erl => ldclient_event_dispatch.erl} (89%) rename src/{eld_event_dispatch_httpc.erl => ldclient_event_dispatch_httpc.erl} (90%) rename src/{eld_event_process_server.erl => ldclient_event_process_server.erl} (84%) rename src/{eld_event_server.erl => ldclient_event_server.erl} (81%) rename src/{eld_event_sup.erl => ldclient_event_sup.erl} (79%) rename src/{eld_flag.erl => ldclient_flag.erl} (93%) rename src/{eld_instance.erl => ldclient_instance.erl} (73%) rename src/{eld_instance_sup.erl => ldclient_instance_sup.erl} (87%) rename src/{eld_rollout.erl => ldclient_rollout.erl} (85%) rename src/{eld_rule.erl => ldclient_rule.erl} (76%) rename src/{eld_segment.erl => ldclient_segment.erl} (87%) rename src/{eld_settings.erl => ldclient_settings.erl} (88%) rename src/{eld_storage_engine.erl => ldclient_storage_engine.erl} (97%) rename src/{eld_storage_ets.erl => ldclient_storage_ets.erl} (78%) rename src/{eld_storage_ets_server.erl => ldclient_storage_ets_server.erl} (98%) rename src/{eld_storage_ets_sup.erl => ldclient_storage_ets_sup.erl} (87%) rename src/{eld_storage_map.erl => ldclient_storage_map.erl} (78%) rename src/{eld_storage_map_server.erl => ldclient_storage_map_server.erl} (99%) rename src/{eld_storage_map_sup.erl => ldclient_storage_map_sup.erl} (87%) rename src/{eld_sup.erl => ldclient_sup.erl} (87%) rename src/{eld_update_null_server.erl => ldclient_update_null_server.erl} (96%) rename src/{eld_update_poll_server.erl => ldclient_update_poll_server.erl} (89%) rename src/{eld_update_processor_state.erl => ldclient_update_processor_state.erl} (88%) create mode 100644 src/ldclient_update_processor_state.hrl rename src/{eld_update_requestor.erl => ldclient_update_requestor.erl} (92%) rename src/{eld_update_requestor_httpc.erl => ldclient_update_requestor_httpc.erl} (84%) rename src/{eld_update_server.erl => ldclient_update_server.erl} (81%) rename src/{eld_update_stream_server.erl => ldclient_update_stream_server.erl} (93%) rename src/{eld_update_sup.erl => ldclient_update_sup.erl} (97%) rename src/{eld_updater.erl => ldclient_updater.erl} (96%) rename src/{eld_user.erl => ldclient_user.erl} (98%) rename src/{eld_user_cache.erl => ldclient_user_cache.erl} (85%) delete mode 100644 test/eld_clause_SUITE.erl delete mode 100644 test/eld_storage_map_SUITE.erl create mode 100644 test/ldclient_clause_SUITE.erl rename test/{eld_eval_SUITE.erl => ldclient_eval_SUITE.erl} (80%) rename test/{eld_event_dispatch_test.erl => ldclient_event_dispatch_test.erl} (86%) rename test/{eld_events_SUITE.erl => ldclient_events_SUITE.erl} (90%) rename test/{eld_parse_SUITE.erl => ldclient_parse_SUITE.erl} (96%) rename test/{eld_poll_SUITE.erl => ldclient_poll_SUITE.erl} (55%) rename test/{eld_storage_ets_SUITE.erl => ldclient_storage_ets_SUITE.erl} (51%) create mode 100644 test/ldclient_storage_map_SUITE.erl rename test/{eld_stream_SUITE.erl => ldclient_stream_SUITE.erl} (78%) rename test/{eld_update_requestor_httpc_SUITE.erl => ldclient_update_requestor_httpc_SUITE.erl} (77%) rename test/{eld_update_requestor_test.erl => ldclient_update_requestor_test.erl} (96%) rename test/{eld_user_SUITE.erl => ldclient_user_SUITE.erl} (74%) diff --git a/.circleci/config.yml b/.circleci/config.yml index 2a5b006..049a90e 100644 --- a/.circleci/config.yml +++ b/.circleci/config.yml @@ -11,29 +11,29 @@ workflows: erlang-docker-template: &erlang-docker-template steps: - checkout: - path: ~/eld + path: ~/ldclient - run: name: install dependencies and compile command: make compile - working_directory: ~/eld + working_directory: ~/ldclient - run: name: run tests command: make tests - working_directory: ~/eld + working_directory: ~/ldclient - run: name: run dialyzer command: make dialyze - working_directory: ~/eld + working_directory: ~/ldclient - run: name: create test-results directory command: mkdir test-results - working_directory: ~/eld + working_directory: ~/ldclient - run: name: copy test results command: cp logs/ct/*/junit_report.xml test-results/ - working_directory: ~/eld + working_directory: ~/ldclient - store_test_results: - path: ~/eld/test-results + path: ~/ldclient/test-results jobs: test-elixir-otp21: diff --git a/.gitignore b/.gitignore index 92b0fc6..927aba1 100644 --- a/.gitignore +++ b/.gitignore @@ -12,7 +12,7 @@ ebin erl_crash.dump logs test/*.beam -eld.d +ldclient.d .DS_Store _build/ rebar.lock diff --git a/.ldrelease/update-version.sh b/.ldrelease/update-version.sh index 7fbcb8f..5179f11 100755 --- a/.ldrelease/update-version.sh +++ b/.ldrelease/update-version.sh @@ -2,13 +2,13 @@ set -e -TARGET_FILE=src/eld.app.src +TARGET_FILE=src/ldclient.app.src TEMP_FILE=${TARGET_FILE}.tmp sed "s/ {vsn, \".*\"},/ {vsn, \"${LD_RELEASE_VERSION}\"},/" "${TARGET_FILE}" > "${TEMP_FILE}" mv "${TEMP_FILE}" "${TARGET_FILE}" -TARGET_FILE=src/eld_settings.erl +TARGET_FILE=src/ldclient_settings.erl TEMP_FILE=${TARGET_FILE}.tmp sed "s/-define(VERSION, \".*\")./-define(VERSION, \"${LD_RELEASE_VERSION}\")./" "${TARGET_FILE}" > "${TEMP_FILE}" diff --git a/CHANGELOG.md b/CHANGELOG.md index f8ff8a2..edacd0f 100644 --- a/CHANGELOG.md +++ b/CHANGELOG.md @@ -2,6 +2,13 @@ All notable changes to the LaunchDarkly Erlang/Elixir SDK will be documented in this file. This project adheres to [Semantic Versioning](http://semver.org). +## [1.0.0-beta2] - 2020-02-20 + +### Changed + +- Renamed `eld` to `ldclient` to better adhere to LaunchDarkly SDK naming conventions. +- Changed the `pkg_name` to `launchdarkly_server_sdk` + ## [1.0.0-beta1] - 2020-02-12 ### Added diff --git a/Makefile b/Makefile index de3b199..5bd2605 100644 --- a/Makefile +++ b/Makefile @@ -23,3 +23,5 @@ doc: tests: @$(REBAR3) ct --logdir logs/ct + +.PHONY: all compile dialyze deps rel run doc tests diff --git a/README.md b/README.md index e04ffb8..362bc5e 100644 --- a/README.md +++ b/README.md @@ -2,7 +2,7 @@ [![Circle CI](https://img.shields.io/circleci/project/launchdarkly/erlang-server-sdk.png)](https://circleci.com/gh/launchdarkly/erlang-server-sdk) -*This version of the SDK is an **alpha** version and should not be considered ready for production use while this message is visible.* +*This version of the SDK is a **beta** version and should not be considered ready for production use while this message is visible.* ## LaunchDarkly overview diff --git a/rebar.config b/rebar.config index 73b2129..6883449 100644 --- a/rebar.config +++ b/rebar.config @@ -17,7 +17,7 @@ ]}. {shell, [ - {apps, [eld]} + {apps, [ldclient]} ]}. {ct_opts, [{ct_hooks, [cth_surefire]}]}. diff --git a/src/eld_update_processor_state.hrl b/src/eld_update_processor_state.hrl deleted file mode 100644 index 5420e88..0000000 --- a/src/eld_update_processor_state.hrl +++ /dev/null @@ -1,2 +0,0 @@ -% Constants --define(UPDATE_PROCESSOR_INITIALIZATION_TABLE, eld_update_processor_initialization). \ No newline at end of file diff --git a/src/eld.app.src b/src/ldclient.app.src similarity index 63% rename from src/eld.app.src rename to src/ldclient.app.src index f63492e..a8e8ba3 100644 --- a/src/eld.app.src +++ b/src/ldclient.app.src @@ -1,8 +1,9 @@ -{application, eld, - [{description, "LaunchDarkly Erlang SDK"}, - {vsn, "1.0.0-beta1"}, +{application, ldclient, + [{description, "LaunchDarkly SDK for Erlang"}, + {pkg_name, "launchdarkly_server_sdk"}, + {vsn, "1.0.0-beta2"}, {registered, []}, - {mod, {eld_app, []}}, + {mod, {ldclient_app, []}}, {applications, [kernel, stdlib, diff --git a/src/eld.erl b/src/ldclient.erl similarity index 75% rename from src/eld.erl rename to src/ldclient.erl index acab0f9..e790328 100644 --- a/src/eld.erl +++ b/src/ldclient.erl @@ -1,12 +1,12 @@ %%------------------------------------------------------------------- -%% @doc `eld' module +%% @doc `ldclient' module %% %% Acts as an interface to most common SDK functions: starting and stopping %% client instances, and evaluating feature flags for users. %% @end %%------------------------------------------------------------------- --module(eld). +-module(ldclient). %% API -export([start_instance/1]). @@ -65,14 +65,14 @@ start_instance(SdkKey, Options) when is_list(SdkKey), is_map(Options) -> -spec start_instance(SdkKey :: string(), Tag :: atom(), Options :: map()) -> ok | {error, atom(), term()}. start_instance(SdkKey, Tag, Options) when is_list(SdkKey), is_atom(Tag), is_map(Options) -> - eld_instance:start(Tag, SdkKey, Options). + ldclient_instance:start(Tag, SdkKey, Options). %% @doc Stop all client instances %% %% @end -spec stop_all_instances() -> ok. stop_all_instances() -> - eld_instance:stop_all(). + ldclient_instance:stop_all(). %% @doc Stop client instance %% @@ -88,7 +88,7 @@ stop_instance() -> %% @end -spec stop_instance(Tag :: atom()) -> ok | {error, not_found, term()}. stop_instance(Tag) when is_atom(Tag) -> - eld_instance:stop(Tag). + ldclient_instance:stop(Tag). %% @doc Returns whether the LaunchDarkly client is in offline mode. %% @@ -98,7 +98,7 @@ stop_instance(Tag) when is_atom(Tag) -> %% @end -spec is_offline(Tag :: atom()) -> boolean(). is_offline(Tag) -> - eld_settings:get_value(Tag, offline). + ldclient_settings:get_value(Tag, offline). %% @doc Returns whether the LaunchDarkly client is in offline mode. %% @@ -109,7 +109,7 @@ is_offline(Tag) -> -spec initialized(Tag :: atom()) -> boolean(). initialized(Tag) -> OfflineMode = not is_offline(Tag), - UpdateProcessorInitialized = eld_instance:update_processor_initialized(Tag), + UpdateProcessorInitialized = ldclient_instance:update_processor_initialized(Tag), OfflineMode or UpdateProcessorInitialized. %% @doc Evaluate given flag key for given user @@ -117,8 +117,8 @@ initialized(Tag) -> %% Evaluates the flag and returns the resulting variation value. The default %% value will be returned in case of any errors. %% @end --spec variation(FlagKey :: binary(), User :: eld_user:user(), DefaultValue :: eld_eval:result_value()) -> - eld_eval:result_value(). +-spec variation(FlagKey :: binary(), User :: ldclient_user:user(), DefaultValue :: ldclient_eval:result_value()) -> + ldclient_eval:result_value(). variation(FlagKey, User, DefaultValue) when is_binary(FlagKey), is_map(User) -> variation(FlagKey, User, DefaultValue, ?DEFAULT_INSTANCE_NAME). @@ -127,13 +127,13 @@ variation(FlagKey, User, DefaultValue) when is_binary(FlagKey), is_map(User) -> %% Evaluates the flag and returns the resulting variation value. The default %% value will be returned in case of any errors. %% @end --spec variation(FlagKey :: binary(), User :: eld_user:user(), DefaultValue :: eld_eval:result_value(), Tag :: atom()) -> - eld_eval:result_value(). +-spec variation(FlagKey :: binary(), User :: ldclient_user:user(), DefaultValue :: ldclient_eval:result_value(), Tag :: atom()) -> + ldclient_eval:result_value(). variation(FlagKey, User, DefaultValue, Tag) when is_binary(FlagKey), is_map(User) -> % Get evaluation result detail - {{_Index, Value, _Reason}, Events} = eld_eval:flag_key_for_user(Tag, FlagKey, User, DefaultValue), + {{_Index, Value, _Reason}, Events} = ldclient_eval:flag_key_for_user(Tag, FlagKey, User, DefaultValue), % Send events - SendEventsFun = fun(Event) -> eld_event_server:add_event(Tag, Event, #{}) end, + SendEventsFun = fun(Event) -> ldclient_event_server:add_event(Tag, Event, #{}) end, lists:foreach(SendEventsFun, Events), % Return evaluation result Value. @@ -144,8 +144,8 @@ variation(FlagKey, User, DefaultValue, Tag) when is_binary(FlagKey), is_map(User %% index, value, and reason why the specific result was chosen. The default %% value will be returned in case of any errors. %% @end --spec variation_detail(FlagKey :: binary(), User :: eld_user:user(), DefaultValue :: eld_eval:result_value()) -> - eld_eval:detail(). +-spec variation_detail(FlagKey :: binary(), User :: ldclient_user:user(), DefaultValue :: ldclient_eval:result_value()) -> + ldclient_eval:detail(). variation_detail(FlagKey, User, DefaultValue) when is_binary(FlagKey), is_map(User) -> variation_detail(FlagKey, User, DefaultValue, ?DEFAULT_INSTANCE_NAME). @@ -155,13 +155,13 @@ variation_detail(FlagKey, User, DefaultValue) when is_binary(FlagKey), is_map(Us %% index, value, and reason why the specific result was chosen. The default %% value will be returned in case of any errors. %% @end --spec variation_detail(FlagKey :: binary(), User :: eld_user:user(), DefaultValue :: eld_eval:result_value(), Tag :: atom()) -> - eld_eval:detail(). +-spec variation_detail(FlagKey :: binary(), User :: ldclient_user:user(), DefaultValue :: ldclient_eval:result_value(), Tag :: atom()) -> + ldclient_eval:detail(). variation_detail(FlagKey, User, DefaultValue, Tag) when is_binary(FlagKey), is_map(User) -> % Get evaluation result detail - {Detail, Events} = eld_eval:flag_key_for_user(Tag, FlagKey, User, DefaultValue), + {Detail, Events} = ldclient_eval:flag_key_for_user(Tag, FlagKey, User, DefaultValue), % Send events - SendEventsFun = fun(Event) -> eld_event_server:add_event(Tag, Event, #{include_reasons => true}) end, + SendEventsFun = fun(Event) -> ldclient_event_server:add_event(Tag, Event, #{include_reasons => true}) end, lists:foreach(SendEventsFun, Events), % Return evaluation detail Detail. @@ -171,7 +171,7 @@ variation_detail(FlagKey, User, DefaultValue, Tag) when is_binary(FlagKey), is_m %% Evaluates all existing flags, but does not create any events as a side %% effect of the evaluation. It returns a map of flag keys to evaluated values. %% @end --spec all_flags_state(User :: eld_user:user()) -> eld_eval:feature_flags_state(). +-spec all_flags_state(User :: ldclient_user:user()) -> ldclient_eval:feature_flags_state(). all_flags_state(User) -> all_flags_state(User, ?DEFAULT_INSTANCE_NAME). @@ -180,15 +180,15 @@ all_flags_state(User) -> %% Evaluates all existing flags, but does not create any events as a side %% effect of the evaluation. It returns a map of flag keys to evaluated values. %% @end --spec all_flags_state(User :: eld_user:user(), Tag :: atom()) -> eld_eval:feature_flags_state(). +-spec all_flags_state(User :: ldclient_user:user(), Tag :: atom()) -> ldclient_eval:feature_flags_state(). all_flags_state(User, Tag) -> - eld_eval:all_flags_eval(User, Tag). + ldclient_eval:all_flags_eval(User, Tag). %% @doc Identify reports details about a user %% %% This function uses the default client instance. %% @end --spec identify(User :: eld_user:user()) -> ok. +-spec identify(User :: ldclient_user:user()) -> ok. identify(User) -> identify(User, ?DEFAULT_INSTANCE_NAME). @@ -196,16 +196,16 @@ identify(User) -> %% %% This is useful to report user to a specific client instance. %% @end --spec identify(User :: eld_user:user(), Tag :: atom()) -> ok. +-spec identify(User :: ldclient_user:user(), Tag :: atom()) -> ok. identify(User, Tag) when is_atom(Tag) -> - Event = eld_event:new_identify(User), - eld_event_server:add_event(Tag, Event, #{}). + Event = ldclient_event:new_identify(User), + ldclient_event_server:add_event(Tag, Event, #{}). %% @doc Track reports that a user has performed an event %% %% Custom data can be attached to the event. %% @end --spec track(Key :: binary(), User :: eld_user:user(), Data :: map()) -> ok. +-spec track(Key :: binary(), User :: ldclient_user:user(), Data :: map()) -> ok. track(Key, User, Data) when is_binary(Key), is_map(Data) -> track(Key, User, Data, ?DEFAULT_INSTANCE_NAME). @@ -213,10 +213,10 @@ track(Key, User, Data) when is_binary(Key), is_map(Data) -> %% %% This is useful for specifying a specific client instance. %% @end --spec track(Key :: binary(), User :: eld_user:user(), Data :: map(), Tag :: atom()) -> ok. +-spec track(Key :: binary(), User :: ldclient_user:user(), Data :: map(), Tag :: atom()) -> ok. track(Key, User, Data, Tag) when is_atom(Tag), is_binary(Key), is_map(Data) -> - Event = eld_event:new_custom(Key, User, Data), - eld_event_server:add_event(Tag, Event, #{}). + Event = ldclient_event:new_custom(Key, User, Data), + ldclient_event_server:add_event(Tag, Event, #{}). %% @doc Reports that a user has performed an event, and associates it with a numeric value. %% @@ -225,7 +225,7 @@ track(Key, User, Data, Tag) when is_atom(Tag), is_binary(Key), is_map(Data) -> %% %% Custom data can also be attached to the event. %% @end --spec track_with_metric(Key :: binary(), User :: eld_user:user(), Data :: map(), Metric :: number()) -> ok. +-spec track_with_metric(Key :: binary(), User :: ldclient_user:user(), Data :: map(), Metric :: number()) -> ok. track_with_metric(Key, User, Data, Metric) -> track_with_metric(Key, User, Data, Metric, ?DEFAULT_INSTANCE_NAME). @@ -236,7 +236,7 @@ track_with_metric(Key, User, Data, Metric) -> %% %% Custom data can also be attached to the event. %% @end --spec track_with_metric(Key :: binary(), User :: eld_user:user(), Data :: map(), Metric :: number(), Tag :: atom()) -> ok. +-spec track_with_metric(Key :: binary(), User :: ldclient_user:user(), Data :: map(), Metric :: number(), Tag :: atom()) -> ok. track_with_metric(Key, User, Data, Metric, Tag) -> - Event = eld_event:new_custom(Key, User, Data, Metric), - eld_event_server:add_event(Tag, Event, #{}). + Event = ldclient_event:new_custom(Key, User, Data, Metric), + ldclient_event_server:add_event(Tag, Event, #{}). diff --git a/src/eld_app.erl b/src/ldclient_app.erl similarity index 79% rename from src/eld_app.erl rename to src/ldclient_app.erl index c6878e8..3aee15a 100644 --- a/src/eld_app.erl +++ b/src/ldclient_app.erl @@ -4,7 +4,7 @@ %% @end %%------------------------------------------------------------------- --module(eld_app). +-module(ldclient_app). -behaviour(application). @@ -17,8 +17,8 @@ %%=================================================================== start(_Type, _Args) -> - ok = eld_settings:init(), - eld_sup:start_link(). + ok = ldclient_settings:init(), + ldclient_sup:start_link(). stop(_State) -> - eld:stop_all_instances(). + ldclient:stop_all_instances(). diff --git a/src/eld_clause.erl b/src/ldclient_clause.erl similarity index 94% rename from src/eld_clause.erl rename to src/ldclient_clause.erl index a1e6c18..46d674d 100644 --- a/src/eld_clause.erl +++ b/src/ldclient_clause.erl @@ -4,7 +4,7 @@ %% @end %%------------------------------------------------------------------- --module(eld_clause). +-module(ldclient_clause). %% API -export([new/1]). @@ -15,7 +15,7 @@ -type clause() :: #{ attribute => binary(), op => operator(), - values => [eld_flag:variation_value()], + values => [ldclient_flag:variation_value()], negate => boolean() }. %% Describes an individual clause within a targeting rule @@ -51,14 +51,14 @@ new(RawClauseMap) -> %% @doc Match clauses to user, no segment_match allowed %% %% @end --spec match_user(clause(), eld_user:user()) -> match | no_match. +-spec match_user(clause(), ldclient_user:user()) -> match | no_match. match_user(Clause, User) -> check_clause(Clause, User). %% @doc Match all clauses to user, includes possible segment_match %% %% @end --spec match_user(clause(), eld_user:user(), atom(), atom()) -> match | no_match. +-spec match_user(clause(), ldclient_user:user(), atom(), atom()) -> match | no_match. match_user(Clause, User, StorageBackend, Tag) -> check_clause(Clause, User, StorageBackend, Tag). @@ -88,7 +88,7 @@ parse_operator(<<"semVerLessThan">>) -> semver_less_than; parse_operator(<<"semVerGreaterThan">>) -> semver_greater_than; parse_operator(_) -> none. --spec check_clause(clause(), eld_user:user(), atom(), atom()) -> match | no_match. +-spec check_clause(clause(), ldclient_user:user(), atom(), atom()) -> match | no_match. check_clause(#{op := segment_match, values := SegmentKeys} = Clause, User, StorageBackend, Tag) -> maybe_negate_match(Clause, check_segment_keys_match(SegmentKeys, User, StorageBackend, Tag)); check_clause(#{op := none}, _User, _StorageBackend, _Tag) -> no_match; @@ -96,7 +96,7 @@ check_clause(Clause, User, _StorageBackend, _Tag) -> check_clause(Clause, User). check_clause(#{attribute := Attribute} = Clause, User) -> - UserValue = eld_user:get(Attribute, User), + UserValue = ldclient_user:get(Attribute, User), check_user_value_null(UserValue, Clause). check_user_value_null(null, _Clause) -> no_match; @@ -223,7 +223,7 @@ check_attribute_result(match, _Rest, _Clause) -> match; check_attribute_result(no_match, Rest, Clause) -> check_attribute(Rest, Clause). --spec check_segment_keys_match([binary()], eld_user:user(), atom(), atom()) -> match | no_match. +-spec check_segment_keys_match([binary()], ldclient_user:user(), atom(), atom()) -> match | no_match. check_segment_keys_match([], _User, _StorageBackend, _Tag) -> no_match; check_segment_keys_match([SegmentKey|Rest], User, StorageBackend, Tag) -> Result = check_segment_key_match(SegmentKey, User, StorageBackend, Tag), @@ -239,8 +239,8 @@ check_segment_key_match(SegmentKey, User, StorageBackend, Tag) -> check_segments_match([], _User) -> no_match; check_segments_match([{_SegmentKey, SegmentProperties}|_], User) -> - Segment = eld_segment:new(SegmentProperties), - eld_segment:match_user(Segment, User). + Segment = ldclient_segment:new(SegmentProperties), + ldclient_segment:match_user(Segment, User). -spec maybe_negate_match(clause(), match | no_match) -> match | no_match. maybe_negate_match(#{negate := false}, Match) -> Match; diff --git a/src/eld_eval.erl b/src/ldclient_eval.erl similarity index 86% rename from src/eld_eval.erl rename to src/ldclient_eval.erl index d22a11a..c1f6f67 100644 --- a/src/eld_eval.erl +++ b/src/ldclient_eval.erl @@ -4,7 +4,7 @@ %% @end %%------------------------------------------------------------------- --module(eld_eval). +-module(ldclient_eval). %% API -export([flag_key_for_user/4]). @@ -13,14 +13,14 @@ %% Types -type result() :: { Detail :: detail(), - Events :: [eld_event:event()] + Events :: [ldclient_event:event()] }. -type detail() :: { VariationIndex :: variation_index(), Value :: result_value(), Reason :: reason() }. --type result_value() :: null | eld_flag:variation_value(). +-type result_value() :: null | ldclient_flag:variation_value(). -type variation_index() :: null | non_neg_integer(). -type reason() :: target_match @@ -49,16 +49,16 @@ %% @end -spec flag_key_for_user( Tag :: atom(), - FlagKey :: eld_flag:key(), - User :: eld_user:user(), + FlagKey :: ldclient_flag:key(), + User :: ldclient_user:user(), DefaultValue :: result_value() ) -> result(). flag_key_for_user(Tag, FlagKey, User, DefaultValue) -> flag_key_for_user(Tag, FlagKey, User, DefaultValue, get_state(Tag), get_initialization_state(Tag)). -spec flag_key_for_user( Tag :: atom(), - FlagKey :: eld_flag:key(), - User :: eld_user:user(), + FlagKey :: ldclient_flag:key(), + User :: ldclient_user:user(), DefaultValue :: result_value(), Offline :: atom(), Initialized :: atom() @@ -68,7 +68,7 @@ flag_key_for_user(_Tag, _FlagKey, _User, DefaultValue, offline, _) -> flag_key_for_user(_Tag, _FlagKey, _User, DefaultValue, _, not_initialized) -> {{null, DefaultValue, {error, client_not_ready}}, []}; flag_key_for_user(Tag, FlagKey, User, DefaultValue, online, initialized) -> - StorageBackend = eld_settings:get_value(Tag, storage_backend), + StorageBackend = ldclient_settings:get_value(Tag, storage_backend), FlagRecs = StorageBackend:get(Tag, flags, FlagKey), flag_recs_for_user(FlagKey, FlagRecs, User, StorageBackend, Tag, DefaultValue). @@ -76,13 +76,13 @@ flag_key_for_user(Tag, FlagKey, User, DefaultValue, online, initialized) -> %% %% @end -spec all_flags_eval( - User :: eld_user:user(), + User :: ldclient_user:user(), Tag :: atom() ) -> feature_flags_state(). all_flags_eval(User, Tag) -> all_flags_eval(User, Tag, get_state(Tag), get_initialization_state(Tag)). -spec all_flags_eval( - User :: eld_user:user(), + User :: ldclient_user:user(), Tag :: atom(), Offline :: atom(), Initialized :: atom() @@ -94,7 +94,7 @@ all_flags_eval(_User, _Tag, _, not_initialized) -> error_logger:warning_msg("Called all_flags_state before client initialization. Returning empty state"), #{flag_values => #{}}; all_flags_eval(User, Tag, online, initialized) -> - StorageBackend = eld_settings:get_value(Tag, storage_backend), + StorageBackend = ldclient_settings:get_value(Tag, storage_backend), AllFlags = [FlagKey || {FlagKey, _} <- StorageBackend:list(Tag, flags)], EvalFun = fun(FlagKey, Acc) -> {{_, V, _}, _Events} = flag_key_for_user(Tag, FlagKey, User, null), @@ -107,23 +107,23 @@ all_flags_eval(User, Tag, online, initialized) -> %%=================================================================== -spec get_state(Tag :: atom()) -> atom(). -get_state(Tag) -> get_state(Tag, eld:is_offline(Tag)). +get_state(Tag) -> get_state(Tag, ldclient:is_offline(Tag)). -spec get_state(Tag :: atom(), Offline :: boolean()) -> atom(). get_state(_Tag, true) -> offline; get_state(_Tag, false) -> online. -spec get_initialization_state(Tag :: atom()) -> atom(). -get_initialization_state(Tag) -> get_initialization_state(Tag, eld:initialized(Tag)). +get_initialization_state(Tag) -> get_initialization_state(Tag, ldclient:initialized(Tag)). -spec get_initialization_state(Tag :: atom(), Initialized :: boolean()) -> atom(). get_initialization_state(_Tag, true) -> initialized; get_initialization_state(_Tag, false) -> not_initialized. -spec flag_recs_for_user( - FlagKey :: eld_flag:key(), - FlagRecs :: [{eld_flag:key(), map()}], - User :: eld_user:user(), + FlagKey :: ldclient_flag:key(), + FlagRecs :: [{ldclient_flag:key(), map()}], + User :: ldclient_user:user(), StorageBackend :: atom(), Tag :: atom(), DefaultValue :: result_value() @@ -132,20 +132,20 @@ flag_recs_for_user(FlagKey, [], User, _StorageBackend, _Tag, DefaultValue) -> % Flag not found error_logger:warning_msg("Unknown feature flag ~p; returning default value", [FlagKey]), Reason = {error, flag_not_found}, - Events = [eld_event:new_for_unknown_flag(FlagKey, User, DefaultValue, Reason)], + Events = [ldclient_event:new_for_unknown_flag(FlagKey, User, DefaultValue, Reason)], {{null, DefaultValue, Reason}, Events}; flag_recs_for_user(FlagKey, [{FlagKey, #{<<"deleted">> := true}}|_], User, _StorageBackend, _Tag, DefaultValue) -> % Flag found, but it's deleted error_logger:warning_msg("Unknown feature flag ~p; returning default value", [FlagKey]), Reason = {error, flag_not_found}, - Events = [eld_event:new_for_unknown_flag(FlagKey, User, DefaultValue, Reason)], + Events = [ldclient_event:new_for_unknown_flag(FlagKey, User, DefaultValue, Reason)], {{null, DefaultValue, Reason}, Events}; flag_recs_for_user(FlagKey, [{FlagKey, FlagProperties}|_], User, StorageBackend, Tag, DefaultValue) -> % Flag found - Flag = eld_flag:new(FlagProperties), + Flag = ldclient_flag:new(FlagProperties), flag_for_user_check_empty_key(Flag, User, StorageBackend, Tag, DefaultValue). --spec flag_for_user_check_empty_key(eld_flag:flag(), eld_user:user(), atom(), atom(), result_value()) -> result(). +-spec flag_for_user_check_empty_key(ldclient_flag:flag(), ldclient_user:user(), atom(), atom(), result_value()) -> result(). flag_for_user_check_empty_key(Flag, #{key := <<>>} = User, StorageBackend, Tag, DefaultValue) -> error_logger:warning_msg("User key is blank. Flag evaluation will proceed, but the user will not be stored in Launchdarkly"), flag_for_user(Flag, User, StorageBackend, Tag, DefaultValue); @@ -158,19 +158,19 @@ flag_for_user_check_empty_key(Flag, User, _StorageBackend, _Tag, DefaultValue) - % User has no key flag_for_user_with_no_key(Flag, User, DefaultValue). --spec flag_for_user_with_no_key(eld_flag:flag(), eld_user:user(), result_value()) -> result(). +-spec flag_for_user_with_no_key(ldclient_flag:flag(), ldclient_user:user(), result_value()) -> result(). flag_for_user_with_no_key(Flag, User, DefaultValue) -> Reason = {error, user_not_specified}, - Events = [eld_event:new_flag_eval(null, DefaultValue, DefaultValue, User, Reason, Flag)], + Events = [ldclient_event:new_flag_eval(null, DefaultValue, DefaultValue, User, Reason, Flag)], {{null, DefaultValue, Reason}, Events}. --spec flag_for_user(eld_flag:flag(), eld_user:user(), atom(), atom(), result_value()) -> result(). +-spec flag_for_user(ldclient_flag:flag(), ldclient_user:user(), atom(), atom(), result_value()) -> result(). flag_for_user(Flag, User, StorageBackend, Tag, DefaultValue) -> {{Variation, VariationValue, Reason}, Events} = flag_for_user_valid(Flag, User, StorageBackend, Tag, DefaultValue), - FlagEvalEvent = eld_event:new_flag_eval(Variation, VariationValue, DefaultValue, User, Reason, Flag), + FlagEvalEvent = ldclient_event:new_flag_eval(Variation, VariationValue, DefaultValue, User, Reason, Flag), {{Variation, VariationValue, Reason}, [FlagEvalEvent|Events]}. --spec flag_for_user_valid(eld_flag:flag(), eld_user:user(), atom(), atom(), result_value()) -> result(). +-spec flag_for_user_valid(ldclient_flag:flag(), ldclient_user:user(), atom(), atom(), result_value()) -> result(). flag_for_user_valid(#{on := false, off_variation := OffVariation} = Flag, _User, _StorageBackend, _Tag, _DefaultValue) when is_integer(OffVariation), OffVariation >= 0 -> result_for_variation_index(OffVariation, off, Flag, []); @@ -180,7 +180,7 @@ flag_for_user_valid(#{on := false}, _User, _StorageBackend, _Tag, DefaultValue) flag_for_user_valid(#{prerequisites := Prerequisites} = Flag, User, StorageBackend, Tag, DefaultValue) -> check_prerequisites(Prerequisites, Flag, User, StorageBackend, Tag, DefaultValue). --spec check_prerequisites([eld_flag:prerequisite()], eld_flag:flag(), eld_user:user(), atom(), atom(), result_value()) -> +-spec check_prerequisites([ldclient_flag:prerequisite()], ldclient_flag:flag(), ldclient_user:user(), atom(), atom(), result_value()) -> result(). check_prerequisites(Prerequisites, Flag, User, StorageBackend, Tag, DefaultValue) -> check_prerequisites(Prerequisites, Flag, User, StorageBackend, Tag, DefaultValue, []). @@ -196,7 +196,7 @@ check_prerequisite_recs([], PrerequisiteKey, _Variation, _Prerequisites, #{key : error_logger:error_msg("Could not retrieve prerequisite flag ~p when evaluating ~p", [PrerequisiteKey, FlagKey]), flag_for_user_prerequisites({fail, {prerequisite_failed, [PrerequisiteKey]}}, Flag, User, StorageBackend, Tag, DefaultValue, Events); check_prerequisite_recs([{PrerequisiteKey, PrerequisiteProperties}|_], PrerequisiteKey, Variation, Prerequisites, Flag, User, StorageBackend, Tag, DefaultValue, Events) -> - PrerequisiteFlag = eld_flag:new(PrerequisiteProperties), + PrerequisiteFlag = ldclient_flag:new(PrerequisiteProperties), check_prerequisite_flag(PrerequisiteFlag, Variation, Prerequisites, Flag, User, StorageBackend, Tag, DefaultValue, Events). check_prerequisite_flag(#{key := PrerequisiteKey, deleted := true}, _, _, Flag, User, StorageBackend, Tag, DefaultValue, Events) -> @@ -209,7 +209,7 @@ check_prerequisite_flag(#{key := PrerequisiteKey, on := false}, _, _, Flag, User flag_for_user_prerequisites(Result, Flag, User, StorageBackend, Tag, DefaultValue, Events); check_prerequisite_flag(#{prerequisites := SubPrerequisites} = PrerequisiteFlag, Variation, Prerequisites, #{key := FlagKey} = Flag, User, StorageBackend, Tag, DefaultValue, Events) -> {{ResultVariation, ResultVariationValue, ResultReason}, ResultEvents} = check_prerequisites(SubPrerequisites, PrerequisiteFlag, User, StorageBackend, Tag, DefaultValue, Events), - NewEvents = [eld_event:new_prerequisite_eval(ResultVariation, ResultVariationValue, FlagKey, User, ResultReason, PrerequisiteFlag)|ResultEvents], + NewEvents = [ldclient_event:new_prerequisite_eval(ResultVariation, ResultVariationValue, FlagKey, User, ResultReason, PrerequisiteFlag)|ResultEvents], check_prerequisite_flag_result(PrerequisiteFlag, Variation =:= ResultVariation, Prerequisites, Flag, User, StorageBackend, Tag, DefaultValue, NewEvents). check_prerequisite_flag_result(#{key := PrerequisiteKey}, false, _Prerequisites, Flag, User, StorageBackend, Tag, DefaultValue, Events) -> @@ -249,7 +249,7 @@ flag_for_user_targets(no_match, #{rules := Rules} = Flag, User, StorageBackend, check_rules([], Flag, User, _StorageBackend, _Tag, Events, _) -> flag_for_user_rules(no_match, Flag, User, Events); check_rules([Rule|Rest], Flag, User, StorageBackend, Tag, Events, Index) -> - Result = eld_rule:match_user(Rule, User, StorageBackend, Tag), + Result = ldclient_rule:match_user(Rule, User, StorageBackend, Tag), check_rule_result({Result, Rule, Index}, Rest, Flag, User, StorageBackend, Tag, Events). check_rule_result({no_match, _Rule, Index}, Rest, Flag, User, StorageBackend, Tag, Events) -> @@ -267,7 +267,7 @@ flag_for_user_rules(no_match, #{fallthrough := Fallthrough} = Flag, User, Events flag_for_user_variation_or_rollout(Variation, Reason, Flag, _User, Events) when is_integer(Variation) -> result_for_variation_index(Variation, Reason, Flag, Events); flag_for_user_variation_or_rollout(Rollout, Reason, Flag, User, Events) when is_map(Rollout) -> - Result = eld_rollout:rollout_user(Rollout, Flag, User), + Result = ldclient_rollout:rollout_user(Rollout, Flag, User), flag_for_user_rollout_result(Result, Reason, Flag, Events). flag_for_user_rollout_result(null, _Reason, #{key := FlagKey}, Events) -> @@ -278,7 +278,7 @@ flag_for_user_rollout_result(Variation, Reason, Flag, Events) -> result_for_variation_index(Variation, Reason, Flag, Events). result_for_variation_index(Variation, Reason, Flag, Events) -> - VariationValue = eld_flag:get_variation(Flag, Variation), + VariationValue = ldclient_flag:get_variation(Flag, Variation), result_for_variation_value(VariationValue, Variation, Reason, Flag, Events). result_for_variation_value(null, _Variation, _Reason, _Flag, Events) -> diff --git a/src/eld_event.erl b/src/ldclient_event.erl similarity index 74% rename from src/eld_event.erl rename to src/ldclient_event.erl index 21f38a0..268c430 100644 --- a/src/eld_event.erl +++ b/src/ldclient_event.erl @@ -4,7 +4,7 @@ %% @end %%------------------------------------------------------------------- --module(eld_event). +-module(ldclient_event). %% API -export([new/4]). @@ -27,17 +27,17 @@ -type feature_request() :: #{ type := feature_request, timestamp := non_neg_integer(), - user := eld_user:user(), + user := ldclient_user:user(), data := #{ - key := eld_flag:key(), - variation := eld_flag:variation() | null, - value := eld_eval:result_value(), - default := eld_eval:result_value(), - version := eld_flag:version() | null, - prereq_of := eld_flag:key() | null, + key := ldclient_flag:key(), + variation := ldclient_flag:variation() | null, + value := ldclient_eval:result_value(), + default := ldclient_eval:result_value(), + version := ldclient_flag:version() | null, + prereq_of := ldclient_flag:key() | null, track_events := boolean() | null, debug_events_until_date := boolean() | null, - eval_reason := eld_eval:reason() | null, + eval_reason := ldclient_eval:reason() | null, include_reason := boolean(), debug := boolean() } @@ -46,20 +46,20 @@ -type identify() :: #{ type := identify, timestamp := non_neg_integer(), - user := eld_user:user() + user := ldclient_user:user() }. -type index() :: #{ type := index, timestamp := non_neg_integer(), - user := eld_user:user() + user := ldclient_user:user() }. -type custom() :: #{ type := custom, timestamp := non_neg_integer(), key := binary(), - user := eld_user:user(), + user := ldclient_user:user(), data => map(), metric_value => number() }. @@ -79,7 +79,7 @@ %% @end -spec new( Type :: event_type(), - User :: eld_user:user(), + User :: ldclient_user:user(), Timestamp :: non_neg_integer(), Data :: map() ) -> event(). @@ -96,15 +96,15 @@ new(index, User, Timestamp, #{}) -> user => User }; new(feature_request, User, Timestamp, #{ - key := Key, % eld_flag:key() - variation := Variation, % null | eld_flag:variation() - value := Value, % eld_eval:result_value() - default := Default, % eld_eval:result_value() - version := Version, % null | eld_flag:version() - prereq_of := PrereqOf, % null | eld_flag:key() + key := Key, % ldclient_flag:key() + variation := Variation, % null | ldclient_flag:variation() + value := Value, % ldclient_eval:result_value() + default := Default, % ldclient_eval:result_value() + version := Version, % null | ldclient_flag:version() + prereq_of := PrereqOf, % null | ldclient_flag:key() track_events := TrackEvents, % null | boolean() debug_events_until_date := DebugEventsUntilDate, % null | boolean() - eval_reason := EvalReason, % null | eld_eval:reason() + eval_reason := EvalReason, % null | ldclient_eval:reason() include_reason := IncludeReason % boolean() }) -> #{ @@ -129,7 +129,7 @@ new(feature_request, User, Timestamp, #{ -spec new( custom, Key :: binary(), - User:: eld_user:user(), + User:: ldclient_user:user(), Timestamp :: non_neg_integer(), Data :: map() ) -> event(). @@ -143,10 +143,10 @@ new(custom, Key, User, Timestamp, Data) when is_map(Data) -> }. -spec new_for_unknown_flag( - FlagKey :: eld_flag:key(), - User :: eld_user:user(), - DefaultValue :: eld_eval:result_value(), - Reason :: eld_eval:reason() + FlagKey :: ldclient_flag:key(), + User :: ldclient_user:user(), + DefaultValue :: ldclient_eval:result_value(), + Reason :: ldclient_eval:reason() ) -> event(). new_for_unknown_flag(FlagKey, User, DefaultValue, Reason) -> EventData = #{ @@ -165,12 +165,12 @@ new_for_unknown_flag(FlagKey, User, DefaultValue, Reason) -> new(feature_request, User, erlang:system_time(milli_seconds), EventData). -spec new_flag_eval( - VariationIndex :: eld_flag:variation(), - VariationValue :: eld_eval:result_value(), - DefaultValue :: eld_eval:result_value(), - User :: eld_user:user(), - Reason :: eld_eval:reason() | null, - Flag :: eld_flag:flag() + VariationIndex :: ldclient_flag:variation(), + VariationValue :: ldclient_eval:result_value(), + DefaultValue :: ldclient_eval:result_value(), + User :: ldclient_user:user(), + Reason :: ldclient_eval:reason() | null, + Flag :: ldclient_flag:flag() ) -> event(). new_flag_eval(VariationIndex, VariationValue, DefaultValue, User, Reason, #{ key := Key, @@ -195,12 +195,12 @@ new_flag_eval(VariationIndex, VariationValue, DefaultValue, User, Reason, #{ new(feature_request, User, erlang:system_time(milli_seconds), EventData). -spec new_prerequisite_eval( - VariationIndex :: eld_flag:variation(), - VariationValue :: eld_flag:variation_value(), - PrerequisiteOf :: eld_flag:key(), - User :: eld_user:user(), - Reason :: eld_eval:reason() | null, - Flag :: eld_flag:flag() + VariationIndex :: ldclient_flag:variation(), + VariationValue :: ldclient_flag:variation_value(), + PrerequisiteOf :: ldclient_flag:key(), + User :: ldclient_user:user(), + Reason :: ldclient_eval:reason() | null, + Flag :: ldclient_flag:flag() ) -> event(). new_prerequisite_eval(VariationIndex, VariationValue, PrerequisiteOf, User, Reason, #{ key := Key, @@ -224,15 +224,15 @@ new_prerequisite_eval(VariationIndex, VariationValue, PrerequisiteOf, User, Reas }, new(feature_request, User, erlang:system_time(milli_seconds), EventData). --spec new_identify(User :: eld_user:user()) -> event(). +-spec new_identify(User :: ldclient_user:user()) -> event(). new_identify(User) -> new(identify, User, erlang:system_time(milli_seconds), #{}). --spec new_index(User :: eld_user:user(), Timestamp :: non_neg_integer()) -> event(). +-spec new_index(User :: ldclient_user:user(), Timestamp :: non_neg_integer()) -> event(). new_index(User, Timestamp) -> new(index, User, Timestamp, #{}). --spec new_custom(Key :: binary(), User :: eld_user:user(), Data :: map()) -> event(). +-spec new_custom(Key :: binary(), User :: ldclient_user:user(), Data :: map()) -> event(). new_custom(Key, User, Data) when is_binary(Key), is_map(Data) -> #{ type => custom, @@ -242,7 +242,7 @@ new_custom(Key, User, Data) when is_binary(Key), is_map(Data) -> data => Data }. --spec new_custom(Key :: binary(), User :: eld_user:user(), Data :: map(), MetricValue :: number()) -> event(). +-spec new_custom(Key :: binary(), User :: ldclient_user:user(), Data :: map(), MetricValue :: number()) -> event(). new_custom(Key, User, Data, MetricValue) when is_binary(Key), is_map(Data), is_number(MetricValue) -> #{ type => custom, @@ -253,7 +253,7 @@ new_custom(Key, User, Data, MetricValue) when is_binary(Key), is_map(Data), is_n metric_value => MetricValue }. --spec strip_eval_reason(eld_event:event()) -> eld_event:event(). +-spec strip_eval_reason(ldclient_event:event()) -> ldclient_event:event(). strip_eval_reason(#{type := feature_request, data := Data} = Event) -> Event#{data => maps:remove(eval_reason, Data)}. @@ -261,7 +261,7 @@ strip_eval_reason(#{type := feature_request, data := Data} = Event) -> %% Internal functions %%=================================================================== --spec is_experiment(eld_eval:reason(), eld_flag:flag()) -> boolean(). +-spec is_experiment(ldclient_eval:reason(), ldclient_flag:flag()) -> boolean(). is_experiment(fallthrough, #{track_events_fallthrough := true}) -> true; is_experiment({rule_match, RuleIndex, _}, #{rules := Rules}) when RuleIndex >=0, RuleIndex < length(Rules) -> Rule = lists:nth(RuleIndex + 1, Rules), diff --git a/src/eld_event_dispatch.erl b/src/ldclient_event_dispatch.erl similarity index 89% rename from src/eld_event_dispatch.erl rename to src/ldclient_event_dispatch.erl index ac5fa6d..3b45947 100644 --- a/src/eld_event_dispatch.erl +++ b/src/ldclient_event_dispatch.erl @@ -1,12 +1,12 @@ %%------------------------------------------------------------------- -%% @doc `eld_event_dispatch' module +%% @doc `ldclient_event_dispatch' module %% %% This is a behavior that event dispatchers must implement. It is used to send %% event batches to LaunchDarkly. %% @end %%------------------------------------------------------------------- --module(eld_event_dispatch). +-module(ldclient_event_dispatch). %% `send' must dispatch the batch of events. It takes the list of events, the %% destination URI and SDK key. It must return success or temporary or diff --git a/src/eld_event_dispatch_httpc.erl b/src/ldclient_event_dispatch_httpc.erl similarity index 90% rename from src/eld_event_dispatch_httpc.erl rename to src/ldclient_event_dispatch_httpc.erl index fa4f14a..734c81c 100644 --- a/src/eld_event_dispatch_httpc.erl +++ b/src/ldclient_event_dispatch_httpc.erl @@ -4,9 +4,9 @@ %% @end %%------------------------------------------------------------------- --module(eld_event_dispatch_httpc). +-module(ldclient_event_dispatch_httpc). --behaviour(eld_event_dispatch). +-behaviour(ldclient_event_dispatch). %% Behavior callbacks -export([send/4]). @@ -22,8 +22,8 @@ send(JsonEvents, PayloadId, Uri, SdkKey) -> Headers = [ {"Authorization", SdkKey}, - {"X-LaunchDarkly-Event-Schema", eld_settings:get_event_schema()}, - {"User-Agent", eld_settings:get_user_agent()}, + {"X-LaunchDarkly-Event-Schema", ldclient_settings:get_event_schema()}, + {"User-Agent", ldclient_settings:get_user_agent()}, {"X-LaunchDarkly-Payload-ID", uuid:uuid_to_string(PayloadId)} ], {ok, {{Version, StatusCode, ReasonPhrase}, _Headers, _Body}} = diff --git a/src/eld_event_process_server.erl b/src/ldclient_event_process_server.erl similarity index 84% rename from src/eld_event_process_server.erl rename to src/ldclient_event_process_server.erl index b852fe2..2189dc5 100644 --- a/src/eld_event_process_server.erl +++ b/src/ldclient_event_process_server.erl @@ -4,7 +4,7 @@ %% @end %%------------------------------------------------------------------- --module(eld_event_process_server). +-module(ldclient_event_process_server). -behaviour(gen_server). @@ -22,7 +22,7 @@ sdk_key := string(), dispatcher := atom(), inline_users := boolean(), - global_private_attributes := eld_settings:private_attributes(), + global_private_attributes := ldclient_settings:private_attributes(), events_uri := string() }. @@ -33,7 +33,7 @@ %% @doc Send events to LaunchDarkly event server %% %% @end --spec send_events(Tag :: atom(), Events :: [eld_event:event()], SummaryEvent :: eld_event_server:summary_event()) -> +-spec send_events(Tag :: atom(), Events :: [ldclient_event:event()], SummaryEvent :: ldclient_event_server:summary_event()) -> ok. send_events(Tag, Events, SummaryEvent) -> ServerName = get_local_reg_name(Tag), @@ -57,11 +57,11 @@ start_link(Tag) -> {ok, State :: state()} | {ok, State :: state(), timeout() | hibernate} | {stop, Reason :: term()} | ignore. init([Tag]) -> - SdkKey = eld_settings:get_value(Tag, sdk_key), - Dispatcher = eld_settings:get_value(Tag, events_dispatcher), - InlineUsers = eld_settings:get_value(Tag, inline_users_in_events), - GlobalPrivateAttributes = eld_settings:get_value(Tag, private_attributes), - EventsUri = eld_settings:get_value(Tag, events_uri) ++ "/api/events/bulk", + SdkKey = ldclient_settings:get_value(Tag, sdk_key), + Dispatcher = ldclient_settings:get_value(Tag, events_dispatcher), + InlineUsers = ldclient_settings:get_value(Tag, inline_users_in_events), + GlobalPrivateAttributes = ldclient_settings:get_value(Tag, private_attributes), + EventsUri = ldclient_settings:get_value(Tag, events_uri) ++ "/api/events/bulk", State = #{ sdk_key => SdkKey, dispatcher => Dispatcher, @@ -124,12 +124,13 @@ code_change(_OldVsn, State, _Extra) -> %% Internal functions %%=================================================================== --spec format_events([eld_event:event()], boolean(), eld_settings:private_attributes()) -> list(). +-spec format_events([ldclient_event:event()], boolean(), ldclient_settings:private_attributes()) -> list(). format_events(Events, InlineUsers, GlobalPrivateAttributes) -> {FormattedEvents, _, _} = lists:foldl(fun format_event/2, {[], InlineUsers, GlobalPrivateAttributes}, Events), FormattedEvents. --spec format_event(eld_event:event(), {list(), boolean(), eld_settings:private_attributes()}) -> {list(), boolean(), eld_settings:private_attributes()}. +-spec format_event(ldclient_event:event(), {list(), boolean(), ldclient_settings:private_attributes()}) -> + {list(), boolean(), ldclient_settings:private_attributes()}. format_event( #{ type := feature_request, @@ -187,13 +188,13 @@ format_event(#{type := custom, timestamp := Timestamp, key := Key, user := User, FormattedEvent = format_event_set_user(Kind, User, OutputEvent, InlineUsers, GlobalPrivateAttributes), {[FormattedEvent|FormattedEvents], InlineUsers, GlobalPrivateAttributes}. --spec maybe_set_reason(eld_event:event(), #{binary() => any()}) -> #{binary() => any()}. +-spec maybe_set_reason(ldclient_event:event(), #{binary() => any()}) -> #{binary() => any()}. maybe_set_reason(#{data := #{eval_reason := EvalReason}}, OutputEvent) -> OutputEvent#{<<"reason">> => format_eval_reason(EvalReason)}; maybe_set_reason(_Event, OutputEvent) -> OutputEvent. --spec format_eval_reason(eld_eval:reason()) -> map(). +-spec format_eval_reason(ldclient_eval:reason()) -> map(). format_eval_reason(target_match) -> #{<<"kind">> => <<"TARGET_MATCH">>}; format_eval_reason({rule_match, RuleIndex, RuleId}) -> #{kind => <<"RULE_MATCH">>, ruleIndex => RuleIndex, ruleId => RuleId}; format_eval_reason({prerequisite_failed, [PrereqKey|_]}) -> #{<<"kind">> => <<"PREREQUISITE_FAILED">>, prerequisiteKey => PrereqKey}; @@ -206,9 +207,9 @@ format_eval_reason({error, exception}) -> #{kind => <<"ERROR">>, errorKind => << format_eval_reason(fallthrough) -> #{<<"kind">> => <<"FALLTHROUGH">>}; format_eval_reason(off) -> #{<<"kind">> => <<"OFF">>}. --spec format_event_set_user(binary(), eld_user:user(), map(), boolean(), eld_settings:private_attributes()) -> map(). +-spec format_event_set_user(binary(), ldclient_user:user(), map(), boolean(), ldclient_settings:private_attributes()) -> map(). format_event_set_user(<<"feature">>, User, OutputEvent, true, GlobalPrivateAttributes) -> - {ScrubbedUser, ScrubbedAttrNames} = eld_user:scrub(User, GlobalPrivateAttributes), + {ScrubbedUser, ScrubbedAttrNames} = ldclient_user:scrub(User, GlobalPrivateAttributes), OutputEvent#{ <<"user">> => ScrubbedUser#{<<"privateAttrs">> => ScrubbedAttrNames} }; @@ -218,36 +219,36 @@ format_event_set_user(<<"feature">>, _User, OutputEvent, _, _) -> % User has no key OutputEvent#{<<"userKey">> => null}; format_event_set_user(<<"debug">>, User, OutputEvent, _, GlobalPrivateAttributes) -> - {ScrubbedUser, ScrubbedAttrNames} = eld_user:scrub(User, GlobalPrivateAttributes), + {ScrubbedUser, ScrubbedAttrNames} = ldclient_user:scrub(User, GlobalPrivateAttributes), OutputEvent#{ <<"user">> => ScrubbedUser#{<<"privateAttrs">> => ScrubbedAttrNames} }; format_event_set_user(<<"identify">>, #{key := UserKey} = User, OutputEvent, _, GlobalPrivateAttributes) -> - {ScrubbedUser, ScrubbedAttrNames} = eld_user:scrub(User, GlobalPrivateAttributes), + {ScrubbedUser, ScrubbedAttrNames} = ldclient_user:scrub(User, GlobalPrivateAttributes), OutputEvent#{ <<"key">> => UserKey, <<"user">> => ScrubbedUser#{<<"privateAttrs">> => ScrubbedAttrNames} }; format_event_set_user(<<"index">>, User, OutputEvent, _, GlobalPrivateAttributes) -> - {ScrubbedUser, ScrubbedAttrNames} = eld_user:scrub(User, GlobalPrivateAttributes), + {ScrubbedUser, ScrubbedAttrNames} = ldclient_user:scrub(User, GlobalPrivateAttributes), OutputEvent#{ <<"user">> => ScrubbedUser#{<<"privateAttrs">> => ScrubbedAttrNames} }; format_event_set_user(<<"custom">>, User, OutputEvent, true, GlobalPrivateAttributes) -> - {ScrubbedUser, ScrubbedAttrNames} = eld_user:scrub(User, GlobalPrivateAttributes), + {ScrubbedUser, ScrubbedAttrNames} = ldclient_user:scrub(User, GlobalPrivateAttributes), OutputEvent#{ <<"user">> => ScrubbedUser#{<<"privateAttrs">> => ScrubbedAttrNames} }; format_event_set_user(<<"custom">>, #{key := UserKey}, OutputEvent, false, _) -> OutputEvent#{<<"userKey">> => UserKey}. --spec maybe_set_metric_value(eld_event:event(), map()) -> map(). +-spec maybe_set_metric_value(ldclient_event:event(), map()) -> map(). maybe_set_metric_value(#{metric_value := MetricValue}, OutputEvent) -> OutputEvent#{<<"metricValue">> => MetricValue}; maybe_set_metric_value(_, OutputEvent) -> OutputEvent. --spec format_summary_event(eld_event_server:summary_event()) -> map(). +-spec format_summary_event(ldclient_event_server:summary_event()) -> map(). format_summary_event(SummaryEvent) when map_size(SummaryEvent) == 0 -> #{}; format_summary_event(#{start_date := StartDate, end_date := EndDate, counters := Counters}) -> #{ @@ -257,11 +258,11 @@ format_summary_event(#{start_date := StartDate, end_date := EndDate, counters := <<"features">> => format_summary_event_counters(Counters) }. --spec format_summary_event_counters(eld_event_server:counters()) -> map(). +-spec format_summary_event_counters(ldclient_event_server:counters()) -> map(). format_summary_event_counters(Counters) -> maps:fold(fun format_summary_event_counters/3, #{}, Counters). --spec format_summary_event_counters(eld_event_server:counter_key(), eld_event_server:counter_value(), map()) -> +-spec format_summary_event_counters(ldclient_event_server:counter_key(), ldclient_event_server:counter_value(), map()) -> map(). format_summary_event_counters( #{ @@ -302,4 +303,4 @@ send(OutputEvents, PayloadId, Dispatcher, Uri, SdkKey) -> -spec get_local_reg_name(Tag :: atom()) -> atom(). get_local_reg_name(Tag) -> - list_to_atom("eld_event_process_server_" ++ atom_to_list(Tag)). + list_to_atom("ldclient_event_process_server_" ++ atom_to_list(Tag)). diff --git a/src/eld_event_server.erl b/src/ldclient_event_server.erl similarity index 81% rename from src/eld_event_server.erl rename to src/ldclient_event_server.erl index 43168e6..583a504 100644 --- a/src/eld_event_server.erl +++ b/src/ldclient_event_server.erl @@ -3,7 +3,7 @@ %% %% @end %%------------------------------------------------------------------- --module(eld_event_server). +-module(ldclient_event_server). -behaviour(gen_server). @@ -17,7 +17,7 @@ -export([add_event/3, flush/1]). -type state() :: #{ - events := [eld_event:event()], + events := [ldclient_event:event()], summary_event := summary_event(), capacity := pos_integer(), inline_users => boolean(), @@ -37,14 +37,14 @@ }. -type counter_key() :: #{ - key := eld_flag:key(), + key := ldclient_flag:key(), variation := non_neg_integer(), version := non_neg_integer() }. -type counter_value() :: #{ count := non_neg_integer(), - flag_value := eld_eval:result_value(), + flag_value := ldclient_eval:result_value(), flag_default := term() }. @@ -66,7 +66,7 @@ %% Events are not sent immediately. They are kept in buffer up to configured %% size and flushed at configured interval. %% @end --spec add_event(Tag :: atom(), Event :: eld_event:event(), Options :: options()) -> +-spec add_event(Tag :: atom(), Event :: ldclient_event:event(), Options :: options()) -> ok. add_event(Tag, Event, Options) when is_atom(Tag) -> ServerName = get_local_reg_name(Tag), @@ -98,11 +98,11 @@ start_link(Tag) -> {ok, State :: state()} | {ok, State :: state(), timeout() | hibernate} | {stop, Reason :: term()} | ignore. init([Tag]) -> - FlushInterval = eld_settings:get_value(Tag, events_flush_interval), - Capacity = eld_settings:get_value(Tag, events_capacity), - InlineUsers = eld_settings:get_value(Tag, inline_users_in_events), + FlushInterval = ldclient_settings:get_value(Tag, events_flush_interval), + Capacity = ldclient_settings:get_value(Tag, events_capacity), + InlineUsers = ldclient_settings:get_value(Tag, inline_users_in_events), TimerRef = erlang:send_after(FlushInterval, self(), {flush, Tag}), - OfflineMode = eld:is_offline(Tag), + OfflineMode = ldclient:is_offline(Tag), % Need to trap exit so supervisor:terminate_child calls terminate callback process_flag(trap_exit, true), State = #{ @@ -131,7 +131,7 @@ handle_call({add_event, Event, Tag, Options}, _From, #{events := Events, summary {reply, ok, State#{events := NewEvents, summary_event := NewSummaryEvent}}; handle_call({flush, Tag}, _From, #{events := Events, summary_event := SummaryEvent, flush_interval := FlushInterval, timer_ref := TimerRef} = State) -> _ = erlang:cancel_timer(TimerRef), - ok = eld_event_process_server:send_events(Tag, Events, SummaryEvent), + ok = ldclient_event_process_server:send_events(Tag, Events, SummaryEvent), NewTimerRef = erlang:send_after(FlushInterval, self(), {flush, Tag}), {reply, ok, State#{events := [], summary_event := #{}, timer_ref := NewTimerRef}}. @@ -139,7 +139,7 @@ handle_cast(_Request, State) -> {noreply, State}. handle_info({flush, Tag}, #{events := Events, summary_event := SummaryEvent, flush_interval := FlushInterval} = State) -> - ok = eld_event_process_server:send_events(Tag, Events, SummaryEvent), + ok = ldclient_event_process_server:send_events(Tag, Events, SummaryEvent), TimerRef = erlang:send_after(FlushInterval, self(), {flush, Tag}), {noreply, State#{events := [], summary_event := #{}, timer_ref := TimerRef}}; handle_info(_Info, State) -> @@ -161,8 +161,8 @@ code_change(_OldVsn, State, _Extra) -> %% Internal functions %%=================================================================== --spec add_event(atom(), eld_event:event(), options(), [eld_event:event()], summary_event(), pos_integer(), boolean()) -> - {[eld_event:event()], summary_event()}. +-spec add_event(atom(), ldclient_event:event(), options(), [ldclient_event:event()], summary_event(), pos_integer(), boolean()) -> + {[ldclient_event:event()], summary_event()}. add_event(Tag, #{type := feature_request, user := User, timestamp := Timestamp} = Event, Options, Events, SummaryEvent, Capacity, InlineUsers) -> AddFull = should_add_full_event(Event), AddDebug = should_add_debug_event(Event), @@ -179,15 +179,15 @@ add_event(Tag, #{type := custom, user := User, timestamp := Timestamp} = Event, EventsWithIndex = maybe_add_index_event(Tag, User, Timestamp, Events, Capacity, AddIndex), {add_raw_event(Event, EventsWithIndex, Capacity), SummaryEvent}. --spec add_raw_event(eld_event:event(), [eld_event:event()], pos_integer()) -> - [eld_event:event()]. +-spec add_raw_event(ldclient_event:event(), [ldclient_event:event()], pos_integer()) -> + [ldclient_event:event()]. add_raw_event(Event, Events, Capacity) when length(Events) < Capacity -> [Event|Events]; add_raw_event(_, Events, _) -> error_logger:warning_msg("Exceeded event queue capacity. Increase capacity to avoid dropping events."), Events. --spec add_feature_request_event(eld_event:event(), summary_event()) -> +-spec add_feature_request_event(ldclient_event:event(), summary_event()) -> summary_event(). add_feature_request_event( #{ @@ -242,49 +242,49 @@ add_feature_request_event( end_date => NewEndDate }. --spec should_add_full_event(eld_event:event()) -> boolean(). +-spec should_add_full_event(ldclient_event:event()) -> boolean(). should_add_full_event(#{data := #{track_events := true}}) -> true; should_add_full_event(_) -> false. --spec maybe_add_feature_request_full_fidelity(boolean(), eld_event:event(), options(), [eld_event:event()], pos_integer()) -> - [eld_event:event()]. +-spec maybe_add_feature_request_full_fidelity(boolean(), ldclient_event:event(), options(), [ldclient_event:event()], pos_integer()) -> + [ldclient_event:event()]. maybe_add_feature_request_full_fidelity(true, Event, #{include_reasons := true}, Events, Capacity) -> add_raw_event(Event, Events, Capacity); maybe_add_feature_request_full_fidelity(true, #{data := #{include_reason := true}} = Event, _Options, Events, Capacity) -> add_raw_event(Event, Events, Capacity); maybe_add_feature_request_full_fidelity(true, Event, _Options, Events, Capacity) -> - add_raw_event(eld_event:strip_eval_reason(Event), Events, Capacity); + add_raw_event(ldclient_event:strip_eval_reason(Event), Events, Capacity); maybe_add_feature_request_full_fidelity(false, _Event, _Options, Events, _Capacity) -> Events. --spec maybe_add_index_event(atom(), eld_user:user(), non_neg_integer(), [eld_event:event()], pos_integer(), boolean()) -> - [eld_event:event()]. +-spec maybe_add_index_event(atom(), ldclient_user:user(), non_neg_integer(), [ldclient_event:event()], pos_integer(), boolean()) -> + [ldclient_event:event()]. maybe_add_index_event(_, _, _, Events, _, false) -> Events; maybe_add_index_event(Tag, User, Timestamp, Events, Capacity, true) -> - case eld_user_cache:notice_user(Tag, User) of + case ldclient_user_cache:notice_user(Tag, User) of true -> Events; false -> add_index_event(User, Timestamp, Events, Capacity) end. --spec add_index_event(User :: eld_user:user(), Timestamp :: non_neg_integer(), Events :: [eld_event:event()], pos_integer()) -> - [eld_event:event()]. +-spec add_index_event(User :: ldclient_user:user(), Timestamp :: non_neg_integer(), Events :: [ldclient_event:event()], pos_integer()) -> + [ldclient_event:event()]. add_index_event(User, Timestamp, Events, Capacity) -> - IndexEvent = eld_event:new_index(User, Timestamp), + IndexEvent = ldclient_event:new_index(User, Timestamp), add_raw_event(IndexEvent, Events, Capacity). --spec should_add_debug_event(eld_event:event()) -> boolean(). +-spec should_add_debug_event(ldclient_event:event()) -> boolean(). should_add_debug_event(#{data := #{debug_events_until_date := null}}) -> false; should_add_debug_event(#{data := #{debug_events_until_date := DebugDate}}) -> Now = erlang:system_time(milli_seconds), DebugDate > Now. --spec maybe_add_debug_event(boolean(), eld_event:event(), [eld_event:event()], pos_integer()) -> - [eld_event:event()]. +-spec maybe_add_debug_event(boolean(), ldclient_event:event(), [ldclient_event:event()], pos_integer()) -> + [ldclient_event:event()]. maybe_add_debug_event(false, _, Events, _) -> Events; maybe_add_debug_event(true, #{data := EventData} = FeatureEvent, Events, Capacity) -> add_raw_event(FeatureEvent#{data := EventData#{debug => true}}, Events, Capacity). --spec create_summary_event_key(eld_flag:key(), eld_flag:variation(), eld_flag:version()) -> +-spec create_summary_event_key(ldclient_flag:key(), ldclient_flag:variation(), ldclient_flag:version()) -> counter_key(). create_summary_event_key(Key, Variation, Version) -> #{ @@ -293,7 +293,7 @@ create_summary_event_key(Key, Variation, Version) -> version => Version }. --spec create_summary_event_value(eld_eval:result_value(), term()) -> +-spec create_summary_event_value(ldclient_eval:result_value(), term()) -> counter_value(). create_summary_event_value(Value, Default) -> #{ @@ -304,4 +304,4 @@ create_summary_event_value(Value, Default) -> -spec get_local_reg_name(Tag :: atom()) -> atom(). get_local_reg_name(Tag) -> - list_to_atom("eld_event_server_" ++ atom_to_list(Tag)). + list_to_atom("ldclient_event_server_" ++ atom_to_list(Tag)). diff --git a/src/eld_event_sup.erl b/src/ldclient_event_sup.erl similarity index 79% rename from src/eld_event_sup.erl rename to src/ldclient_event_sup.erl index 69fac93..3feb91f 100644 --- a/src/eld_event_sup.erl +++ b/src/ldclient_event_sup.erl @@ -4,7 +4,7 @@ %% @end %%------------------------------------------------------------------- --module(eld_event_sup). +-module(ldclient_event_sup). -behaviour(supervisor). @@ -35,9 +35,9 @@ init([Tag]) -> -spec children(Tag :: atom()) -> [supervisor:child_spec()]. children(Tag) -> - UserCacheName = eld_user_cache:get_local_reg_name(Tag), - UserKeysCapacity = eld_settings:get_value(Tag, user_keys_capacity), + UserCacheName = ldclient_user_cache:get_local_reg_name(Tag), + UserKeysCapacity = ldclient_settings:get_value(Tag, user_keys_capacity), UserCacheWorker = ?CHILD(lru, lru, [{local, UserCacheName}, UserKeysCapacity, []], worker), - EventStorageWorker = ?CHILD(eld_event_server, eld_event_server, [Tag], worker), - EventProcessWorker = ?CHILD(eld_event_process_server, eld_event_process_server, [Tag], worker), + EventStorageWorker = ?CHILD(ldclient_event_server, ldclient_event_server, [Tag], worker), + EventProcessWorker = ?CHILD(ldclient_event_process_server, ldclient_event_process_server, [Tag], worker), [UserCacheWorker, EventStorageWorker, EventProcessWorker]. diff --git a/src/eld_flag.erl b/src/ldclient_flag.erl similarity index 93% rename from src/eld_flag.erl rename to src/ldclient_flag.erl index 316248e..9e85b33 100644 --- a/src/eld_flag.erl +++ b/src/ldclient_flag.erl @@ -4,7 +4,7 @@ %% @end %%------------------------------------------------------------------- --module(eld_flag). +-module(ldclient_flag). %% API -export([new/1]). @@ -19,7 +19,7 @@ off_variation => variation(), on => boolean(), prerequisites => [prerequisite()], - rules => [eld_rule:rule()], + rules => [ldclient_rule:rule()], salt => binary(), targets => [target()], track_events => boolean(), @@ -34,7 +34,7 @@ -type variation() :: non_neg_integer() | null. %% Variation index --type variation_or_rollout() :: variation() | eld_rollout:rollout(). +-type variation_or_rollout() :: variation() | ldclient_rollout:rollout(). %% Contains either the fixed variation or percent rollout to serve -type prerequisite() :: #{ @@ -44,7 +44,7 @@ %% Describes a requirement that another feature flag return a specific variation -type target() :: #{ - values => [eld_user:key()], + values => [ldclient_user:key()], variation => variation() }. %% Describes a set of users who will receive a specific variation @@ -148,10 +148,10 @@ parse_prerequisites(Prerequisites) -> end, lists:foldr(F, [], Prerequisites). --spec parse_rules([map()]) -> [eld_rule:rule()]. +-spec parse_rules([map()]) -> [ldclient_rule:rule()]. parse_rules(Rules) -> F = fun(#{<<"clauses">> := Clauses} = Rule, Acc) when is_list(Clauses) -> - [eld_rule:new(Rule)|Acc]; + [ldclient_rule:new(Rule)|Acc]; (_, Acc) -> Acc end, @@ -169,5 +169,5 @@ parse_targets(Targets) -> -spec parse_variation_or_rollout(map()) -> variation_or_rollout(). parse_variation_or_rollout(#{<<"variation">> := Variation}) when is_integer(Variation) -> Variation; parse_variation_or_rollout(#{<<"rollout">> := #{<<"variations">> := Variations} = Rollout}) when is_list(Variations) -> - eld_rollout:new(Rollout); -parse_variation_or_rollout(_) -> eld_rollout:new(#{<<"variations">> => []}). + ldclient_rollout:new(Rollout); +parse_variation_or_rollout(_) -> ldclient_rollout:new(#{<<"variations">> => []}). diff --git a/src/eld_instance.erl b/src/ldclient_instance.erl similarity index 73% rename from src/eld_instance.erl rename to src/ldclient_instance.erl index b5c07af..955d414 100644 --- a/src/eld_instance.erl +++ b/src/ldclient_instance.erl @@ -1,12 +1,12 @@ %%------------------------------------------------------------------- -%% @doc `eld_instance' module +%% @doc `ldclient_instance' module %% %% @end %%------------------------------------------------------------------- --module(eld_instance). +-module(ldclient_instance). --include("eld_update_processor_state.hrl"). +-include("ldclient_update_processor_state.hrl"). %% API -export([start/3]). @@ -23,7 +23,7 @@ events_dispatcher => atom(), user_keys_capacity => pos_integer(), inline_users_in_events => boolean(), - private_attributes => eld_settings:private_attributes(), + private_attributes => ldclient_settings:private_attributes(), stream => boolean(), polling_interval => pos_integer(), polling_update_requestor => atom() @@ -44,15 +44,15 @@ start(Tag, SdkKey, Options) -> % TODO check if Tag already exists and return already_started error % Parse options into settings - Settings = eld_settings:parse_options(SdkKey, Options), - ok = eld_settings:register(Tag, Settings), + Settings = ldclient_settings:parse_options(SdkKey, Options), + ok = ldclient_settings:register(Tag, Settings), % Start instance supervisor SupName = get_ref_from_tag(instance, Tag), StartStream = maps:get(stream, Settings), UpdateSupName = get_ref_from_tag(instance_stream, Tag), UpdateWorkerModule = get_update_processor(StartStream, maps:get(offline, Settings)), EventsSupName = get_ref_from_tag(instance_events, Tag), - {ok, _} = supervisor:start_child(eld_sup, [SupName, UpdateSupName, UpdateWorkerModule, EventsSupName, Tag]), + {ok, _} = supervisor:start_child(ldclient_sup, [SupName, UpdateSupName, UpdateWorkerModule, EventsSupName, Tag]), % Start storage backend StorageBackend = maps:get(storage_backend, Settings), ok = StorageBackend:init(SupName, Tag, []), @@ -68,22 +68,22 @@ stop(Tag) when is_atom(Tag) -> % TODO only stop stream instance if it's running % Terminate stream StreamSupName = get_ref_from_tag(instance_stream, Tag), - ok = eld_updater:stop(StreamSupName), + ok = ldclient_updater:stop(StreamSupName), % Terminate storage - StorageBackend = eld_settings:get_value(Tag, storage_backend), + StorageBackend = ldclient_settings:get_value(Tag, storage_backend), ok = StorageBackend:terminate(Tag), % Terminate instance supervisors SupName = get_ref_from_tag(instance, Tag), SupPid = erlang:whereis(SupName), - ok = supervisor:terminate_child(eld_sup, SupPid), - eld_settings:unregister(Tag). + ok = supervisor:terminate_child(ldclient_sup, SupPid), + ldclient_settings:unregister(Tag). %% @doc Stop all client instances %% %% @end -spec stop_all() -> ok. stop_all() -> - Tags = eld_settings:get_registered_tags(), + Tags = ldclient_settings:get_registered_tags(), lists:foreach(fun stop/1, Tags). %% @doc Whether an instance's update processor has initialized @@ -91,7 +91,7 @@ stop_all() -> %% @end -spec update_processor_initialized(Tag :: atom()) -> boolean(). update_processor_initialized(Tag) -> - eld_update_processor_state:get_initialized_state(Tag). + ldclient_update_processor_state:get_initialized_state(Tag). %%=================================================================== %% Internal functions @@ -103,11 +103,11 @@ update_processor_initialized(Tag) -> %% @end -spec get_ref_from_tag(atom(), Tag :: atom()) -> atom(). get_ref_from_tag(instance, Tag) when is_atom(Tag) -> - list_to_atom("eld_instance_" ++ atom_to_list(Tag)); + list_to_atom("ldclient_instance_" ++ atom_to_list(Tag)); get_ref_from_tag(instance_stream, Tag) when is_atom(Tag) -> - list_to_atom("eld_instance_stream_" ++ atom_to_list(Tag)); + list_to_atom("ldclient_instance_stream_" ++ atom_to_list(Tag)); get_ref_from_tag(instance_events, Tag) when is_atom(Tag) -> - list_to_atom("eld_instance_events_" ++ atom_to_list(Tag)). + list_to_atom("ldclient_instance_events_" ++ atom_to_list(Tag)). %% @doc Initialize update processor client and start listening %% @private @@ -116,13 +116,13 @@ get_ref_from_tag(instance_events, Tag) when is_atom(Tag) -> -spec start_updater(atom(), atom(), atom()) -> ok. start_updater(UpdateSupName, UpdateWorkerModule, Tag) -> - ok = eld_updater:start(UpdateSupName, UpdateWorkerModule, Tag). + ok = ldclient_updater:start(UpdateSupName, UpdateWorkerModule, Tag). %% @doc Get update processor module name depending on settings %% @private %% %% @end -spec get_update_processor(Stream :: boolean(), Offline :: boolean()) -> atom(). -get_update_processor(_Stream, true) -> eld_update_null_server; -get_update_processor(true, _Offline) -> eld_update_stream_server; -get_update_processor(false, _Offline) -> eld_update_poll_server. +get_update_processor(_Stream, true) -> ldclient_update_null_server; +get_update_processor(true, _Offline) -> ldclient_update_stream_server; +get_update_processor(false, _Offline) -> ldclient_update_poll_server. diff --git a/src/eld_instance_sup.erl b/src/ldclient_instance_sup.erl similarity index 87% rename from src/eld_instance_sup.erl rename to src/ldclient_instance_sup.erl index 395e7e9..2a33c47 100644 --- a/src/eld_instance_sup.erl +++ b/src/ldclient_instance_sup.erl @@ -4,7 +4,7 @@ %% @end %%------------------------------------------------------------------- --module(eld_instance_sup). +-module(ldclient_instance_sup). -behaviour(supervisor). @@ -46,6 +46,6 @@ init([UpdateSupName, UpdateWorkerModule, EventSupName, Tag]) -> Tag :: atom() ) -> [supervisor:child_spec()]. children(UpdateSupName, UpdateWorkerModule, EventSupName, Tag) -> - UpdateSup = ?CHILD(eld_update_sup, eld_update_sup, [UpdateSupName, UpdateWorkerModule], supervisor), - EventSup = ?CHILD(eld_event_sup, eld_event_sup, [EventSupName, Tag], supervisor), + UpdateSup = ?CHILD(ldclient_update_sup, ldclient_update_sup, [UpdateSupName, UpdateWorkerModule], supervisor), + EventSup = ?CHILD(ldclient_event_sup, ldclient_event_sup, [EventSupName, Tag], supervisor), [UpdateSup, EventSup]. diff --git a/src/eld_rollout.erl b/src/ldclient_rollout.erl similarity index 85% rename from src/eld_rollout.erl rename to src/ldclient_rollout.erl index 279323c..0bf76d2 100644 --- a/src/eld_rollout.erl +++ b/src/ldclient_rollout.erl @@ -4,7 +4,7 @@ %% @end %%------------------------------------------------------------------- --module(eld_rollout). +-module(ldclient_rollout). %% API -export([new/1]). @@ -14,12 +14,12 @@ %% Types -type rollout() :: #{ variations => [weighted_variation()], - bucket_by => eld_user:attribute() + bucket_by => ldclient_user:attribute() }. %% Describes how users will be bucketed into variations during a percentage rollout -type weighted_variation() :: #{ - variation => eld_flag:variation(), + variation => ldclient_flag:variation(), weight => non_neg_integer() % 0 to 100000 }. %% Describes a fraction of users who will receive a specific variation @@ -45,15 +45,15 @@ new(#{<<"variations">> := Variations}) -> bucket_by => key }. --spec rollout_user(rollout(), eld_flag:flag(), eld_user:user()) -> eld_flag:variation() | null. +-spec rollout_user(rollout(), ldclient_flag:flag(), ldclient_user:user()) -> ldclient_flag:variation() | null. rollout_user(#{variations := WeightedVariations, bucket_by := BucketBy}, #{key := FlagKey, salt := FlagSalt}, User) -> Bucket = bucket_user(FlagKey, FlagSalt, User, BucketBy), match_weighted_variations(Bucket, WeightedVariations). --spec bucket_user(eld_flag:key(), binary(), eld_user:user(), eld_user:attribute()) -> float(). +-spec bucket_user(ldclient_flag:key(), binary(), ldclient_user:user(), ldclient_user:attribute()) -> float(). bucket_user(Key, Salt, User, BucketBy) -> - UserValue = eld_user:get(BucketBy, User), - UserSecondary = eld_user:get(secondary, User), + UserValue = ldclient_user:get(BucketBy, User), + UserSecondary = ldclient_user:get(secondary, User), bucket_user_value(Key, Salt, bucketable_value(UserValue), UserSecondary). %%=================================================================== @@ -71,12 +71,12 @@ parse_variations(Variations) -> end, lists:foldr(F, [], Variations). --spec match_weighted_variations(float(), [weighted_variation()]) -> eld_flag:variation(). +-spec match_weighted_variations(float(), [weighted_variation()]) -> ldclient_flag:variation(). match_weighted_variations(_, []) -> null; match_weighted_variations(Bucket, WeightedVariations) -> match_weighted_variations(Bucket, WeightedVariations, 0.0). --spec match_weighted_variations(float(), [weighted_variation()], float()) -> eld_flag:variation(). +-spec match_weighted_variations(float(), [weighted_variation()], float()) -> ldclient_flag:variation(). match_weighted_variations(_Bucket, [], _Sum) -> null; match_weighted_variations(_Bucket, [#{variation := Variation}|[]], _Sum) -> Variation; match_weighted_variations(Bucket, [#{variation := Variation, weight := Weight}|_], Sum) @@ -85,7 +85,7 @@ match_weighted_variations(Bucket, [#{variation := Variation, weight := Weight}|_ match_weighted_variations(Bucket, [#{weight := Weight}|Rest], Sum) -> match_weighted_variations(Bucket, Rest, Sum + Weight / 100000). --spec bucket_user_value(eld_flag:key(), binary(), binary() | null, binary()) -> float(). +-spec bucket_user_value(ldclient_flag:key(), binary(), binary() | null, binary()) -> float(). bucket_user_value(_Key, _Salt, null, _Secondary) -> 0.0; bucket_user_value(Key, Salt, UserAttribute, null) -> bucket_hash(<>); diff --git a/src/eld_rule.erl b/src/ldclient_rule.erl similarity index 76% rename from src/eld_rule.erl rename to src/ldclient_rule.erl index d86fab5..1d7d838 100644 --- a/src/eld_rule.erl +++ b/src/ldclient_rule.erl @@ -4,7 +4,7 @@ %% @end %%------------------------------------------------------------------- --module(eld_rule). +-module(ldclient_rule). %% API -export([new/1]). @@ -13,9 +13,9 @@ %% Types -type rule() :: #{ id => binary(), - clauses => [eld_clause:clause()], + clauses => [ldclient_clause:clause()], track_events => boolean(), - variation_or_rollout => eld_flag:variation_or_rollout() + variation_or_rollout => ldclient_flag:variation_or_rollout() }. %% Expresses a set of AND-ed matching conditions for a user, along with either %% a fixed variation or a set of rollout percentages @@ -39,7 +39,7 @@ new(RawRuleMap) -> %% @doc Match all clauses to user, includes segment_match %% %% @end --spec match_user(rule(), User :: eld_user:user(), StorageBackend :: atom(), Tag :: atom()) -> match | no_match. +-spec match_user(rule(), User :: ldclient_user:user(), StorageBackend :: atom(), Tag :: atom()) -> match | no_match. match_user(#{clauses := Clauses}, User, StorageBackend, Tag) -> check_clauses(Clauses, User, StorageBackend, Tag). @@ -57,23 +57,23 @@ new_from_template(#{<<"id">> := Id, <<"clauses">> := Clauses, <<"trackEvents">> id => Id, clauses => parse_clauses(Clauses), track_events => TrackEvents, - variation_or_rollout => eld_rollout:new(Rollout) + variation_or_rollout => ldclient_rollout:new(Rollout) }; new_from_template(#{<<"id">> := Id, <<"clauses">> := Clauses, <<"trackEvents">> := TrackEvents}) -> #{id => Id, clauses => parse_clauses(Clauses), track_events => TrackEvents, variation_or_rollout => 0}. --spec parse_clauses([map()]) -> [eld_clause:clause()]. +-spec parse_clauses([map()]) -> [ldclient_clause:clause()]. parse_clauses(Clauses) -> - F = fun(Clause) -> eld_clause:new(Clause) end, + F = fun(Clause) -> ldclient_clause:new(Clause) end, lists:map(F, Clauses). --spec check_clauses([eld_clause:clause()], eld_user:user(), atom(), atom()) -> match | no_match. +-spec check_clauses([ldclient_clause:clause()], ldclient_user:user(), atom(), atom()) -> match | no_match. check_clauses([], _User, _StorageBackend, _Tag) -> match; check_clauses([Clause|Rest], User, StorageBackend, Tag) -> - Result = eld_clause:match_user(Clause, User, StorageBackend, Tag), + Result = ldclient_clause:match_user(Clause, User, StorageBackend, Tag), check_clause_result(Result, Rest, User, StorageBackend, Tag). --spec check_clause_result(match | no_match, [eld_clause:clause()], eld_user:user(), atom(), atom()) -> match | no_match. +-spec check_clause_result(match | no_match, [ldclient_clause:clause()], ldclient_user:user(), atom(), atom()) -> match | no_match. check_clause_result(no_match, _Rest, _User, _StorageBackend, _Tag) -> no_match; check_clause_result(match, Rest, User, StorageBackend, Tag) -> check_clauses(Rest, User, StorageBackend, Tag). diff --git a/src/eld_segment.erl b/src/ldclient_segment.erl similarity index 87% rename from src/eld_segment.erl rename to src/ldclient_segment.erl index 4e97ea5..f5026a6 100644 --- a/src/eld_segment.erl +++ b/src/ldclient_segment.erl @@ -4,7 +4,7 @@ %% @end %%------------------------------------------------------------------- --module(eld_segment). +-module(ldclient_segment). %% API -export([new/1]). @@ -22,9 +22,9 @@ }. -type rule() :: #{ - clauses => [eld_clause:clause()], + clauses => [ldclient_clause:clause()], weight => null | non_neg_integer(), - bucket_by => eld_user:attribute(), + bucket_by => ldclient_user:attribute(), segment_key => binary(), segment_salt => binary() }. @@ -49,7 +49,7 @@ new(RawSegmentMap) -> SegmentMap = maps:merge(SegmentTemplate, RawSegmentMap), new_from_template(SegmentMap). --spec match_user(segment(), eld_user:user()) -> match | no_match. +-spec match_user(segment(), ldclient_user:user()) -> match | no_match. match_user(Segment, User) -> check_user_in_segment(Segment, User). @@ -97,9 +97,9 @@ parse_rule_optional_attributes(Rule, RuleRaw) -> BucketBy = maps:get(<<"bucketBy">>, RuleRaw, key), Rule#{weight => Weight, bucket_by => BucketBy}. --spec parse_clauses([map()]) -> [eld_clause:clause()]. +-spec parse_clauses([map()]) -> [ldclient_clause:clause()]. parse_clauses(Clauses) -> - F = fun(Clause) -> eld_clause:new(Clause) end, + F = fun(Clause) -> ldclient_clause:new(Clause) end, lists:map(F, Clauses). check_user_in_segment(Segment, User) -> @@ -134,18 +134,18 @@ check_rule(#{clauses := Clauses} = Rule, User) -> Result = check_clauses(Clauses, User), check_clauses_result(Result, Rule, User). --spec check_clauses([eld_clause:clause()], eld_user:user()) -> match | no_match. +-spec check_clauses([ldclient_clause:clause()], ldclient_user:user()) -> match | no_match. check_clauses([], _User) -> match; check_clauses([Clause|Rest], User) -> % Non-segment match - Result = eld_clause:match_user(Clause, User), + Result = ldclient_clause:match_user(Clause, User), check_clause_result(Result, Rest, User). check_clauses_result(no_match, _Rule, _User) -> no_match; check_clauses_result(match, Rule, User) -> check_rule_weight(Rule, User). --spec check_clause_result(match | no_match, [eld_clause:clause()], eld_user:user()) -> match | no_match. +-spec check_clause_result(match | no_match, [ldclient_clause:clause()], ldclient_user:user()) -> match | no_match. check_clause_result(no_match, _Rest, _User) -> no_match; check_clause_result(match, Rest, User) -> check_clauses(Rest, User). @@ -155,7 +155,7 @@ check_rule_weight(Rule, User) -> check_user_bucket(Rule, User). check_user_bucket(#{segment_key := SegmentKey, segment_salt := SegmentSalt, bucket_by := BucketBy, weight := Weight}, User) -> - Bucket = eld_rollout:bucket_user(SegmentKey, SegmentSalt, User, BucketBy), + Bucket = ldclient_rollout:bucket_user(SegmentKey, SegmentSalt, User, BucketBy), check_user_bucket_result(Bucket, Weight). check_user_bucket_result(Bucket, Weight) when Bucket < Weight / 100000 -> match; diff --git a/src/eld_settings.erl b/src/ldclient_settings.erl similarity index 88% rename from src/eld_settings.erl rename to src/ldclient_settings.erl index ab4fe2f..aafc8c1 100644 --- a/src/eld_settings.erl +++ b/src/ldclient_settings.erl @@ -1,11 +1,11 @@ %%------------------------------------------------------------------- -%% @doc `eld_settings' module +%% @doc `ldclient_settings' module %% %% Acts as a storage interface for SDK client instance settings. %% @end %%------------------------------------------------------------------- --module(eld_settings). +-module(ldclient_settings). %% API -export([init/0]). @@ -37,7 +37,7 @@ }. % Settings stored for each running SDK instance --type private_attributes() :: all | [eld_user:attribute()]. +-type private_attributes() :: all | [ldclient_user:attribute()]. -export_type([private_attributes/0]). @@ -45,18 +45,18 @@ -define(DEFAULT_BASE_URI, "https://app.launchdarkly.com"). -define(DEFAULT_EVENTS_URI, "https://events.launchdarkly.com"). -define(DEFAULT_STREAM_URI, "https://stream.launchdarkly.com"). --define(DEFAULT_STORAGE_BACKEND, eld_storage_ets). +-define(DEFAULT_STORAGE_BACKEND, ldclient_storage_ets). -define(DEFAULT_EVENTS_CAPACITY, 10000). -define(DEFAULT_EVENTS_FLUSH_INTERVAL, 30000). --define(DEFAULT_EVENTS_DISPATCHER, eld_event_dispatch_httpc). +-define(DEFAULT_EVENTS_DISPATCHER, ldclient_event_dispatch_httpc). -define(DEFAULT_USER_KEYS_CAPACITY, 1000). -define(DEFAULT_INLINE_USERS_IN_EVENTS, false). -define(DEFAULT_PRIVATE_ATTRIBUTES, []). -define(DEFAULT_STREAM, true). --define(DEFAULT_POLLING_UPDATE_REQUESTOR, eld_update_requestor_httpc). +-define(DEFAULT_POLLING_UPDATE_REQUESTOR, ldclient_update_requestor_httpc). -define(MINIMUM_POLLING_INTERVAL, 30). -define(USER_AGENT, "ErlangClient"). --define(VERSION, "1.0.0-beta1"). +-define(VERSION, "1.0.0-beta2"). -define(EVENT_SCHEMA, "3"). -define(DEFAULT_OFFLINE, false). @@ -70,8 +70,8 @@ %% @end -spec init() -> ok. init() -> - ok = eld_update_processor_state:init(), - application:set_env(eld, instances, #{}). + ok = ldclient_update_processor_state:init(), + application:set_env(ldclient, instances, #{}). %% @doc Parses given map of options %% @private @@ -129,7 +129,7 @@ get_registered_tags() -> %% @end -spec get_value(Tag :: atom(), Key :: atom()) -> undefined | term(). get_value(Tag, Key) when is_atom(Tag), is_atom(Key) -> - {ok, Instances} = application:get_env(eld, instances), + {ok, Instances} = application:get_env(ldclient, instances), InstanceSettings = maps:get(Tag, Instances), maps:get(Key, InstanceSettings). @@ -140,7 +140,7 @@ get_value(Tag, Key) when is_atom(Tag), is_atom(Key) -> register(Tag, Settings) when is_atom(Tag), is_map(Settings) -> Instances = get_all(), NewInstances = Instances#{Tag => Settings}, - application:set_env(eld, instances, NewInstances). + application:set_env(ldclient, instances, NewInstances). %% @doc Unregister settings for a client instance %% @@ -148,7 +148,7 @@ register(Tag, Settings) when is_atom(Tag), is_map(Settings) -> -spec unregister(Tag :: atom()) -> ok. unregister(Tag) when is_atom(Tag) -> NewInstances = maps:remove(Tag, get_all()), - application:set_env(eld, instances, NewInstances). + application:set_env(ldclient, instances, NewInstances). -spec get_user_agent() -> string(). get_user_agent() -> @@ -164,5 +164,5 @@ get_event_schema() -> -spec get_all() -> #{Tag :: atom() => instance()}. get_all() -> - {ok, Instances} = application:get_env(eld, instances), + {ok, Instances} = application:get_env(ldclient, instances), Instances. diff --git a/src/eld_storage_engine.erl b/src/ldclient_storage_engine.erl similarity index 97% rename from src/eld_storage_engine.erl rename to src/ldclient_storage_engine.erl index 89f999f..69ad794 100644 --- a/src/eld_storage_engine.erl +++ b/src/ldclient_storage_engine.erl @@ -1,12 +1,12 @@ %%------------------------------------------------------------------- -%% @doc `eld_storage_engine' module +%% @doc `ldclient_storage_engine' module %% %% This is a behavior that all storage engines must implement. It works with %% the concept of buckets and keys. %% @end %%------------------------------------------------------------------- --module(eld_storage_engine). +-module(ldclient_storage_engine). %% Types -type event_operation() :: put | patch | delete. diff --git a/src/eld_storage_ets.erl b/src/ldclient_storage_ets.erl similarity index 78% rename from src/eld_storage_ets.erl rename to src/ldclient_storage_ets.erl index 5de49bd..099f333 100644 --- a/src/eld_storage_ets.erl +++ b/src/ldclient_storage_ets.erl @@ -1,13 +1,13 @@ %%------------------------------------------------------------------- -%% @doc `eld_storage_ets' module +%% @doc `ldclient_storage_ets' module %% %% Provides implementation of ETS storage backend behavior. %% @end %%------------------------------------------------------------------- --module(eld_storage_ets). +-module(ldclient_storage_ets). --behaviour(eld_storage_engine). +-behaviour(ldclient_storage_engine). %% Helper macro for declaring children of supervisor -define(CHILD(Id, Module, Args, Type), {Id, {Module, start_link, Args}, permanent, 5000, Type, [Module]}). @@ -31,7 +31,7 @@ init(SupRef, Tag, _) -> SupRegName = get_local_reg_name(supervisor, Tag), WorkerRegName = get_local_reg_name(worker, Tag), - StorageSup = ?CHILD(eld_storage_ets_sup, eld_storage_ets_sup, [SupRegName, WorkerRegName], supervisor), + StorageSup = ?CHILD(ldclient_storage_ets_sup, ldclient_storage_ets_sup, [SupRegName, WorkerRegName], supervisor), {ok, _} = supervisor:start_child(SupRef, StorageSup), % Pre-create flags and segments buckets ok = create(Tag, flags), @@ -42,42 +42,42 @@ init(SupRef, Tag, _) -> {error, already_exists, string()}. create(Tag, Bucket) -> ServerRef = get_local_reg_name(worker, Tag), - eld_storage_ets_server:create(ServerRef, Bucket). + ldclient_storage_ets_server:create(ServerRef, Bucket). -spec empty(Tag :: atom(), Bucket :: atom()) -> ok | {error, bucket_not_found, string()}. empty(Tag, Bucket) -> ServerRef = get_local_reg_name(worker, Tag), - eld_storage_ets_server:empty(ServerRef, Bucket). + ldclient_storage_ets_server:empty(ServerRef, Bucket). -spec get(Tag :: atom(), Bucket :: atom(), Key :: binary()) -> [{Key :: binary(), Value :: any()}] | {error, bucket_not_found, string()}. get(Tag, Bucket, Key) -> ServerRef = get_local_reg_name(worker, Tag), - eld_storage_ets_server:get(ServerRef, Bucket, Key). + ldclient_storage_ets_server:get(ServerRef, Bucket, Key). -spec list(Tag :: atom(), Bucket :: atom()) -> [{Key :: binary(), Value :: any()}] | {error, bucket_not_found, string()}. list(Tag, Bucket) -> ServerRef = get_local_reg_name(worker, Tag), - eld_storage_ets_server:list(ServerRef, Bucket). + ldclient_storage_ets_server:list(ServerRef, Bucket). -spec put(Tag :: atom(), Bucket :: atom(), Items :: #{Key :: binary() => Value :: any()}) -> ok | {error, bucket_not_found, string()}. put(Tag, Bucket, Items) -> ServerRef = get_local_reg_name(worker, Tag), - eld_storage_ets_server:put(ServerRef, Bucket, Items). + ldclient_storage_ets_server:put(ServerRef, Bucket, Items). -spec put_clean(Tag :: atom(), Bucket :: atom(), Items :: #{Key :: binary() => Value :: any()}) -> ok | {error, bucket_not_found, string()}. put_clean(Tag, Bucket, Items) -> ServerRef = get_local_reg_name(worker, Tag), - eld_storage_ets_server:put_clean(ServerRef, Bucket, Items). + ldclient_storage_ets_server:put_clean(ServerRef, Bucket, Items). -spec terminate(Tag :: atom()) -> ok. terminate(_Tag) -> ok. @@ -88,6 +88,6 @@ terminate(_Tag) -> ok. -spec get_local_reg_name(atom(), Tag :: atom()) -> atom(). get_local_reg_name(supervisor, Tag) -> - list_to_atom("eld_storage_ets_sup_" ++ atom_to_list(Tag)); + list_to_atom("ldclient_storage_ets_sup_" ++ atom_to_list(Tag)); get_local_reg_name(worker, Tag) -> - list_to_atom("eld_storage_ets_server_" ++ atom_to_list(Tag)). + list_to_atom("ldclient_storage_ets_server_" ++ atom_to_list(Tag)). diff --git a/src/eld_storage_ets_server.erl b/src/ldclient_storage_ets_server.erl similarity index 98% rename from src/eld_storage_ets_server.erl rename to src/ldclient_storage_ets_server.erl index 6daea4e..e5b7ed6 100644 --- a/src/eld_storage_ets_server.erl +++ b/src/ldclient_storage_ets_server.erl @@ -1,11 +1,11 @@ %%------------------------------------------------------------------- -%% @doc `eld_storage_ets_server' module +%% @doc `ldclient_storage_ets_server' module %% %% This is a simple in-memory implementation of an storage server using ETS. %% @end %%------------------------------------------------------------------- --module(eld_storage_ets_server). +-module(ldclient_storage_ets_server). -behaviour(gen_server). diff --git a/src/eld_storage_ets_sup.erl b/src/ldclient_storage_ets_sup.erl similarity index 87% rename from src/eld_storage_ets_sup.erl rename to src/ldclient_storage_ets_sup.erl index 32a33ed..d1596c2 100644 --- a/src/eld_storage_ets_sup.erl +++ b/src/ldclient_storage_ets_sup.erl @@ -1,11 +1,11 @@ %%------------------------------------------------------------------- -%% @doc `eld_storage_ets_sup' module +%% @doc `ldclient_storage_ets_sup' module %% %% This is a supervisor for ETS storage worker. %% @end %%------------------------------------------------------------------- --module(eld_storage_ets_sup). +-module(ldclient_storage_ets_sup). -behaviour(supervisor). @@ -35,5 +35,5 @@ init([WorkerRegName]) -> -spec children(WorkerRegName :: atom()) -> [supervisor:child_spec()]. children(WorkerRegName) -> - FlagStorageServer = ?CHILD(eld_storage_ets_server, eld_storage_ets_server, [WorkerRegName], worker), + FlagStorageServer = ?CHILD(ldclient_storage_ets_server, ldclient_storage_ets_server, [WorkerRegName], worker), [FlagStorageServer]. diff --git a/src/eld_storage_map.erl b/src/ldclient_storage_map.erl similarity index 78% rename from src/eld_storage_map.erl rename to src/ldclient_storage_map.erl index 22c692b..4d0a746 100644 --- a/src/eld_storage_map.erl +++ b/src/ldclient_storage_map.erl @@ -1,13 +1,13 @@ %%------------------------------------------------------------------- -%% @doc `eld_storage_map' module +%% @doc `ldclient_storage_map' module %% %% Provides implementation of storage backend using Erlang map. %% @end %%------------------------------------------------------------------- --module(eld_storage_map). +-module(ldclient_storage_map). --behaviour(eld_storage_engine). +-behaviour(ldclient_storage_engine). %% Helper macro for declaring children of supervisor -define(CHILD(Id, Module, Args, Type), {Id, {Module, start_link, Args}, permanent, 5000, Type, [Module]}). @@ -31,7 +31,7 @@ init(SupRef, Tag, _) -> SupRegName = get_local_reg_name(supervisor, Tag), WorkerRegName = get_local_reg_name(worker, Tag), - StorageMapSup = ?CHILD(eld_storage_map_sup, eld_storage_map_sup, [SupRegName, WorkerRegName], supervisor), + StorageMapSup = ?CHILD(ldclient_storage_map_sup, ldclient_storage_map_sup, [SupRegName, WorkerRegName], supervisor), {ok, _} = supervisor:start_child(SupRef, StorageMapSup), % Pre-create flags and segments buckets ok = create(Tag, flags), @@ -42,42 +42,42 @@ init(SupRef, Tag, _) -> {error, already_exists, string()}. create(Tag, Bucket) -> ServerRef = get_local_reg_name(worker, Tag), - eld_storage_map_server:create(ServerRef, Bucket). + ldclient_storage_map_server:create(ServerRef, Bucket). -spec empty(Tag :: atom(), Bucket :: atom()) -> ok | {error, bucket_not_found, string()}. empty(Tag, Bucket) -> ServerRef = get_local_reg_name(worker, Tag), - eld_storage_map_server:empty(ServerRef, Bucket). + ldclient_storage_map_server:empty(ServerRef, Bucket). -spec get(Tag :: atom(), Bucket :: atom(), Key :: binary()) -> [{Key :: binary(), Value :: any()}] | {error, bucket_not_found, string()}. get(Tag, Bucket, Key) -> ServerRef = get_local_reg_name(worker, Tag), - eld_storage_map_server:get(ServerRef, Bucket, Key). + ldclient_storage_map_server:get(ServerRef, Bucket, Key). -spec list(Tag :: atom(), Bucket :: atom()) -> [{Key :: binary(), Value :: any()}] | {error, bucket_not_found, string()}. list(Tag, Bucket) -> ServerRef = get_local_reg_name(worker, Tag), - eld_storage_map_server:list(ServerRef, Bucket). + ldclient_storage_map_server:list(ServerRef, Bucket). -spec put(Tag :: atom(), Bucket :: atom(), Items :: #{Key :: binary() => Value :: any()}) -> ok | {error, bucket_not_found, string()}. put(Tag, Bucket, Items) -> ServerRef = get_local_reg_name(worker, Tag), - eld_storage_map_server:put(ServerRef, Bucket, Items). + ldclient_storage_map_server:put(ServerRef, Bucket, Items). -spec put_clean(Tag :: atom(), Bucket :: atom(), Items :: #{Key :: binary() => Value :: any()}) -> ok | {error, bucket_not_found, string()}. put_clean(Tag, Bucket, Items) -> ServerRef = get_local_reg_name(worker, Tag), - eld_storage_map_server:put_clean(ServerRef, Bucket, Items). + ldclient_storage_map_server:put_clean(ServerRef, Bucket, Items). -spec terminate(Tag :: atom()) -> ok. terminate(_Tag) -> ok. @@ -88,6 +88,6 @@ terminate(_Tag) -> ok. -spec get_local_reg_name(atom(), Tag :: atom()) -> atom(). get_local_reg_name(supervisor, Tag) -> - list_to_atom("eld_storage_map_sup_" ++ atom_to_list(Tag)); + list_to_atom("ldclient_storage_map_sup_" ++ atom_to_list(Tag)); get_local_reg_name(worker, Tag) -> - list_to_atom("eld_storage_map_server_" ++ atom_to_list(Tag)). + list_to_atom("ldclient_storage_map_server_" ++ atom_to_list(Tag)). diff --git a/src/eld_storage_map_server.erl b/src/ldclient_storage_map_server.erl similarity index 99% rename from src/eld_storage_map_server.erl rename to src/ldclient_storage_map_server.erl index ffaba0b..11fa993 100644 --- a/src/eld_storage_map_server.erl +++ b/src/ldclient_storage_map_server.erl @@ -1,12 +1,12 @@ %%------------------------------------------------------------------- -%% @doc `eld_storage_map_server' module +%% @doc `ldclient_storage_map_server' module %% %% This is a simple in-memory implementation of an storage server using Erlang %% map. %% @end %%------------------------------------------------------------------- --module(eld_storage_map_server). +-module(ldclient_storage_map_server). -behaviour(gen_server). diff --git a/src/eld_storage_map_sup.erl b/src/ldclient_storage_map_sup.erl similarity index 87% rename from src/eld_storage_map_sup.erl rename to src/ldclient_storage_map_sup.erl index 46824e5..971a657 100644 --- a/src/eld_storage_map_sup.erl +++ b/src/ldclient_storage_map_sup.erl @@ -1,11 +1,11 @@ %%------------------------------------------------------------------- -%% @doc `eld_storage_map_sup' module +%% @doc `ldclient_storage_map_sup' module %% %% This is a supervisor for map storage worker. %% @end %%------------------------------------------------------------------- --module(eld_storage_map_sup). +-module(ldclient_storage_map_sup). -behaviour(supervisor). @@ -35,5 +35,5 @@ init([WorkerRegName]) -> -spec children(WorkerRegName :: atom()) -> [supervisor:child_spec()]. children(WorkerRegName) -> - FlagStorageServer = ?CHILD(eld_storage_map_server, eld_storage_map_server, [WorkerRegName], worker), + FlagStorageServer = ?CHILD(ldclient_storage_map_server, ldclient_storage_map_server, [WorkerRegName], worker), [FlagStorageServer]. diff --git a/src/eld_sup.erl b/src/ldclient_sup.erl similarity index 87% rename from src/eld_sup.erl rename to src/ldclient_sup.erl index 0a835e7..977035f 100644 --- a/src/eld_sup.erl +++ b/src/ldclient_sup.erl @@ -4,7 +4,7 @@ %% @end %%------------------------------------------------------------------- --module(eld_sup). +-module(ldclient_sup). -behaviour(supervisor). @@ -26,11 +26,11 @@ init([]) -> MaxRestart = 10, MaxTime = 3600, ChildSpec = { - eld_instance_sup, - {eld_instance_sup, start_link, []}, + ldclient_instance_sup, + {ldclient_instance_sup, start_link, []}, permanent, 5000, % shutdown time supervisor, - [eld_instance_sup] + [ldclient_instance_sup] }, {ok, {{simple_one_for_one, MaxRestart, MaxTime}, [ChildSpec]}}. diff --git a/src/eld_update_null_server.erl b/src/ldclient_update_null_server.erl similarity index 96% rename from src/eld_update_null_server.erl rename to src/ldclient_update_null_server.erl index 96f0aab..2957969 100644 --- a/src/eld_update_null_server.erl +++ b/src/ldclient_update_null_server.erl @@ -4,10 +4,10 @@ %% @end %%------------------------------------------------------------------- --module(eld_update_null_server). +-module(ldclient_update_null_server). -behaviour(gen_server). --behaviour(eld_update_server). +-behaviour(ldclient_update_server). %% Supervision -export([start_link/1, init/1]). diff --git a/src/eld_update_poll_server.erl b/src/ldclient_update_poll_server.erl similarity index 89% rename from src/eld_update_poll_server.erl rename to src/ldclient_update_poll_server.erl index 61aa644..cc3e446 100644 --- a/src/eld_update_poll_server.erl +++ b/src/ldclient_update_poll_server.erl @@ -4,10 +4,10 @@ %% @end %%------------------------------------------------------------------- --module(eld_update_poll_server). +-module(ldclient_update_poll_server). -behaviour(gen_server). --behaviour(eld_update_server). +-behaviour(ldclient_update_server). %% Supervision -export([start_link/1, init/1]). @@ -65,11 +65,11 @@ start_link(Tag) -> {ok, State :: state()} | {ok, State :: state(), timeout() | hibernate} | {stop, Reason :: term()} | ignore. init([Tag]) -> - SdkKey = eld_settings:get_value(Tag, sdk_key), - StorageBackend = eld_settings:get_value(Tag, storage_backend), - Requestor = eld_settings:get_value(Tag, polling_update_requestor), - PollUri = eld_settings:get_value(Tag, base_uri) ++ ?LATEST_ALL_PATH, - PollInterval = eld_settings:get_value(Tag, polling_interval) * 1000, + SdkKey = ldclient_settings:get_value(Tag, sdk_key), + StorageBackend = ldclient_settings:get_value(Tag, storage_backend), + Requestor = ldclient_settings:get_value(Tag, polling_update_requestor), + PollUri = ldclient_settings:get_value(Tag, base_uri) ++ ?LATEST_ALL_PATH, + PollInterval = ldclient_settings:get_value(Tag, polling_interval) * 1000, % Need to trap exit so supervisor:terminate_child calls terminate callback process_flag(trap_exit, true), State = #{ @@ -133,10 +133,10 @@ poll(#{ sdk_key := SdkKey, storage_tag := Tag } = State) -> {Result, NewRequestorState} = Requestor:all(Uri, SdkKey, RequestorState), ok = process_response(Result, StorageBackend, Tag, Uri), - true = eld_update_processor_state:set_initialized_state(Tag, true), + true = ldclient_update_processor_state:set_initialized_state(Tag, true), State#{requestor_state := NewRequestorState}. --spec process_response(eld_update_requestor:response(), atom(), atom(), string()) -> ok. +-spec process_response(ldclient_update_requestor:response(), atom(), atom(), string()) -> ok. process_response({error, {bad_status, 401, _Reason}}, _, _, Uri) -> error_logger:warning_msg("Invalid SDK key when when polling for updates at URL ~p. Verify that your SDK key is correct.", [Uri]), ok; diff --git a/src/eld_update_processor_state.erl b/src/ldclient_update_processor_state.erl similarity index 88% rename from src/eld_update_processor_state.erl rename to src/ldclient_update_processor_state.erl index 24bccf1..1920a93 100644 --- a/src/eld_update_processor_state.erl +++ b/src/ldclient_update_processor_state.erl @@ -1,12 +1,12 @@ %%------------------------------------------------------------------- -%% @doc `eld_update_processor_state' module +%% @doc `ldclient_update_processor_state' module %% %% @end %%------------------------------------------------------------------- --module(eld_update_processor_state). +-module(ldclient_update_processor_state). --include("eld_update_processor_state.hrl"). +-include("ldclient_update_processor_state.hrl"). % API -export([init/0]). @@ -39,4 +39,4 @@ set_initialized_state(Tag, Value) -> -spec get_initialized_state(Tag :: atom()) -> boolean(). get_initialized_state(Tag) -> [{_Tag, Initialized}] = ets:lookup(?UPDATE_PROCESSOR_INITIALIZATION_TABLE, Tag), - Initialized. \ No newline at end of file + Initialized. diff --git a/src/ldclient_update_processor_state.hrl b/src/ldclient_update_processor_state.hrl new file mode 100644 index 0000000..e50f39d --- /dev/null +++ b/src/ldclient_update_processor_state.hrl @@ -0,0 +1,2 @@ +% Constants +-define(UPDATE_PROCESSOR_INITIALIZATION_TABLE, ldclient_update_processor_initialization). diff --git a/src/eld_update_requestor.erl b/src/ldclient_update_requestor.erl similarity index 92% rename from src/eld_update_requestor.erl rename to src/ldclient_update_requestor.erl index ebee938..523af4c 100644 --- a/src/eld_update_requestor.erl +++ b/src/ldclient_update_requestor.erl @@ -1,12 +1,12 @@ %%------------------------------------------------------------------- -%% @doc `eld_update_requestor' module +%% @doc `ldclient_update_requestor' module %% %% This is a behavior that event dispatchers must implement. It is used to send %% event batches to LaunchDarkly. %% @end %%------------------------------------------------------------------- --module(eld_update_requestor). +-module(ldclient_update_requestor). -type response() :: {ok, binary() | not_modified} | {error, errors()}. diff --git a/src/eld_update_requestor_httpc.erl b/src/ldclient_update_requestor_httpc.erl similarity index 84% rename from src/eld_update_requestor_httpc.erl rename to src/ldclient_update_requestor_httpc.erl index 6b91640..de41529 100644 --- a/src/eld_update_requestor_httpc.erl +++ b/src/ldclient_update_requestor_httpc.erl @@ -4,9 +4,9 @@ %% @end %%------------------------------------------------------------------- --module(eld_update_requestor_httpc). +-module(ldclient_update_requestor_httpc). --behaviour(eld_update_requestor). +-behaviour(ldclient_update_requestor). %% Behavior callbacks -export([init/0, all/3]). @@ -26,12 +26,12 @@ init() -> #{}. %% %% @end -spec all(Uri :: string(), SdkKey :: string(), State :: state()) -> - {eld_update_requestor:response(), state()}. + {ldclient_update_requestor:response(), state()}. all(Uri, SdkKey, State) -> Headers = [ {"Authorization", SdkKey}, - {"X-LaunchDarkly-Event-Schema", eld_settings:get_event_schema()}, - {"User-Agent", eld_settings:get_user_agent()} + {"X-LaunchDarkly-Event-Schema", ldclient_settings:get_event_schema()}, + {"User-Agent", ldclient_settings:get_user_agent()} ], ETagHeaders = case maps:find(Uri, State) of error -> Headers; @@ -58,6 +58,6 @@ all(Uri, SdkKey, State) -> %% Internal functions %%=================================================================== --spec bad_status_error(StatusLine :: httpc:status_line()) -> eld_update_requestor:errors(). +-spec bad_status_error(StatusLine :: httpc:status_line()) -> ldclient_update_requestor:errors(). bad_status_error({Version, StatusCode, ReasonPhrase}) -> {bad_status, StatusCode, io_lib:format("~s ~b ~s", [Version, StatusCode, ReasonPhrase])}. diff --git a/src/eld_update_server.erl b/src/ldclient_update_server.erl similarity index 81% rename from src/eld_update_server.erl rename to src/ldclient_update_server.erl index a95562e..13001a8 100644 --- a/src/eld_update_server.erl +++ b/src/ldclient_update_server.erl @@ -1,11 +1,11 @@ %%------------------------------------------------------------------- -%% @doc `eld_update_server' module +%% @doc `ldclient_update_server' module %% %% This is a behavior that update processors must implement. %% @end %%------------------------------------------------------------------- --module(eld_update_server). +-module(ldclient_update_server). %% `listen' must make the worker start listening for flag and segment updates. -callback listen(Pid :: pid()) -> ok. diff --git a/src/eld_update_stream_server.erl b/src/ldclient_update_stream_server.erl similarity index 93% rename from src/eld_update_stream_server.erl rename to src/ldclient_update_stream_server.erl index 413d052..db9f962 100644 --- a/src/eld_update_stream_server.erl +++ b/src/ldclient_update_stream_server.erl @@ -4,10 +4,10 @@ %% @end %%------------------------------------------------------------------- --module(eld_update_stream_server). +-module(ldclient_update_stream_server). -behaviour(gen_server). --behaviour(eld_update_server). +-behaviour(ldclient_update_server). %% Supervision -export([start_link/1, init/1]). @@ -61,9 +61,9 @@ start_link(Tag) -> {ok, State :: state()} | {ok, State :: state(), timeout() | hibernate} | {stop, Reason :: term()} | ignore. init([Tag]) -> - SdkKey = eld_settings:get_value(Tag, sdk_key), - StreamUri = eld_settings:get_value(Tag, stream_uri) ++ "/all", - StorageBackend = eld_settings:get_value(Tag, storage_backend), + SdkKey = ldclient_settings:get_value(Tag, sdk_key), + StreamUri = ldclient_settings:get_value(Tag, stream_uri) ++ "/all", + StorageBackend = ldclient_settings:get_value(Tag, storage_backend), Backoff = backoff:type(backoff:init(100, 30000, self(), listen), jitter), % Need to trap exit so supervisor:terminate_child calls terminate callback process_flag(trap_exit, true), @@ -177,7 +177,7 @@ do_listen(Uri, StorageBackend, Tag, SdkKey) -> Options = #{async => true, async_mode => sse, handle_event => F}, Headers = #{ "Authorization" => SdkKey, - "User-Agent" => eld_settings:get_user_agent() + "User-Agent" => ldclient_settings:get_user_agent() }, case shotgun:get(Pid, Path ++ Query, Headers, Options) of {error, Reason} -> @@ -197,16 +197,16 @@ process_event(#{event := Event, data := Data}, StorageBackend, Tag) -> EventOperation = get_event_operation(Event), DecodedData = decode_data(EventOperation, Data), ProcessResult = process_items(EventOperation, DecodedData, StorageBackend, Tag), - true = eld_update_processor_state:set_initialized_state(Tag, true), + true = ldclient_update_processor_state:set_initialized_state(Tag, true), ProcessResult. --spec get_event_operation(Event :: binary()) -> eld_storage_engine:event_operation() | other. +-spec get_event_operation(Event :: binary()) -> ldclient_storage_engine:event_operation() | other. get_event_operation(<<"put">>) -> put; get_event_operation(<<"delete">>) -> delete; get_event_operation(<<"patch">>) -> patch; get_event_operation(_) -> other. --spec decode_data(eld_storage_engine:event_operation() | other, binary()) -> map() | binary(). +-spec decode_data(ldclient_storage_engine:event_operation() | other, binary()) -> map() | binary(). decode_data(other, Data) -> Data; decode_data(_, Data) -> jsx:decode(Data, [return_maps]). @@ -214,7 +214,7 @@ decode_data(_, Data) -> jsx:decode(Data, [return_maps]). %% @private %% %% @end --spec process_items(EventOperation :: eld_storage_engine:event_operation(), Data :: map(), StorageBackend :: atom(), Tag :: atom()) -> ok. +-spec process_items(EventOperation :: ldclient_storage_engine:event_operation(), Data :: map(), StorageBackend :: atom(), Tag :: atom()) -> ok. process_items(put, Data, StorageBackend, Tag) -> [Flags, Segments] = get_put_items(Data), error_logger:info_msg("Received event with ~p flags and ~p segments", [maps:size(Flags), maps:size(Segments)]), diff --git a/src/eld_update_sup.erl b/src/ldclient_update_sup.erl similarity index 97% rename from src/eld_update_sup.erl rename to src/ldclient_update_sup.erl index 5570438..4e66213 100644 --- a/src/eld_update_sup.erl +++ b/src/ldclient_update_sup.erl @@ -4,7 +4,7 @@ %% @end %%------------------------------------------------------------------- --module(eld_update_sup). +-module(ldclient_update_sup). -behaviour(supervisor). diff --git a/src/eld_updater.erl b/src/ldclient_updater.erl similarity index 96% rename from src/eld_updater.erl rename to src/ldclient_updater.erl index 01c8276..ea97c7d 100644 --- a/src/eld_updater.erl +++ b/src/ldclient_updater.erl @@ -1,11 +1,11 @@ %%------------------------------------------------------------------- -%% @doc `eld_updater' module +%% @doc `ldclient_updater' module %% %% Used to start and stop client stream listener. %% @end %%------------------------------------------------------------------- --module(eld_updater). +-module(ldclient_updater). %% API -export([start/3]). diff --git a/src/eld_user.erl b/src/ldclient_user.erl similarity index 98% rename from src/eld_user.erl rename to src/ldclient_user.erl index 4adff33..b310b03 100644 --- a/src/eld_user.erl +++ b/src/ldclient_user.erl @@ -4,7 +4,7 @@ %% @end %%------------------------------------------------------------------- --module(eld_user). +-module(ldclient_user). %% API -export([new/1]). @@ -91,7 +91,7 @@ set_private_attribute_names(AttributeNames, User) when is_list(AttributeNames) - %% Returns the scrubbed user and the list of attributes that were actually %% scrubbed. %% @end --spec scrub(user(), eld_settings:private_attributes()) -> {user(), private_attribute_names()}. +-spec scrub(user(), ldclient_settings:private_attributes()) -> {user(), private_attribute_names()}. scrub(User, all) -> AllStandardAttributes = [<<"key">>, <<"secondary">>, <<"ip">>, <<"country">>, <<"email">>, <<"first_name">>, <<"last_name">>, <<"avatar">>, <<"name">>, <<"anonymous">>], AllCustomAttributes = maps:keys(maps:get(custom, User, #{})), diff --git a/src/eld_user_cache.erl b/src/ldclient_user_cache.erl similarity index 85% rename from src/eld_user_cache.erl rename to src/ldclient_user_cache.erl index 8197dd8..28fb36d 100644 --- a/src/eld_user_cache.erl +++ b/src/ldclient_user_cache.erl @@ -4,7 +4,7 @@ %% @end %%------------------------------------------------------------------- --module(eld_user_cache). +-module(ldclient_user_cache). %% API -export([get_local_reg_name/1]). @@ -16,13 +16,13 @@ -spec get_local_reg_name(Tag :: atom()) -> atom(). get_local_reg_name(Tag) -> - list_to_atom("eld_user_cache_" ++ atom_to_list(Tag)). + list_to_atom("ldclient_user_cache_" ++ atom_to_list(Tag)). %% @doc Add to the set of the users we've noticed, and return true if the user %% was already known to us. %% %% @end --spec notice_user(Tag :: atom(), User :: eld_user:user()) -> boolean(). +-spec notice_user(Tag :: atom(), User :: ldclient_user:user()) -> boolean(). notice_user(_Tag, #{key := null}) -> % Null user key always returns true so it's not indexed true; diff --git a/test/eld_clause_SUITE.erl b/test/eld_clause_SUITE.erl deleted file mode 100644 index 427d217..0000000 --- a/test/eld_clause_SUITE.erl +++ /dev/null @@ -1,81 +0,0 @@ --module(eld_clause_SUITE). - --include_lib("common_test/include/ct.hrl"). - -%% ct functions --export([all/0]). --export([init_per_suite/1]). --export([end_per_suite/1]). --export([init_per_testcase/2]). --export([end_per_testcase/2]). - -%% Tests --export([ - check_attribute_against_clause_value/1 -]). - -%%==================================================================== -%% ct functions -%%==================================================================== - -all() -> - [ - check_attribute_against_clause_value - ]. - -init_per_suite(Config) -> - Config. - -end_per_suite(_) -> - ok. - -init_per_testcase(_, Config) -> - Config. - -end_per_testcase(_, _Config) -> - ok. - -%%==================================================================== -%% Helpers -%%==================================================================== - -%%==================================================================== -%% Tests -%%==================================================================== - -check_attribute_against_clause_value(_) -> - % Invalid date types - false = eld_clause:check_attribute_against_clause_value(true, before, 123456789), - false = eld_clause:check_attribute_against_clause_value(123456789, before, [false]), - false = eld_clause:check_attribute_against_clause_value([], before, []), - false = eld_clause:check_attribute_against_clause_value(true, 'after', 123456789), - false = eld_clause:check_attribute_against_clause_value(123456789, 'after', [false]), - false = eld_clause:check_attribute_against_clause_value([], 'after', []), - % Semver equal - true = eld_clause:check_attribute_against_clause_value(<<"2.0.0">>, semver_equal, <<"2.0.0">>), - true = eld_clause:check_attribute_against_clause_value(<<"2.0">>, semver_equal, <<"2.0.0">>), - true = eld_clause:check_attribute_against_clause_value(<<"2">>, semver_equal, <<"2.0.0">>), - true = eld_clause:check_attribute_against_clause_value(<<"2-rc1">>, semver_equal, <<"2.0.0-rc1">>), - true = eld_clause:check_attribute_against_clause_value(<<"2+build2">>, semver_equal, <<"2.0.0+build2">>), - true = eld_clause:check_attribute_against_clause_value(<<"2+build123">>, semver_equal, <<"2.0.0+build2">>), - false = eld_clause:check_attribute_against_clause_value(<<"2.0.0">>, semver_equal, <<"2.0.1">>), - false = eld_clause:check_attribute_against_clause_value(<<"bad.vers.ion">>, semver_equal, <<"2.0.1">>), - % Semver less than - true = eld_clause:check_attribute_against_clause_value(<<"2.0.0">>, semver_less_than, <<"2.0.1">>), - true = eld_clause:check_attribute_against_clause_value(<<"2.0">>, semver_less_than, <<"2.0.1">>), - true = eld_clause:check_attribute_against_clause_value(<<"2">>, semver_less_than, <<"2.0.1">>), - true = eld_clause:check_attribute_against_clause_value(<<"2.0.0-rc">>, semver_less_than, <<"2.0.0-rc.beta">>), - false = eld_clause:check_attribute_against_clause_value(<<"2.0.1">>, semver_less_than, <<"2.0.0">>), - false = eld_clause:check_attribute_against_clause_value(<<"2.0.1">>, semver_less_than, <<"2.0">>), - false = eld_clause:check_attribute_against_clause_value(<<"2.0.1">>, semver_less_than, <<"2">>), - false = eld_clause:check_attribute_against_clause_value(<<"bad.vers.ion">>, semver_less_than, <<"2">>), - % Semver greater than - true = eld_clause:check_attribute_against_clause_value(<<"2.0.1">>, semver_greater_than, <<"2.0.0">>), - true = eld_clause:check_attribute_against_clause_value(<<"2.0.1">>, semver_greater_than, <<"2.0">>), - true = eld_clause:check_attribute_against_clause_value(<<"2.0.1">>, semver_greater_than, <<"2">>), - true = eld_clause:check_attribute_against_clause_value(<<"2.0.0-rc1">>, semver_greater_than, <<"2.0.0-rc0">>), - false = eld_clause:check_attribute_against_clause_value(<<"2.0.0">>, semver_greater_than, <<"2.0.0">>), - false = eld_clause:check_attribute_against_clause_value(<<"2.0.0">>, semver_greater_than, <<"2.0">>), - false = eld_clause:check_attribute_against_clause_value(<<"2.0.0">>, semver_greater_than, <<"2">>), - false = eld_clause:check_attribute_against_clause_value(<<"bad.vers.ion">>, semver_greater_than, <<"2">>), - ok. diff --git a/test/eld_storage_map_SUITE.erl b/test/eld_storage_map_SUITE.erl deleted file mode 100644 index 4ce7b04..0000000 --- a/test/eld_storage_map_SUITE.erl +++ /dev/null @@ -1,159 +0,0 @@ --module(eld_storage_map_SUITE). - --include_lib("common_test/include/ct.hrl"). - -%% ct functions --export([all/0]). --export([init_per_suite/1]). --export([end_per_suite/1]). --export([init_per_testcase/2]). --export([end_per_testcase/2]). - -%% Tests --export([ - server_init/1, - server_bucket_exists/1, - server_get_put/1, - server_put_clean/1, - server_list/1, - server_process_events_put/1, - server_process_events_patch/1 -]). - -%%==================================================================== -%% ct functions -%%==================================================================== - -all() -> - [ - server_init, - server_bucket_exists, - server_get_put, - server_put_clean, - server_list, - server_process_events_put, - server_process_events_patch - ]. - -init_per_suite(Config) -> - {ok, _} = application:ensure_all_started(eld), - Options = #{ - storage_backend => eld_storage_map, - stream => false, - polling_update_requestor => eld_update_requestor_test - }, - eld:start_instance("", Options), - eld:start_instance("", another1, Options), - Config. - -end_per_suite(_) -> - ok = application:stop(eld). - -init_per_testcase(_, Config) -> - Config. - -end_per_testcase(_, _Config) -> - ok = eld_storage_map:empty(default, flags), - ok = eld_storage_map:empty(another1, flags), - ok. - -%%==================================================================== -%% Helpers -%%==================================================================== - -%%==================================================================== -%% Tests -%%==================================================================== - -server_init(_) -> - % Verify flags and segments buckets are pre-created - {error, already_exists, _} = eld_storage_map:create(default, flags), - {error, already_exists, _} = eld_storage_map:create(default, segments), - {error, already_exists, _} = eld_storage_map:create(another1, flags), - {error, already_exists, _} = eld_storage_map:create(another1, segments). - -server_bucket_exists(_) -> - {error, bucket_not_found, _} = eld_storage_map:get(default, eld_testing, <<"testing">>), - ok = eld_storage_map:create(default, eld_testing), - [] = eld_storage_map:get(default, eld_testing, <<"testing">>), - {error, bucket_not_found, _} = eld_storage_map:get(another1, eld_testing, <<"testing">>). - -server_get_put(_) -> - [] = eld_storage_map:get(default, flags, <<"flag1">>), - ok = eld_storage_map:put(default, flags, #{<<"flag1">> => [{<<"value1">>, 0.5}]}), - [] = eld_storage_map:get(another1, flags, <<"flag1">>), - [{<<"flag1">>, [{<<"value1">>, 0.5}]}] = eld_storage_map:get(default, flags, <<"flag1">>), - [] = eld_storage_map:get(another1, flags, <<"flag1">>), - ok = eld_storage_map:put(another1, flags, #{<<"flag1">> => [{<<"valueA">>, 0.9}]}), - [{<<"flag1">>, [{<<"valueA">>, 0.9}]}] = eld_storage_map:get(another1, flags, <<"flag1">>), - [{<<"flag1">>, [{<<"value1">>, 0.5}]}] = eld_storage_map:get(default, flags, <<"flag1">>). - -server_put_clean(_) -> - ok = eld_storage_map:put(default, flags, #{<<"flag1">> => [{<<"value1">>, 0.5}]}), - [{<<"flag1">>, [{<<"value1">>, 0.5}]}] = eld_storage_map:get(default, flags, <<"flag1">>), - ok = eld_storage_map:put_clean(default, flags, #{<<"flag2">> => [{<<"value2">>, 0.9}]}), - [{<<"flag2">>, [{<<"value2">>, 0.9}]}] = eld_storage_map:list(default, flags). - -server_list(_) -> - [] = eld_storage_map:list(default, flags), - [] = eld_storage_map:list(another1, flags), - ok = eld_storage_map:put(default, flags, #{<<"flag1">> => [{<<"value1">>, 0.5}]}), - ok = eld_storage_map:put(default, flags, #{<<"flag2">> => [{<<"value2">>, 0.7}]}), - ok = eld_storage_map:put(another1, flags, #{<<"flag1">> => [{<<"value1">>, 0.9}]}), - ok = eld_storage_map:put(another1, flags, #{<<"flag5">> => [{<<"value2">>, 0.77}]}), - [ - {<<"flag1">>, [{<<"value1">>, 0.5}]}, - {<<"flag2">>, [{<<"value2">>, 0.7}]} - ] = lists:sort(eld_storage_map:list(default, flags)), - [ - {<<"flag1">>, [{<<"value1">>, 0.9}]}, - {<<"flag5">>, [{<<"value2">>, 0.77}]} - ] = lists:sort(eld_storage_map:list(another1, flags)). - -server_process_events_put(_) -> - Event = #{ - <<"path">> => <<"/">>, - <<"data">> => #{ - <<"flags">> => #{ - <<"flag-key-1">> => <<"flag-value-1">>, - <<"flag-key-2">> => <<"flag-value-2">>, - <<"flag-key-3">> => <<"flag-value-3">> - }, - <<"segments">> => #{ - <<"segment-key-1">> => <<"segment-value-1">>, - <<"segment-key-2">> => <<"segment-value-2">> - } - } - }, - ok = eld_update_stream_server:process_items(put, Event, eld_storage_map, default), - [ - {<<"flag-key-1">>, <<"flag-value-1">>}, - {<<"flag-key-2">>, <<"flag-value-2">>}, - {<<"flag-key-3">>, <<"flag-value-3">>} - ] = lists:sort(eld_storage_map:list(default, flags)), - [ - {<<"segment-key-1">>, <<"segment-value-1">>}, - {<<"segment-key-2">>, <<"segment-value-2">>} - ] = lists:sort(eld_storage_map:list(default, segments)). - -server_process_events_patch(_) -> - PutEvent = #{ - <<"path">> => <<"/">>, - <<"data">> => #{ - <<"flags">> => #{ - <<"flag-key-1">> => #{<<"key">> => <<"flag-key-1">>, <<"on">> => true}, - <<"flag-key-2">> => #{<<"key">> => <<"flag-key-2">>, <<"on">> => true} - }, - <<"segments">> => #{} - } - }, - ok = eld_update_stream_server:process_items(put, PutEvent, eld_storage_map, default), - PatchEvent = #{ - <<"path">> => <<"/flags/flag-key-2">>, - <<"data">> => #{<<"key">> => <<"flag-key-2">>, <<"on">> => false} - }, - ok = eld_update_stream_server:process_items(patch, PatchEvent, eld_storage_map, default), - [ - {<<"flag-key-1">>, #{<<"key">> := <<"flag-key-1">>, <<"on">> := true}}, - {<<"flag-key-2">>, #{<<"key">> := <<"flag-key-2">>, <<"on">> := false}} - ] = lists:sort(eld_storage_map:list(default, flags)). diff --git a/test/ldclient_clause_SUITE.erl b/test/ldclient_clause_SUITE.erl new file mode 100644 index 0000000..2224d8b --- /dev/null +++ b/test/ldclient_clause_SUITE.erl @@ -0,0 +1,81 @@ +-module(ldclient_clause_SUITE). + +-include_lib("common_test/include/ct.hrl"). + +%% ct functions +-export([all/0]). +-export([init_per_suite/1]). +-export([end_per_suite/1]). +-export([init_per_testcase/2]). +-export([end_per_testcase/2]). + +%% Tests +-export([ + check_attribute_against_clause_value/1 +]). + +%%==================================================================== +%% ct functions +%%==================================================================== + +all() -> + [ + check_attribute_against_clause_value + ]. + +init_per_suite(Config) -> + Config. + +end_per_suite(_) -> + ok. + +init_per_testcase(_, Config) -> + Config. + +end_per_testcase(_, _Config) -> + ok. + +%%==================================================================== +%% Helpers +%%==================================================================== + +%%==================================================================== +%% Tests +%%==================================================================== + +check_attribute_against_clause_value(_) -> + % Invalid date types + false = ldclient_clause:check_attribute_against_clause_value(true, before, 123456789), + false = ldclient_clause:check_attribute_against_clause_value(123456789, before, [false]), + false = ldclient_clause:check_attribute_against_clause_value([], before, []), + false = ldclient_clause:check_attribute_against_clause_value(true, 'after', 123456789), + false = ldclient_clause:check_attribute_against_clause_value(123456789, 'after', [false]), + false = ldclient_clause:check_attribute_against_clause_value([], 'after', []), + % Semver equal + true = ldclient_clause:check_attribute_against_clause_value(<<"2.0.0">>, semver_equal, <<"2.0.0">>), + true = ldclient_clause:check_attribute_against_clause_value(<<"2.0">>, semver_equal, <<"2.0.0">>), + true = ldclient_clause:check_attribute_against_clause_value(<<"2">>, semver_equal, <<"2.0.0">>), + true = ldclient_clause:check_attribute_against_clause_value(<<"2-rc1">>, semver_equal, <<"2.0.0-rc1">>), + true = ldclient_clause:check_attribute_against_clause_value(<<"2+build2">>, semver_equal, <<"2.0.0+build2">>), + true = ldclient_clause:check_attribute_against_clause_value(<<"2+build123">>, semver_equal, <<"2.0.0+build2">>), + false = ldclient_clause:check_attribute_against_clause_value(<<"2.0.0">>, semver_equal, <<"2.0.1">>), + false = ldclient_clause:check_attribute_against_clause_value(<<"bad.vers.ion">>, semver_equal, <<"2.0.1">>), + % Semver less than + true = ldclient_clause:check_attribute_against_clause_value(<<"2.0.0">>, semver_less_than, <<"2.0.1">>), + true = ldclient_clause:check_attribute_against_clause_value(<<"2.0">>, semver_less_than, <<"2.0.1">>), + true = ldclient_clause:check_attribute_against_clause_value(<<"2">>, semver_less_than, <<"2.0.1">>), + true = ldclient_clause:check_attribute_against_clause_value(<<"2.0.0-rc">>, semver_less_than, <<"2.0.0-rc.beta">>), + false = ldclient_clause:check_attribute_against_clause_value(<<"2.0.1">>, semver_less_than, <<"2.0.0">>), + false = ldclient_clause:check_attribute_against_clause_value(<<"2.0.1">>, semver_less_than, <<"2.0">>), + false = ldclient_clause:check_attribute_against_clause_value(<<"2.0.1">>, semver_less_than, <<"2">>), + false = ldclient_clause:check_attribute_against_clause_value(<<"bad.vers.ion">>, semver_less_than, <<"2">>), + % Semver greater than + true = ldclient_clause:check_attribute_against_clause_value(<<"2.0.1">>, semver_greater_than, <<"2.0.0">>), + true = ldclient_clause:check_attribute_against_clause_value(<<"2.0.1">>, semver_greater_than, <<"2.0">>), + true = ldclient_clause:check_attribute_against_clause_value(<<"2.0.1">>, semver_greater_than, <<"2">>), + true = ldclient_clause:check_attribute_against_clause_value(<<"2.0.0-rc1">>, semver_greater_than, <<"2.0.0-rc0">>), + false = ldclient_clause:check_attribute_against_clause_value(<<"2.0.0">>, semver_greater_than, <<"2.0.0">>), + false = ldclient_clause:check_attribute_against_clause_value(<<"2.0.0">>, semver_greater_than, <<"2.0">>), + false = ldclient_clause:check_attribute_against_clause_value(<<"2.0.0">>, semver_greater_than, <<"2">>), + false = ldclient_clause:check_attribute_against_clause_value(<<"bad.vers.ion">>, semver_greater_than, <<"2">>), + ok. diff --git a/test/eld_eval_SUITE.erl b/test/ldclient_eval_SUITE.erl similarity index 80% rename from test/eld_eval_SUITE.erl rename to test/ldclient_eval_SUITE.erl index a43d68c..aa4aae3 100644 --- a/test/eld_eval_SUITE.erl +++ b/test/ldclient_eval_SUITE.erl @@ -1,4 +1,4 @@ --module(eld_eval_SUITE). +-module(ldclient_eval_SUITE). -include_lib("common_test/include/ct.hrl"). @@ -116,23 +116,23 @@ all() -> ]. init_per_suite(Config) -> - {ok, _} = application:ensure_all_started(eld), + {ok, _} = application:ensure_all_started(ldclient), Options = #{ stream => false, - polling_update_requestor => eld_update_requestor_test + polling_update_requestor => ldclient_update_requestor_test }, OfflineOptions = #{ - polling_update_requestor => eld_update_requestor_test, + polling_update_requestor => ldclient_update_requestor_test, offline => true }, - eld:start_instance("", Options), - eld:start_instance("", another1, Options), - eld:start_instance("", offline, OfflineOptions), + ldclient:start_instance("", Options), + ldclient:start_instance("", another1, Options), + ldclient:start_instance("", offline, OfflineOptions), ok = create_flags(), Config. end_per_suite(_) -> - ok = application:stop(eld). + ok = application:stop(ldclient). init_per_testcase(_, Config) -> Config. @@ -145,12 +145,12 @@ end_per_testcase(_, Config) -> %%==================================================================== create_flags() -> - DataFilename = code:priv_dir(eld) ++ "/flags-segments-put-data.json", - DataFilename2 = code:priv_dir(eld) ++ "/flags-segments-put-data-another1.json", + DataFilename = code:priv_dir(ldclient) ++ "/flags-segments-put-data.json", + DataFilename2 = code:priv_dir(ldclient) ++ "/flags-segments-put-data-another1.json", {ok, PutData} = file:read_file(DataFilename), {ok, PutData2} = file:read_file(DataFilename2), - ok = eld_update_stream_server:process_event(#{event => <<"put">>, data => PutData}, eld_storage_ets, default), - ok = eld_update_stream_server:process_event(#{event => <<"put">>, data => PutData2}, eld_storage_ets, another1). + ok = ldclient_update_stream_server:process_event(#{event => <<"put">>, data => PutData}, ldclient_storage_ets, default), + ok = ldclient_update_stream_server:process_event(#{event => <<"put">>, data => PutData2}, ldclient_storage_ets, another1). extract_events(Events) -> [ @@ -174,11 +174,11 @@ extract_events(Events) -> sdk_offline(_) -> {{null, "foo", {error, client_not_ready}}, []} = - eld_eval:flag_key_for_user(offline, <<"keep-it-off">>, #{key => <<"some-user">>}, "foo"). + ldclient_eval:flag_key_for_user(offline, <<"keep-it-off">>, #{key => <<"some-user">>}, "foo"). unknown_flag(_) -> {{null, "foo", {error, flag_not_found}}, Events} = - eld_eval:flag_key_for_user(default, <<"flag-that-does-not-exist">>, #{key => <<"some-user">>}, "foo"), + ldclient_eval:flag_key_for_user(default, <<"flag-that-does-not-exist">>, #{key => <<"some-user">>}, "foo"), ExpectedEvents = lists:sort([ {<<"flag-that-does-not-exist">>, feature_request, null, "foo", "foo", {error, flag_not_found}, null} ]), @@ -188,7 +188,7 @@ unknown_flag(_) -> unknown_flag_another(_) -> % Flag exists in default instance, doesn't exist in another1 instance {{null, "foo", {error, flag_not_found}}, Events} = - eld_eval:flag_key_for_user(another1, <<"bad-variation">>, #{key => <<"some-user">>}, "foo"), + ldclient_eval:flag_key_for_user(another1, <<"bad-variation">>, #{key => <<"some-user">>}, "foo"), ExpectedEvents = lists:sort([ {<<"bad-variation">>, feature_request, null, "foo", "foo", {error, flag_not_found}, null} ]), @@ -197,7 +197,7 @@ unknown_flag_another(_) -> user_with_no_key(_) -> {{null, "foo", {error, user_not_specified}}, Events} = - eld_eval:flag_key_for_user(default, <<"keep-it-off">>, #{name => <<"some-user">>}, "foo"), + ldclient_eval:flag_key_for_user(default, <<"keep-it-off">>, #{name => <<"some-user">>}, "foo"), ExpectedEvents = lists:sort([ {<<"keep-it-off">>, feature_request, null, "foo", "foo", {error, user_not_specified}, null} ]), @@ -206,7 +206,7 @@ user_with_no_key(_) -> user_with_null_key(_) -> {{null, "foo", {error, user_not_specified}}, Events} = - eld_eval:flag_key_for_user(default, <<"keep-it-off">>, #{key => null}, "foo"), + ldclient_eval:flag_key_for_user(default, <<"keep-it-off">>, #{key => null}, "foo"), ExpectedEvents = lists:sort([ {<<"keep-it-off">>, feature_request, null, "foo", "foo", {error, user_not_specified}, null} ]), @@ -214,32 +214,32 @@ user_with_null_key(_) -> ExpectedEvents = ActualEvents. off_flag(_) -> - {{1, false, off}, Events} = eld_eval:flag_key_for_user(default, <<"keep-it-off">>, #{key => <<"user123">>}, "foo"), + {{1, false, off}, Events} = ldclient_eval:flag_key_for_user(default, <<"keep-it-off">>, #{key => <<"user123">>}, "foo"), ExpectedEvents = lists:sort([{<<"keep-it-off">>, feature_request, 1, false, "foo", off, null}]), ActualEvents = lists:sort(extract_events(Events)), ExpectedEvents = ActualEvents. off_flag_another(_) -> - {{1, false, off}, Events} = eld_eval:flag_key_for_user(another1, <<"keep-it-off">>, #{key => <<"user123">>}, "foo"), + {{1, false, off}, Events} = ldclient_eval:flag_key_for_user(another1, <<"keep-it-off">>, #{key => <<"user123">>}, "foo"), ExpectedEvents = lists:sort([{<<"keep-it-off">>, feature_request, 1, false, "foo", off, null}]), ActualEvents = lists:sort(extract_events(Events)), ExpectedEvents = ActualEvents. off_flag_null_off_variation(_) -> - {{null, "foo", off}, Events} = eld_eval:flag_key_for_user(default, <<"keep-it-off-null-off-variation">>, #{key => <<"user123">>}, "foo"), + {{null, "foo", off}, Events} = ldclient_eval:flag_key_for_user(default, <<"keep-it-off-null-off-variation">>, #{key => <<"user123">>}, "foo"), ExpectedEvents = lists:sort([{<<"keep-it-off-null-off-variation">>, feature_request, null, "foo", "foo", off, null}]), ActualEvents = lists:sort(extract_events(Events)), ExpectedEvents = ActualEvents. deleted_flag(_) -> - {{null, "foo", {error, flag_not_found}}, Events} = eld_eval:flag_key_for_user(default, <<"keep-it-deleted">>, #{key => <<"user123">>}, "foo"), + {{null, "foo", {error, flag_not_found}}, Events} = ldclient_eval:flag_key_for_user(default, <<"keep-it-deleted">>, #{key => <<"user123">>}, "foo"), ExpectedEvents = lists:sort([{<<"keep-it-deleted">>, feature_request, null, "foo", "foo", {error, flag_not_found}, null}]), ActualEvents = lists:sort(extract_events(Events)), ExpectedEvents = ActualEvents. prerequisite_fail_off(_) -> {{1, false, {prerequisite_failed, [<<"keep-it-off">>]}}, Events} = - eld_eval:flag_key_for_user(default, <<"prereqs-fail-off">>, #{key => <<"user123">>}, "foo"), + ldclient_eval:flag_key_for_user(default, <<"prereqs-fail-off">>, #{key => <<"user123">>}, "foo"), ExpectedEvents = lists:sort([ {<<"prereqs-fail-off">>, feature_request, 1, false, "foo", {prerequisite_failed, [<<"keep-it-off">>]}, null} ]), @@ -248,7 +248,7 @@ prerequisite_fail_off(_) -> prerequisite_fail_off_null(_) -> {{null, "foo", {prerequisite_failed, [<<"keep-it-off">>]}}, Events} = - eld_eval:flag_key_for_user(default, <<"prereqs-fail-off-null">>, #{key => <<"user123">>}, "foo"), + ldclient_eval:flag_key_for_user(default, <<"prereqs-fail-off-null">>, #{key => <<"user123">>}, "foo"), ExpectedEvents = lists:sort([ {<<"prereqs-fail-off-null">>, feature_request, null, "foo", "foo", {prerequisite_failed, [<<"keep-it-off">>]}, null} ]), @@ -257,7 +257,7 @@ prerequisite_fail_off_null(_) -> prerequisite_fail_variation(_) -> {{1, false, {prerequisite_failed, [<<"keep-it-on">>]}}, Events} = - eld_eval:flag_key_for_user(default, <<"prereqs-fail-variation">>, #{key => <<"user123">>}, "foo"), + ldclient_eval:flag_key_for_user(default, <<"prereqs-fail-variation">>, #{key => <<"user123">>}, "foo"), ExpectedEvents = lists:sort([ {<<"keep-it-on">>, feature_request, 0, true, null, fallthrough, <<"prereqs-fail-variation">>}, {<<"keep-it-on-two">>, feature_request, 0, true, null, fallthrough, <<"keep-it-on">>}, @@ -268,7 +268,7 @@ prerequisite_fail_variation(_) -> prerequisite_success(_) -> {{1, false, fallthrough}, Events} = - eld_eval:flag_key_for_user(default, <<"prereqs-success">>, #{key => <<"user123">>}, "foo"), + ldclient_eval:flag_key_for_user(default, <<"prereqs-success">>, #{key => <<"user123">>}, "foo"), ExpectedEvents = lists:sort([ {<<"prereqs-success">>, feature_request, 1, false, "foo", fallthrough, null}, {<<"keep-it-on-another">>, feature_request, 0, true, null, fallthrough, <<"prereqs-success">>}, @@ -280,7 +280,7 @@ prerequisite_success(_) -> target_user(_) -> {{0, true, target_match}, Events} = - eld_eval:flag_key_for_user(default, <<"target-me">>, #{key => <<"user-33333">>}, "foo"), + ldclient_eval:flag_key_for_user(default, <<"target-me">>, #{key => <<"user-33333">>}, "foo"), ExpectedEvents = lists:sort([ {<<"target-me">>, feature_request, 0, true, "foo", target_match, null} ]), @@ -290,7 +290,7 @@ target_user(_) -> target_user_another(_) -> % Same user, different instance, different target result {{1, false, target_match}, Events} = - eld_eval:flag_key_for_user(another1, <<"target-me">>, #{key => <<"user-33333">>}, "foo"), + ldclient_eval:flag_key_for_user(another1, <<"target-me">>, #{key => <<"user-33333">>}, "foo"), ExpectedEvents = lists:sort([ {<<"target-me">>, feature_request, 1, false, "foo", target_match, null} ]), @@ -300,7 +300,7 @@ target_user_another(_) -> segment_included(_) -> ExpectedReason = {rule_match, 0, <<"ab4a9fb3-7e85-429f-8078-23aa70094540">>}, {{1, false, ExpectedReason}, Events} = - eld_eval:flag_key_for_user(default, <<"segment-me">>, #{key => <<"user-12345">>}, "foo"), + ldclient_eval:flag_key_for_user(default, <<"segment-me">>, #{key => <<"user-12345">>}, "foo"), ExpectedEvents = lists:sort([ {<<"segment-me">>, feature_request, 1, false, "foo", ExpectedReason, null} ]), @@ -310,7 +310,7 @@ segment_included(_) -> segment_excluded_negated(_) -> ExpectedReason = {rule_match, 1, <<"489a185d-caaf-4db9-b192-e09e927d070c">>}, {{1, false, ExpectedReason}, Events} = - eld_eval:flag_key_for_user(default, <<"segment-me">>, #{key => <<"user-33333">>}, "foo"), + ldclient_eval:flag_key_for_user(default, <<"segment-me">>, #{key => <<"user-33333">>}, "foo"), ExpectedEvents = lists:sort([ {<<"segment-me">>, feature_request, 1, false, "foo", ExpectedReason, null} ]), @@ -321,7 +321,7 @@ segment_excluded_negated_nonuser(_) -> % This user isn't specified in a segment ExpectedReason = {rule_match, 1, <<"489a185d-caaf-4db9-b192-e09e927d070c">>}, {{1, false, ExpectedReason}, Events} = - eld_eval:flag_key_for_user(default, <<"segment-me">>, #{key => <<"user-99999">>}, "foo"), + ldclient_eval:flag_key_for_user(default, <<"segment-me">>, #{key => <<"user-99999">>}, "foo"), ExpectedEvents = lists:sort([ {<<"segment-me">>, feature_request, 1, false, "foo", ExpectedReason, null} ]), @@ -332,7 +332,7 @@ segment_excluded_another(_) -> % Same user, different instance, different segment result ExpectedReason = {rule_match, 1, <<"489a185d-caaf-4db9-b192-e09e927d070c">>}, {{1, false, ExpectedReason}, Events} = - eld_eval:flag_key_for_user(another1, <<"segment-me">>, #{key => <<"user-12345">>}, "foo"), + ldclient_eval:flag_key_for_user(another1, <<"segment-me">>, #{key => <<"user-12345">>}, "foo"), ExpectedEvents = lists:sort([ {<<"segment-me">>, feature_request, 1, false, "foo", ExpectedReason, null} ]), @@ -342,7 +342,7 @@ segment_excluded_another(_) -> rule_match_in(_) -> ExpectedReason = {rule_match, 0, <<"08b9b261-5df6-4881-892b-e25bdb28b6d3">>}, {{0, <<"a">>, ExpectedReason}, Events} = - eld_eval:flag_key_for_user(default, <<"rule-me">>, #{key => <<"user-key-match@example.com">>}, "foo"), + ldclient_eval:flag_key_for_user(default, <<"rule-me">>, #{key => <<"user-key-match@example.com">>}, "foo"), ExpectedEvents = lists:sort([ {<<"rule-me">>, feature_request, 0, <<"a">>, "foo", ExpectedReason, null} ]), @@ -352,7 +352,7 @@ rule_match_in(_) -> rule_match_ends_with(_) -> ExpectedReason = {rule_match, 1, <<"2fac50d0-d912-424a-831e-ab60ad0547b4">>}, {{1, <<"b">>, ExpectedReason}, Events} = - eld_eval:flag_key_for_user(default, <<"rule-me">>, #{key => <<"user-ends-with@example.com">>}, "foo"), + ldclient_eval:flag_key_for_user(default, <<"rule-me">>, #{key => <<"user-ends-with@example.com">>}, "foo"), ExpectedEvents = lists:sort([ {<<"rule-me">>, feature_request, 1, <<"b">>, "foo", ExpectedReason, null} ]), @@ -362,7 +362,7 @@ rule_match_ends_with(_) -> rule_match_ends_and_starts_with_order(_) -> ExpectedReason = {rule_match, 1, <<"2fac50d0-d912-424a-831e-ab60ad0547b4">>}, {{1, <<"b">>, ExpectedReason}, Events} = - eld_eval:flag_key_for_user(default, <<"rule-me">>, #{key => <<"user-starts-with@example.com">>}, "foo"), + ldclient_eval:flag_key_for_user(default, <<"rule-me">>, #{key => <<"user-starts-with@example.com">>}, "foo"), ExpectedEvents = lists:sort([ {<<"rule-me">>, feature_request, 1, <<"b">>, "foo", ExpectedReason, null} ]), @@ -372,7 +372,7 @@ rule_match_ends_and_starts_with_order(_) -> rule_match_starts_with(_) -> ExpectedReason = {rule_match, 2, <<"e3b70ddf-a000-4649-93c5-ac0eaea675f8">>}, {{2, <<"c">>, ExpectedReason}, Events} = - eld_eval:flag_key_for_user(default, <<"rule-me">>, #{key => <<"user-starts-with@foo.com">>}, "foo"), + ldclient_eval:flag_key_for_user(default, <<"rule-me">>, #{key => <<"user-starts-with@foo.com">>}, "foo"), ExpectedEvents = lists:sort([ {<<"rule-me">>, feature_request, 2, <<"c">>, "foo", ExpectedReason, null} ]), @@ -382,7 +382,7 @@ rule_match_starts_with(_) -> rule_match_regex(_) -> ExpectedReason = {rule_match, 3, <<"1d63c99a-3016-4778-bf1f-68d1fce5004e">>}, {{3, <<"d">>, ExpectedReason}, Events} = - eld_eval:flag_key_for_user(default, <<"rule-me">>, #{key => <<"user-regex-match@foo.com">>}, "foo"), + ldclient_eval:flag_key_for_user(default, <<"rule-me">>, #{key => <<"user-regex-match@foo.com">>}, "foo"), ExpectedEvents = lists:sort([ {<<"rule-me">>, feature_request, 3, <<"d">>, "foo", ExpectedReason, null} ]), @@ -392,7 +392,7 @@ rule_match_regex(_) -> rule_match_contains(_) -> ExpectedReason = {rule_match, 4, <<"1f1dadfc-0e66-42e0-b479-979186d972ce">>}, {{4, <<"e">>, ExpectedReason}, Events} = - eld_eval:flag_key_for_user(default, <<"rule-me">>, #{key => <<"user-contains@foo.com">>}, "foo"), + ldclient_eval:flag_key_for_user(default, <<"rule-me">>, #{key => <<"user-contains@foo.com">>}, "foo"), ExpectedEvents = lists:sort([ {<<"rule-me">>, feature_request, 4, <<"e">>, "foo", ExpectedReason, null} ]), @@ -408,7 +408,7 @@ rule_match_less_than(_) -> }, ExpectedReason = {rule_match, 5, <<"ca092500-1cb7-4b14-a11c-81b46ca19cae">>}, {{5, <<"f">>, ExpectedReason}, Events} = - eld_eval:flag_key_for_user(default, <<"rule-me">>, User, "foo"), + ldclient_eval:flag_key_for_user(default, <<"rule-me">>, User, "foo"), ExpectedEvents = lists:sort([ {<<"rule-me">>, feature_request, 5, <<"f">>, "foo", ExpectedReason, null} ]), @@ -424,7 +424,7 @@ rule_match_less_than_or_equal(_) -> }, ExpectedReason = {rule_match, 6, <<"d38e11f8-93d1-453e-8022-6d8ed7f106ea">>}, {{6, <<"g">>, ExpectedReason}, Events} = - eld_eval:flag_key_for_user(default, <<"rule-me">>, User, "foo"), + ldclient_eval:flag_key_for_user(default, <<"rule-me">>, User, "foo"), ExpectedEvents = lists:sort([ {<<"rule-me">>, feature_request, 6, <<"g">>, "foo", ExpectedReason, null} ]), @@ -440,7 +440,7 @@ rule_match_greater_than(_) -> }, ExpectedReason = {rule_match, 7, <<"a92a93c2-2004-482b-9e4a-38abe81d7050">>}, {{7, <<"h">>, ExpectedReason}, Events} = - eld_eval:flag_key_for_user(default, <<"rule-me">>, User, "foo"), + ldclient_eval:flag_key_for_user(default, <<"rule-me">>, User, "foo"), ExpectedEvents = lists:sort([ {<<"rule-me">>, feature_request, 7, <<"h">>, "foo", ExpectedReason, null} ]), @@ -456,7 +456,7 @@ rule_match_greater_than_or_equal(_) -> }, ExpectedReason = {rule_match, 8, <<"9158e01a-a70f-4924-8cf8-9401e2cf6c67">>}, {{8, <<"i">>, ExpectedReason}, Events} = - eld_eval:flag_key_for_user(default, <<"rule-me">>, User, "foo"), + ldclient_eval:flag_key_for_user(default, <<"rule-me">>, User, "foo"), ExpectedEvents = lists:sort([ {<<"rule-me">>, feature_request, 8, <<"i">>, "foo", ExpectedReason, null} ]), @@ -472,7 +472,7 @@ rule_match_before_int(_) -> }, ExpectedReason = {rule_match, 9, <<"500633a7-2c82-4baf-8201-4892b68b31b4">>}, {{9, <<"j">>, ExpectedReason}, Events} = - eld_eval:flag_key_for_user(default, <<"rule-me">>, User, "foo"), + ldclient_eval:flag_key_for_user(default, <<"rule-me">>, User, "foo"), ExpectedEvents = lists:sort([ {<<"rule-me">>, feature_request, 9, <<"j">>, "foo", ExpectedReason, null} ]), @@ -488,7 +488,7 @@ rule_match_after_int(_) -> }, ExpectedReason = {rule_match, 10, <<"77473bea-d93f-4787-84d2-92cf08b35f2b">>}, {{10, <<"k">>, ExpectedReason}, Events} = - eld_eval:flag_key_for_user(default, <<"rule-me">>, User, "foo"), + ldclient_eval:flag_key_for_user(default, <<"rule-me">>, User, "foo"), ExpectedEvents = lists:sort([ {<<"rule-me">>, feature_request, 10, <<"k">>, "foo", ExpectedReason, null} ]), @@ -504,7 +504,7 @@ rule_match_semver_equal(_) -> }, ExpectedReason = {rule_match, 11, <<"9398cafc-0ab7-4d0d-8e01-6683cc4d17ec">>}, {{11, <<"l">>, ExpectedReason}, Events} = - eld_eval:flag_key_for_user(default, <<"rule-me">>, User, "foo"), + ldclient_eval:flag_key_for_user(default, <<"rule-me">>, User, "foo"), ExpectedEvents = lists:sort([ {<<"rule-me">>, feature_request, 11, <<"l">>, "foo", ExpectedReason, null} ]), @@ -520,7 +520,7 @@ rule_match_semver_greater_than(_) -> }, ExpectedReason = {rule_match, 12, <<"3570714f-d03b-4068-ab79-18f15c74382d">>}, {{12, <<"m">>, ExpectedReason}, Events} = - eld_eval:flag_key_for_user(default, <<"rule-me">>, User, "foo"), + ldclient_eval:flag_key_for_user(default, <<"rule-me">>, User, "foo"), ExpectedEvents = lists:sort([ {<<"rule-me">>, feature_request, 12, <<"m">>, "foo", ExpectedReason, null} ]), @@ -536,7 +536,7 @@ rule_match_semver_less_than(_) -> }, ExpectedReason = {rule_match, 13, <<"2c002923-2db0-4fcc-a95e-f3cb5b4bd13d">>}, {{13, <<"n">>, ExpectedReason}, Events} = - eld_eval:flag_key_for_user(default, <<"rule-me">>, User, "foo"), + ldclient_eval:flag_key_for_user(default, <<"rule-me">>, User, "foo"), ExpectedEvents = lists:sort([ {<<"rule-me">>, feature_request, 13, <<"n">>, "foo", ExpectedReason, null} ]), @@ -552,7 +552,7 @@ rule_match_before_date(_) -> }, ExpectedReason = {rule_match, 14, <<"b6c5ceec-364d-4c23-a041-7865f4f136d3">>}, {{14, <<"o">>, ExpectedReason}, Events} = - eld_eval:flag_key_for_user(default, <<"rule-me">>, User, "foo"), + ldclient_eval:flag_key_for_user(default, <<"rule-me">>, User, "foo"), ExpectedEvents = lists:sort([ {<<"rule-me">>, feature_request, 14, <<"o">>, "foo", ExpectedReason, null} ]), @@ -568,7 +568,7 @@ rule_match_after_date(_) -> }, ExpectedReason = {rule_match, 15, <<"764c5346-6478-4d34-83e7-59c0afc7a15b">>}, {{15, <<"p">>, ExpectedReason}, Events} = - eld_eval:flag_key_for_user(default, <<"rule-me">>, User, "foo"), + ldclient_eval:flag_key_for_user(default, <<"rule-me">>, User, "foo"), ExpectedEvents = lists:sort([ {<<"rule-me">>, feature_request, 15, <<"p">>, "foo", ExpectedReason, null} ]), @@ -578,7 +578,7 @@ rule_match_after_date(_) -> rule_nomatch_in_negated_null_attribute(_) -> ExpectedReason = fallthrough, {{0, <<"a">>, ExpectedReason}, Events} = - eld_eval:flag_key_for_user(default, <<"rule-me">>, #{key => <<"no-match">>}, "foo"), + ldclient_eval:flag_key_for_user(default, <<"rule-me">>, #{key => <<"no-match">>}, "foo"), ExpectedEvents = lists:sort([ {<<"rule-me">>, feature_request, 0, <<"a">>, "foo", ExpectedReason, null} ]), @@ -588,7 +588,7 @@ rule_nomatch_in_negated_null_attribute(_) -> fallthrough_rollout(_) -> ExpectedReason = fallthrough, {{1, <<"b">>, ExpectedReason}, Events} = - eld_eval:flag_key_for_user(default, <<"roll-me">>, #{key => <<"user-foo">>, secondary => <<"bar">>}, "foo"), + ldclient_eval:flag_key_for_user(default, <<"roll-me">>, #{key => <<"user-foo">>, secondary => <<"bar">>}, "foo"), ExpectedEvents = lists:sort([ {<<"roll-me">>, feature_request, 1, <<"b">>, "foo", ExpectedReason, null} ]), @@ -604,7 +604,7 @@ fallthrough_rollout_custom(_) -> } }, {{4, <<"e">>, ExpectedReason}, Events} = - eld_eval:flag_key_for_user(default, <<"roll-me-custom">>, User, "foo"), + ldclient_eval:flag_key_for_user(default, <<"roll-me-custom">>, User, "foo"), ExpectedEvents = lists:sort([ {<<"roll-me-custom">>, feature_request, 4, <<"e">>, "foo", ExpectedReason, null} ]), @@ -620,7 +620,7 @@ fallthrough_rollout_custom_integer(_) -> } }, {{4, <<"e">>, ExpectedReason}, Events} = - eld_eval:flag_key_for_user(default, <<"roll-me-custom">>, User, "foo"), + ldclient_eval:flag_key_for_user(default, <<"roll-me-custom">>, User, "foo"), ExpectedEvents = lists:sort([ {<<"roll-me-custom">>, feature_request, 4, <<"e">>, "foo", ExpectedReason, null} ]), @@ -636,7 +636,7 @@ fallthrough_rollout_custom_float(_) -> } }, {{4, <<"e">>, ExpectedReason}, Events} = - eld_eval:flag_key_for_user(default, <<"roll-me-custom">>, User, "foo"), + ldclient_eval:flag_key_for_user(default, <<"roll-me-custom">>, User, "foo"), ExpectedEvents = lists:sort([ {<<"roll-me-custom">>, feature_request, 4, <<"e">>, "foo", ExpectedReason, null} ]), @@ -652,7 +652,7 @@ fallthrough_rollout_custom_float_invalid(_) -> } }, {{0, <<"a">>, ExpectedReason}, Events} = - eld_eval:flag_key_for_user(default, <<"roll-me-custom">>, User, "foo"), + ldclient_eval:flag_key_for_user(default, <<"roll-me-custom">>, User, "foo"), ExpectedEvents = lists:sort([ {<<"roll-me-custom">>, feature_request, 0, <<"a">>, "foo", ExpectedReason, null} ]), @@ -662,7 +662,7 @@ fallthrough_rollout_custom_float_invalid(_) -> fallthrough_rollout_invalid_last_variation(_) -> ExpectedReason = fallthrough, {{1, <<"b">>, ExpectedReason}, Events} = - eld_eval:flag_key_for_user(default, <<"roll-me-invalid">>, #{key => <<"user-foo">>, secondary => <<"bar">>}, "foo"), + ldclient_eval:flag_key_for_user(default, <<"roll-me-invalid">>, #{key => <<"user-foo">>, secondary => <<"bar">>}, "foo"), ExpectedEvents = lists:sort([ {<<"roll-me-invalid">>, feature_request, 1, <<"b">>, "foo", ExpectedReason, null} ]), @@ -671,7 +671,7 @@ fallthrough_rollout_invalid_last_variation(_) -> variation_out_of_range(_) -> {{null, null, {error, malformed_flag}}, Events} = - eld_eval:flag_key_for_user(default, <<"bad-variation">>, #{key => <<"some-user">>}, "foo"), + ldclient_eval:flag_key_for_user(default, <<"bad-variation">>, #{key => <<"some-user">>}, "foo"), ExpectedEvents = lists:sort([ {<<"bad-variation">>, feature_request, null, null, "foo", {error, malformed_flag}, null} ]), @@ -681,7 +681,7 @@ variation_out_of_range(_) -> extra_fields(_) -> ExpectedReason = {rule_match, 0, <<"ab4a9fb3-7e85-429f-8078-23aa70094540">>}, {{1, false, ExpectedReason}, Events} = - eld_eval:flag_key_for_user(default, <<"extra-fields">>, #{key => <<"user-12345">>, secondary => <<"bar">>}, "foo"), + ldclient_eval:flag_key_for_user(default, <<"extra-fields">>, #{key => <<"user-12345">>, secondary => <<"bar">>}, "foo"), ExpectedEvents = lists:sort([ {<<"extra-fields">>, feature_request, 1, false, "foo", ExpectedReason, null} ]), @@ -691,7 +691,7 @@ extra_fields(_) -> missing_some_fields(_) -> ExpectedReason = fallthrough, {{0, true, ExpectedReason}, Events} = - eld_eval:flag_key_for_user(default, <<"missing-some-fields">>, #{key => <<"user-msf">>}, "foo"), + ldclient_eval:flag_key_for_user(default, <<"missing-some-fields">>, #{key => <<"user-msf">>}, "foo"), ExpectedEvents = lists:sort([ {<<"missing-some-fields">>, feature_request, 0, true, "foo", ExpectedReason, null} ]), @@ -701,7 +701,7 @@ missing_some_fields(_) -> missing_all_fields(_) -> ExpectedReason = {error, malformed_flag}, {{null, null, ExpectedReason}, Events} = - eld_eval:flag_key_for_user(default, <<"missing-all-fields">>, #{key => <<"user-maf">>}, "foo"), + ldclient_eval:flag_key_for_user(default, <<"missing-all-fields">>, #{key => <<"user-maf">>}, "foo"), ExpectedEvents = lists:sort([ {<<"missing-all-fields">>, feature_request, null, null, "foo", ExpectedReason, null} ]), diff --git a/test/eld_event_dispatch_test.erl b/test/ldclient_event_dispatch_test.erl similarity index 86% rename from test/eld_event_dispatch_test.erl rename to test/ldclient_event_dispatch_test.erl index 2cb0941..29f1e93 100644 --- a/test/eld_event_dispatch_test.erl +++ b/test/ldclient_event_dispatch_test.erl @@ -4,9 +4,9 @@ %% @end %%------------------------------------------------------------------- --module(eld_event_dispatch_test). +-module(ldclient_event_dispatch_test). --behaviour(eld_event_dispatch). +-behaviour(ldclient_event_dispatch). %% Behavior callbacks -export([send/4]). @@ -27,5 +27,5 @@ send(OutputEvents, PayloadId, _Uri, SdkKey) -> _ -> ok end, - eld_test_events ! {OutputEvents, PayloadId}, + ldclient_test_events ! {OutputEvents, PayloadId}, Result. diff --git a/test/eld_events_SUITE.erl b/test/ldclient_events_SUITE.erl similarity index 90% rename from test/eld_events_SUITE.erl rename to test/ldclient_events_SUITE.erl index 96f3102..eed54ce 100644 --- a/test/eld_events_SUITE.erl +++ b/test/ldclient_events_SUITE.erl @@ -1,4 +1,4 @@ --module(eld_events_SUITE). +-module(ldclient_events_SUITE). -include_lib("common_test/include/ct.hrl"). @@ -50,28 +50,28 @@ all() -> ]. init_per_suite(Config) -> - {ok, _} = application:ensure_all_started(eld), + {ok, _} = application:ensure_all_started(ldclient), Options = #{ stream => false, - events_dispatcher => eld_event_dispatch_test, - polling_update_requestor => eld_update_requestor_test + events_dispatcher => ldclient_event_dispatch_test, + polling_update_requestor => ldclient_update_requestor_test }, - eld:start_instance("", Options), + ldclient:start_instance("", Options), Another1Options = Options#{ events_capacity => 2, events_flush_interval => 1000 }, - eld:start_instance("", another1, Another1Options), - eld:start_instance("sdk-key-events-fail", failer, Another1Options), + ldclient:start_instance("", another1, Another1Options), + ldclient:start_instance("sdk-key-events-fail", failer, Another1Options), InlineOptions = Options#{ stream => false, inline_users_in_events => true }, - eld:start_instance("", inliner, InlineOptions), + ldclient:start_instance("", inliner, InlineOptions), Config. end_per_suite(_) -> - ok = application:stop(eld). + ok = application:stop(ldclient). init_per_testcase(_, Config) -> Config. @@ -197,8 +197,8 @@ send_await_events(Events, Options, Tag) -> register_event_forwarding_process(), IncludeReasons = maps:get(include_reasons, Options, false), Flush = maps:get(flush, Options, false), - [ok = eld_event_server:add_event(Tag, E, #{include_reasons => IncludeReasons}) || E <- Events], - ok = if Flush -> eld_event_server:flush(Tag); true -> ok end, + [ok = ldclient_event_server:add_event(Tag, E, #{include_reasons => IncludeReasons}) || E <- Events], + ok = if Flush -> ldclient_event_server:flush(Tag); true -> ok end, receive_events(). await_events() -> @@ -223,7 +223,7 @@ receive_events() -> register_event_forwarding_process() -> TestPid = self(), ErPid = spawn(fun() -> receive ErEvents -> TestPid ! ErEvents end end), - true = register(eld_test_events, ErPid). + true = register(ldclient_test_events, ErPid). %%==================================================================== @@ -232,8 +232,8 @@ register_event_forwarding_process() -> add_flag_eval_events_flush_with_track(_) -> FlagBin = get_simple_flag_track(), - Flag = eld_flag:new(FlagBin), - Event = eld_event:new_flag_eval( + Flag = ldclient_flag:new(FlagBin), + Event = ldclient_event:new_flag_eval( 5, <<"variation-value-5">>, <<"default-value">>, @@ -283,8 +283,8 @@ add_flag_eval_events_flush_with_track(_) -> add_flag_eval_events_flush_with_track_no_reasons(_) -> FlagBin = get_simple_flag_track(), - Flag = eld_flag:new(FlagBin), - Event = eld_event:new_flag_eval( + Flag = ldclient_flag:new(FlagBin), + Event = ldclient_event:new_flag_eval( 5, <<"variation-value-5">>, <<"default-value">>, @@ -333,8 +333,8 @@ add_flag_eval_events_flush_with_track_no_reasons(_) -> add_flag_eval_events_flush_with_track_experimentation_rule(_) -> FlagBin = get_simple_flag_experimentation_rule(), - Flag = eld_flag:new(FlagBin), - Event = eld_event:new_flag_eval( + Flag = ldclient_flag:new(FlagBin), + Event = ldclient_event:new_flag_eval( 5, <<"variation-value-5">>, <<"default-value">>, @@ -384,8 +384,8 @@ add_flag_eval_events_flush_with_track_experimentation_rule(_) -> add_flag_eval_events_flush_with_track_experimentation_fallthrough(_) -> FlagBin = get_simple_flag_experimentation_fallthrough(), - Flag = eld_flag:new(FlagBin), - Event = eld_event:new_flag_eval( + Flag = ldclient_flag:new(FlagBin), + Event = ldclient_event:new_flag_eval( 5, <<"variation-value-5">>, <<"default-value">>, @@ -435,8 +435,8 @@ add_flag_eval_events_flush_with_track_experimentation_fallthrough(_) -> add_flag_eval_events_flush_with_track_inline(_) -> FlagBin = get_simple_flag_track(), - Flag = eld_flag:new(FlagBin), - Event = eld_event:new_flag_eval( + Flag = ldclient_flag:new(FlagBin), + Event = ldclient_event:new_flag_eval( 5, <<"variation-value-5">>, <<"default-value">>, @@ -481,8 +481,8 @@ add_flag_eval_events_flush_with_track_inline(_) -> add_flag_eval_events_flush_no_track(_) -> FlagBin = get_simple_flag_no_track(), - Flag = eld_flag:new(FlagBin), - Event = eld_event:new_flag_eval( + Flag = ldclient_flag:new(FlagBin), + Event = ldclient_event:new_flag_eval( 5, <<"variation-value-5">>, <<"default-value">>, @@ -519,7 +519,7 @@ add_flag_eval_events_flush_no_track(_) -> } ] = ActualEvents, % Evaluate flag for same user - Event2 = eld_event:new_flag_eval( + Event2 = ldclient_event:new_flag_eval( 5, <<"variation-value-5">>, <<"default-value">>, @@ -554,8 +554,8 @@ add_flag_eval_events_flush_no_track(_) -> add_flag_eval_events_with_debug(_) -> FlagBin = get_simple_flag_debug(), - Flag = eld_flag:new(FlagBin), - Event = eld_event:new_flag_eval( + Flag = ldclient_flag:new(FlagBin), + Event = ldclient_event:new_flag_eval( 5, <<"variation-value-5">>, <<"default-value">>, @@ -604,8 +604,8 @@ add_flag_eval_events_with_debug(_) -> ] = ActualEvents. add_identify_events(_) -> - Event1 = eld_event:new_identify(#{key => <<"12345">>}), - Event2 = eld_event:new_identify(#{key => <<"abcde">>}), + Event1 = ldclient_event:new_identify(#{key => <<"12345">>}), + Event2 = ldclient_event:new_identify(#{key => <<"abcde">>}), Events = [Event1, Event2], {ActualEvents, _} = send_await_events(Events, #{flush => true}), [ @@ -624,9 +624,9 @@ add_identify_events(_) -> ] = ActualEvents. add_custom_events(_) -> - Event1 = eld_event:new_custom(<<"event-foo">>, #{key => <<"12345">>}, #{k1 => <<"v1">>}), - Event2 = eld_event:new_custom(<<"event-bar">>, #{key => <<"abcde">>}, #{k2 => <<"v2">>}), - Event3 = eld_event:new_custom(<<"event-baz">>, #{key => <<"98765">>}, #{k3 => <<"v3">>}, 123), + Event1 = ldclient_event:new_custom(<<"event-foo">>, #{key => <<"12345">>}, #{k1 => <<"v1">>}), + Event2 = ldclient_event:new_custom(<<"event-bar">>, #{key => <<"abcde">>}, #{k2 => <<"v2">>}), + Event3 = ldclient_event:new_custom(<<"event-baz">>, #{key => <<"98765">>}, #{k3 => <<"v3">>}, 123), Events = [Event1, Event2, Event3], {ActualEvents, _} = send_await_events(Events, #{flush => true}), [ @@ -670,8 +670,8 @@ add_custom_events(_) -> ] = ActualEvents. add_custom_events_inline(_) -> - Event1 = eld_event:new_custom(<<"event-foo">>, #{key => <<"12345-custom-inline">>}, #{k1 => <<"v1">>}), - Event2 = eld_event:new_custom(<<"event-bar">>, #{key => <<"abcde-custom-inline">>}, #{k2 => <<"v2">>}), + Event1 = ldclient_event:new_custom(<<"event-foo">>, #{key => <<"12345-custom-inline">>}, #{k1 => <<"v1">>}), + Event2 = ldclient_event:new_custom(<<"event-bar">>, #{key => <<"abcde-custom-inline">>}, #{k2 => <<"v2">>}), Events = [Event1, Event2], {ActualEvents, _} = send_await_events(Events, #{flush => true}, inliner), [ @@ -692,8 +692,8 @@ add_custom_events_inline(_) -> ] = ActualEvents. auto_flush(_) -> - Event1 = eld_event:new_identify(#{key => <<"12345">>}), - Event2 = eld_event:new_identify(#{key => <<"abcde">>}), + Event1 = ldclient_event:new_identify(#{key => <<"12345">>}), + Event2 = ldclient_event:new_identify(#{key => <<"abcde">>}), Events = [Event1, Event2], {ActualEvents, _} = send_await_events(Events, #{flush => false}, another1), [ @@ -712,9 +712,9 @@ auto_flush(_) -> ] = ActualEvents. exceed_capacity(_) -> - Event1 = eld_event:new_identify(#{key => <<"foo">>}), - Event2 = eld_event:new_identify(#{key => <<"bar">>}), - Event3 = eld_event:new_identify(#{key => <<"baz">>}), + Event1 = ldclient_event:new_identify(#{key => <<"foo">>}), + Event2 = ldclient_event:new_identify(#{key => <<"bar">>}), + Event3 = ldclient_event:new_identify(#{key => <<"baz">>}), Events = [Event1, Event2, Event3], {ActualEvents, _} = send_await_events(Events, #{flush => true}, another1), [ @@ -733,8 +733,8 @@ exceed_capacity(_) -> ] = ActualEvents. fail_and_retry(_) -> - Event1 = eld_event:new_identify(#{key => <<"foo">>}), - Event2 = eld_event:new_identify(#{key => <<"bar">>}), + Event1 = ldclient_event:new_identify(#{key => <<"foo">>}), + Event2 = ldclient_event:new_identify(#{key => <<"bar">>}), Events = [Event1, Event2], % Await and match events and payload ID (first try) {ActualEvents, PayloadId} = send_await_events(Events, #{flush => true}, failer), @@ -756,7 +756,7 @@ fail_and_retry(_) -> {ActualEvents, PayloadId} = await_events(). payload_id_differs(_) -> - Event1 = eld_event:new_identify(#{key => <<"foo">>}), + Event1 = ldclient_event:new_identify(#{key => <<"foo">>}), % Await and match events and payload ID (first try) {ActualEvents1, PayloadId1} = send_await_events([Event1], #{flush => true}), [ @@ -767,7 +767,7 @@ payload_id_differs(_) -> <<"creationDate">> := _ } ] = ActualEvents1, - Event2 = eld_event:new_identify(#{key => <<"bar">>}), + Event2 = ldclient_event:new_identify(#{key => <<"bar">>}), {ActualEvents2, PayloadId2} = send_await_events([Event2], #{flush => true}), [ #{ diff --git a/test/eld_parse_SUITE.erl b/test/ldclient_parse_SUITE.erl similarity index 96% rename from test/eld_parse_SUITE.erl rename to test/ldclient_parse_SUITE.erl index c2731c6..41e3b7c 100644 --- a/test/eld_parse_SUITE.erl +++ b/test/ldclient_parse_SUITE.erl @@ -1,4 +1,4 @@ --module(eld_parse_SUITE). +-module(ldclient_parse_SUITE). -include_lib("common_test/include/ct.hrl"). @@ -77,7 +77,7 @@ parse_flag_empty(_) -> variations => [], version => 0 }, - FlagExpected = eld_flag:new(FlagRaw). + FlagExpected = ldclient_flag:new(FlagRaw). parse_flag_key_only(_) -> FlagRaw = #{ @@ -99,7 +99,7 @@ parse_flag_key_only(_) -> variations => [], version => 0 }, - FlagExpected = eld_flag:new(FlagRaw). + FlagExpected = ldclient_flag:new(FlagRaw). parse_flag_bare(_) -> FlagRaw = #{ @@ -134,7 +134,7 @@ parse_flag_bare(_) -> variations => [true, false], version => 10 }, - FlagExpected = eld_flag:new(FlagRaw). + FlagExpected = ldclient_flag:new(FlagRaw). parse_flag_full(_) -> FlagRaw = #{ @@ -227,7 +227,7 @@ parse_flag_full(_) -> variations => [<<"A">>, <<"B">>, <<"C">>], version => 9 }, - FlagExpected = eld_flag:new(FlagRaw). + FlagExpected = ldclient_flag:new(FlagRaw). parse_flag_ignore_invalid(_) -> FlagRaw = #{ @@ -272,7 +272,7 @@ parse_flag_ignore_invalid(_) -> variations => [<<"A">>, <<"B">>, <<"C">>], version => 0 }, - FlagExpected = eld_flag:new(FlagRaw). + FlagExpected = ldclient_flag:new(FlagRaw). parse_flag_invalid_fallthrough(_) -> FlagRaw = #{ @@ -295,7 +295,7 @@ parse_flag_invalid_fallthrough(_) -> variations => [], version => 0 }, - FlagExpected = eld_flag:new(FlagRaw). + FlagExpected = ldclient_flag:new(FlagRaw). parse_segment_empty(_) -> SegmentRaw = #{}, @@ -308,7 +308,7 @@ parse_segment_empty(_) -> salt => <<>>, version => 0 }, - SegmentExpected = eld_segment:new(SegmentRaw). + SegmentExpected = ldclient_segment:new(SegmentRaw). parse_segment_key_only(_) -> SegmentRaw = #{ @@ -323,7 +323,7 @@ parse_segment_key_only(_) -> salt => <<>>, version => 0 }, - SegmentExpected = eld_segment:new(SegmentRaw). + SegmentExpected = ldclient_segment:new(SegmentRaw). parse_segment_full(_) -> SegmentRaw = #{ @@ -373,4 +373,4 @@ parse_segment_full(_) -> salt => <<"segment-full-salt">>, version => 5 }, - SegmentExpected = eld_segment:new(SegmentRaw). + SegmentExpected = ldclient_segment:new(SegmentRaw). diff --git a/test/eld_poll_SUITE.erl b/test/ldclient_poll_SUITE.erl similarity index 55% rename from test/eld_poll_SUITE.erl rename to test/ldclient_poll_SUITE.erl index 2470579..2218c62 100644 --- a/test/eld_poll_SUITE.erl +++ b/test/ldclient_poll_SUITE.erl @@ -1,4 +1,4 @@ --module(eld_poll_SUITE). +-module(ldclient_poll_SUITE). -include_lib("common_test/include/ct.hrl"). @@ -34,11 +34,11 @@ all() -> ]. init_per_suite(Config) -> - {ok, _} = application:ensure_all_started(eld), + {ok, _} = application:ensure_all_started(ldclient), Config. end_per_suite(_) -> - ok = application:stop(eld). + ok = application:stop(ldclient). init_per_testcase(_, Config) -> Config. @@ -53,69 +53,69 @@ end_per_testcase(_, _Config) -> instance_options() -> #{ stream => false, - polling_update_requestor => eld_update_requestor_test + polling_update_requestor => ldclient_update_requestor_test }. set_storage_simple() -> - {FlagKey, _, FlagMap} = eld_update_requestor_test:get_simple_flag(), - {SegmentKey, _, SegmentMap} = eld_update_requestor_test:get_simple_segment(), - eld_storage_ets:put_clean(default, flags, #{FlagKey => FlagMap}), - eld_storage_ets:put_clean(default, segments, #{SegmentKey => SegmentMap}). + {FlagKey, _, FlagMap} = ldclient_update_requestor_test:get_simple_flag(), + {SegmentKey, _, SegmentMap} = ldclient_update_requestor_test:get_simple_segment(), + ldclient_storage_ets:put_clean(default, flags, #{FlagKey => FlagMap}), + ldclient_storage_ets:put_clean(default, segments, #{SegmentKey => SegmentMap}). trigger_poll() -> - [{_,Pid,_,_}] = supervisor:which_children(eld_instance_stream_default), + [{_,Pid,_,_}] = supervisor:which_children(ldclient_instance_stream_default), gen_server:call(Pid, {poll}). check_storage_simple() -> - {FlagKey, _, FlagMap} = eld_update_requestor_test:get_simple_flag(), - {SegmentKey, _, SegmentMap} = eld_update_requestor_test:get_simple_segment(), - [{FlagKey, FlagMap}] = eld_storage_ets:list(default, flags), - [{SegmentKey, SegmentMap}] = eld_storage_ets:list(default, segments). + {FlagKey, _, FlagMap} = ldclient_update_requestor_test:get_simple_flag(), + {SegmentKey, _, SegmentMap} = ldclient_update_requestor_test:get_simple_segment(), + [{FlagKey, FlagMap}] = ldclient_storage_ets:list(default, flags), + [{SegmentKey, SegmentMap}] = ldclient_storage_ets:list(default, segments). check_storage_empty() -> - [] = eld_storage_ets:list(default, flags), - [] = eld_storage_ets:list(default, segments). + [] = ldclient_storage_ets:list(default, flags), + [] = ldclient_storage_ets:list(default, segments). %%==================================================================== %% Tests %%==================================================================== response_error_unauthorized(_) -> - ok = eld:start_instance("sdk-key-unauthorized", instance_options()), + ok = ldclient:start_instance("sdk-key-unauthorized", instance_options()), set_storage_simple(), trigger_poll(), check_storage_simple(), - ok = eld:stop_instance(). + ok = ldclient:stop_instance(). response_error_not_found(_) -> - ok = eld:start_instance("sdk-key-not-found", instance_options()), + ok = ldclient:start_instance("sdk-key-not-found", instance_options()), set_storage_simple(), trigger_poll(), check_storage_simple(), - ok = eld:stop_instance(). + ok = ldclient:stop_instance(). response_error_internal(_) -> - ok = eld:start_instance("sdk-key-internal-error", instance_options()), + ok = ldclient:start_instance("sdk-key-internal-error", instance_options()), set_storage_simple(), trigger_poll(), check_storage_simple(), - ok = eld:stop_instance(). + ok = ldclient:stop_instance(). response_error_network(_) -> - ok = eld:start_instance("sdk-key-network-error", instance_options()), + ok = ldclient:start_instance("sdk-key-network-error", instance_options()), set_storage_simple(), trigger_poll(), check_storage_simple(), - ok = eld:stop_instance(). + ok = ldclient:stop_instance(). response_flags_segments(_) -> - ok = eld:start_instance("sdk-key-flags-segments", instance_options()), + ok = ldclient:start_instance("sdk-key-flags-segments", instance_options()), check_storage_simple(), - ok = eld:stop_instance(). + ok = ldclient:stop_instance(). successful_response_override_existing_flags(_) -> - ok = eld:start_instance("sdk-key-empty-payload", instance_options()), + ok = ldclient:start_instance("sdk-key-empty-payload", instance_options()), set_storage_simple(), trigger_poll(), check_storage_empty(), - ok = eld:stop_instance(). + ok = ldclient:stop_instance(). diff --git a/test/eld_storage_ets_SUITE.erl b/test/ldclient_storage_ets_SUITE.erl similarity index 51% rename from test/eld_storage_ets_SUITE.erl rename to test/ldclient_storage_ets_SUITE.erl index 3f03858..e0d2e5a 100644 --- a/test/eld_storage_ets_SUITE.erl +++ b/test/ldclient_storage_ets_SUITE.erl @@ -1,4 +1,4 @@ --module(eld_storage_ets_SUITE). +-module(ldclient_storage_ets_SUITE). -include_lib("common_test/include/ct.hrl"). @@ -36,24 +36,24 @@ all() -> ]. init_per_suite(Config) -> - {ok, _} = application:ensure_all_started(eld), + {ok, _} = application:ensure_all_started(ldclient), Options = #{ stream => false, - polling_update_requestor => eld_update_requestor_test + polling_update_requestor => ldclient_update_requestor_test }, - eld:start_instance("", Options), - eld:start_instance("", another1, Options), + ldclient:start_instance("", Options), + ldclient:start_instance("", another1, Options), Config. end_per_suite(_) -> - ok = application:stop(eld). + ok = application:stop(ldclient). init_per_testcase(_, Config) -> Config. end_per_testcase(_, _Config) -> - ok = eld_storage_ets:empty(default, flags), - ok = eld_storage_ets:empty(another1, flags), + ok = ldclient_storage_ets:empty(default, flags), + ok = ldclient_storage_ets:empty(another1, flags), ok. %%==================================================================== @@ -66,44 +66,44 @@ end_per_testcase(_, _Config) -> server_init(_) -> % Verify flags and segments buckets are pre-created - {error, already_exists, _} = eld_storage_ets:create(default, flags), - {error, already_exists, _} = eld_storage_ets:create(default, segments), - {error, already_exists, _} = eld_storage_ets:create(another1, flags), - {error, already_exists, _} = eld_storage_ets:create(another1, segments). + {error, already_exists, _} = ldclient_storage_ets:create(default, flags), + {error, already_exists, _} = ldclient_storage_ets:create(default, segments), + {error, already_exists, _} = ldclient_storage_ets:create(another1, flags), + {error, already_exists, _} = ldclient_storage_ets:create(another1, segments). server_bucket_exists(_) -> - {error, bucket_not_found, _} = eld_storage_ets:get(default, eld_testing, <<"testing">>), - ok = eld_storage_ets:create(default, eld_testing), - [] = eld_storage_ets:get(default, eld_testing, <<"testing">>), - {error, bucket_not_found, _} = eld_storage_ets:get(another1, eld_testing, <<"testing">>). + {error, bucket_not_found, _} = ldclient_storage_ets:get(default, ldclient_testing, <<"testing">>), + ok = ldclient_storage_ets:create(default, ldclient_testing), + [] = ldclient_storage_ets:get(default, ldclient_testing, <<"testing">>), + {error, bucket_not_found, _} = ldclient_storage_ets:get(another1, ldclient_testing, <<"testing">>). server_get_put(_) -> - [] = eld_storage_ets:get(default, flags, <<"flag1">>), - ok = eld_storage_ets:put(default, flags, #{<<"flag1">> => [{<<"value1">>, 0.5}]}), - [{<<"flag1">>, [{<<"value1">>, 0.5}]}] = eld_storage_ets:get(default, flags, <<"flag1">>), - [] = eld_storage_ets:get(another1, flags, <<"flag1">>), - ok = eld_storage_ets:put(another1, flags, #{<<"flag1">> => [{<<"valueA">>, 0.9}]}), - [{<<"flag1">>, [{<<"valueA">>, 0.9}]}] = eld_storage_ets:get(another1, flags, <<"flag1">>), - [{<<"flag1">>, [{<<"value1">>, 0.5}]}] = eld_storage_ets:get(default, flags, <<"flag1">>). + [] = ldclient_storage_ets:get(default, flags, <<"flag1">>), + ok = ldclient_storage_ets:put(default, flags, #{<<"flag1">> => [{<<"value1">>, 0.5}]}), + [{<<"flag1">>, [{<<"value1">>, 0.5}]}] = ldclient_storage_ets:get(default, flags, <<"flag1">>), + [] = ldclient_storage_ets:get(another1, flags, <<"flag1">>), + ok = ldclient_storage_ets:put(another1, flags, #{<<"flag1">> => [{<<"valueA">>, 0.9}]}), + [{<<"flag1">>, [{<<"valueA">>, 0.9}]}] = ldclient_storage_ets:get(another1, flags, <<"flag1">>), + [{<<"flag1">>, [{<<"value1">>, 0.5}]}] = ldclient_storage_ets:get(default, flags, <<"flag1">>). server_put_clean(_) -> - ok = eld_storage_ets:put(default, flags, #{<<"flag1">> => [{<<"value1">>, 0.5}]}), - ok = eld_storage_ets:put_clean(default, flags, #{<<"flag2">> => [{<<"value2">>, 0.9}]}), - [{<<"flag2">>, [{<<"value2">>, 0.9}]}] = eld_storage_ets:list(default, flags). + ok = ldclient_storage_ets:put(default, flags, #{<<"flag1">> => [{<<"value1">>, 0.5}]}), + ok = ldclient_storage_ets:put_clean(default, flags, #{<<"flag2">> => [{<<"value2">>, 0.9}]}), + [{<<"flag2">>, [{<<"value2">>, 0.9}]}] = ldclient_storage_ets:list(default, flags). server_list(_) -> - [] = eld_storage_ets:list(default, flags), - [] = eld_storage_ets:list(another1, flags), - ok = eld_storage_ets:put(default, flags, #{<<"flag1">> => [{<<"value1">>, 0.5}], <<"flag2">> => [{<<"value2">>, 0.7}]}), - ok = eld_storage_ets:put(another1, flags, #{<<"flag1">> => [{<<"value1">>, 0.9}], <<"flag5">> => [{<<"value2">>, 0.77}]}), + [] = ldclient_storage_ets:list(default, flags), + [] = ldclient_storage_ets:list(another1, flags), + ok = ldclient_storage_ets:put(default, flags, #{<<"flag1">> => [{<<"value1">>, 0.5}], <<"flag2">> => [{<<"value2">>, 0.7}]}), + ok = ldclient_storage_ets:put(another1, flags, #{<<"flag1">> => [{<<"value1">>, 0.9}], <<"flag5">> => [{<<"value2">>, 0.77}]}), [ {<<"flag1">>, [{<<"value1">>, 0.5}]}, {<<"flag2">>, [{<<"value2">>, 0.7}]} - ] = lists:sort(eld_storage_ets:list(default, flags)), + ] = lists:sort(ldclient_storage_ets:list(default, flags)), [ {<<"flag1">>, [{<<"value1">>, 0.9}]}, {<<"flag5">>, [{<<"value2">>, 0.77}]} - ] = lists:sort(eld_storage_ets:list(another1, flags)). + ] = lists:sort(ldclient_storage_ets:list(another1, flags)). server_process_events_put(_) -> Event = #{ @@ -120,16 +120,16 @@ server_process_events_put(_) -> } } }, - ok = eld_update_stream_server:process_items(put, Event, eld_storage_ets, default), + ok = ldclient_update_stream_server:process_items(put, Event, ldclient_storage_ets, default), [ {<<"flag-key-1">>, <<"flag-value-1">>}, {<<"flag-key-2">>, <<"flag-value-2">>}, {<<"flag-key-3">>, <<"flag-value-3">>} - ] = lists:sort(eld_storage_ets:list(default, flags)), + ] = lists:sort(ldclient_storage_ets:list(default, flags)), [ {<<"segment-key-1">>, <<"segment-value-1">>}, {<<"segment-key-2">>, <<"segment-value-2">>} - ] = lists:sort(eld_storage_ets:list(default, segments)). + ] = lists:sort(ldclient_storage_ets:list(default, segments)). server_process_events_patch(_) -> PutEvent = #{ @@ -142,13 +142,13 @@ server_process_events_patch(_) -> <<"segments">> => #{} } }, - ok = eld_update_stream_server:process_items(put, PutEvent, eld_storage_ets, default), + ok = ldclient_update_stream_server:process_items(put, PutEvent, ldclient_storage_ets, default), PatchEvent = #{ <<"path">> => <<"/flags/flag-key-2">>, <<"data">> => #{<<"key">> => <<"flag-key-2">>, <<"on">> => false} }, - ok = eld_update_stream_server:process_items(patch, PatchEvent, eld_storage_ets, default), + ok = ldclient_update_stream_server:process_items(patch, PatchEvent, ldclient_storage_ets, default), [ {<<"flag-key-1">>, #{<<"key">> := <<"flag-key-1">>, <<"on">> := true}}, {<<"flag-key-2">>, #{<<"key">> := <<"flag-key-2">>, <<"on">> := false}} - ] = lists:sort(eld_storage_ets:list(default, flags)). + ] = lists:sort(ldclient_storage_ets:list(default, flags)). diff --git a/test/ldclient_storage_map_SUITE.erl b/test/ldclient_storage_map_SUITE.erl new file mode 100644 index 0000000..f1371ab --- /dev/null +++ b/test/ldclient_storage_map_SUITE.erl @@ -0,0 +1,159 @@ +-module(ldclient_storage_map_SUITE). + +-include_lib("common_test/include/ct.hrl"). + +%% ct functions +-export([all/0]). +-export([init_per_suite/1]). +-export([end_per_suite/1]). +-export([init_per_testcase/2]). +-export([end_per_testcase/2]). + +%% Tests +-export([ + server_init/1, + server_bucket_exists/1, + server_get_put/1, + server_put_clean/1, + server_list/1, + server_process_events_put/1, + server_process_events_patch/1 +]). + +%%==================================================================== +%% ct functions +%%==================================================================== + +all() -> + [ + server_init, + server_bucket_exists, + server_get_put, + server_put_clean, + server_list, + server_process_events_put, + server_process_events_patch + ]. + +init_per_suite(Config) -> + {ok, _} = application:ensure_all_started(ldclient), + Options = #{ + storage_backend => ldclient_storage_map, + stream => false, + polling_update_requestor => ldclient_update_requestor_test + }, + ldclient:start_instance("", Options), + ldclient:start_instance("", another1, Options), + Config. + +end_per_suite(_) -> + ok = application:stop(ldclient). + +init_per_testcase(_, Config) -> + Config. + +end_per_testcase(_, _Config) -> + ok = ldclient_storage_map:empty(default, flags), + ok = ldclient_storage_map:empty(another1, flags), + ok. + +%%==================================================================== +%% Helpers +%%==================================================================== + +%%==================================================================== +%% Tests +%%==================================================================== + +server_init(_) -> + % Verify flags and segments buckets are pre-created + {error, already_exists, _} = ldclient_storage_map:create(default, flags), + {error, already_exists, _} = ldclient_storage_map:create(default, segments), + {error, already_exists, _} = ldclient_storage_map:create(another1, flags), + {error, already_exists, _} = ldclient_storage_map:create(another1, segments). + +server_bucket_exists(_) -> + {error, bucket_not_found, _} = ldclient_storage_map:get(default, ldclient_testing, <<"testing">>), + ok = ldclient_storage_map:create(default, ldclient_testing), + [] = ldclient_storage_map:get(default, ldclient_testing, <<"testing">>), + {error, bucket_not_found, _} = ldclient_storage_map:get(another1, ldclient_testing, <<"testing">>). + +server_get_put(_) -> + [] = ldclient_storage_map:get(default, flags, <<"flag1">>), + ok = ldclient_storage_map:put(default, flags, #{<<"flag1">> => [{<<"value1">>, 0.5}]}), + [] = ldclient_storage_map:get(another1, flags, <<"flag1">>), + [{<<"flag1">>, [{<<"value1">>, 0.5}]}] = ldclient_storage_map:get(default, flags, <<"flag1">>), + [] = ldclient_storage_map:get(another1, flags, <<"flag1">>), + ok = ldclient_storage_map:put(another1, flags, #{<<"flag1">> => [{<<"valueA">>, 0.9}]}), + [{<<"flag1">>, [{<<"valueA">>, 0.9}]}] = ldclient_storage_map:get(another1, flags, <<"flag1">>), + [{<<"flag1">>, [{<<"value1">>, 0.5}]}] = ldclient_storage_map:get(default, flags, <<"flag1">>). + +server_put_clean(_) -> + ok = ldclient_storage_map:put(default, flags, #{<<"flag1">> => [{<<"value1">>, 0.5}]}), + [{<<"flag1">>, [{<<"value1">>, 0.5}]}] = ldclient_storage_map:get(default, flags, <<"flag1">>), + ok = ldclient_storage_map:put_clean(default, flags, #{<<"flag2">> => [{<<"value2">>, 0.9}]}), + [{<<"flag2">>, [{<<"value2">>, 0.9}]}] = ldclient_storage_map:list(default, flags). + +server_list(_) -> + [] = ldclient_storage_map:list(default, flags), + [] = ldclient_storage_map:list(another1, flags), + ok = ldclient_storage_map:put(default, flags, #{<<"flag1">> => [{<<"value1">>, 0.5}]}), + ok = ldclient_storage_map:put(default, flags, #{<<"flag2">> => [{<<"value2">>, 0.7}]}), + ok = ldclient_storage_map:put(another1, flags, #{<<"flag1">> => [{<<"value1">>, 0.9}]}), + ok = ldclient_storage_map:put(another1, flags, #{<<"flag5">> => [{<<"value2">>, 0.77}]}), + [ + {<<"flag1">>, [{<<"value1">>, 0.5}]}, + {<<"flag2">>, [{<<"value2">>, 0.7}]} + ] = lists:sort(ldclient_storage_map:list(default, flags)), + [ + {<<"flag1">>, [{<<"value1">>, 0.9}]}, + {<<"flag5">>, [{<<"value2">>, 0.77}]} + ] = lists:sort(ldclient_storage_map:list(another1, flags)). + +server_process_events_put(_) -> + Event = #{ + <<"path">> => <<"/">>, + <<"data">> => #{ + <<"flags">> => #{ + <<"flag-key-1">> => <<"flag-value-1">>, + <<"flag-key-2">> => <<"flag-value-2">>, + <<"flag-key-3">> => <<"flag-value-3">> + }, + <<"segments">> => #{ + <<"segment-key-1">> => <<"segment-value-1">>, + <<"segment-key-2">> => <<"segment-value-2">> + } + } + }, + ok = ldclient_update_stream_server:process_items(put, Event, ldclient_storage_map, default), + [ + {<<"flag-key-1">>, <<"flag-value-1">>}, + {<<"flag-key-2">>, <<"flag-value-2">>}, + {<<"flag-key-3">>, <<"flag-value-3">>} + ] = lists:sort(ldclient_storage_map:list(default, flags)), + [ + {<<"segment-key-1">>, <<"segment-value-1">>}, + {<<"segment-key-2">>, <<"segment-value-2">>} + ] = lists:sort(ldclient_storage_map:list(default, segments)). + +server_process_events_patch(_) -> + PutEvent = #{ + <<"path">> => <<"/">>, + <<"data">> => #{ + <<"flags">> => #{ + <<"flag-key-1">> => #{<<"key">> => <<"flag-key-1">>, <<"on">> => true}, + <<"flag-key-2">> => #{<<"key">> => <<"flag-key-2">>, <<"on">> => true} + }, + <<"segments">> => #{} + } + }, + ok = ldclient_update_stream_server:process_items(put, PutEvent, ldclient_storage_map, default), + PatchEvent = #{ + <<"path">> => <<"/flags/flag-key-2">>, + <<"data">> => #{<<"key">> => <<"flag-key-2">>, <<"on">> => false} + }, + ok = ldclient_update_stream_server:process_items(patch, PatchEvent, ldclient_storage_map, default), + [ + {<<"flag-key-1">>, #{<<"key">> := <<"flag-key-1">>, <<"on">> := true}}, + {<<"flag-key-2">>, #{<<"key">> := <<"flag-key-2">>, <<"on">> := false}} + ] = lists:sort(ldclient_storage_map:list(default, flags)). diff --git a/test/eld_stream_SUITE.erl b/test/ldclient_stream_SUITE.erl similarity index 78% rename from test/eld_stream_SUITE.erl rename to test/ldclient_stream_SUITE.erl index 3d8b005..918bb3b 100644 --- a/test/eld_stream_SUITE.erl +++ b/test/ldclient_stream_SUITE.erl @@ -1,4 +1,4 @@ --module(eld_stream_SUITE). +-module(ldclient_stream_SUITE). -include_lib("common_test/include/ct.hrl"). @@ -34,22 +34,22 @@ all() -> ]. init_per_suite(Config) -> - {ok, _} = application:ensure_all_started(eld), + {ok, _} = application:ensure_all_started(ldclient), Options = #{ stream => false, - polling_update_requestor => eld_update_requestor_test + polling_update_requestor => ldclient_update_requestor_test }, - eld:start_instance("", Options), + ldclient:start_instance("", Options), Config. end_per_suite(_) -> - ok = application:stop(eld). + ok = application:stop(ldclient). init_per_testcase(_, Config) -> Config. end_per_testcase(_, _Config) -> - ok = eld_storage_ets:empty(default, flags), + ok = ldclient_storage_ets:empty(default, flags), ok. %%==================================================================== @@ -267,13 +267,13 @@ server_process_event_put_patch(_) -> "\"segments\":{}", "}", "}">>, - ok = eld_update_stream_server:process_event(#{event => <<"put">>, data => PutData}, eld_storage_ets, default), - [] = eld_storage_ets:list(default, segments), - [{FlagSimpleKey, FlagSimpleMap}] = eld_storage_ets:list(default, flags), + ok = ldclient_update_stream_server:process_event(#{event => <<"put">>, data => PutData}, ldclient_storage_ets, default), + [] = ldclient_storage_ets:list(default, segments), + [{FlagSimpleKey, FlagSimpleMap}] = ldclient_storage_ets:list(default, flags), {FlagSimpleKey, FlagPatchBin, FlagPatchMap} = get_simple_flag_patch(), PatchData = <<"{\"path\":\"/flags/", FlagSimpleKey/binary, "\",", FlagPatchBin/binary, "}">>, - ok = eld_update_stream_server:process_event(#{event => <<"patch">>, data => PatchData}, eld_storage_ets, default), - [{FlagSimpleKey, FlagPatchMap}] = eld_storage_ets:list(default, flags), + ok = ldclient_update_stream_server:process_event(#{event => <<"patch">>, data => PatchData}, ldclient_storage_ets, default), + [{FlagSimpleKey, FlagPatchMap}] = ldclient_storage_ets:list(default, flags), ok. server_process_event_put_patch_flag_with_extra_property(_) -> @@ -286,13 +286,13 @@ server_process_event_put_patch_flag_with_extra_property(_) -> "\"segments\":{}", "}", "}">>, - ok = eld_update_stream_server:process_event(#{event => <<"put">>, data => PutData}, eld_storage_ets, default), - [] = eld_storage_ets:list(default, segments), - [{FlagSimpleKey, FlagSimpleMap}] = eld_storage_ets:list(default, flags), + ok = ldclient_update_stream_server:process_event(#{event => <<"put">>, data => PutData}, ldclient_storage_ets, default), + [] = ldclient_storage_ets:list(default, segments), + [{FlagSimpleKey, FlagSimpleMap}] = ldclient_storage_ets:list(default, flags), {FlagSimpleKey, FlagPatchBin, FlagPatchMap} = get_simple_flag_patch(), PatchData = <<"{\"path\":\"/flags/", FlagSimpleKey/binary, "\",", FlagPatchBin/binary, "}">>, - ok = eld_update_stream_server:process_event(#{event => <<"patch">>, data => PatchData}, eld_storage_ets, default), - [{FlagSimpleKey, FlagPatchMap}] = eld_storage_ets:list(default, flags), + ok = ldclient_update_stream_server:process_event(#{event => <<"patch">>, data => PatchData}, ldclient_storage_ets, default), + [{FlagSimpleKey, FlagPatchMap}] = ldclient_storage_ets:list(default, flags), ok. server_process_event_put_patch_old_version(_) -> @@ -305,13 +305,13 @@ server_process_event_put_patch_old_version(_) -> "\"segments\":{}", "}", "}">>, - ok = eld_update_stream_server:process_event(#{event => <<"put">>, data => PutData}, eld_storage_ets, default), - [] = eld_storage_ets:list(default, segments), - [{FlagSimpleKey, FlagSimpleMap}] = eld_storage_ets:list(default, flags), + ok = ldclient_update_stream_server:process_event(#{event => <<"put">>, data => PutData}, ldclient_storage_ets, default), + [] = ldclient_storage_ets:list(default, segments), + [{FlagSimpleKey, FlagSimpleMap}] = ldclient_storage_ets:list(default, flags), {FlagSimpleKey, FlagPatchBin, _FlagPatchMap} = get_simple_flag_patch_old(), PatchData = <<"{\"path\":\"/flags/", FlagSimpleKey/binary, "\",", FlagPatchBin/binary, "}">>, - ok = eld_update_stream_server:process_event(#{event => <<"patch">>, data => PatchData}, eld_storage_ets, default), - [{FlagSimpleKey, FlagSimpleMap}] = eld_storage_ets:list(default, flags), + ok = ldclient_update_stream_server:process_event(#{event => <<"patch">>, data => PatchData}, ldclient_storage_ets, default), + [{FlagSimpleKey, FlagSimpleMap}] = ldclient_storage_ets:list(default, flags), ok. server_process_event_put_delete(_) -> @@ -324,12 +324,12 @@ server_process_event_put_delete(_) -> "\"segments\":{}", "}", "}">>, - ok = eld_update_stream_server:process_event(#{event => <<"put">>, data => PutData}, eld_storage_ets, default), - [] = eld_storage_ets:list(default, segments), - [{FlagSimpleKey, FlagSimpleMap}] = eld_storage_ets:list(default, flags), - ok = eld_update_stream_server:process_event(#{event => <<"delete">>, data => PutData}, eld_storage_ets, default), + ok = ldclient_update_stream_server:process_event(#{event => <<"put">>, data => PutData}, ldclient_storage_ets, default), + [] = ldclient_storage_ets:list(default, segments), + [{FlagSimpleKey, FlagSimpleMap}] = ldclient_storage_ets:list(default, flags), + ok = ldclient_update_stream_server:process_event(#{event => <<"delete">>, data => PutData}, ldclient_storage_ets, default), {FlagSimpleKey, _FlagDeleteBin, FlagDeleteMap} = get_simple_flag_delete(), - [{FlagSimpleKey, FlagDeleteMap}] = eld_storage_ets:list(default, flags), + [{FlagSimpleKey, FlagDeleteMap}] = ldclient_storage_ets:list(default, flags), ok. server_process_event_put_delete_single(_) -> @@ -342,17 +342,17 @@ server_process_event_put_delete_single(_) -> "\"segments\":{}", "}", "}">>, - ok = eld_update_stream_server:process_event(#{event => <<"put">>, data => PutData}, eld_storage_ets, default), - [] = eld_storage_ets:list(default, segments), - [{FlagSimpleKey, FlagSimpleMap}] = eld_storage_ets:list(default, flags), + ok = ldclient_update_stream_server:process_event(#{event => <<"put">>, data => PutData}, ldclient_storage_ets, default), + [] = ldclient_storage_ets:list(default, segments), + [{FlagSimpleKey, FlagSimpleMap}] = ldclient_storage_ets:list(default, flags), DeleteData = <<"{\"path\":\"/flags/", FlagSimpleKey/binary, "\"}">>, - ok = eld_update_stream_server:process_event(#{event => <<"delete">>, data => DeleteData}, eld_storage_ets, default), + ok = ldclient_update_stream_server:process_event(#{event => <<"delete">>, data => DeleteData}, ldclient_storage_ets, default), {FlagSimpleKey, _FlagDeleteBin, FlagDeleteMap} = get_simple_flag_delete(), - [{FlagSimpleKey, FlagDeleteMap}] = eld_storage_ets:list(default, flags), + [{FlagSimpleKey, FlagDeleteMap}] = ldclient_storage_ets:list(default, flags), ok. server_process_event_other(_) -> - ok = eld_update_stream_server:process_event(#{event => <<"unsupported-event">>, data => <<"foo">>}, eld_storage_ets, default), - [] = eld_storage_ets:list(default, flags), - [] = eld_storage_ets:list(default, segments), + ok = ldclient_update_stream_server:process_event(#{event => <<"unsupported-event">>, data => <<"foo">>}, ldclient_storage_ets, default), + [] = ldclient_storage_ets:list(default, flags), + [] = ldclient_storage_ets:list(default, segments), ok. diff --git a/test/eld_update_requestor_httpc_SUITE.erl b/test/ldclient_update_requestor_httpc_SUITE.erl similarity index 77% rename from test/eld_update_requestor_httpc_SUITE.erl rename to test/ldclient_update_requestor_httpc_SUITE.erl index 86dc360..56d6a41 100644 --- a/test/eld_update_requestor_httpc_SUITE.erl +++ b/test/ldclient_update_requestor_httpc_SUITE.erl @@ -1,4 +1,4 @@ --module(eld_update_requestor_httpc_SUITE). +-module(ldclient_update_requestor_httpc_SUITE). -include_lib("common_test/include/ct.hrl"). @@ -67,58 +67,58 @@ end_per_testcase(_, _Config) -> authorization_header_set_on_request(_Config) -> bookish_spork:stub_request([200, #{}, <<>>]), - {{ok, <<>>}, #{}} = eld_update_requestor_httpc:all(?MOCK_URI, "sdk-key", #{}), + {{ok, <<>>}, #{}} = ldclient_update_requestor_httpc:all(?MOCK_URI, "sdk-key", #{}), {ok, Request} = bookish_spork:capture_request(), "sdk-key" = bookish_spork_request:header(Request, "authorization"). user_agent_header_set_on_request(_Config) -> bookish_spork:stub_request([200, #{}, <<>>]), - {{ok, <<>>}, #{}} = eld_update_requestor_httpc:all(?MOCK_URI, "sdk-key", #{}), + {{ok, <<>>}, #{}} = ldclient_update_requestor_httpc:all(?MOCK_URI, "sdk-key", #{}), {ok, Request} = bookish_spork:capture_request(), UserAgent = bookish_spork_request:header(Request, "user-agent"), true = string:prefix(UserAgent, "ErlangClient") /= nomatch. event_schema_set_on_request(_Config) -> bookish_spork:stub_request([200, #{}, <<>>]), - {{ok, <<>>}, #{}} = eld_update_requestor_httpc:all(?MOCK_URI, "sdk-key", #{}), + {{ok, <<>>}, #{}} = ldclient_update_requestor_httpc:all(?MOCK_URI, "sdk-key", #{}), {ok, Request} = bookish_spork:capture_request(), "3" = bookish_spork_request:header(Request, "x-launchdarkly-event-schema"). none_match_is_not_set_with_empty_state(_Config) -> bookish_spork:stub_request([200, #{}, <<>>]), - {{ok, <<>>}, #{}} = eld_update_requestor_httpc:all(?MOCK_URI, "sdk-key", #{}), + {{ok, <<>>}, #{}} = ldclient_update_requestor_httpc:all(?MOCK_URI, "sdk-key", #{}), {ok, Request} = bookish_spork:capture_request(), nil = bookish_spork_request:header(Request, "if-none-match"). none_match_is_set_with_state(_Config) -> bookish_spork:stub_request([200, #{}, <<>>]), State = #{?MOCK_URI => "etagval"}, - {{ok, <<>>}, State} = eld_update_requestor_httpc:all(?MOCK_URI, "sdk-key", State), + {{ok, <<>>}, State} = ldclient_update_requestor_httpc:all(?MOCK_URI, "sdk-key", State), {ok, Request} = bookish_spork:capture_request(), "etagval" = bookish_spork_request:header(Request, "if-none-match"). etag_response_recorded(_Config) -> bookish_spork:stub_request([200, #{<<"etag">> => <<"etagval">>}, <<>>]), - {{ok, <<>>}, #{?MOCK_URI := "etagval"}} = eld_update_requestor_httpc:all(?MOCK_URI, "sdk-key", #{}). + {{ok, <<>>}, #{?MOCK_URI := "etagval"}} = ldclient_update_requestor_httpc:all(?MOCK_URI, "sdk-key", #{}). not_modified_test(_Config) -> bookish_spork:stub_request([304, #{}, <<>>]), - {{ok, not_modified}, #{}} = eld_update_requestor_httpc:all(?MOCK_URI, "sdk-key", #{}). + {{ok, not_modified}, #{}} = ldclient_update_requestor_httpc:all(?MOCK_URI, "sdk-key", #{}). etag_updated_on_modified(_Config) -> bookish_spork:stub_request([200, #{<<"etag">> => <<"etagval2">>}, <<>>]), - {{ok, <<>>}, State} = eld_update_requestor_httpc:all(?MOCK_URI, "sdk-key", #{?MOCK_URI => "etagval1"}), + {{ok, <<>>}, State} = ldclient_update_requestor_httpc:all(?MOCK_URI, "sdk-key", #{?MOCK_URI => "etagval1"}), #{?MOCK_URI := "etagval2"} = State. error_status_returned(_Config) -> bookish_spork:stub_request([504, #{}, <<>>]), - {Response, #{}} = eld_update_requestor_httpc:all(?MOCK_URI, "sdk-key", #{}), + {Response, #{}} = ldclient_update_requestor_httpc:all(?MOCK_URI, "sdk-key", #{}), {error, {bad_status, 504, _FormattedResponse}} = Response. invalid_uri_test(_Config) -> - {Response, #{}} = eld_update_requestor_httpc:all(?INVALID_URI, "sdk-key", #{}), + {Response, #{}} = ldclient_update_requestor_httpc:all(?INVALID_URI, "sdk-key", #{}), {error, network_error} = Response. no_server_uri_test(_Config) -> - {Response, #{}} = eld_update_requestor_httpc:all(?NO_SERVER_URI, "sdk-key", #{}), + {Response, #{}} = ldclient_update_requestor_httpc:all(?NO_SERVER_URI, "sdk-key", #{}), {error, network_error} = Response. diff --git a/test/eld_update_requestor_test.erl b/test/ldclient_update_requestor_test.erl similarity index 96% rename from test/eld_update_requestor_test.erl rename to test/ldclient_update_requestor_test.erl index 7cf8fbb..1695e02 100644 --- a/test/eld_update_requestor_test.erl +++ b/test/ldclient_update_requestor_test.erl @@ -4,9 +4,9 @@ %% @end %%------------------------------------------------------------------- --module(eld_update_requestor_test). +-module(ldclient_update_requestor_test). --behaviour(eld_update_requestor). +-behaviour(ldclient_update_requestor). %% API -export([get_simple_flag/0]). @@ -92,7 +92,7 @@ init() -> ok. %% @doc Return static values mocking the polling service %% %% @end --spec all(Uri :: string(), SdkKey :: string(), State :: any()) -> {eld_update_requestor:response(), any()}. +-spec all(Uri :: string(), SdkKey :: string(), State :: any()) -> {ldclient_update_requestor:response(), any()}. all(_Uri, SdkKey, State) -> Result = case SdkKey of "sdk-key-unauthorized" -> diff --git a/test/eld_user_SUITE.erl b/test/ldclient_user_SUITE.erl similarity index 74% rename from test/eld_user_SUITE.erl rename to test/ldclient_user_SUITE.erl index 3e6f380..e4805a5 100644 --- a/test/eld_user_SUITE.erl +++ b/test/ldclient_user_SUITE.erl @@ -1,4 +1,4 @@ --module(eld_user_SUITE). +-module(ldclient_user_SUITE). -include_lib("common_test/include/ct.hrl"). @@ -81,13 +81,13 @@ end_per_testcase(_, _Config) -> new_from_key(_) -> Key = <<"123">>, - User = eld_user:new(Key), + User = ldclient_user:new(Key), User = #{key => Key}. new_from_map_key_only(_) -> Key = <<"123">>, Map = #{<<"key">> => Key}, - User = eld_user:new_from_map(Map), + User = ldclient_user:new_from_map(Map), User = #{key => Key}. new_from_map_custom_only(_) -> @@ -97,7 +97,7 @@ new_from_map_custom_only(_) -> CustomVal1 = <<"custom-val1">>, CustomVal2 = 12345, Map = #{CustomAttr1 => CustomVal1, CustomAttr2 => CustomVal2}, - User = eld_user:new_from_map(Map), + User = ldclient_user:new_from_map(Map), User = #{custom => #{CustomAttr1 => CustomVal1, CustomAttr2Expected => CustomVal2}}. new_from_map_full(_) -> @@ -129,7 +129,7 @@ new_from_map_full(_) -> CustomKey1 => CustomValue1, CustomKey2 => CustomValue2 }, - User = eld_user:new_from_map(Map), + User = ldclient_user:new_from_map(Map), UserExpected = #{ key => Key, secondary => Secondary, @@ -152,35 +152,35 @@ new_from_map_full(_) -> get(_) -> Key = <<"123">>, - User = eld_user:new(Key), - Key = eld_user:get(key, User), - Key = eld_user:get(<<"key">>, User). + User = ldclient_user:new(Key), + Key = ldclient_user:get(key, User), + Key = ldclient_user:get(<<"key">>, User). get_custom(_) -> CustomAttrAtom = 'my-custom-attr', CustomAttrBin = atom_to_binary(CustomAttrAtom, utf8), CustomVal = 12345, User = #{custom => #{CustomAttrBin => CustomVal}}, - CustomVal = eld_user:get(CustomAttrBin, User), - CustomVal = eld_user:get(CustomAttrAtom, User). + CustomVal = ldclient_user:get(CustomAttrBin, User), + CustomVal = ldclient_user:get(CustomAttrAtom, User). set(_) -> Key = <<"12345">>, KeyNew = 789, - User = eld_user:set(key, KeyNew, eld_user:new(Key)), + User = ldclient_user:set(key, KeyNew, ldclient_user:new(Key)), User = #{key => KeyNew}. set_binary(_) -> Key = <<"12345">>, KeyNew = 789, - User = eld_user:set(<<"key">>, KeyNew, eld_user:new(Key)), + User = ldclient_user:set(<<"key">>, KeyNew, ldclient_user:new(Key)), User = #{key => KeyNew}. set_custom(_) -> Key = <<"12345">>, CustomAttr = <<"my-custom-attr">>, CustomVal = 345, - User = eld_user:set(CustomAttr, CustomVal, eld_user:new(Key)), + User = ldclient_user:set(CustomAttr, CustomVal, ldclient_user:new(Key)), User = #{key => Key, custom => #{CustomAttr => CustomVal}}. set_custom_atom(_) -> @@ -188,29 +188,29 @@ set_custom_atom(_) -> CustomAttr = 'my-custom-attr', CustomAttrExpected = atom_to_binary(CustomAttr, utf8), CustomVal = 345, - User = eld_user:set(CustomAttr, CustomVal, eld_user:new(Key)), + User = ldclient_user:set(CustomAttr, CustomVal, ldclient_user:new(Key)), User = #{key => Key, custom => #{CustomAttrExpected => CustomVal}}. set_private_attribute_names(_) -> Key = <<"123">>, PrivateAttributeNames = ["name", "country"], - User = eld_user:new(Key), - UserActual = eld_user:set_private_attribute_names(PrivateAttributeNames, User), + User = ldclient_user:new(Key), + UserActual = ldclient_user:set_private_attribute_names(PrivateAttributeNames, User), UserExpected = #{key => Key, private_attribute_names => PrivateAttributeNames}, UserExpected = UserActual. set_private_attribute_names_empty(_) -> Key = <<"123">>, - User = eld_user:new(Key), - UserActual = eld_user:set_private_attribute_names([], User), + User = ldclient_user:new(Key), + UserActual = ldclient_user:set_private_attribute_names([], User), User = UserActual. set_private_attribute_names_reset(_) -> Key = <<"123">>, PrivateAttributeNames = ["name", "country"], - User = eld_user:new(Key), - UserWithPrivateAttributes = eld_user:set_private_attribute_names(PrivateAttributeNames, User), - UserActual = eld_user:set_private_attribute_names([], UserWithPrivateAttributes), + User = ldclient_user:new(Key), + UserWithPrivateAttributes = ldclient_user:set_private_attribute_names(PrivateAttributeNames, User), + UserActual = ldclient_user:set_private_attribute_names([], UserWithPrivateAttributes), User = UserActual. scrub(_) -> @@ -222,7 +222,7 @@ scrub(_) -> Custom2Name = <<"custom-attr-2">>, Custom2Value = 789, Custom3Name = <<"custom-attr-3">>, - User = eld_user:new_from_map(#{ + User = ldclient_user:new_from_map(#{ key => Key, name => Name, country => Country, @@ -230,9 +230,9 @@ scrub(_) -> Custom2Name => Custom2Value }), PrivateAttributeNames = [<<"country">>, Custom1Name, Custom3Name], - UserWithPrivateAttrs = eld_user:set_private_attribute_names(PrivateAttributeNames, User), - {UserActual, ScrubbedActual} = eld_user:scrub(UserWithPrivateAttrs, []), - UserExpected = eld_user:new_from_map(#{ + UserWithPrivateAttrs = ldclient_user:set_private_attribute_names(PrivateAttributeNames, User), + {UserActual, ScrubbedActual} = ldclient_user:scrub(UserWithPrivateAttrs, []), + UserExpected = ldclient_user:new_from_map(#{ key => Key, name => Name, Custom2Name => Custom2Value @@ -245,13 +245,13 @@ scrub_empty(_) -> Name = "foo", Custom1Name = <<"custom-attr-1">>, Custom1Value = 345, - User = eld_user:new_from_map(#{ + User = ldclient_user:new_from_map(#{ key => Key, name => Name, Custom1Name => Custom1Value }), - UserWithPrivateAttrs = eld_user:set_private_attribute_names([], User), - {UserActual, ScrubbedActual} = eld_user:scrub(UserWithPrivateAttrs, []), + UserWithPrivateAttrs = ldclient_user:set_private_attribute_names([], User), + {UserActual, ScrubbedActual} = ldclient_user:scrub(UserWithPrivateAttrs, []), {User, []} = {UserActual, ScrubbedActual}. scrub_null(_) -> @@ -259,13 +259,13 @@ scrub_null(_) -> Name = "foo", Custom1Name = <<"custom-attr-1">>, Custom1Value = 345, - User = eld_user:new_from_map(#{ + User = ldclient_user:new_from_map(#{ key => Key, name => Name, Custom1Name => Custom1Value }), - UserWithPrivateAttrs = eld_user:set_private_attribute_names(null, User), - {UserActual, ScrubbedActual} = eld_user:scrub(UserWithPrivateAttrs, []), + UserWithPrivateAttrs = ldclient_user:set_private_attribute_names(null, User), + {UserActual, ScrubbedActual} = ldclient_user:scrub(UserWithPrivateAttrs, []), {User, []} = {UserActual, ScrubbedActual}. scrub_key(_) -> @@ -273,13 +273,13 @@ scrub_key(_) -> Name = "foo", Custom1Name = <<"custom-attr-1">>, Custom1Value = 345, - User = eld_user:new_from_map(#{ + User = ldclient_user:new_from_map(#{ key => Key, name => Name, Custom1Name => Custom1Value }), - UserWithPrivateAttrs = eld_user:set_private_attribute_names([key], User), - {UserActual, ScrubbedActual} = eld_user:scrub(UserWithPrivateAttrs, []), + UserWithPrivateAttrs = ldclient_user:set_private_attribute_names([key], User), + {UserActual, ScrubbedActual} = ldclient_user:scrub(UserWithPrivateAttrs, []), {User, []} = {UserActual, ScrubbedActual}. scrub_all_attributes_private(_) -> @@ -287,13 +287,13 @@ scrub_all_attributes_private(_) -> Name = "foo", Custom1Name = <<"custom-attr-1">>, Custom1Value = 345, - User = eld_user:new_from_map(#{ + User = ldclient_user:new_from_map(#{ key => Key, name => Name, Custom1Name => Custom1Value }), - {UserActual, ScrubbedActual} = eld_user:scrub(User, all), - UserExpected = eld_user:new_from_map(#{key => Key}), + {UserActual, ScrubbedActual} = ldclient_user:scrub(User, all), + UserExpected = ldclient_user:new_from_map(#{key => Key}), {UserExpected, [<<"name">>, Custom1Name]} = {UserActual, ScrubbedActual}. scrub_global_private_attributes(_) -> @@ -303,14 +303,14 @@ scrub_global_private_attributes(_) -> Custom1Value = 345, Custom2Name = <<"custom-attr-2">>, Custom2Value = 789, - User = eld_user:new_from_map(#{ + User = ldclient_user:new_from_map(#{ key => Key, name => Name, Custom1Name => Custom1Value, Custom2Name => Custom2Value }), - {UserActual, ScrubbedActual} = eld_user:scrub(User, [<<"name">>, Custom2Name]), - UserExpected = eld_user:new_from_map(#{ + {UserActual, ScrubbedActual} = ldclient_user:scrub(User, [<<"name">>, Custom2Name]), + UserExpected = ldclient_user:new_from_map(#{ key => Key, Custom1Name => Custom1Value }),