Skip to content

Commit

Permalink
Merge #6311: fix: 2 follow-ups for PeriodicStats
Browse files Browse the repository at this point in the history
802efc5 fix: update DEFAULT_STATSD_HOST (UdjinM6)
44d7806 fix: use correct rpc interruption point in `PeriodicStats` (UdjinM6)

Pull request description:

  ## Issue being fixed or feature implemented
  - 5c2c2b3: dash-qt with stats enabled crashes
  - b92ce3d: help text for `-statshost` is misleading

  ## What was done?

  ## How Has This Been Tested?

  ## Breaking Changes

  ## Checklist:
  - [ ] I have performed a self-review of my own code
  - [ ] I have commented my code, particularly in hard-to-understand areas
  - [ ] I have added or updated relevant unit/integration/functional/e2e tests
  - [ ] I have made corresponding changes to the documentation
  - [ ] I have assigned this pull request to a milestone _(for repository code-owners and collaborators only)_

ACKs for top commit:
  knst:
    utACK 802efc5

Tree-SHA512: 093229a96e726dc30c8aef210046bebaef040179785fd8be20de5052d766b361426f18f41338ef059997e820645faa7fba424f056be2f6454ca3190f8c3c0906
  • Loading branch information
PastaPastaPasta committed Oct 7, 2024
2 parents a76395c + 802efc5 commit 79bd3d9
Show file tree
Hide file tree
Showing 3 changed files with 10 additions and 7 deletions.
9 changes: 6 additions & 3 deletions src/init.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -837,12 +837,15 @@ static void StartupNotify(const ArgsManager& args)
}
#endif

static void PeriodicStats(ArgsManager& args, ChainstateManager& chainman, const CTxMemPool& mempool)
static void PeriodicStats(NodeContext& node)
{
assert(::g_stats_client->active());
const ArgsManager& args = *Assert(node.args);
ChainstateManager& chainman = *Assert(node.chainman);
const CTxMemPool& mempool = *Assert(node.mempool);
CCoinsStats stats{CoinStatsHashType::NONE};
chainman.ActiveChainstate().ForceFlushStateToDisk();
if (WITH_LOCK(cs_main, return GetUTXOStats(&chainman.ActiveChainstate().CoinsDB(), std::ref(chainman.m_blockman), stats, RpcInterruptionPoint, chainman.ActiveChain().Tip()))) {
if (WITH_LOCK(cs_main, return GetUTXOStats(&chainman.ActiveChainstate().CoinsDB(), chainman.m_blockman, stats, node.rpc_interruption_point, chainman.ActiveChain().Tip()))) {
::g_stats_client->gauge("utxoset.tx", stats.nTransactions, 1.0f);
::g_stats_client->gauge("utxoset.txOutputs", stats.nTransactionOutputs, 1.0f);
::g_stats_client->gauge("utxoset.dbSizeBytes", stats.nDiskSize, 1.0f);
Expand Down Expand Up @@ -2299,7 +2302,7 @@ bool AppInitMain(NodeContext& node, interfaces::BlockAndHeaderTipInfo* tip_info)

if (::g_stats_client->active()) {
int nStatsPeriod = std::min(std::max((int)args.GetArg("-statsperiod", DEFAULT_STATSD_PERIOD), MIN_STATSD_PERIOD), MAX_STATSD_PERIOD);
node.scheduler->scheduleEvery(std::bind(&PeriodicStats, std::ref(*node.args), std::ref(chainman), std::cref(*node.mempool)), std::chrono::seconds{nStatsPeriod});
node.scheduler->scheduleEvery(std::bind(&PeriodicStats, std::ref(node)), std::chrono::seconds{nStatsPeriod});
}

// ********************************************************* Step 11: import blocks
Expand Down
6 changes: 3 additions & 3 deletions src/stats/client.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -34,12 +34,12 @@ std::unique_ptr<StatsdClient> g_stats_client;
std::unique_ptr<StatsdClient> InitStatsClient(const ArgsManager& args)
{
auto is_enabled = args.GetBoolArg("-statsenabled", /*fDefault=*/false);
auto host = args.GetArg("-statshost", /*fDefault=*/"");
auto host = args.GetArg("-statshost", /*fDefault=*/DEFAULT_STATSD_HOST);

if (is_enabled && host.empty()) {
// Stats are enabled but host has not been specified, then use
// default host. This is to preserve old behavior.
host = DEFAULT_STATSD_HOST;
// default legacy host. This is to preserve old behavior.
host = "127.0.0.1";
} else if (!host.empty()) {
// Host is specified but stats are not explcitly enabled. Assume
// that if a host has been specified, we want stats enabled. This
Expand Down
2 changes: 1 addition & 1 deletion src/stats/client.h
Original file line number Diff line number Diff line change
Expand Up @@ -19,7 +19,7 @@ class RawSender;
/** Default port used to connect to a Statsd server */
static constexpr uint16_t DEFAULT_STATSD_PORT{8125};
/** Default host assumed to be running a Statsd server */
static const std::string DEFAULT_STATSD_HOST{"127.0.0.1"};
static const std::string DEFAULT_STATSD_HOST{""};
/** Default prefix prepended to Statsd message keys */
static const std::string DEFAULT_STATSD_PREFIX{""};
/** Default suffix appended to Statsd message keys */
Expand Down

0 comments on commit 79bd3d9

Please sign in to comment.