From 8c8d36d4f4a489909488be7aa26fbe8f1b2978a7 Mon Sep 17 00:00:00 2001 From: jeffgrunewald Date: Mon, 8 Aug 2022 16:01:01 -0400 Subject: [PATCH] updating latest core rebase changes --- include/metrics.hrl | 11 +++-- rebar.config | 2 +- rebar.lock | 2 +- src/handlers/miner_hbbft_handler.erl | 2 +- ...eporter.erl => miner_metrics_exporter.erl} | 2 +- src/metrics/miner_metrics_server.erl | 40 +++++++++++-------- 6 files changed, 34 insertions(+), 25 deletions(-) rename src/metrics/{miner_metrics_reporter.erl => miner_metrics_exporter.erl} (92%) diff --git a/include/metrics.hrl b/include/metrics.hrl index 886b8e9f1..e9052c7f0 100644 --- a/include/metrics.hrl +++ b/include/metrics.hrl @@ -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"). @@ -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"}, diff --git a/rebar.config b/rebar.config index 484668333..a41d4fb1a 100644 --- a/rebar.config +++ b/rebar.config @@ -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", diff --git a/rebar.lock b/rebar.lock index caf470f07..3784e6e5c 100644 --- a/rebar.lock +++ b/rebar.lock @@ -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">>, diff --git a/src/handlers/miner_hbbft_handler.erl b/src/handlers/miner_hbbft_handler.erl index ba3b1ed06..01b83ab36 100644 --- a/src/handlers/miner_hbbft_handler.erl +++ b/src/handlers/miner_hbbft_handler.erl @@ -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 -> diff --git a/src/metrics/miner_metrics_reporter.erl b/src/metrics/miner_metrics_exporter.erl similarity index 92% rename from src/metrics/miner_metrics_reporter.erl rename to src/metrics/miner_metrics_exporter.erl index 949161166..14ebb6fe3 100644 --- a/src/metrics/miner_metrics_reporter.erl +++ b/src/metrics/miner_metrics_exporter.erl @@ -1,4 +1,4 @@ --module(miner_metrics_reporter). +-module(miner_metrics_exporter). -behaviour(elli_handler). diff --git a/src/metrics/miner_metrics_server.erl b/src/metrics/miner_metrics_server.erl index c2f7e4487..d4509410a 100644 --- a/src/metrics/miner_metrics_server.erl +++ b/src/metrics/miner_metrics_server.erl @@ -29,7 +29,7 @@ }. -type metrics() :: [metric()]. --type reporter_opts() :: [ +-type exporter_opts() :: [ {callback, module()} | {callback_args, map()} | {port, integer()} @@ -37,8 +37,8 @@ -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) -> @@ -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) -> @@ -74,10 +74,10 @@ 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}. @@ -85,10 +85,10 @@ handle_info(_Msg, 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, @@ -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),