Skip to content

Commit 0305502

Browse files
authored
Prepare 1.0.0-alpha2 release (#3)
1 parent fcf7b0a commit 0305502

File tree

12 files changed

+522
-124
lines changed

12 files changed

+522
-124
lines changed

CHANGELOG.md

Lines changed: 21 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -2,6 +2,27 @@
22

33
All notable changes to the LaunchDarkly Erlang/Elixir SDK will be documented in this file. This project adheres to [Semantic Versioning](http://semver.org).
44

5+
## [1.0.0-alpha2] - 2019-08-07
6+
7+
### Added
8+
9+
- Support for all server side LaunchDarkly events
10+
- `eld:variation/3-4` and `eld:variation_detail/3-4` functions to replace `eld:evaluate/3-4` to reflect the naming convention
11+
- Feature to inline users inside events
12+
- Feature to define global private user attributes, including making all user attributes private
13+
14+
### Fixed
15+
16+
- Events POST URI, it no longer gets HTTP 405 Method Not Allowed error
17+
18+
### Deprecated
19+
- `eld:evaluate/3-4` will be removed in a future release
20+
21+
### Missing
22+
23+
- Polling support
24+
- Known issues for some edge case error conditions, and other minor missing features
25+
526
## [1.0.0-alpha1] - 2019-07-24
627

728
### Added

Makefile

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -1,6 +1,6 @@
11
PROJECT = eld
22
PROJECT_DESCRIPTION = Erlang LaunchDarkly SDK Client
3-
PROJECT_VERSION = 1.0.0-alpha1
3+
PROJECT_VERSION = 1.0.0-alpha2
44

55
# Dependencies
66

relx.config

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -1,2 +1,2 @@
1-
{release, {eld, "1.0.0-alpha1"}, [eld]}.
1+
{release, {eld, "1.0.0-alpha2"}, [eld]}.
22
{extended_start_script, true}.

src/eld.app.src

Lines changed: 3 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -1,6 +1,6 @@
11
{application, eld,
22
[{description, "LaunchDarkly Erlang SDK"},
3-
{vsn, "1.0.0-alpha1"},
3+
{vsn, "1.0.0-alpha2"},
44
{registered, []},
55
{mod, {eld_app, []}},
66
{applications,
@@ -14,7 +14,8 @@
1414
shotgun,
1515
jsx,
1616
lru,
17-
backoff
17+
backoff,
18+
verl
1819
]},
1920
{env,[]},
2021
{modules, []},

src/eld.erl

Lines changed: 67 additions & 12 deletions
Original file line numberDiff line numberDiff line change
@@ -17,6 +17,10 @@
1717
-export([stop_instance/1]).
1818
-export([evaluate/3]).
1919
-export([evaluate/4]).
20+
-export([variation/3]).
21+
-export([variation/4]).
22+
-export([variation_detail/3]).
23+
-export([variation_detail/4]).
2024
-export([all_flags_state/1]).
2125
-export([all_flags_state/2]).
2226
-export([identify/1]).
@@ -93,6 +97,33 @@ stop_instance(Tag) when is_atom(Tag) ->
9397

9498
%% @doc Evaluate given flag key for given user
9599
%%
100+
%% Evaluates the flag and returns the resulting variation value. The default
101+
%% value will be returned in case of any errors.
102+
%% @end
103+
-spec variation(FlagKey :: binary(), User :: eld_user:user(), DefaultValue :: eld_eval:result_value()) ->
104+
eld_eval:result_value().
105+
variation(FlagKey, User, DefaultValue) when is_binary(FlagKey), is_map(User) ->
106+
variation(FlagKey, User, DefaultValue, ?DEFAULT_INSTANCE_NAME).
107+
108+
%% @doc Evaluate given flag key for given user and given client instance
109+
%%
110+
%% Evaluates the flag and returns the resulting variation value. The default
111+
%% value will be returned in case of any errors.
112+
%% @end
113+
-spec variation(FlagKey :: binary(), User :: eld_user:user(), DefaultValue :: eld_eval:result_value(), Tag :: atom()) ->
114+
eld_eval:result_value().
115+
variation(FlagKey, User, DefaultValue, Tag) when is_binary(FlagKey), is_map(User) ->
116+
% Get evaluation result detail
117+
{{_Index, Value, _Reason}, Events} = eld_eval:flag_key_for_user(Tag, FlagKey, User, DefaultValue),
118+
% Send events
119+
SendEventsFun = fun(Event) -> eld_event_server:add_event(Tag, Event, #{}) end,
120+
lists:foreach(SendEventsFun, Events),
121+
% Return evaluation result
122+
Value.
123+
124+
%% @doc Evaluate given flag key for given user
125+
%% @deprecated
126+
%%
96127
%% Evaluation iterates through flag's prerequisites, targets, rules, associated
97128
%% clauses and percentage rollouts. It returns the flag variation index, value
98129
%% and reason, explaining why the specific result was chosen.
@@ -103,6 +134,7 @@ evaluate(FlagKey, User, DefaultValue) when is_binary(FlagKey), is_map(User) ->
103134
evaluate(?DEFAULT_INSTANCE_NAME, FlagKey, User, DefaultValue).
104135

105136
%% @doc Evaluate given flag key for given user and given client instance
137+
%% @deprecated
106138
%%
107139
%% Evaluation iterates through flag's prerequisites, targets, rules, associated
108140
%% clauses and percentage rollouts. It returns the flag variation index, value
@@ -111,10 +143,33 @@ evaluate(FlagKey, User, DefaultValue) when is_binary(FlagKey), is_map(User) ->
111143
-spec evaluate(Tag :: atom(), FlagKey :: binary(), User :: eld_user:user(), DefaultValue :: eld_eval:result_value()) ->
112144
eld_eval:detail().
113145
evaluate(Tag, FlagKey, User, DefaultValue) when is_binary(FlagKey), is_map(User) ->
146+
error_logger:info_msg("eld:evaluate/3-4 is deprecated, use eld:variation_detail/3-4 instead."),
147+
variation_detail(FlagKey, User, DefaultValue, Tag).
148+
149+
%% @doc Evaluate given flag key for given user
150+
%%
151+
%% Evaluates the flag and returns the result detail containing the variation
152+
%% index, value, and reason why the specific result was chosen. The default
153+
%% value will be returned in case of any errors.
154+
%% @end
155+
-spec variation_detail(FlagKey :: binary(), User :: eld_user:user(), DefaultValue :: eld_eval:result_value()) ->
156+
eld_eval:detail().
157+
variation_detail(FlagKey, User, DefaultValue) when is_binary(FlagKey), is_map(User) ->
158+
variation_detail(FlagKey, User, DefaultValue, ?DEFAULT_INSTANCE_NAME).
159+
160+
%% @doc Evaluate given flag key for given user and given client instance
161+
%%
162+
%% Evaluates the flag and returns the result detail containing the variation
163+
%% index, value, and reason why the specific result was chosen. The default
164+
%% value will be returned in case of any errors.
165+
%% @end
166+
-spec variation_detail(FlagKey :: binary(), User :: eld_user:user(), DefaultValue :: eld_eval:result_value(), Tag :: atom()) ->
167+
eld_eval:detail().
168+
variation_detail(FlagKey, User, DefaultValue, Tag) when is_binary(FlagKey), is_map(User) ->
114169
% Get evaluation result detail
115170
{Detail, Events} = eld_eval:flag_key_for_user(Tag, FlagKey, User, DefaultValue),
116171
% Send events
117-
SendEventsFun = fun(Event) -> eld_event_server:add_event(Tag, Event) end,
172+
SendEventsFun = fun(Event) -> eld_event_server:add_event(Tag, Event, #{include_reasons => true}) end,
118173
lists:foreach(SendEventsFun, Events),
119174
% Return evaluation detail
120175
Detail.
@@ -126,15 +181,15 @@ evaluate(Tag, FlagKey, User, DefaultValue) when is_binary(FlagKey), is_map(User)
126181
%% @end
127182
-spec all_flags_state(User :: eld_user:user()) -> feature_flags_state().
128183
all_flags_state(User) ->
129-
all_flags_state(?DEFAULT_INSTANCE_NAME, User).
184+
all_flags_state(User, ?DEFAULT_INSTANCE_NAME).
130185

131186
%% @doc Evaluate all flags for a given user and given client instance
132187
%%
133188
%% Evaluates all existing flags, but does not create any events as a side
134189
%% effect of the evaluation. It returns a map of flag keys to evaluated values.
135190
%% @end
136-
-spec all_flags_state(Tag :: atom(), User :: eld_user:user()) -> feature_flags_state().
137-
all_flags_state(Tag, User) ->
191+
-spec all_flags_state(User :: eld_user:user(), Tag :: atom()) -> feature_flags_state().
192+
all_flags_state(User, Tag) ->
138193
StorageBackend = eld_settings:get_value(Tag, storage_backend),
139194
AllFlags = [FlagKey || {FlagKey, _} <- StorageBackend:list(default, flags)],
140195
EvalFun = fun(FlagKey, Acc) ->
@@ -149,30 +204,30 @@ all_flags_state(Tag, User) ->
149204
%% @end
150205
-spec identify(User :: eld_user:user()) -> ok.
151206
identify(User) ->
152-
identify(?DEFAULT_INSTANCE_NAME, User).
207+
identify(User, ?DEFAULT_INSTANCE_NAME).
153208

154209
%% @doc Identify reports details about a user
155210
%%
156211
%% This is useful to report user to a specific client instance.
157212
%% @end
158-
-spec identify(Tag :: atom(), User :: eld_user:user()) -> ok.
159-
identify(Tag, User) when is_atom(Tag) ->
213+
-spec identify(User :: eld_user:user(), Tag :: atom()) -> ok.
214+
identify(User, Tag) when is_atom(Tag) ->
160215
Event = eld_event:new_identify(User),
161-
eld_event_server:add_event(Tag, Event).
216+
eld_event_server:add_event(Tag, Event, #{}).
162217

163218
%% @doc Track reports that a user has performed an event
164219
%%
165220
%% Custom data can be attached to the event.
166221
%% @end
167222
-spec track(Key :: binary(), User :: eld_user:user(), Data :: map()) -> ok.
168223
track(Key, User, Data) when is_binary(Key), is_map(Data) ->
169-
track(?DEFAULT_INSTANCE_NAME, Key, User, Data).
224+
track(Key, User, Data, ?DEFAULT_INSTANCE_NAME).
170225

171226
%% @doc Track reports that a user has performed an event
172227
%%
173228
%% This is useful for specifying a specific client instance.
174229
%% @end
175-
-spec track(Tag :: atom(), Key :: binary(), User :: eld_user:user(), Data :: map()) -> ok.
176-
track(Tag, Key, User, Data) when is_atom(Tag), is_binary(Key), is_map(Data) ->
230+
-spec track(Key :: binary(), User :: eld_user:user(), Data :: map(), Tag :: atom()) -> ok.
231+
track(Key, User, Data, Tag) when is_atom(Tag), is_binary(Key), is_map(Data) ->
177232
Event = eld_event:new_custom(Key, User, Data),
178-
eld_event_server:add_event(Tag, Event).
233+
eld_event_server:add_event(Tag, Event, #{}).

src/eld_event.erl

Lines changed: 5 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -15,6 +15,7 @@
1515
-export([new_identify/1]).
1616
-export([new_index/2]).
1717
-export([new_custom/3]).
18+
-export([strip_eval_reason/1]).
1819

1920
%% Types
2021
-type event() :: #{
@@ -192,3 +193,7 @@ new_index(User, Timestamp) ->
192193
-spec new_custom(Key :: binary(), User :: eld_user:user(), Data :: map()) -> event().
193194
new_custom(Key, User, Data) when is_binary(Key), is_map(Data) ->
194195
new(custom, Key, User, erlang:system_time(milli_seconds), Data).
196+
197+
-spec strip_eval_reason(eld_event:event()) -> eld_event:event().
198+
strip_eval_reason(#{type := feature_request, data := Data} = Event) ->
199+
Event#{data => maps:remove(eval_reason, Data)}.

0 commit comments

Comments
 (0)