Skip to content

Commit

Permalink
doc: Include list of autorates and metrics in the documentation
Browse files Browse the repository at this point in the history
  • Loading branch information
ieQu1 committed Feb 20, 2024
1 parent f3ca5a9 commit 1f425ba
Show file tree
Hide file tree
Showing 2 changed files with 30 additions and 4 deletions.
16 changes: 14 additions & 2 deletions src/framework/emqttb_autorate.erl
Original file line number Diff line number Diff line change
@@ -1,5 +1,5 @@
%%--------------------------------------------------------------------
%% Copyright (c) 2022-2023 EMQ Technologies Co., Ltd. All Rights Reserved.
%% Copyright (c) 2022-2024 EMQ Technologies Co., Ltd. All Rights Reserved.
%%
%% Licensed under the Apache License, Version 2.0 (the "License");
%% you may not use this file except in compliance with the License.
Expand Down Expand Up @@ -29,7 +29,7 @@
%% gen_server callbacks:
-export([init/1, handle_call/3, handle_cast/2, handle_info/2]).
%% lee_metatype callbacks:
-export([names/1, metaparams/1, meta_validate/2, validate_node/5]).
-export([names/1, metaparams/1, meta_validate/2, validate_node/5, description/3]).

%% internal exports:
-export([start_link/1, model/0, from_model/1]).
Expand Down Expand Up @@ -284,6 +284,18 @@ from_model(Key) ->
#mnode{metaparams = #{autorate_id := Id}} = lee_model:get(Key, ?MYMODEL),
Id.

description(autorate = MT, Model, _Options) ->
Chapter = autorate,
Content = [begin
#mnode{metaparams = Attrs} = lee_model:get(Key, Model),
Title = atom_to_list(?m_attr(autorate, autorate_id, Attrs)),
lee_doc:refer_value(Model, Chapter, Key, Title)
end || Key <- lee_model:get_metatype_index(MT, Model)
],
lee_doc:chapter(MT, "Automatically adjusted values", Content);
description(_, _, _) ->
[].

%%================================================================================
%% gen_server callbacks
%%================================================================================
Expand Down
18 changes: 16 additions & 2 deletions src/metrics/emqttb_metrics.erl
Original file line number Diff line number Diff line change
@@ -1,5 +1,5 @@
%%--------------------------------------------------------------------
%% Copyright (c) 2022-2023 EMQ Technologies Co., Ltd. All Rights Reserved.
%% Copyright (c) 2022-2024 EMQ Technologies Co., Ltd. All Rights Reserved.
%%
%% Licensed under the Apache License, Version 2.0 (the "License");
%% you may not use this file except in compliance with the License.
Expand Down Expand Up @@ -30,7 +30,7 @@
-export([init/1, handle_call/3, handle_cast/2, handle_info/2, terminate/2]).

%% lee_metatype callbacks:
-export([names/1, metaparams/1, meta_validate/2, validate_node/5]).
-export([names/1, metaparams/1, meta_validate/2, validate_node/5, description/3]).

%% internal exports:
-export([start_link/0]).
Expand Down Expand Up @@ -218,6 +218,20 @@ validate_node(metric_id, Model, Data, Key, _) ->
validate_node(metric, _, _, _, _) ->
{[], []}.

description(metric = MT, Model, _Options) ->
Chapter = metrics,
Content = [begin
#mnode{metaparams = MPs} = lee_model:get(Key, Model),
Oneliner = ?m_attr(metric, oneliner, MPs, ""),
{refsection, [{'xml:id', lee_doc:format_key(Chapter, Key)}],
[ {title, [lee_lib:term_to_string(Key)]}
, {para, [Oneliner]}
]}
end || Key <- lee_model:get_metatype_index(MT, Model)],
lee_doc:chapter(Chapter, "Metrics", Content);
description(_, _, _) ->
[].

ls(Model) ->
lee_model:get_metatype_index(metric, Model).

Expand Down

0 comments on commit 1f425ba

Please sign in to comment.