perf: avoid getting metrics (gen_server:call) for each resource lookup
This commit is contained in:
parent
fe450ca2d9
commit
fb61c2b266
|
@ -43,7 +43,7 @@
|
||||||
config := resource_config(),
|
config := resource_config(),
|
||||||
state := resource_state(),
|
state := resource_state(),
|
||||||
status := resource_status(),
|
status := resource_status(),
|
||||||
metrics := emqx_metrics_worker:metrics()
|
metrics => emqx_metrics_worker:metrics()
|
||||||
}.
|
}.
|
||||||
-type resource_group() :: binary().
|
-type resource_group() :: binary().
|
||||||
-type creation_opts() :: #{
|
-type creation_opts() :: #{
|
||||||
|
|
|
@ -238,7 +238,7 @@ lookup(ResId) ->
|
||||||
ets_lookup(ResId) ->
|
ets_lookup(ResId) ->
|
||||||
case read_cache(ResId) of
|
case read_cache(ResId) of
|
||||||
{Group, Data} ->
|
{Group, Data} ->
|
||||||
{ok, Group, data_record_to_external_map_with_metrics(Data)};
|
{ok, Group, data_record_to_external_map(Data)};
|
||||||
not_found ->
|
not_found ->
|
||||||
{error, not_found}
|
{error, not_found}
|
||||||
end.
|
end.
|
||||||
|
@ -620,8 +620,8 @@ maybe_reply(Actions, undefined, _Reply) ->
|
||||||
maybe_reply(Actions, From, Reply) ->
|
maybe_reply(Actions, From, Reply) ->
|
||||||
[{reply, From, Reply} | Actions].
|
[{reply, From, Reply} | Actions].
|
||||||
|
|
||||||
-spec data_record_to_external_map_with_metrics(data()) -> resource_data().
|
-spec data_record_to_external_map(data()) -> resource_data().
|
||||||
data_record_to_external_map_with_metrics(Data) ->
|
data_record_to_external_map(Data) ->
|
||||||
#{
|
#{
|
||||||
id => Data#data.id,
|
id => Data#data.id,
|
||||||
mod => Data#data.mod,
|
mod => Data#data.mod,
|
||||||
|
@ -629,10 +629,14 @@ data_record_to_external_map_with_metrics(Data) ->
|
||||||
query_mode => Data#data.query_mode,
|
query_mode => Data#data.query_mode,
|
||||||
config => Data#data.config,
|
config => Data#data.config,
|
||||||
status => Data#data.status,
|
status => Data#data.status,
|
||||||
state => Data#data.state,
|
state => Data#data.state
|
||||||
metrics => get_metrics(Data#data.id)
|
|
||||||
}.
|
}.
|
||||||
|
|
||||||
|
-spec data_record_to_external_map_with_metrics(data()) -> resource_data().
|
||||||
|
data_record_to_external_map_with_metrics(Data) ->
|
||||||
|
DataMap = data_record_to_external_map(Data),
|
||||||
|
DataMap#{metrics => get_metrics(Data#data.id)}.
|
||||||
|
|
||||||
-spec wait_for_ready(resource_id(), integer()) -> ok | timeout | {error, term()}.
|
-spec wait_for_ready(resource_id(), integer()) -> ok | timeout | {error, term()}.
|
||||||
wait_for_ready(ResId, WaitTime) ->
|
wait_for_ready(ResId, WaitTime) ->
|
||||||
do_wait_for_ready(ResId, WaitTime div ?WAIT_FOR_RESOURCE_DELAY).
|
do_wait_for_ready(ResId, WaitTime div ?WAIT_FOR_RESOURCE_DELAY).
|
||||||
|
|
Loading…
Reference in New Issue