Skip to content

Instantly share code, notes, and snippets.

@iilyak
iilyak / couch_log_formatter.erl
Created July 20, 2020 15:50
Remove sensitive data
do_format({error, _GL, {Pid, "** gen_event handler" ++ _, Args}}) ->
%% gen_event handler terminate
[ID, Name, LastMsg, State, Reason] = Args,
MsgFmt = "gen_event ~w installed in ~w terminated with reason: ~s~n" ++
case config:get_boolean("couch_log", "strip_sensitive", true) of
true ->
MsgFmt = "gen_event ~w installed in ~w terminated with reason: ~s~n" ++
" last msg: reducted~n state: ~p",
MsgArgs = [ID, Name, format_reason(Reason), State],
format(error, Pid, MsgFmt, MsgArgs);
@iilyak
iilyak / ADR-0001-otter-configuration.md
Last active September 13, 2019 16:58
ADR-0001 :: Store filter configuration for otter
@iilyak
iilyak / readme.md
Last active September 12, 2019 17:14
Jaeger expriment to check parallel spans

CouchDB is a distributed system which submits jobs from coordinator nodes to storage nodes. To handle single request, we send it to every node in parallel and then aggregate responses. In order to adequately represent it in traces we need support for nested spans. This quick experiment tests how this case is rendered in Jaeger.

Run jaeger as follows

./jaeger-all-in-one --collector.zipkin.http-port=9411

Execute test script

python3 trace.py
git clone https://github.com/apache/couchdb-mochiweb
cd couchdb-mochiweb
git diff bd6eb60..CouchDB-2.12.0-1
@iilyak
iilyak / couch_ejson_size.erl
Created August 21, 2017 20:37
Generating JSON using proper
%% https://github.com/cloudant/couchdb/pull/7-module(couch_ejson_size).
-export([ejson_size/1]).
-ifdef(TEST).
-compile(export_all).
-include_lib("proper/include/proper.hrl").
-endif.
@iilyak
iilyak / erlang_skip_term.erl
Created July 11, 2017 19:40
skip binary encoded term
skip_n_terms(Bin, N) ->
lists:foldl(fun(_, {Acc, Bin}) ->
{Skipped, R} = skip_term(Bin),
{Skipped + Acc, R}
end, {0, Bin}, lists:seq(1, N)).
skip_term(<<97, _:1/binary, Rest/binary>>) -> %% SMALL_INTEGER_EXT
{2, Rest};
skip_term(<<98, _:4/binary, Rest/binary>>) -> %% INTEGER_EXT
{5, Rest};
@iilyak
iilyak / cloudant-master.md
Last active March 1, 2017 23:43
Possible strategies to maintain forks

Pros and Cons

Pros

  • Team members always issue PRs for the same branch.
  • We can merge PRs anytime.
  • The history of cloudant-master would always be like upstream master with few commits on top

Cons

set -e
function pr_label {
REPO_URL=${1}
PR=${2}
REPO=${REPO_URL##https://github.com/}
echo `curl -s https://api.github.com/repos/${REPO}/pulls/${PR} \
| jq .head.label | tr -d '"'`
}
--- a/rebar.config.script
+++ b/rebar.config.script
@@ -21,6 +23,12 @@ os:putenv("COUCHDB_CONFIG", ConfigureEnv).
os:putenv("COUCHDB_APPS_CONFIG_DIR", filename:join([COUCHDB_ROOT, "rel/apps"])).
+Features = lists:filter(fun({_K, Flag}) -> Flag end, [
+ {'HAS_ERL_SCAN_TOKEN_INFO', erlang:function_exported(erl_scan, token_info, 1)}
+]),
+
export SUFFIX=`date "+test-%s"`
export PORT=15984
export HOST=localhost
export DB=test-${SUFFIX}
export USER=foo-${SUFFIX}
echo -e "\033[32mCreate user"
cat <<EOF | http -v --auth='adm:pass' PUT http://${HOST}:${PORT}/_users/org.couchdb.user:${USER}
{
"_id": "org.couchdb.user:${USER}",