fix(monitor): unify metric names for consistency and simplicity

This commit is contained in:
Andrew Mayorov 2024-05-24 14:32:02 +02:00
parent 7b137c0aaf
commit fd9655bc35
No known key found for this signature in database
GPG Key ID: 2837C62ACFBFED5D
4 changed files with 22 additions and 25 deletions

View File

@ -73,14 +73,14 @@
-define(GAUGE_SAMPLER_LIST, [
disconnected_durable_sessions,
durable_subscriptions,
subscriptions_durable,
subscriptions,
topics,
connections,
live_connections
]).
-define(SAMPLER_LIST, ?GAUGE_SAMPLER_LIST ++ ?DELTA_SAMPLER_LIST).
-define(SAMPLER_LIST, (?GAUGE_SAMPLER_LIST ++ ?DELTA_SAMPLER_LIST)).
-define(DELTA_SAMPLER_RATE_MAP, #{
received => received_msg_rate,
@ -102,6 +102,11 @@
] ++ ?LICENSE_QUOTA
).
-define(CLUSTERONLY_SAMPLER_LIST, [
subscriptions_durable,
disconnected_durable_sessions
]).
-if(?EMQX_RELEASE_EDITION == ee).
-define(LICENSE_QUOTA, [license_quota]).
-else.

View File

@ -118,8 +118,7 @@ current_rate(all) ->
current_rate_cluster();
current_rate(Node) when Node == node() ->
try
{ok, Rate} = do_call(current_rate),
{ok, adjust_individual_node_metrics(Rate)}
do_call(current_rate)
catch
_E:R ->
?SLOG(warning, #{msg => "dashboard_monitor_error", reason => R}),
@ -243,8 +242,7 @@ match_spec(Time) ->
merge_cluster_samplers(NodeSamples, Cluster) ->
maps:fold(fun merge_cluster_samplers/3, Cluster, NodeSamples).
merge_cluster_samplers(TS, NodeSample0, Cluster) ->
NodeSample = adjust_individual_node_metrics(NodeSample0),
merge_cluster_samplers(TS, NodeSample, Cluster) ->
case maps:get(TS, Cluster, undefined) of
undefined ->
Cluster#{TS => NodeSample};
@ -292,10 +290,6 @@ merge_cluster_rate(Node, Cluster) ->
end,
maps:fold(Fun, Cluster, Node).
adjust_individual_node_metrics(Metrics0) ->
%% ensure renamed
emqx_utils_maps:rename(durable_subscriptions, subscriptions_durable, Metrics0).
adjust_synthetic_cluster_metrics(Metrics0) ->
DSSubs = maps:get(subscriptions_durable, Metrics0, 0),
RamSubs = maps:get(subscriptions, Metrics0, 0),
@ -454,7 +448,7 @@ stats(connections) ->
emqx_stats:getstat('connections.count');
stats(disconnected_durable_sessions) ->
emqx_persistent_session_bookkeeper:get_disconnected_session_count();
stats(durable_subscriptions) ->
stats(subscriptions_durable) ->
emqx_stats:getstat('durable_subscriptions.count');
stats(live_connections) ->
emqx_stats:getstat('live_connections.count');

View File

@ -202,11 +202,10 @@ swagger_desc(persisted) ->
swagger_desc_format("Messages saved to the durable storage ");
swagger_desc(disconnected_durable_sessions) ->
<<"Disconnected durable sessions at the time of sampling.", ?APPROXIMATE_DESC>>;
swagger_desc(durable_subscriptions) ->
swagger_desc(subscriptions_durable) ->
<<"Subscriptions from durable sessions at the time of sampling.", ?APPROXIMATE_DESC>>;
swagger_desc(subscriptions) ->
<<"Subscriptions at the time of sampling (not considering durable sessions).",
?APPROXIMATE_DESC>>;
<<"Subscriptions at the time of sampling.", ?APPROXIMATE_DESC>>;
swagger_desc(topics) ->
<<"Count topics at the time of sampling.", ?APPROXIMATE_DESC>>;
swagger_desc(connections) ->
@ -252,8 +251,4 @@ swagger_desc_format(Format, Type) ->
maybe_reject_cluster_only_metrics(<<"all">>, Rates) ->
Rates;
maybe_reject_cluster_only_metrics(_Node, Rates) ->
ClusterOnlyMetrics = [
subscriptions_durable,
disconnected_durable_sessions
],
maps:without(ClusterOnlyMetrics, Rates).
maps:without(?CLUSTERONLY_SAMPLER_LIST, Rates).

View File

@ -224,13 +224,16 @@ t_monitor_current_api(_) ->
],
?assert(maps:is_key(<<"subscriptions_durable">>, Rate)),
?assert(maps:is_key(<<"disconnected_durable_sessions">>, Rate)),
ClusterOnlyMetrics = [durable_subscriptions, disconnected_durable_sessions],
{ok, NodeRate} = request(["monitor_current", "nodes", node()]),
[
?assert(maps:is_key(atom_to_binary(Key, utf8), NodeRate), #{key => Key, rates => NodeRate})
|| Key <- maps:values(?DELTA_SAMPLER_RATE_MAP) ++ ?GAUGE_SAMPLER_LIST,
not lists:member(Key, ClusterOnlyMetrics)
],
ExpectedKeys = lists:map(
fun atom_to_binary/1,
(?GAUGE_SAMPLER_LIST ++ maps:values(?DELTA_SAMPLER_RATE_MAP)) -- ?CLUSTERONLY_SAMPLER_LIST
),
?assertEqual(
[],
ExpectedKeys -- maps:keys(NodeRate),
NodeRate
),
?assertNot(maps:is_key(<<"subscriptions_durable">>, NodeRate)),
?assertNot(maps:is_key(<<"subscriptions_ram">>, NodeRate)),
?assertNot(maps:is_key(<<"disconnected_durable_sessions">>, NodeRate)),