Skip to content
Draft
Show file tree
Hide file tree
Changes from all commits
Commits
Show all changes
60 commits
Select commit Hold shift + click to select a range
b9a84e3
added ignore
WWWcool Feb 17, 2021
439b1c6
initial
WWWcool Feb 17, 2021
bdaca98
added rebar lock
WWWcool Feb 17, 2021
563fb97
added build_utils
WWWcool Feb 17, 2021
9bf3e29
P2C-14: Limiter (#1)
WWWcool May 17, 2021
c1aa300
Bump to damsel rbkmoney/damsel@d4b40ea
0x42 Jun 1, 2021
70c1494
Merge pull request #2 from rbkmoney/ED-156/ft/add_latest_clock
0x42 Jun 4, 2021
d6561f9
fix bug calc shard id(same usec); add in config day limit
0x42 Jun 7, 2021
148979f
Merge pull request #3 from rbkmoney/ED-156/ft/add_latest_clock
0x42 Jun 7, 2021
9e83224
fix same usec
0x42 Jun 7, 2021
c5572a9
Merge pull request #4 from rbkmoney/ED-156/ft/add_latest_clock
0x42 Jun 7, 2021
4beba47
add subtraction behaviour in limit amount computation
0x42 Jun 21, 2021
74a6367
Merge branch 'master' into fix/debug
0x42 Jun 21, 2021
5a86c52
format
0x42 Jun 21, 2021
fb6c6bc
upd proto, param op_behaviour set from api
0x42 Jun 22, 2021
731859d
delete junk code, refactor
0x42 Jun 23, 2021
886acc0
Merge pull request #5 from rbkmoney/ED-181/ft/subtraction_behaviour
0x42 Jun 23, 2021
c7e9606
fix (#6)
0x42 Jul 19, 2021
689aea6
ED-297: New create method (#7)
WWWcool Oct 20, 2021
9a5ae48
Drop proprietary CI stuff
keynslug Apr 14, 2022
f577d12
TD-275: Add CI through GH Actions (#1)
keynslug Apr 18, 2022
3b10d1c
TD-275: Ensure limit changes handled idempotently (#3)
keynslug Apr 19, 2022
b1cd093
TD-303: Add multiscope support (#7)
keynslug Jun 3, 2022
0c6b2af
🔄 Synced file(s) with valitydev/configurations (#4)
valitydev-bot Jun 9, 2022
d36b97f
TD-304: Handle `amount` limit body type (#8)
keynslug Jun 10, 2022
2dff7b5
TD-305: Add new payproc context and payment tool scope implementetion…
WWWcool Jun 20, 2022
618a751
TD-329: Add withdrawal context support (#12)
keynslug Jul 6, 2022
40e4b22
Reuse valitydev/action-deploy-docker@v2 (#13)
keynslug Jul 12, 2022
cd37acd
added party scope test (#14)
WWWcool Aug 5, 2022
edbdccb
TD-407: Add provider, terminal, wallet, identity, email scopes (#15)
WWWcool Oct 2, 2022
daf099b
TD-427: Add plan id wrap with hash (#16)
WWWcool Oct 21, 2022
5c61eaf
Temporarily disable currency conversion (#17)
ndiezel0 Dec 7, 2022
7c416e2
Fix InvalidRequest (#18)
ndiezel0 Dec 7, 2022
d7febd5
TD-511: Adds app configuration flag to disable currency conversion (#19)
nanodirijabl Feb 20, 2023
3eff7dd
VEN-9: Adds support for versioned limit config object (#20)
nanodirijabl Mar 1, 2023
5af0cc6
TD-550: Adds new exceptions support for hold operation (#21)
nanodirijabl Apr 6, 2023
2b8723b
TD-550: Adds business exceptions for rollback (#22)
nanodirijabl Apr 14, 2023
32484db
bumped to valitydev/damsel@52dbefd (#23)
WWWcool May 21, 2023
d5fc565
OPS-268: Setups user in `Dockerfile` (#24)
nanodirijabl Jul 5, 2023
6c3bfe3
OPS-268: Adds default logger permissions (#25)
nanodirijabl Jul 13, 2023
e9e5e63
OPS-356: Remove inv adj (#26)
WWWcool Sep 4, 2023
920d6ac
TD-686: Adopts opentelemetry API (#27)
nanodirijabl Oct 24, 2023
bcff0b7
CP-12: Adds support for 'currency_conversion' config option (#28)
nanodirijabl May 29, 2024
9c1ee9f
CP-4: Adds support for 'sender' and 'receiver' scopes for withdrawal …
nanodirijabl Jun 4, 2024
0fc3b48
EMP-74: Adds scope support for withdrawal's destination field, e.g. p…
nanodirijabl Oct 29, 2024
553e18d
Adds support for prometheus woody metrics (#32)
nanodirijabl Oct 31, 2024
2646b71
TD-958: New backend (#30)
WWWcool Nov 25, 2024
2271094
Adds missing liminator client to default `sys.config` (#33)
nanodirijabl Nov 25, 2024
a6f63ea
EMP-170: Generic cond bump (#34)
WWWcool Dec 10, 2024
bcf48f3
TECH-76: Upgrades to Erlang/OTP 27 (#35)
nanodirijabl Feb 6, 2025
08cdd07
Epic: Party here! (#36)
WWWcool May 29, 2025
8fd529e
Upgrades to dmt v2 #major (#37)
nanodirijabl Jun 5, 2025
9eb96a7
BG-327: Bump damsel (#38)
WWWcool Aug 1, 2025
9ed4e6e
BG-378: Bump (#39)
WWWcool Aug 27, 2025
7b27571
BG-378: Bump dmt client (#40)
WWWcool Aug 27, 2025
2a3f78d
Removes obsolete machinery-based limit support (#43)
nanodirijabl Oct 9, 2025
80fb5bc
Bumps liminator and reenables partial-commit testcases (#45)
nanodirijabl Oct 10, 2025
67cf0b7
BG-753: Adds operations grouping by finalization behaviour (#46)
nanodirijabl Feb 25, 2026
77b12a0
bump liminator (#48)
D-Baykov May 11, 2026
9e0cd11
Merge remote-tracking branch 'limiter-upstream/master' into ft/limite…
nanodirijabl Jul 16, 2026
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
1 change: 0 additions & 1 deletion .env
Original file line number Diff line number Diff line change
@@ -1,4 +1,3 @@
SERVICE_NAME=hellgate
OTP_VERSION=28.5.0
REBAR_VERSION=3.26
THRIFT_VERSION=0.14.2.3
5 changes: 5 additions & 0 deletions README.md
Original file line number Diff line number Diff line change
@@ -1,3 +1,5 @@
**TODO: Clean up readme!**

# Hellgate

Core logic service for payment states processing.
Expand Down Expand Up @@ -99,3 +101,6 @@ $ make wdeps-test
## Служебные лимиты

Нужно уметь _ограничивать_ максимальное _ожидаемое_ количество тех или иных объектов, превышение которого может негативно влиять на качество обслуживания системы. Например, мы можем считать количество _выводов_ одним участником неограниченным, однако при этом неограниченное количество созданных _личностей_ мы совершенно не ожидаем. В этом случае возможно будет разумно ограничить их количество сверху труднодостижимой для подавляющего большинства планкой, например, в 1000 объектов. В идеале подобное должно быть точечно конфигурируемым.

# limiter
Service for limits calculating
51 changes: 51 additions & 0 deletions apps/limiter/src/lim_body.erl
Original file line number Diff line number Diff line change
@@ -0,0 +1,51 @@
-module(lim_body).

-export([get/3]).

-type amount() :: integer().
-type cash() :: #{
amount := amount(),
currency := currency()
}.

-type currency() :: dmsl_domain_thrift:'CurrencySymbolicCode'().
-type config() :: lim_config_machine:config().
-type body_type() :: full | partial.

-export_type([amount/0]).
-export_type([currency/0]).
-export_type([cash/0]).

-import(lim_pipeline, [do/1, unwrap/1]).

-spec get(body_type(), config(), lim_context:t()) ->
{ok, cash()} | {error, notfound}.
get(BodyType, Config, LimitContext) ->
do(fun() ->
ContextType = lim_config_machine:context_type(Config),
Operation = unwrap(lim_context:get_operation(ContextType, LimitContext)),
Body = unwrap(get_body_for_operation(BodyType, ContextType, LimitContext)),
apply_op_behaviour(Operation, Body, Config)
end).

-spec get_body_for_operation(body_type(), lim_context:context_type(), lim_context:t()) ->
{ok, cash()} | {error, notfound}.
get_body_for_operation(full, ContextType, LimitContext) ->
lim_context:get_value(ContextType, cost, LimitContext);
get_body_for_operation(partial, ContextType, LimitContext) ->
lim_context:get_value(ContextType, capture_cost, LimitContext).

apply_op_behaviour(Operation, Body, #{op_behaviour := ComputationConfig}) ->
case maps:get(Operation, ComputationConfig, undefined) of
addition ->
Body;
subtraction ->
invert_body(Body);
undefined ->
Body
end;
apply_op_behaviour(_Operation, Body, _Config) ->
Body.

invert_body(#{amount := Amount} = Cash) ->
Cash#{amount := -Amount}.
59 changes: 59 additions & 0 deletions apps/limiter/src/lim_client_woody.erl
Original file line number Diff line number Diff line change
@@ -0,0 +1,59 @@
-module(lim_client_woody).

-export([call/4]).
-export([call/5]).
-export([get_service_client_url/1]).

-define(APP, limiter).
-define(DEFAULT_DEADLINE, 5000).

%%
-type service_name() :: atom().

-spec call(service_name(), woody:func(), woody:args(), woody_context:ctx()) -> woody:result().
call(ServiceName, Function, Args, Context) ->
EventHandler = {scoper_woody_event_handler, #{}},
call(ServiceName, Function, Args, Context, EventHandler).

-spec call(service_name(), woody:func(), woody:args(), woody_context:ctx(), woody:ev_handler()) -> woody:result().
call(ServiceName, Function, Args, Context0, EventHandler) ->
Deadline = get_service_deadline(ServiceName),
Context1 = set_deadline(Deadline, Context0),
Url = get_service_client_url(ServiceName),
Service = get_service_modname(ServiceName),
Request = {Service, Function, Args},
woody_client:call(
Request,
#{url => Url, event_handler => EventHandler},
Context1
).

get_service_client_config(ServiceName) ->
ServiceClients = genlib_app:env(?APP, service_clients, #{}),
maps:get(ServiceName, ServiceClients, #{}).

-spec get_service_client_url(atom()) -> lim_maybe:'maybe'(woody:url()).
get_service_client_url(ServiceName) ->
maps:get(url, get_service_client_config(ServiceName), undefined).

-spec get_service_modname(service_name()) -> woody:service().
get_service_modname(xrates) ->
{xrates_rate_thrift, 'Rates'};
get_service_modname(liminator) ->
{liminator_liminator_thrift, 'LiminatorService'};
get_service_modname(accounter) ->
{dmsl_accounter_thrift, 'Accounter'}.

-spec get_service_deadline(service_name()) -> undefined | woody_deadline:deadline().
get_service_deadline(ServiceName) ->
ServiceClient = get_service_client_config(ServiceName),
Timeout = maps:get(deadline, ServiceClient, ?DEFAULT_DEADLINE),
woody_deadline:from_timeout(Timeout).

set_deadline(Deadline, Context) ->
case woody_context:get_deadline(Context) of
undefined ->
woody_context:set_deadline(Deadline, Context);
_AlreadySet ->
Context
end.
Loading
Loading