stats: move statsd_client to stats directory

In upcoming commits, message sending will be split off into a separate
file and stats capabilities will be fleshed out. Prepare for that by
giving it its own directory.

Also get rid of `statsd` namespace, it is entirely unnecessary.

Co-authored-by: UdjinM6 <UdjinM6@users.noreply.github.com>
This commit is contained in:
Kittywhiskers Van Gogh 2024-09-12 15:25:38 +00:00
parent f782dfd562
commit 92690685be
No known key found for this signature in database
GPG Key ID: 30CD0C065E5C4AAD
12 changed files with 27 additions and 29 deletions

View File

@ -26,7 +26,7 @@ EXCLUDE = [
'src/crypto/*', 'src/crypto/*',
'src/ctpl_stl.h', 'src/ctpl_stl.h',
'src/reverse_iterator.h', 'src/reverse_iterator.h',
'src/statsd_client.cpp', 'src/stats/client.cpp',
'src/test/fuzz/FuzzedDataProvider.h', 'src/test/fuzz/FuzzedDataProvider.h',
'src/tinyformat.h', 'src/tinyformat.h',
'src/bench/nanobench.h', 'src/bench/nanobench.h',

View File

@ -313,7 +313,7 @@ BITCOIN_CORE_H = \
spork.h \ spork.h \
stacktraces.h \ stacktraces.h \
streams.h \ streams.h \
statsd_client.h \ stats/client.h \
support/allocators/mt_pooled_secure.h \ support/allocators/mt_pooled_secure.h \
support/allocators/pool.h \ support/allocators/pool.h \
support/allocators/pooled_secure.h \ support/allocators/pooled_secure.h \
@ -526,7 +526,7 @@ libbitcoin_server_a_SOURCES = \
script/sigcache.cpp \ script/sigcache.cpp \
shutdown.cpp \ shutdown.cpp \
spork.cpp \ spork.cpp \
statsd_client.cpp \ stats/client.cpp \
timedata.cpp \ timedata.cpp \
torcontrol.cpp \ torcontrol.cpp \
txdb.cpp \ txdb.cpp \

View File

@ -105,7 +105,7 @@
#include <llmq/snapshot.h> #include <llmq/snapshot.h>
#include <llmq/signing_shares.h> #include <llmq/signing_shares.h>
#include <statsd_client.h> #include <stats/client.h>
#include <algorithm> #include <algorithm>
#include <condition_variable> #include <condition_variable>
@ -1539,11 +1539,11 @@ bool AppInitMain(NodeContext& node, interfaces::BlockAndHeaderTipInfo* tip_info)
// We need to initialize g_stats_client early as currently, g_stats_client is called // We need to initialize g_stats_client early as currently, g_stats_client is called
// regardless of whether transmitting stats are desirable or not and if // regardless of whether transmitting stats are desirable or not and if
// g_stats_client isn't present when that attempt is made, the client will crash. // g_stats_client isn't present when that attempt is made, the client will crash.
::g_stats_client = std::make_unique<statsd::StatsdClient>(args.GetArg("-statshost", DEFAULT_STATSD_HOST), ::g_stats_client = std::make_unique<StatsdClient>(args.GetArg("-statshost", DEFAULT_STATSD_HOST),
args.GetArg("-statshostname", DEFAULT_STATSD_HOSTNAME), args.GetArg("-statshostname", DEFAULT_STATSD_HOSTNAME),
args.GetArg("-statsport", DEFAULT_STATSD_PORT), args.GetArg("-statsport", DEFAULT_STATSD_PORT),
args.GetArg("-statsns", DEFAULT_STATSD_NAMESPACE), args.GetArg("-statsns", DEFAULT_STATSD_NAMESPACE),
args.GetBoolArg("-statsenabled", DEFAULT_STATSD_ENABLE)); args.GetBoolArg("-statsenabled", DEFAULT_STATSD_ENABLE));
{ {

View File

@ -41,7 +41,7 @@
#include <coinjoin/coinjoin.h> #include <coinjoin/coinjoin.h>
#include <evo/deterministicmns.h> #include <evo/deterministicmns.h>
#include <statsd_client.h> #include <stats/client.h>
#ifdef WIN32 #ifdef WIN32
#include <string.h> #include <string.h>

View File

@ -69,7 +69,7 @@
#include <llmq/signing_shares.h> #include <llmq/signing_shares.h>
#include <llmq/snapshot.h> #include <llmq/snapshot.h>
#include <statsd_client.h> #include <stats/client.h>
/** Maximum number of in-flight objects from a peer */ /** Maximum number of in-flight objects from a peer */
static constexpr int32_t MAX_PEER_OBJECT_IN_FLIGHT = 100; static constexpr int32_t MAX_PEER_OBJECT_IN_FLIGHT = 100;

View File

@ -33,7 +33,7 @@ OR TORT (INCLUDING NEGLIGENCE OR OTHERWISE) ARISING IN ANY WAY OUT OF THE USE
OF THIS SOFTWARE, EVEN IF ADVISED OF THE POSSIBILITY OF SUCH DAMAGE. OF THIS SOFTWARE, EVEN IF ADVISED OF THE POSSIBILITY OF SUCH DAMAGE.
**/ **/
#include <statsd_client.h> #include <stats/client.h>
#include <compat.h> #include <compat.h>
#include <netbase.h> #include <netbase.h>
@ -43,9 +43,8 @@ OF THIS SOFTWARE, EVEN IF ADVISED OF THE POSSIBILITY OF SUCH DAMAGE.
#include <cstdio> #include <cstdio>
#include <random> #include <random>
std::unique_ptr<statsd::StatsdClient> g_stats_client; std::unique_ptr<StatsdClient> g_stats_client;
namespace statsd {
bool StatsdClient::ShouldSend(float sample_rate) bool StatsdClient::ShouldSend(float sample_rate)
{ {
sample_rate = std::clamp(sample_rate, 0.f, 1.f); sample_rate = std::clamp(sample_rate, 0.f, 1.f);
@ -193,4 +192,3 @@ bool StatsdClient::send(const std::string& message)
return true; return true;
} }
} // namespace statsd

View File

@ -3,15 +3,15 @@
// Distributed under the MIT software license, see the accompanying // Distributed under the MIT software license, see the accompanying
// file COPYING or http://www.opensource.org/licenses/mit-license.php. // file COPYING or http://www.opensource.org/licenses/mit-license.php.
#ifndef BITCOIN_STATSD_CLIENT_H #ifndef BITCOIN_STATS_CLIENT_H
#define BITCOIN_STATSD_CLIENT_H #define BITCOIN_STATS_CLIENT_H
#include <random.h> #include <random.h>
#include <threadsafety.h> #include <threadsafety.h>
#include <util/sock.h> #include <util/sock.h>
#include <string>
#include <memory> #include <memory>
#include <string>
static constexpr bool DEFAULT_STATSD_ENABLE{false}; static constexpr bool DEFAULT_STATSD_ENABLE{false};
static constexpr uint16_t DEFAULT_STATSD_PORT{8125}; static constexpr uint16_t DEFAULT_STATSD_PORT{8125};
@ -24,8 +24,8 @@ static constexpr int DEFAULT_STATSD_PERIOD{60};
static constexpr int MIN_STATSD_PERIOD{5}; static constexpr int MIN_STATSD_PERIOD{5};
static constexpr int MAX_STATSD_PERIOD{60 * 60}; static constexpr int MAX_STATSD_PERIOD{60 * 60};
namespace statsd { class StatsdClient
class StatsdClient { {
public: public:
explicit StatsdClient(const std::string& host, const std::string& nodename, uint16_t port, explicit StatsdClient(const std::string& host, const std::string& nodename, uint16_t port,
const std::string& ns, bool enabled); const std::string& ns, bool enabled);
@ -66,8 +66,7 @@ private:
const std::string m_nodename; const std::string m_nodename;
const std::string m_ns; const std::string m_ns;
}; };
} // namespace statsd
extern std::unique_ptr<statsd::StatsdClient> g_stats_client; extern std::unique_ptr<StatsdClient> g_stats_client;
#endif // BITCOIN_STATSD_CLIENT_H #endif // BITCOIN_STATS_CLIENT_H

View File

@ -39,7 +39,7 @@
#include <scheduler.h> #include <scheduler.h>
#include <script/sigcache.h> #include <script/sigcache.h>
#include <spork.h> #include <spork.h>
#include <statsd_client.h> #include <stats/client.h>
#include <streams.h> #include <streams.h>
#include <test/util/index.h> #include <test/util/index.h>
#include <txdb.h> #include <txdb.h>
@ -183,7 +183,7 @@ BasicTestingSetup::BasicTestingSetup(const std::string& chainName, const std::ve
SetupNetworking(); SetupNetworking();
InitSignatureCache(); InitSignatureCache();
InitScriptExecutionCache(); InitScriptExecutionCache();
::g_stats_client = std::make_unique<statsd::StatsdClient>( ::g_stats_client = std::make_unique<StatsdClient>(
m_node.args->GetArg("-statshost", DEFAULT_STATSD_HOST), m_node.args->GetArg("-statshost", DEFAULT_STATSD_HOST),
m_node.args->GetArg("-statshostname", DEFAULT_STATSD_HOSTNAME), m_node.args->GetArg("-statshostname", DEFAULT_STATSD_HOSTNAME),
m_node.args->GetArg("-statsport", DEFAULT_STATSD_PORT), m_node.args->GetArg("-statsport", DEFAULT_STATSD_PORT),

View File

@ -7,7 +7,7 @@
#include <consensus/validation.h> #include <consensus/validation.h>
#include <logging.h> #include <logging.h>
#include <policy/policy.h> #include <policy/policy.h>
#include <statsd_client.h> #include <stats/client.h>
#include <cassert> #include <cassert>

View File

@ -66,7 +66,7 @@
#include <llmq/instantsend.h> #include <llmq/instantsend.h>
#include <llmq/chainlocks.h> #include <llmq/chainlocks.h>
#include <statsd_client.h> #include <stats/client.h>
#include <algorithm> #include <algorithm>
#include <cassert> #include <cassert>

View File

@ -45,7 +45,7 @@ KNOWN_VIOLATIONS=(
"src/bitcoin-tx.cpp.*stoul" "src/bitcoin-tx.cpp.*stoul"
"src/dbwrapper.cpp:.*vsnprintf" "src/dbwrapper.cpp:.*vsnprintf"
"src/rest.cpp:.*strtol" "src/rest.cpp:.*strtol"
"src/statsd_client.cpp:.*snprintf" "src/stats/client.cpp:.*snprintf"
"src/test/dbwrapper_tests.cpp:.*snprintf" "src/test/dbwrapper_tests.cpp:.*snprintf"
"src/test/fuzz/locale.cpp" "src/test/fuzz/locale.cpp"
"src/test/fuzz/string.cpp" "src/test/fuzz/string.cpp"

View File

@ -29,7 +29,8 @@ src/rpc/quorums.cpp
src/saltedhasher.* src/saltedhasher.*
src/spork.* src/spork.*
src/stacktraces.* src/stacktraces.*
src/statsd_client.* src/stats/*.cpp
src/stats/*.h
src/test/block_reward_reallocation_tests.cpp src/test/block_reward_reallocation_tests.cpp
src/test/bls_tests.cpp src/test/bls_tests.cpp
src/test/dip0020opcodes_tests.cpp src/test/dip0020opcodes_tests.cpp