New issue
Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.
By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.
Already on GitHub? Sign in to your account
feat: refactor kinesis bridge to connector and action #12376
Merged
Merged
Changes from 2 commits
Commits
Show all changes
4 commits
Select commit
Hold shift + click to select a range
fa84273
feat: refactor kinesis bridge to connector and action
kjellwinblad 25a88cc
docs: add change log entry for Kinesis bridge refactoring
kjellwinblad cfad092
chore: use macros for connector and action status atoms
kjellwinblad 2887a05
refactor: simplify emqx_bridge_kinesis (thanks to @thalesmg's tips)
kjellwinblad File filter
Filter by extension
Conversations
Failed to load comments.
Jump to
Jump to file
Failed to load files.
Diff view
Diff view
There are no files selected for viewing
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -1,13 +1,13 @@ | ||
{application, emqx_bridge_kinesis, [ | ||
{description, "EMQX Enterprise Amazon Kinesis Bridge"}, | ||
{vsn, "0.1.3"}, | ||
{vsn, "0.1.4"}, | ||
{registered, []}, | ||
{applications, [ | ||
kernel, | ||
stdlib, | ||
erlcloud | ||
]}, | ||
{env, []}, | ||
{env, [{emqx_action_info_modules, [emqx_bridge_kinesis_action_info]}]}, | ||
{modules, []}, | ||
{links, []} | ||
]}. |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
|
@@ -15,7 +15,9 @@ | |
]). | ||
|
||
-export([ | ||
conn_bridge_examples/1 | ||
bridge_v2_examples/1, | ||
conn_bridge_examples/1, | ||
connector_examples/1 | ||
]). | ||
|
||
%%------------------------------------------------------------------------------------------------- | ||
|
@@ -28,6 +30,37 @@ namespace() -> | |
roots() -> | ||
[]. | ||
|
||
fields(Field) when | ||
Field == "get_connector"; | ||
Field == "put_connector"; | ||
Field == "post_connector" | ||
-> | ||
emqx_connector_schema:api_fields( | ||
Field, | ||
kinesis, | ||
connector_config_fields() | ||
); | ||
fields(action) -> | ||
{kinesis, | ||
hoconsc:mk( | ||
hoconsc:map(name, hoconsc:ref(?MODULE, kinesis_action)), | ||
#{ | ||
desc => <<"Kinesis Action Config">>, | ||
required => false | ||
} | ||
)}; | ||
fields(action_parameters) -> | ||
fields(producer); | ||
fields(kinesis_action) -> | ||
emqx_bridge_v2_schema:make_producer_action_schema( | ||
hoconsc:mk( | ||
hoconsc:ref(?MODULE, action_parameters), | ||
There was a problem hiding this comment. Choose a reason for hiding this commentThe reason will be displayed to describe this comment to others. Learn more. |
||
#{ | ||
required => true, | ||
desc => ?DESC("action_parameters") | ||
} | ||
) | ||
); | ||
fields("config_producer") -> | ||
emqx_bridge_schema:common_bridge_fields() ++ | ||
fields("resource_opts") ++ | ||
|
@@ -134,12 +167,38 @@ fields("get_producer") -> | |
fields("post_producer") -> | ||
[type_field_producer(), name_field() | fields("config_producer")]; | ||
fields("put_producer") -> | ||
fields("config_producer"). | ||
fields("config_producer"); | ||
fields("config_connector") -> | ||
emqx_connector_schema:common_fields() ++ | ||
connector_config_fields() ++ | ||
emqx_connector_schema:resource_opts_ref(?MODULE, connector_resource_opts); | ||
fields(connector_resource_opts) -> | ||
emqx_connector_schema:resource_opts_fields(); | ||
fields("put_bridge_v2") -> | ||
fields(kinesis_action); | ||
fields("get_bridge_v2") -> | ||
fields(kinesis_action); | ||
fields("post_bridge_v2") -> | ||
fields("post", kinesis, kinesis_action). | ||
kjellwinblad marked this conversation as resolved.
Show resolved
Hide resolved
|
||
|
||
fields("post", Type, StructName) -> | ||
[type_field(Type), name_field() | fields(StructName)]. | ||
|
||
type_field(Type) -> | ||
{type, hoconsc:mk(hoconsc:enum([Type]), #{required => true, desc => ?DESC("desc_type")})}. | ||
|
||
desc("config_producer") -> | ||
?DESC("desc_config"); | ||
desc("creation_opts") -> | ||
?DESC(emqx_resource_schema, "creation_opts"); | ||
desc("config_connector") -> | ||
?DESC("config_connector"); | ||
desc(kinesis_action) -> | ||
?DESC("kinesis_action"); | ||
desc(action_parameters) -> | ||
?DESC("action_parameters"); | ||
desc(connector_resource_opts) -> | ||
?DESC(emqx_resource_schema, "resource_opts"); | ||
desc(_) -> | ||
undefined. | ||
|
||
|
@@ -153,6 +212,103 @@ conn_bridge_examples(Method) -> | |
} | ||
]. | ||
|
||
connector_examples(Method) -> | ||
[ | ||
#{ | ||
<<"kinesis">> => #{ | ||
summary => <<"Kinesis Connector">>, | ||
value => values({Method, connector}) | ||
} | ||
} | ||
]. | ||
|
||
bridge_v2_examples(Method) -> | ||
[ | ||
#{ | ||
<<"kinesis">> => #{ | ||
summary => <<"Kinesis Action">>, | ||
value => values({Method, bridge_v2_producer}) | ||
thalesmg marked this conversation as resolved.
Show resolved
Hide resolved
|
||
} | ||
} | ||
]. | ||
|
||
values({get, connector}) -> | ||
maps:merge( | ||
#{ | ||
status => <<"connected">>, | ||
node_status => [ | ||
#{ | ||
node => <<"emqx@localhost">>, | ||
status => <<"connected">> | ||
} | ||
], | ||
actions => [<<"my_action">>] | ||
}, | ||
values({post, connector}) | ||
); | ||
values({get, Type}) -> | ||
maps:merge( | ||
#{ | ||
status => <<"connected">>, | ||
node_status => [ | ||
#{ | ||
node => <<"emqx@localhost">>, | ||
status => <<"connected">> | ||
} | ||
] | ||
}, | ||
values({post, Type}) | ||
); | ||
values({post, connector}) -> | ||
maps:merge( | ||
#{ | ||
name => <<"my_kinesis_connector">>, | ||
type => <<"kinesis">> | ||
}, | ||
values(common_config) | ||
); | ||
values({post, Type}) -> | ||
maps:merge( | ||
#{ | ||
name => <<"my_kinesis_action">>, | ||
type => <<"kinesis">> | ||
}, | ||
values({put, Type}) | ||
); | ||
values({put, bridge_v2_producer}) -> | ||
values(bridge_v2_producer); | ||
values({put, connector}) -> | ||
values(common_config); | ||
values({put, Type}) -> | ||
maps:merge(values(common_config), values(Type)); | ||
values(bridge_v2_producer) -> | ||
#{ | ||
enable => true, | ||
connector => <<"my_kinesis_connector">>, | ||
parameters => values(producer_values), | ||
resource_opts => #{ | ||
<<"batch_size">> => 100, | ||
<<"inflight_window">> => 100, | ||
<<"max_buffer_bytes">> => <<"256MB">>, | ||
<<"request_ttl">> => <<"45s">> | ||
} | ||
}; | ||
values(common_config) -> | ||
#{ | ||
<<"enable">> => true, | ||
<<"aws_access_key_id">> => <<"your_access_key">>, | ||
<<"aws_secret_access_key">> => <<"aws_secret_key">>, | ||
<<"endpoint">> => <<"http://localhost:4566">>, | ||
<<"max_retries">> => 2, | ||
<<"pool_size">> => 8 | ||
}; | ||
values(producer_values) -> | ||
#{ | ||
<<"partition_key">> => <<"any_key">>, | ||
<<"payload_template">> => <<"${.}">>, | ||
<<"stream_name">> => <<"my_stream">> | ||
}. | ||
|
||
values(producer, _Method) -> | ||
#{ | ||
aws_access_key_id => <<"aws_access_key_id">>, | ||
|
@@ -174,6 +330,9 @@ values(producer, _Method) -> | |
%% Helper fns | ||
%%------------------------------------------------------------------------------------------------- | ||
|
||
connector_config_fields() -> | ||
fields(connector_config). | ||
|
||
sc(Type, Meta) -> hoconsc:mk(Type, Meta). | ||
|
||
mk(Type, Meta) -> hoconsc:mk(Type, Meta). | ||
|
22 changes: 22 additions & 0 deletions
22
apps/emqx_bridge_kinesis/src/emqx_bridge_kinesis_action_info.erl
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,22 @@ | ||
%%-------------------------------------------------------------------- | ||
%% Copyright (c) 2022-2023 EMQ Technologies Co., Ltd. All Rights Reserved. | ||
kjellwinblad marked this conversation as resolved.
Show resolved
Hide resolved
|
||
%%-------------------------------------------------------------------- | ||
|
||
-module(emqx_bridge_kinesis_action_info). | ||
|
||
-behaviour(emqx_action_info). | ||
|
||
-export([ | ||
bridge_v1_type_name/0, | ||
action_type_name/0, | ||
connector_type_name/0, | ||
schema_module/0 | ||
]). | ||
|
||
bridge_v1_type_name() -> kinesis_producer. | ||
|
||
action_type_name() -> kinesis. | ||
|
||
connector_type_name() -> kinesis. | ||
|
||
schema_module() -> emqx_bridge_kinesis. |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Oops, something went wrong.
Oops, something went wrong.
Add this suggestion to a batch that can be applied as a single commit.
This suggestion is invalid because no changes were made to the code.
Suggestions cannot be applied while the pull request is closed.
Suggestions cannot be applied while viewing a subset of changes.
Only one suggestion per line can be applied in a batch.
Add this suggestion to a batch that can be applied as a single commit.
Applying suggestions on deleted lines is not supported.
You must change the existing code in this line in order to create a valid suggestion.
Outdated suggestions cannot be applied.
This suggestion has been applied or marked resolved.
Suggestions cannot be applied from pending reviews.
Suggestions cannot be applied on multi-line comments.
Suggestions cannot be applied while the pull request is queued to merge.
Suggestion cannot be applied right now. Please check back later.
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
Missing the
resource_opts
configuratione.g:
emqx/apps/emqx_bridge_mongodb/src/emqx_bridge_mongodb.erl
Lines 53 to 56 in dbe2baa