Skip to content

Commit

Permalink
Prepare 1.0.0-alpha2 release (#3)
Browse files Browse the repository at this point in the history
  • Loading branch information
zurab-darkly authored Aug 8, 2019
1 parent fcf7b0a commit 0305502
Show file tree
Hide file tree
Showing 12 changed files with 522 additions and 124 deletions.
21 changes: 21 additions & 0 deletions CHANGELOG.md
Original file line number Diff line number Diff line change
Expand Up @@ -2,6 +2,27 @@

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-alpha2] - 2019-08-07

### Added

- Support for all server side LaunchDarkly events
- `eld:variation/3-4` and `eld:variation_detail/3-4` functions to replace `eld:evaluate/3-4` to reflect the naming convention
- Feature to inline users inside events
- Feature to define global private user attributes, including making all user attributes private

### Fixed

- Events POST URI, it no longer gets HTTP 405 Method Not Allowed error

### Deprecated
- `eld:evaluate/3-4` will be removed in a future release

### Missing

- Polling support
- Known issues for some edge case error conditions, and other minor missing features

## [1.0.0-alpha1] - 2019-07-24

### Added
Expand Down
2 changes: 1 addition & 1 deletion Makefile
Original file line number Diff line number Diff line change
@@ -1,6 +1,6 @@
PROJECT = eld
PROJECT_DESCRIPTION = Erlang LaunchDarkly SDK Client
PROJECT_VERSION = 1.0.0-alpha1
PROJECT_VERSION = 1.0.0-alpha2

# Dependencies

Expand Down
2 changes: 1 addition & 1 deletion relx.config
Original file line number Diff line number Diff line change
@@ -1,2 +1,2 @@
{release, {eld, "1.0.0-alpha1"}, [eld]}.
{release, {eld, "1.0.0-alpha2"}, [eld]}.
{extended_start_script, true}.
5 changes: 3 additions & 2 deletions src/eld.app.src
Original file line number Diff line number Diff line change
@@ -1,6 +1,6 @@
{application, eld,
[{description, "LaunchDarkly Erlang SDK"},
{vsn, "1.0.0-alpha1"},
{vsn, "1.0.0-alpha2"},
{registered, []},
{mod, {eld_app, []}},
{applications,
Expand All @@ -14,7 +14,8 @@
shotgun,
jsx,
lru,
backoff
backoff,
verl
]},
{env,[]},
{modules, []},
Expand Down
79 changes: 67 additions & 12 deletions src/eld.erl
Original file line number Diff line number Diff line change
Expand Up @@ -17,6 +17,10 @@
-export([stop_instance/1]).
-export([evaluate/3]).
-export([evaluate/4]).
-export([variation/3]).
-export([variation/4]).
-export([variation_detail/3]).
-export([variation_detail/4]).
-export([all_flags_state/1]).
-export([all_flags_state/2]).
-export([identify/1]).
Expand Down Expand Up @@ -93,6 +97,33 @@ stop_instance(Tag) when is_atom(Tag) ->

%% @doc Evaluate given flag key for given 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()) ->
eld_eval:result_value().
variation(FlagKey, User, DefaultValue) when is_binary(FlagKey), is_map(User) ->
variation(FlagKey, User, DefaultValue, ?DEFAULT_INSTANCE_NAME).

%% @doc Evaluate given flag key for given user and given client instance
%%
%% 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().
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),
% Send events
SendEventsFun = fun(Event) -> eld_event_server:add_event(Tag, Event, #{}) end,
lists:foreach(SendEventsFun, Events),
% Return evaluation result
Value.

%% @doc Evaluate given flag key for given user
%% @deprecated
%%
%% Evaluation iterates through flag's prerequisites, targets, rules, associated
%% clauses and percentage rollouts. It returns the flag variation index, value
%% and reason, explaining why the specific result was chosen.
Expand All @@ -103,6 +134,7 @@ evaluate(FlagKey, User, DefaultValue) when is_binary(FlagKey), is_map(User) ->
evaluate(?DEFAULT_INSTANCE_NAME, FlagKey, User, DefaultValue).

%% @doc Evaluate given flag key for given user and given client instance
%% @deprecated
%%
%% Evaluation iterates through flag's prerequisites, targets, rules, associated
%% clauses and percentage rollouts. It returns the flag variation index, value
Expand All @@ -111,10 +143,33 @@ evaluate(FlagKey, User, DefaultValue) when is_binary(FlagKey), is_map(User) ->
-spec evaluate(Tag :: atom(), FlagKey :: binary(), User :: eld_user:user(), DefaultValue :: eld_eval:result_value()) ->
eld_eval:detail().
evaluate(Tag, FlagKey, User, DefaultValue) when is_binary(FlagKey), is_map(User) ->
error_logger:info_msg("eld:evaluate/3-4 is deprecated, use eld:variation_detail/3-4 instead."),
variation_detail(FlagKey, User, DefaultValue, Tag).

%% @doc Evaluate given flag key for given user
%%
%% Evaluates the flag and returns the result detail containing the variation
%% 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().
variation_detail(FlagKey, User, DefaultValue) when is_binary(FlagKey), is_map(User) ->
variation_detail(FlagKey, User, DefaultValue, ?DEFAULT_INSTANCE_NAME).

%% @doc Evaluate given flag key for given user and given client instance
%%
%% Evaluates the flag and returns the result detail containing the variation
%% 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().
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),
% Send events
SendEventsFun = fun(Event) -> eld_event_server:add_event(Tag, Event) end,
SendEventsFun = fun(Event) -> eld_event_server:add_event(Tag, Event, #{include_reasons => true}) end,
lists:foreach(SendEventsFun, Events),
% Return evaluation detail
Detail.
Expand All @@ -126,15 +181,15 @@ evaluate(Tag, FlagKey, User, DefaultValue) when is_binary(FlagKey), is_map(User)
%% @end
-spec all_flags_state(User :: eld_user:user()) -> feature_flags_state().
all_flags_state(User) ->
all_flags_state(?DEFAULT_INSTANCE_NAME, User).
all_flags_state(User, ?DEFAULT_INSTANCE_NAME).

%% @doc Evaluate all flags for a given user and given client instance
%%
%% 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(Tag :: atom(), User :: eld_user:user()) -> feature_flags_state().
all_flags_state(Tag, User) ->
-spec all_flags_state(User :: eld_user:user(), Tag :: atom()) -> feature_flags_state().
all_flags_state(User, Tag) ->
StorageBackend = eld_settings:get_value(Tag, storage_backend),
AllFlags = [FlagKey || {FlagKey, _} <- StorageBackend:list(default, flags)],
EvalFun = fun(FlagKey, Acc) ->
Expand All @@ -149,30 +204,30 @@ all_flags_state(Tag, User) ->
%% @end
-spec identify(User :: eld_user:user()) -> ok.
identify(User) ->
identify(?DEFAULT_INSTANCE_NAME, User).
identify(User, ?DEFAULT_INSTANCE_NAME).

%% @doc Identify reports details about a user
%%
%% This is useful to report user to a specific client instance.
%% @end
-spec identify(Tag :: atom(), User :: eld_user:user()) -> ok.
identify(Tag, User) when is_atom(Tag) ->
-spec identify(User :: eld_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).
eld_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.
track(Key, User, Data) when is_binary(Key), is_map(Data) ->
track(?DEFAULT_INSTANCE_NAME, Key, User, Data).
track(Key, User, Data, ?DEFAULT_INSTANCE_NAME).

%% @doc Track reports that a user has performed an event
%%
%% This is useful for specifying a specific client instance.
%% @end
-spec track(Tag :: atom(), Key :: binary(), User :: eld_user:user(), Data :: map()) -> ok.
track(Tag, Key, User, Data) when is_atom(Tag), is_binary(Key), is_map(Data) ->
-spec track(Key :: binary(), User :: eld_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).
eld_event_server:add_event(Tag, Event, #{}).
5 changes: 5 additions & 0 deletions src/eld_event.erl
Original file line number Diff line number Diff line change
Expand Up @@ -15,6 +15,7 @@
-export([new_identify/1]).
-export([new_index/2]).
-export([new_custom/3]).
-export([strip_eval_reason/1]).

%% Types
-type event() :: #{
Expand Down Expand Up @@ -192,3 +193,7 @@ new_index(User, Timestamp) ->
-spec new_custom(Key :: binary(), User :: eld_user:user(), Data :: map()) -> event().
new_custom(Key, User, Data) when is_binary(Key), is_map(Data) ->
new(custom, Key, User, erlang:system_time(milli_seconds), Data).

-spec strip_eval_reason(eld_event:event()) -> eld_event:event().
strip_eval_reason(#{type := feature_request, data := Data} = Event) ->
Event#{data => maps:remove(eval_reason, Data)}.
Loading

0 comments on commit 0305502

Please sign in to comment.