Skip to content

Commit 9ec7cec

Browse files
authored
Adds support for hybrid and progressor machinery backends (#40)
* Adds support for hybrid and progressor machinery backends * Adds missing app dependency * Fixes testsuite setup * Fixes keeper_apps dialyzer warn * TECH-156: bump machinery * TECH-156: bump machinery --------- Co-authored-by: losto
1 parent ae7fc11 commit 9ec7cec

9 files changed

Lines changed: 232 additions & 46 deletions

File tree

compose.tracing.yaml

Lines changed: 12 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -1,5 +1,17 @@
11
services:
2+
3+
machinegun:
4+
environment: &otlp_enabled
5+
OTEL_TRACES_EXPORTER: otlp
6+
OTEL_TRACES_SAMPLER: parentbased_always_off
7+
OTEL_EXPORTER_OTLP_PROTOCOL: http_protobuf
8+
OTEL_EXPORTER_OTLP_ENDPOINT: http://jaeger:4318
9+
210
testrunner:
11+
environment:
12+
<<: *otlp_enabled
13+
OTEL_SERVICE_NAME: hellgate_testrunner
14+
OTEL_TRACES_SAMPLER: parentbased_always_on
315
depends_on:
416
jaeger:
517
condition: service_healthy

compose.yaml

Lines changed: 31 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -11,13 +11,15 @@ services:
1111
- .:$PWD
1212
hostname: $SERVICE_NAME
1313
depends_on:
14+
postgres:
15+
condition: service_healthy
1416
machinegun:
1517
condition: service_healthy
1618
working_dir: $PWD
1719
command: /sbin/init
1820

1921
machinegun:
20-
image: ghcr.io/valitydev/machinegun:sha-5c0db56
22+
image: ghcr.io/valitydev/mg2:sha-8bbcd29
2123
command: /opt/machinegun/bin/machinegun foreground
2224
volumes:
2325
- ./test/machinegun/config.yaml:/opt/machinegun/etc/config.yaml
@@ -27,3 +29,31 @@ services:
2729
interval: 5s
2830
timeout: 1s
2931
retries: 20
32+
33+
postgres:
34+
image: postgres:15-bookworm
35+
command: -c 'max_connections=200'
36+
environment:
37+
POSTGRES_DB: "progressor_db"
38+
POSTGRES_USER: "progressor"
39+
POSTGRES_PASSWORD: "progressor"
40+
PGDATA: "/tmp/postgresql/data/pgdata"
41+
volumes:
42+
- progressor-data:/tmp/postgresql/data
43+
ports:
44+
- "5432:5432"
45+
healthcheck:
46+
test: ["CMD-SHELL", "pg_isready -U progressor -d progressor_db"]
47+
interval: 10s
48+
timeout: 5s
49+
retries: 5
50+
start_period: 10s
51+
restart: unless-stopped
52+
deploy:
53+
resources:
54+
limits:
55+
cpus: '1'
56+
memory: 4G
57+
58+
volumes:
59+
progressor-data:

config/sys.config

Lines changed: 62 additions & 9 deletions
Original file line numberDiff line numberDiff line change
@@ -162,6 +162,17 @@
162162
{storages, #{
163163
<<"com.rbkmoney.apikeymgmt">> =>
164164
{machinegun, #{
165+
%% Available options for 'machinery_backend'
166+
%% machinegun | progressor | hybrid
167+
%%
168+
%% For 'progressor' and 'hybrid' backends ensure
169+
%% config '{progressor, [ ... ]}' is set.
170+
%%
171+
%% Backends 'hybrid' and 'machinegun' require
172+
%% 'namespace' and 'automation' set in this opts,
173+
%% and also '{token_keeper, [..., {machinegun, #{
174+
%% ... }} ]' to be configured.
175+
machinery_backend => hybrid,
165176
namespace => apikeymgmt,
166177
automaton => #{
167178
url => <<"http://machinegun:8022/v1/automaton">>,
@@ -187,15 +198,6 @@
187198
}}
188199
]}
189200
]},
190-
% {how_are_you, [
191-
% {metrics_publishers, [
192-
% {hay_statsd_publisher, #{
193-
% key_prefix => <<"bender.">>,
194-
% host => "localhost",
195-
% port => 8125
196-
% }}
197-
% ]}
198-
% ]},
199201
{scoper, [
200202
{storage, scoper_storage_logger}
201203
]},
@@ -204,6 +206,57 @@
204206
{max_backward_clock_moving, 1000}
205207
% {machine_id, hostname_hash}
206208
]},
209+
{epg_connector, [
210+
{databases, #{
211+
default_db => #{
212+
host => "postgres",
213+
port => 5432,
214+
database => "progressor_db",
215+
username => "progressor",
216+
password => "progressor"
217+
}
218+
}},
219+
{pools, #{
220+
default_pool => #{
221+
database => default_db,
222+
size => 30
223+
}
224+
}}
225+
]},
226+
{progressor, [
227+
{call_wait_timeout, 20},
228+
{defaults, #{
229+
storage => #{
230+
client => prg_pg_backend,
231+
options => #{
232+
pool => default_pool
233+
}
234+
},
235+
retry_policy => #{
236+
initial_timeout => 5,
237+
backoff_coefficient => 1.0,
238+
%% seconds
239+
max_timeout => 180,
240+
max_attempts => 3,
241+
non_retryable_errors => []
242+
},
243+
task_scan_timeout => 1,
244+
worker_pool_size => 100,
245+
process_step_timeout => 30
246+
}},
247+
{namespaces, #{
248+
'apikeymgmt' => #{
249+
processor => #{
250+
client => machinery_prg_backend,
251+
options => #{
252+
namespace => 'apikeymgmt',
253+
handler => {tk_storage_machinegun, #{}},
254+
schema => tk_storage_machinegun_schema
255+
}
256+
}
257+
}
258+
}}
259+
]},
207260

208261
{prometheus, [
209262
{collectors, [default]}

rebar.config

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -40,7 +40,7 @@
4040
{erl_health, {git, "https://github.com/valitydev/erlang-health.git", {branch, "master"}}},
4141
%% Only needed for some utility functions
4242
{bouncer_client, {git, "https://github.com/valitydev/bouncer-client-erlang.git", {tag, "v1.1.0"}}},
43-
{machinery, {git, "https://github.com/valitydev/machinery-erlang.git", {tag, "v1.1.1"}}},
43+
{machinery, {git, "https://github.com/valitydev/machinery-erlang.git", {tag, "v1.1.5"}}},
4444
{prometheus, "4.11.0"},
4545
{prometheus_cowboy, "0.1.9"},
4646
%% OpenTelemetry deps

rebar.lock

Lines changed: 6 additions & 6 deletions
Original file line numberDiff line numberDiff line change
@@ -27,7 +27,7 @@
2727
{<<"ctx">>,{pkg,<<"ctx">>,<<"0.6.0">>},2},
2828
{<<"epg_connector">>,
2929
{git,"https://github.com/valitydev/epg_connector.git",
30-
{ref,"35a7480b298ac4318352a03824ce06619b75f9da"}},
30+
{ref,"82055002c8cb73ef938e7035865419074e7f959b"}},
3131
2},
3232
{<<"epgsql">>,
3333
{git,"https://github.com/epgsql/epgsql.git",
@@ -55,7 +55,7 @@
5555
{<<"kafka_protocol">>,{pkg,<<"kafka_protocol">>,<<"4.1.10">>},3},
5656
{<<"machinery">>,
5757
{git,"https://github.com/valitydev/machinery-erlang.git",
58-
{ref,"4ead222fe26bf5341585f69cd2311cdbf8f11c67"}},
58+
{ref,"72ac2f56cf42a99c66310be8265b3c2bc84862fc"}},
5959
0},
6060
{<<"metrics">>,{pkg,<<"metrics">>,<<"1.0.1">>},2},
6161
{<<"mg_proto">>,
@@ -75,7 +75,7 @@
7575
{<<"parse_trans">>,{pkg,<<"parse_trans">>,<<"3.3.1">>},2},
7676
{<<"progressor">>,
7777
{git,"https://github.com/valitydev/progressor.git",
78-
{ref,"d261aaba4a5ea34b0074d7d21de6da1da3eee690"}},
78+
{ref,"e2fdf9d11a69e239d3f4dc51aa2dd122d44ee1b0"}},
7979
1},
8080
{<<"prometheus">>,{pkg,<<"prometheus">>,<<"4.11.0">>},0},
8181
{<<"prometheus_cowboy">>,{pkg,<<"prometheus_cowboy">>,<<"0.1.9">>},0},
@@ -97,7 +97,7 @@
9797
{ref,"3a60e5dc5bbd709495024f26e100b041c3547fd9"}},
9898
0},
9999
{<<"tls_certificate_check">>,
100-
{pkg,<<"tls_certificate_check">>,<<"1.26.0">>},
100+
{pkg,<<"tls_certificate_check">>,<<"1.27.0">>},
101101
1},
102102
{<<"token_keeper_proto">>,
103103
{git,"https://github.com/valitydev/token-keeper-proto.git",
@@ -142,7 +142,7 @@
142142
{<<"ranch">>, <<"8C7A100A139FD57F17327B6413E4167AC559FBC04CA7448E9BE9057311597A1D">>},
143143
{<<"recon">>, <<"9052588E83BFEDFD9B72E1034532AEE2A5369D9D9343B61AEB7FBCE761010741">>},
144144
{<<"ssl_verify_fun">>, <<"354C321CF377240C7B8716899E182CE4890C5938111A1296ADD3EC74CF1715DF">>},
145-
{<<"tls_certificate_check">>, <<"C0E8FFAB875748F2B122D4D4E465AEAA7249EA539F1004B7922CB3C61FFE261D">>},
145+
{<<"tls_certificate_check">>, <<"2C1C7FC922A329B9EB45DDF39113C998BBDEB28A534219CD884431E2AEE1811E">>},
146146
{<<"unicode_util_compat">>, <<"BC84380C9AB48177092F43AC89E4DFA2C6D62B40B8BD132B1059ECC7232F9A78">>},
147147
{<<"yamerl">>, <<"07DA13FFA1D8E13948943789665C62CCD679DFA7B324A4A2ED3149DF17F453A4">>}]},
148148
{pkg_hash_ext,[
@@ -177,7 +177,7 @@
177177
{<<"ranch">>, <<"49FBCFD3682FAB1F5D109351B61257676DA1A2FDBE295904176D5E521A2DDFE5">>},
178178
{<<"recon">>, <<"96C6799792D735CC0F0FD0F86267E9D351E63339CBE03DF9D162010CEFC26BB0">>},
179179
{<<"ssl_verify_fun">>, <<"FE4C190E8F37401D30167C8C405EDA19469F34577987C76DDE613E838BBC67F8">>},
180-
{<<"tls_certificate_check">>, <<"1BAD73D88637F788B554A8E939C25DB2BDAAC88B10FFFD5BBA9D1B65F43A6B54">>},
180+
{<<"tls_certificate_check">>, <<"51A5AD3DBD72D4694848965F3B5076E8B55D70EB8D5057FCDDD536029AB8A23C">>},
181181
{<<"unicode_util_compat">>, <<"25EEE6D67DF61960CF6A794239566599B09E17E668D3700247BC498638152521">>},
182182
{<<"yamerl">>, <<"96CB30F9D64344FED0EF8A92E9F16F207DE6C04DFFF4F366752CA79F5BCEB23F">>}]}
183183
].

src/tk_storage_machinegun.erl

Lines changed: 13 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -18,6 +18,7 @@
1818
-export([process_notification/4]).
1919

2020
-type storage_opts() :: #{
21+
machinery_backend := machinegun | progressor | hybrid,
2122
namespace := namespace(),
2223
automaton := automaton()
2324
}.
@@ -141,7 +142,18 @@ create_handler(ProcessorOpts) ->
141142
}
142143
}}.
143144

144-
backend(#{automaton := Automaton}, WoodyContext) ->
145+
backend(#{machinery_backend := hybrid, namespace := _, automaton := _} = Opts, WoodyContext) ->
146+
{machinery_hybrid_backend, #{
147+
primary_backend => backend(Opts#{machinery_backend := progressor}, WoodyContext),
148+
fallback_backend => backend(Opts#{machinery_backend := machinegun}, WoodyContext)
149+
}};
150+
backend(#{machinery_backend := progressor, namespace := Namespace}, WoodyContext) ->
151+
machinery_prg_backend:new(WoodyContext, #{
152+
namespace => Namespace,
153+
handler => ?MODULE,
154+
schema => ?MACHINERY_SCHEMA
155+
});
156+
backend(#{machinery_backend := machinegun, automaton := Automaton}, WoodyContext) ->
145157
machinery_mg_backend:new(WoodyContext, #{
146158
client => get_woody_client(Automaton),
147159
schema => ?MACHINERY_SCHEMA

src/token_keeper.app.src

Lines changed: 1 addition & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -15,6 +15,7 @@
1515
token_keeper_proto,
1616
bouncer_client,
1717
erl_health,
18+
progressor,
1819
machinery,
1920
yamerl,
2021
opentelemetry_api,

test/machinegun/config.yaml

Lines changed: 0 additions & 6 deletions
Original file line numberDiff line numberDiff line change
@@ -18,9 +18,3 @@ woody_server:
1818
logging:
1919
out_type: stdout
2020
level: info
21-
22-
opentelemetry:
23-
service_name: machinegun
24-
exporter:
25-
protocol: http/protobuf
26-
endpoint: http://jaeger:4318

0 commit comments

Comments
 (0)