TD-271: Machine tagging via bender (#32)

This commit is contained in:
Alexey S 2022-05-23 13:58:46 +03:00 committed by GitHub
parent 0d0c59a0c2
commit 4278ab139e
No known key found for this signature in database
GPG Key ID: 4AEE18F83AFDEB23
9 changed files with 116 additions and 15 deletions

View File

@ -136,6 +136,22 @@ start_app(ff_server = AppName) ->
]),
#{}
};
start_app(bender_client = AppName) ->
{
start_app_with(AppName, [
{services, #{
'Bender' => <<"http://bender:8022/v1/bender">>,
'Generator' => <<"http://bender:8022/v1/generator">>
}},
{deadline, 10000},
{retries, #{
'GenerateID' => finish,
'GetInternalID' => finish,
'_' => finish
}}
]),
#{}
};
start_app({AppName, AppEnv}) ->
{start_app_with(AppName, AppEnv), #{}};
start_app(AppName) ->

View File

@ -75,7 +75,8 @@ start_processing_apps(Options) ->
{services, services(Options)},
{providers, identity_provider_config(Options)}
]},
ff_server
ff_server,
bender_client
]),
SuiteSup = ct_sup:start(),
{ok, _} = supervisor:start_child(

View File

@ -130,7 +130,16 @@ repair(ID, Scenario) ->
{ok, process_callback_response()}
| {error, process_callback_error()}.
process_callback(#{tag := Tag} = Params) ->
call({tag, Tag}, {process_callback, Params}).
MachineRef =
case ff_machine_tag:get_binding(?NS, Tag) of
{ok, EntityID} ->
EntityID;
{error, not_found} ->
%% Fallback to machinegun tagging
%% TODO: Remove after migration grace period
{tag, Tag}
end,
call(MachineRef, {process_callback, Params}).
%% machinery callbacks
@ -188,8 +197,9 @@ set_action(continue, _St) ->
continue;
set_action(undefined, _St) ->
undefined;
set_action({setup_callback, Tag, Timer}, _St) ->
[tag_action(Tag), timer_action(Timer)];
set_action({setup_callback, Tag, Timer}, St) ->
ok = ff_machine_tag:create_binding(?NS, Tag, ff_withdrawal_session:id(session(St))),
timer_action(Timer);
set_action({setup_timer, Timer}, _St) ->
timer_action(Timer);
set_action(retry, St) ->
@ -252,10 +262,6 @@ check_deadline_(Now, Deadline) when Now >= Deadline ->
timer_action(Timer) ->
{set_timer, Timer}.
-spec tag_action(machinery:tag()) -> machinery:action().
tag_action(Tag) ->
{tag, Tag}.
backend() ->
fistful:backend(?NS).

View File

@ -0,0 +1,37 @@
-module(ff_machine_tag).
-define(BENDER_NS, <<"machinegun-tag">>).
-export([get_binding/2]).
-export([create_binding/3]).
-type tag() :: mg_proto_base_thrift:'Tag'().
-type ns() :: machinery:namespace().
-type entity_id() :: dmsl_base_thrift:'ID'().
-spec get_binding(ns(), tag()) -> {ok, entity_id()} | {error, not_found}.
get_binding(NS, Tag) ->
WoodyContext = ff_context:get_woody_context(ff_context:load()),
case bender_client:get_internal_id(tag_to_external_id(NS, Tag), WoodyContext) of
{ok, EntityID} ->
{ok, EntityID};
{error, internal_id_not_found} ->
{error, not_found}
end.
-spec create_binding(ns(), tag(), entity_id()) -> ok | no_return().
create_binding(NS, Tag, EntityID) ->
create_binding_(NS, Tag, EntityID, undefined).
%%
create_binding_(NS, Tag, EntityID, Context) ->
WoodyContext = ff_context:get_woody_context(ff_context:load()),
case bender_client:gen_constant(tag_to_external_id(NS, Tag), EntityID, WoodyContext, Context) of
{ok, EntityID} ->
ok
end.
tag_to_external_id(NS, Tag) ->
BinNS = atom_to_binary(NS, utf8),
<<?BENDER_NS/binary, "-", BinNS/binary, "-", Tag/binary>>.

View File

@ -15,7 +15,8 @@
damsel,
dmt_client,
party_client,
binbase_proto
binbase_proto,
bender_client
]},
{env, []},
{maintainers, [

View File

@ -62,6 +62,19 @@
}}
]},
{bender_client, [
{services, #{
'Bender' => <<"http://bender:8022/v1/bender">>,
'Generator' => <<"http://bender:8022/v1/generator">>
}},
{deadline, 60000}
%{retries, #{
% 'GenerateID' => finish,
% 'GetInternalID' => finish,
% '_' => finish
%}}
]},
{fistful, [
{provider, #{
<<"ncoeps">> => #{

View File

@ -20,6 +20,8 @@ services:
condition: service_healthy
shumway:
condition: service_healthy
bender:
condition: service_healthy
working_dir: $PWD
command: /sbin/init
@ -84,6 +86,18 @@ services:
timeout: 5s
retries: 10
bender:
image: ghcr.io/valitydev/bender:sha-d05ea29
command: /opt/bender/bin/bender foreground
depends_on:
machinegun:
condition: service_healthy
healthcheck:
test: "/opt/bender/bin/bender ping"
interval: 10s
timeout: 5s
retries: 10
shumway-db:
image: docker.io/library/postgres:9.6
environment:

View File

@ -34,12 +34,13 @@
{thrift, {git, "https://github.com/valitydev/thrift_erlang.git", {branch, "master"}}},
{woody, {git, "https://github.com/valitydev/woody_erlang.git", {branch, "master"}}},
{erl_health, {git, "https://github.com/valitydev/erlang-health.git", {branch, "master"}}},
{machinery, {git, "https://github.com/valitydev/machinery.git", {branch, "master"}}},
{machinery, {git, "https://github.com/valitydev/machinery-erlang.git", {branch, "master"}}},
{damsel, {git, "https://github.com/valitydev/damsel.git", {branch, "master"}}},
{dmt_client, {git, "https://github.com/valitydev/dmt_client.git", {branch, master}}},
{fistful_proto, {git, "https://github.com/valitydev/fistful-proto.git", {branch, "master"}}},
{binbase_proto, {git, "https://github.com/valitydev/binbase-proto.git", {branch, "master"}}},
{party_client, {git, "https://github.com/valitydev/party-client-erlang.git", {branch, "master"}}}
{party_client, {git, "https://github.com/valitydev/party-client-erlang.git", {branch, "master"}}},
{bender_client, {git, "https://github.com/valitydev/bender-client-erlang.git", {branch, "master"}}}
]}.
{xref_checks, [

View File

@ -1,8 +1,16 @@
{"1.2.0",
[{<<"accept">>,{pkg,<<"accept">>,<<"0.3.5">>},2},
{<<"bender_client">>,
{git,"https://github.com/valitydev/bender-client-erlang.git",
{ref,"7e869938a29c3c232e07eaa335a1a67892e07239"}},
0},
{<<"bender_proto">>,
{git,"https://github.com/valitydev/bender-proto.git",
{ref,"38ce3ffde52fb2f52a8d042e67a3e2715adb7546"}},
1},
{<<"binbase_proto">>,
{git,"https://github.com/valitydev/binbase-proto.git",
{ref,"4c2e11c58bc3574540f729f6ddc88796dba119ce"}},
{ref,"9db92d90e0e28953cdb1b30c719edb529aa86579"}},
0},
{<<"cache">>,{pkg,<<"cache">>,<<"2.3.3">>},1},
{<<"certifi">>,{pkg,<<"certifi">>,<<"2.8.0">>},2},
@ -41,15 +49,19 @@
{<<"idna">>,{pkg,<<"idna">>,<<"6.1.1">>},2},
{<<"jsx">>,{pkg,<<"jsx">>,<<"3.1.0">>},1},
{<<"machinery">>,
{git,"https://github.com/valitydev/machinery.git",
{ref,"db7c94b9913451e9558afa19f2fe77bf48d391da"}},
{git,"https://github.com/valitydev/machinery-erlang.git",
{ref,"ff4cfefb616250f6905c25e79f74a7a30eb1aae5"}},
0},
{<<"metrics">>,{pkg,<<"metrics">>,<<"1.0.1">>},2},
{<<"mg_proto">>,
{git,"https://github.com/valitydev/machinegun-proto.git",
{ref,"d814d6948d4ff13f6f41d12c6613f59c805750b2"}},
{ref,"b43d6fd0939ee4029ec8873dbd16f3c5fbe4a95c"}},
1},
{<<"mimerl">>,{pkg,<<"mimerl">>,<<"1.2.0">>},2},
{<<"msgpack_proto">>,
{git,"https://github.com/rbkmoney/msgpack-proto.git",
{ref,"ec15d5e854ea60c58467373077d90c2faf6273d8"}},
2},
{<<"parse_trans">>,{pkg,<<"parse_trans">>,<<"3.3.1">>},2},
{<<"party_client">>,
{git,"https://github.com/valitydev/party-client-erlang.git",