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

View File

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

View File

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

View File

@ -37,45 +37,27 @@ action_parameters_data.label:
"""Parameter Data"""
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:
"""Timestamp"""
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:
"""Metric"""
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:
"""Tags"""
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:
"""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"""
}