Skip to content
This repository has been archived by the owner on Jun 12, 2023. It is now read-only.

Commit

Permalink
updating latest core rebase changes
Browse files Browse the repository at this point in the history
  • Loading branch information
jeffgrunewald committed Aug 8, 2022
1 parent 2135486 commit 8c8d36d
Show file tree
Hide file tree
Showing 6 changed files with 34 additions and 25 deletions.
11 changes: 7 additions & 4 deletions include/metrics.hrl
Original file line number Diff line number Diff line change
Expand Up @@ -5,11 +5,12 @@
-define(METRICS_BLOCK_HEIGHT, "blockchain_block_height").
-define(METRICS_BLOCK_UNVAL_HEIGHT, "blockchain_block_unval_height").
-define(METRICS_TXN_ABSORB_DURATION, "blockchain_txn_absorb_duration").
-define(METRICS_TXN_BLOCK_SPAN, "blockchain_txn_mgr_block_span").
-define(METRICS_TXN_QUEUE, "blockchain_txn_mgr_queue").
-define(METRICS_TXN_SUBMIT_COUNT, "blockchain_txn_mgr_submited_count").
-define(METRICS_TXN_REJECT_COUNT, "blockchain_txn_mgr_rejected_count").
-define(METRICS_TXN_REJECT_SPAN, "blockchain_txn_mgr_rejected_span").
-define(METRICS_TXN_ACCEPT_COUNT, "blockchain_txn_mgr_accepted_count").
-define(METRICS_TXN_ACCEPT_SPAN, "blockchain_txn_mgr_accepted_span").
-define(METRICS_TXN_UPDATE_COUNT, "blockchain_txn_mgr_updated_count").
-define(METRICS_TXN_PROCESS_DURATION, "blockchain_txn_mgr_process_duration").
-define(METRICS_TXN_CACHE_SIZE, "blockchain_txn_mgr_cache_size").
-define(METRICS_TXN_BLOCK_TIME, "blockchain_txn_mgr_block_time").
Expand Down Expand Up @@ -38,14 +39,16 @@
[blockchain, txn_mgr, submit],
[blockchain, txn_mgr, reject],
[blockchain, txn_mgr, accept],
[blockchain, txn_mgr, update],
[blockchain, txn_mgr, process],
[blockchain, txn_mgr, add_block] ],
[ {?METRICS_TXN_ABSORB_DURATION, prometheus_histogram, [stage], "Txn absorb duration"},
{?METRICS_TXN_BLOCK_SPAN, prometheus_gauge, [], "Block span of transactions"},
{?METRICS_TXN_QUEUE, prometheus_gauge, [], "Txn manager submission queue length"},
{?METRICS_TXN_SUBMIT_COUNT, prometheus_counter, [type], "Count of submitted transactions"},
{?METRICS_TXN_REJECT_COUNT, prometheus_counter, [type], "Count of rejected transactions"},
{?METRICS_TXN_REJECT_SPAN, prometheus_gauge, [type], "Block span of transactions on final rejection"},
{?METRICS_TXN_ACCEPT_COUNT, prometheus_counter, [type], "Count of accepted transactions"},
{?METRICS_TXN_ACCEPT_SPAN, prometheus_gauge, [type], "Block span of transactions on acceptance"},
{?METRICS_TXN_UPDATE_COUNT, prometheus_counter, [type], "Count of updated transactions"},
{?METRICS_TXN_PROCESS_DURATION, prometheus_histogram, [stage], "Transaction manager cache process duration"},
{?METRICS_TXN_CACHE_SIZE, prometheus_gauge, [height], "Transaction manager buffer size"},
{?METRICS_TXN_BLOCK_TIME, prometheus_gauge, [height], "Block time observed from the transaction mgr"},
Expand Down
2 changes: 1 addition & 1 deletion rebar.config
Original file line number Diff line number Diff line change
Expand Up @@ -10,7 +10,7 @@

{deps, [
{blockchain, {git, "https://github.com/helium/blockchain-core.git",
{branch, "jg/txn_absorb_metrics"}}},
{branch, "master"}}},
{sibyl, {git, "https://github.com/helium/sibyl.git",
{branch, "master"}}},
{hbbft, {git, "https://github.com/helium/erlang-hbbft.git",
Expand Down
2 changes: 1 addition & 1 deletion rebar.lock
Original file line number Diff line number Diff line change
Expand Up @@ -8,7 +8,7 @@
{<<"base64url">>,{pkg,<<"base64url">>,<<"1.0.1">>},1},
{<<"blockchain">>,
{git,"https://github.com/helium/blockchain-core.git",
{ref,"0caf2295d0576c0ef803258e834bf6ec3b3e74bc"}},
{ref,"bae8c3696747fdc24074c0e85ac64e745760d8aa"}},
0},
{<<"certifi">>,{pkg,<<"certifi">>,<<"2.9.0">>},2},
{<<"chatterbox">>,
Expand Down
2 changes: 1 addition & 1 deletion src/handlers/miner_hbbft_handler.erl
Original file line number Diff line number Diff line change
Expand Up @@ -79,7 +79,7 @@ metadata(Version, Meta, Chain) ->
Infos = blockchain_ledger_snapshot_v1:get_infos(Chain),
case blockchain_ledger_snapshot_v1:snapshot(Ledger, Blocks, Infos) of
{ok, Snapshot} ->
{ok, _SnapHeight, SnapHash, _SnapSize} = blockchain:add_snapshot(Snapshot, Chain),
{ok, {_SnapHeight, SnapHash, _SnapSize}} = blockchain:add_snapshot(Snapshot, Chain),
lager:info("snapshot hash is ~p", [SnapHash]),
maps:put(snapshot_hash, SnapHash, ChainMeta0);
_Err ->
Expand Down
Original file line number Diff line number Diff line change
@@ -1,4 +1,4 @@
-module(miner_metrics_reporter).
-module(miner_metrics_exporter).

-behaviour(elli_handler).

Expand Down
40 changes: 23 additions & 17 deletions src/metrics/miner_metrics_server.erl
Original file line number Diff line number Diff line change
Expand Up @@ -29,16 +29,16 @@
}.
-type metrics() :: [metric()].

-type reporter_opts() :: [
-type exporter_opts() :: [
{callback, module()} |
{callback_args, map()} |
{port, integer()}
].

-record(state, {
metrics :: metrics(),
reporter_opts :: reporter_opts(),
reporter_pid :: pid() | undefined
exporter_opts :: exporter_opts(),
exporter_pid :: pid() | undefined
}).

handle_metric(Event, Measurements, Metadata, _Config) ->
Expand All @@ -56,15 +56,15 @@ init(_Args) ->
ok = setup_metrics(Metrics),

ElliOpts = [
{callback, miner_metrics_reporter},
{callback, miner_metrics_exporter},
{callback_args, #{}},
{port, application:get_env(miner, metrics_port, 9090)}
],
{ok, ReporterPid} = elli:start_link(ElliOpts),
{ok, ExporterPid} = elli:start_link(ElliOpts),
{ok, #state{
metrics = Metrics,
reporter_opts = ElliOpts,
reporter_pid = ReporterPid}}
exporter_opts = ElliOpts,
exporter_pid = ExporterPid}}
end.

handle_call(_Msg, _From, State) ->
Expand All @@ -74,21 +74,21 @@ handle_call(_Msg, _From, State) ->
handle_cast(_Msg, State) ->
{noreply, State}.

handle_info({'EXIT', ReporterPid, Reason}, #state{reporter_pid=ReporterPid} = State) ->
lager:warning("Metrics reporter exited with reason ~p, restarting", [Reason]),
{ok, NewReporter} = elli:start_link(State#state.reporter_opts),
{noreply, State#state{reporter_pid = NewReporter}};
handle_info({'EXIT', ExporterPid, Reason}, #state{exporter_pid=ExporterPid} = State) ->
lager:warning("Metrics exporter exited with reason ~p, restarting", [Reason]),
{ok, NewExporter} = elli:start_link(State#state.exporter_opts),
{noreply, State#state{exporter_pid = NewExporter}};
handle_info(_Msg, State) ->
lager:debug("Received unknown info msg: ~p", [_Msg]),
{noreply, State}.

code_change(_OldVsn, State, _Extra) ->
{ok, State}.

terminate(Reason, #state{metrics = Metrics, reporter_pid = Reporter}) ->
true = erlang:exit(Reporter, Reason),
terminate(Reason, #state{metrics = Metrics, exporter_pid = Exporter}) ->
true = erlang:exit(Exporter, Reason),
lists:foreach(
fun({Metric, _, Module, _, _}) ->
fun({Metric, Module, _, _}) ->
lager:info("De-registering metric ~p as ~p", [Metric, Module]),
Module:deregister(Metric)
end,
Expand Down Expand Up @@ -145,11 +145,17 @@ handle_metric_event([blockchain, txn_mgr, submit], _Measurements, #{type := Type
ok;
handle_metric_event([blockchain, txn_mgr, reject], #{block_span := Span}, #{type := Type}) ->
prometheus_counter:inc(?METRICS_TXN_REJECT_COUNT, [Type]),
prometheus_gauge:set(?METRICS_TXN_REJECT_SPAN, [Type], Span),
prometheus_gauge:set(?METRICS_TXN_BLOCK_SPAN, [], Span),
ok;
handle_metric_event([blockchain, txn_mgr, accept], #{block_span := Span}, #{type := Type}) ->
handle_metric_event([blockchain, txn_mgr, accept], #{block_span := Span, queue_len := QLen}, #{type := Type}) ->
prometheus_counter:inc(?METRICS_TXN_ACCEPT_COUNT, [Type]),
prometheus_gauge:set(?METRICS_TXN_ACCEPT_SPAN, [Type], Span),
prometheus_gauge:set(?METRICS_TXN_BLOCK_SPAN, [], Span),
prometheus_gauge:set(?METRICS_TXN_QUEUE, [], QLen),
ok;
handle_metric_event([blockchain, txn_mgr, update], #{block_span := Span, queue_len := QLen}, #{type := Type}) ->
prometheus_counter:inc(?METRICS_TXN_UPDATE_COUNT, [Type]),
prometheus_gauge:set(?METRICS_TXN_BLOCK_SPAN, [], Span),
prometheus_gauge:set(?METRICS_TXN_QUEUE, [], QLen),
ok;
handle_metric_event([blockchain, txn_mgr, process], #{duration := Duration}, #{stage := Stage}) ->
prometheus_histogram:observe(?METRICS_TXN_PROCESS_DURATION, [Stage], Duration),
Expand Down

0 comments on commit 8c8d36d

Please sign in to comment.