Merge pull request #12457 from lafirest/fix/opentsdb

fix(opents): change the schema of tags to object style
This commit is contained in:
lafirest 2024-02-02 15:33:50 +08:00 committed by GitHub
commit c724d2127e
No known key found for this signature in database
GPG Key ID: B5690EEEBB952194
4 changed files with 28 additions and 59 deletions

View File

@ -135,6 +135,14 @@ fields(action_parameters) ->
)} )}
]; ];
fields(action_parameters_data) -> fields(action_parameters_data) ->
TagsError = fun(Data) ->
?SLOG(warning, #{
msg => "invalid_tags_template",
path => "opents.parameters.data.tags",
data => Data
}),
false
end,
[ [
{timestamp, {timestamp,
mk( mk(
@ -154,7 +162,7 @@ fields(action_parameters_data) ->
)}, )},
{tags, {tags,
mk( mk(
hoconsc:union([array(ref(?MODULE, action_parameters_data_tags)), binary()]), hoconsc:union([map(), binary()]),
#{ #{
required => true, required => true,
desc => ?DESC("config_parameters_tags"), desc => ?DESC("config_parameters_tags"),
@ -164,17 +172,17 @@ fields(action_parameters_data) ->
[{var, _}] -> [{var, _}] ->
true; true;
_ -> _ ->
?SLOG(warning, #{ TagsError(Tmpl)
msg => "invalid_tags_template",
path => "opents.parameters.data.tags",
data => Tmpl
}),
false
end; end;
([_ | _] = Tags) when is_list(Tags) -> (Map) when is_map(Map) ->
true; case maps:size(Map) >= 1 of
(_) -> true ->
false true;
_ ->
TagsError(Map)
end;
(Any) ->
TagsError(Any)
end end
} }
)}, )},
@ -187,25 +195,6 @@ fields(action_parameters_data) ->
} }
)} )}
]; ];
fields(action_parameters_data_tags) ->
[
{tag,
mk(
binary(),
#{
required => true,
desc => ?DESC("tags_tag")
}
)},
{value,
mk(
binary(),
#{
required => true,
desc => ?DESC("tags_value")
}
)}
];
fields("post_bridge_v2") -> fields("post_bridge_v2") ->
emqx_bridge_schema:type_and_name_fields(enum([opents])) ++ fields(action_config); emqx_bridge_schema:type_and_name_fields(enum([opents])) ++ fields(action_config);
fields("put_bridge_v2") -> fields("put_bridge_v2") ->
@ -221,8 +210,6 @@ desc(action_parameters) ->
?DESC("action_parameters"); ?DESC("action_parameters");
desc(action_parameters_data) -> desc(action_parameters_data) ->
?DESC("action_parameters_data"); ?DESC("action_parameters_data");
desc(action_parameters_data_tags) ->
?DESC("action_parameters_data_tags");
desc(Method) when Method =:= "get"; Method =:= "put"; Method =:= "post" -> desc(Method) when Method =:= "get"; Method =:= "put"; Method =:= "post" ->
["Configuration for OpenTSDB using `", string:to_upper(Method), "` method."]; ["Configuration for OpenTSDB using `", string:to_upper(Method), "` method."];
desc(_) -> desc(_) ->

View File

@ -358,15 +358,15 @@ preproc_data_template(DataList) ->
case Tags of case Tags of
Tmpl when is_binary(Tmpl) -> Tmpl when is_binary(Tmpl) ->
emqx_placeholder:preproc_tmpl(Tmpl); emqx_placeholder:preproc_tmpl(Tmpl);
List -> Map when is_map(Map) ->
[ [
tags tags
| [ | [
{ {
emqx_placeholder:preproc_tmpl(TagName), emqx_placeholder:preproc_tmpl(emqx_utils_conv:bin(TagName)),
emqx_placeholder:preproc_tmpl(TagValue) emqx_placeholder:preproc_tmpl(TagValue)
} }
|| #{tag := TagName, value := TagValue} <- List || {TagName, TagValue} <- maps:to_list(Map)
] ]
] ]
end, end,

View File

@ -311,7 +311,7 @@ t_list_tags(Config) ->
<<"data">> => [ <<"data">> => [
#{ #{
<<"metric">> => <<"${metric}">>, <<"metric">> => <<"${metric}">>,
<<"tags">> => [#{<<"tag">> => <<"host">>, <<"value">> => <<"valueA">>}], <<"tags">> => #{<<"host">> => <<"valueA">>},
value => <<"${value}">> value => <<"${value}">>
} }
] ]
@ -356,7 +356,7 @@ t_list_tags_with_var(Config) ->
<<"data">> => [ <<"data">> => [
#{ #{
<<"metric">> => <<"${metric}">>, <<"metric">> => <<"${metric}">>,
<<"tags">> => [#{<<"tag">> => <<"host">>, <<"value">> => <<"${value}">>}], <<"tags">> => #{<<"host">> => <<"${value}">>},
value => <<"${value}">> value => <<"${value}">>
} }
] ]

View File

@ -37,45 +37,27 @@ action_parameters_data.label:
"""Parameter Data""" """Parameter Data"""
config_parameters_timestamp.desc: config_parameters_timestamp.desc:
"""Timestamp. Placeholders in format of ${var} is supported""" """Timestamp. Placeholders in the format of ${var} are supported"""
config_parameters_timestamp.label: config_parameters_timestamp.label:
"""Timestamp""" """Timestamp"""
config_parameters_metric.desc: config_parameters_metric.desc:
"""Metric. Placeholders in format of ${var} is supported""" """Metric. Placeholders in the format of ${var} are supported"""
config_parameters_metric.label: config_parameters_metric.label:
"""Metric""" """Metric"""
config_parameters_tags.desc: config_parameters_tags.desc:
"""Tags. Only supports with placeholder to extract tags from a variable or a list of tags""" """Tags. Only supports with placeholder to extract tags from a variable or a tags map"""
config_parameters_tags.label: config_parameters_tags.label:
"""Tags""" """Tags"""
config_parameters_value.desc: config_parameters_value.desc:
"""Value. Placeholders in format of ${var} is supported""" """Value. Placeholders in the format of ${var} are supported"""
config_parameters_value.label: config_parameters_value.label:
"""Value""" """Value"""
action_parameters_data_tags.desc:
"""OpenTSDB data tags"""
action_parameters_data_tags.label:
"""Tags"""
tags_tag.desc:
"""The name of this tag. Placeholders in format of ${var} is supported"""
tags_tag.label:
"""Tag"""
tags_value.desc:
"""The value of this tag. Placeholders in format of ${var} is supported"""
tags_value.label:
"""Value"""
} }