Merge pull request #8788 from JimMoen/refine-influxdb-bridge-example

fix(influxdb): refine influxdb bridge example
This commit is contained in:
JimMoen 2022-08-24 15:18:39 +08:00 committed by GitHub
commit 89c7caba37
No known key found for this signature in database
GPG Key ID: 4AEE18F83AFDEB23
1 changed files with 40 additions and 17 deletions

View File

@ -53,30 +53,53 @@ conn_bridge_examples(Method) ->
values(Protocol, get) ->
maps:merge(values(Protocol, post), ?METRICS_EXAMPLE);
values(Protocol, post) ->
case Protocol of
"influxdb_api_v2" ->
SupportUint = <<"uint_value=${payload.uint_key}u,">>;
_ ->
SupportUint = <<>>
end,
#{
values("influxdb_api_v2", post) ->
SupportUint = <<"uint_value=${payload.uint_key}u,">>,
TypeOpts = #{
bucket => <<"example_bucket">>,
org => <<"examlpe_org">>,
token => <<"example_token">>,
server => <<"127.0.0.1:8086">>
},
values(common, "influxdb_api_v2", SupportUint, TypeOpts);
values("influxdb_api_v1", post) ->
SupportUint = <<>>,
TypeOpts = #{
database => <<"example_database">>,
username => <<"example_username">>,
password => <<"examlpe_password">>,
server => <<"127.0.0.1:8086">>
},
values(common, "influxdb_api_v1", SupportUint, TypeOpts);
values("influxdb_udp", post) ->
SupportUint = <<>>,
TypeOpts = #{
server => <<"127.0.0.1:8089">>
},
values(common, "influxdb_udp", SupportUint, TypeOpts);
values(Protocol, put) ->
values(Protocol, post).
values(common, Protocol, SupportUint, TypeOpts) ->
CommonConfigs = #{
type => list_to_atom(Protocol),
name => <<"demo">>,
connector => list_to_binary(Protocol ++ ":connector"),
enable => true,
direction => egress,
local_topic => <<"local/topic/#">>,
write_syntax =>
<<"${topic},clientid=${clientid}", " ", "payload=${payload},",
"${clientid}_int_value=${payload.int_key}i,", SupportUint/binary,
"bool=${payload.bool}">>,
precision => ms,
resource_opts => #{
enable_batch => false,
batch_size => 5,
batch_time => <<"1m">>
};
values(Protocol, put) ->
values(Protocol, post).
},
server => <<"127.0.0.1:8086">>,
ssl => #{enable => false}
},
maps:merge(TypeOpts, CommonConfigs).
%% -------------------------------------------------------------------------------------------------
%% Hocon Schema Definitions
@ -124,7 +147,7 @@ method_fileds(put, ConnectorType) ->
influxdb_bridge_common_fields() ->
emqx_bridge_schema:common_bridge_fields() ++
[
{local_topic, mk(binary(), #{required => true, desc => ?DESC("local_topic")})},
{local_topic, mk(binary(), #{desc => ?DESC("local_topic")})},
{write_syntax, fun write_syntax/1}
] ++
emqx_resource_schema:fields("resource_opts").