You are viewing a plain text version of this content. The canonical link for it is here.
Posted to notifications@couchdb.apache.org by GitBox <gi...@apache.org> on 2018/11/12 19:31:53 UTC

[GitHub] jaydoane commented on a change in pull request #1682: Feature flags

jaydoane commented on a change in pull request #1682: Feature flags
URL: https://github.com/apache/couchdb/pull/1682#discussion_r232079858
 
 

 ##########
 File path: src/couch/src/couch_flags.erl
 ##########
 @@ -0,0 +1,108 @@
+% Licensed under the Apache License, Version 2.0 (the "License"); you may not
+% use this file except in compliance with the License. You may obtain a copy of
+% the License at
+%
+% http://www.apache.org/licenses/LICENSE-2.0
+%
+% Unless required by applicable law or agreed to in writing, software
+% distributed under the License is distributed on an "AS IS" BASIS, WITHOUT
+% WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. See the
+% License for the specific language governing permissions and limitations under
+% the License.
+
+% This module serves two functions
+% - provides public API to use to get value for a given feature flag and subject
+% - implements {feature_flags, couch_flags} service
+
+% The module rely on couch_epi_data_gen which uses the data returned by
+% `couch_flags_config:data()` to generate callback module `couch_epi_data_gen_flags_config`.
+% The generated module shouldn't be used directly. We use following APIs
+% - `couch_epi:get_handle({flags, config})` - to get handler (name of generated module)
+% - `couch_epi:get_value(Handle, Key) - to do efficient matching
+%
+% The generated module implements clauses like the following
+%  - get(couch, {binary_match_rule()}) ->
+%       {matched_pattern(), size(matched_pattern()), [flag()]} | undefined
+% For example
+%  - get(couch, {<<"/shards/test/exact">>}) ->
+%        {<<"/shards/test/exact">>,18,[baz,flag_bar,flag_foo]};
+%  - get(couch, {<<"/shards/test", _/binary>>}) ->
+%        {<<"/shards/test*">>,13,[baz,flag_bar,flag_foo]};
+%  - get(couch, {<<"/shards/exact">>}) ->
+%        {<<"/shards/exact">>,13,[flag_bar,flag_foo]};
+%  - get(couch, {<<"/shards/blacklist", _/binary>>}) ->
+%        {<<"/shards/blacklist*">>,18,[]};
+%  - get(couch, {<<"/", _/binary>>}) ->
+%        {<<"/*">>,2,[flag_foo]};
+%  - get(_, _) -> undefined.
+%
+% The `couch_epi:get/2` uses the Handler module to implement efficient matching.
+
+% In order to distinguish between shards and clustered db the following
+% convention is used.
+% - it is a shard if pattern starts with `/`
+
+-module(couch_flags).
+
+%% Public API
+-export([
+    enabled/1,
+    is_enabled/2
+]).
+
+%% For internal use
+-export([
+    rules/0
+]).
+
+%% For use from plugin
+-export([
+    subject_key/1
+]).
+
+-include_lib("couch/include/couch_db.hrl").
+-include_lib("mem3/include/mem3.hrl").
+-include("couch_db_int.hrl").
+
+-define(SERVICE_ID, feature_flags).
+
+enabled(Subject) ->
 
 Review comment:
   I would love to see type specs defined for public functions

----------------------------------------------------------------
This is an automated message from the Apache Git Service.
To respond to the message, please log on GitHub and use the
URL above to go to the specific comment.
 
For queries about this service, please contact Infrastructure at:
users@infra.apache.org


With regards,
Apache Git Services