From f782dfd562cd168bac4cfde6be009a1343bb0787 Mon Sep 17 00:00:00 2001 From: Kittywhiskers Van Gogh <63189531+kwvg@users.noreply.github.com> Date: Tue, 10 Sep 2024 16:22:07 +0000 Subject: [PATCH 01/12] stats: remove double indentation in header file --- src/statsd_client.h | 64 ++++++++++++++++++++++----------------------- 1 file changed, 32 insertions(+), 32 deletions(-) diff --git a/src/statsd_client.h b/src/statsd_client.h index 7568d8cd0e769..cdda53d2e2f32 100644 --- a/src/statsd_client.h +++ b/src/statsd_client.h @@ -26,45 +26,45 @@ static constexpr int MAX_STATSD_PERIOD{60 * 60}; namespace statsd { class StatsdClient { - public: - explicit StatsdClient(const std::string& host, const std::string& nodename, uint16_t port, - const std::string& ns, bool enabled); +public: + explicit StatsdClient(const std::string& host, const std::string& nodename, uint16_t port, + const std::string& ns, bool enabled); - public: - bool inc(const std::string& key, float sample_rate = 1.f); - bool dec(const std::string& key, float sample_rate = 1.f); - bool count(const std::string& key, int64_t value, float sample_rate = 1.f); - bool gauge(const std::string& key, int64_t value, float sample_rate = 1.f); - bool gaugeDouble(const std::string& key, double value, float sample_rate = 1.f); - bool timing(const std::string& key, int64_t ms, float sample_rate = 1.f); +public: + bool inc(const std::string& key, float sample_rate = 1.f); + bool dec(const std::string& key, float sample_rate = 1.f); + bool count(const std::string& key, int64_t value, float sample_rate = 1.f); + bool gauge(const std::string& key, int64_t value, float sample_rate = 1.f); + bool gaugeDouble(const std::string& key, double value, float sample_rate = 1.f); + bool timing(const std::string& key, int64_t ms, float sample_rate = 1.f); - /* (Low Level Api) manually send a message - * type = "c", "g" or "ms" - */ - bool send(std::string key, int64_t value, const std::string& type, float sample_rate); - bool sendDouble(std::string key, double value, const std::string& type, float sample_rate); + /* (Low Level Api) manually send a message + * type = "c", "g" or "ms" + */ + bool send(std::string key, int64_t value, const std::string& type, float sample_rate); + bool sendDouble(std::string key, double value, const std::string& type, float sample_rate); - private: - /** - * (Low Level Api) manually send a message - * which might be composed of several lines. - */ - bool send(const std::string& message); +private: + /** + * (Low Level Api) manually send a message + * which might be composed of several lines. + */ + bool send(const std::string& message); - void cleanup(std::string& key); - bool ShouldSend(float sample_rate); + void cleanup(std::string& key); + bool ShouldSend(float sample_rate); - private: - mutable Mutex cs; - mutable FastRandomContext insecure_rand GUARDED_BY(cs); +private: + mutable Mutex cs; + mutable FastRandomContext insecure_rand GUARDED_BY(cs); - std::unique_ptr m_sock{nullptr}; - std::pair m_server{{}, sizeof(struct sockaddr_storage)}; + std::unique_ptr m_sock{nullptr}; + std::pair m_server{{}, sizeof(struct sockaddr_storage)}; - const uint16_t m_port; - const std::string m_host; - const std::string m_nodename; - const std::string m_ns; + const uint16_t m_port; + const std::string m_host; + const std::string m_nodename; + const std::string m_ns; }; } // namespace statsd From 92690685be62c89c3bdfc707029873e539fedb7d Mon Sep 17 00:00:00 2001 From: Kittywhiskers Van Gogh <63189531+kwvg@users.noreply.github.com> Date: Thu, 12 Sep 2024 15:25:38 +0000 Subject: [PATCH 02/12] 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 --- contrib/devtools/copyright_header.py | 2 +- src/Makefile.am | 4 ++-- src/init.cpp | 12 ++++++------ src/net.cpp | 2 +- src/net_processing.cpp | 2 +- src/{statsd_client.cpp => stats/client.cpp} | 6 ++---- src/{statsd_client.h => stats/client.h} | 15 +++++++-------- src/test/util/setup_common.cpp | 4 ++-- src/txorphanage.cpp | 2 +- src/validation.cpp | 2 +- test/lint/lint-locale-dependence.sh | 2 +- test/util/data/non-backported.txt | 3 ++- 12 files changed, 27 insertions(+), 29 deletions(-) rename src/{statsd_client.cpp => stats/client.cpp} (98%) rename src/{statsd_client.h => stats/client.h} (91%) diff --git a/contrib/devtools/copyright_header.py b/contrib/devtools/copyright_header.py index e6efff75fd9d6..0f9d2aaae2686 100755 --- a/contrib/devtools/copyright_header.py +++ b/contrib/devtools/copyright_header.py @@ -26,7 +26,7 @@ 'src/crypto/*', 'src/ctpl_stl.h', 'src/reverse_iterator.h', - 'src/statsd_client.cpp', + 'src/stats/client.cpp', 'src/test/fuzz/FuzzedDataProvider.h', 'src/tinyformat.h', 'src/bench/nanobench.h', diff --git a/src/Makefile.am b/src/Makefile.am index ae6b3863e2fa0..e35efcc506003 100644 --- a/src/Makefile.am +++ b/src/Makefile.am @@ -313,7 +313,7 @@ BITCOIN_CORE_H = \ spork.h \ stacktraces.h \ streams.h \ - statsd_client.h \ + stats/client.h \ support/allocators/mt_pooled_secure.h \ support/allocators/pool.h \ support/allocators/pooled_secure.h \ @@ -526,7 +526,7 @@ libbitcoin_server_a_SOURCES = \ script/sigcache.cpp \ shutdown.cpp \ spork.cpp \ - statsd_client.cpp \ + stats/client.cpp \ timedata.cpp \ torcontrol.cpp \ txdb.cpp \ diff --git a/src/init.cpp b/src/init.cpp index 18decacf04163..1afff5b6de236 100644 --- a/src/init.cpp +++ b/src/init.cpp @@ -105,7 +105,7 @@ #include #include -#include +#include #include #include @@ -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 // 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 = std::make_unique(args.GetArg("-statshost", DEFAULT_STATSD_HOST), - args.GetArg("-statshostname", DEFAULT_STATSD_HOSTNAME), - args.GetArg("-statsport", DEFAULT_STATSD_PORT), - args.GetArg("-statsns", DEFAULT_STATSD_NAMESPACE), - args.GetBoolArg("-statsenabled", DEFAULT_STATSD_ENABLE)); + ::g_stats_client = std::make_unique(args.GetArg("-statshost", DEFAULT_STATSD_HOST), + args.GetArg("-statshostname", DEFAULT_STATSD_HOSTNAME), + args.GetArg("-statsport", DEFAULT_STATSD_PORT), + args.GetArg("-statsns", DEFAULT_STATSD_NAMESPACE), + args.GetBoolArg("-statsenabled", DEFAULT_STATSD_ENABLE)); { diff --git a/src/net.cpp b/src/net.cpp index d7863ab05b6c8..c3a51a103a38d 100644 --- a/src/net.cpp +++ b/src/net.cpp @@ -41,7 +41,7 @@ #include #include -#include +#include #ifdef WIN32 #include diff --git a/src/net_processing.cpp b/src/net_processing.cpp index 1735df86697f5..bdaf5b660b10c 100644 --- a/src/net_processing.cpp +++ b/src/net_processing.cpp @@ -69,7 +69,7 @@ #include #include -#include +#include /** Maximum number of in-flight objects from a peer */ static constexpr int32_t MAX_PEER_OBJECT_IN_FLIGHT = 100; diff --git a/src/statsd_client.cpp b/src/stats/client.cpp similarity index 98% rename from src/statsd_client.cpp rename to src/stats/client.cpp index d9ef85242b1d4..a2683e6156207 100644 --- a/src/statsd_client.cpp +++ b/src/stats/client.cpp @@ -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. **/ -#include +#include #include #include @@ -43,9 +43,8 @@ OF THIS SOFTWARE, EVEN IF ADVISED OF THE POSSIBILITY OF SUCH DAMAGE. #include #include -std::unique_ptr g_stats_client; +std::unique_ptr g_stats_client; -namespace statsd { bool StatsdClient::ShouldSend(float sample_rate) { sample_rate = std::clamp(sample_rate, 0.f, 1.f); @@ -193,4 +192,3 @@ bool StatsdClient::send(const std::string& message) return true; } -} // namespace statsd diff --git a/src/statsd_client.h b/src/stats/client.h similarity index 91% rename from src/statsd_client.h rename to src/stats/client.h index cdda53d2e2f32..eb8a48399882e 100644 --- a/src/statsd_client.h +++ b/src/stats/client.h @@ -3,15 +3,15 @@ // Distributed under the MIT software license, see the accompanying // file COPYING or http://www.opensource.org/licenses/mit-license.php. -#ifndef BITCOIN_STATSD_CLIENT_H -#define BITCOIN_STATSD_CLIENT_H +#ifndef BITCOIN_STATS_CLIENT_H +#define BITCOIN_STATS_CLIENT_H #include #include #include -#include #include +#include static constexpr bool DEFAULT_STATSD_ENABLE{false}; 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 MAX_STATSD_PERIOD{60 * 60}; -namespace statsd { -class StatsdClient { +class StatsdClient +{ public: explicit StatsdClient(const std::string& host, const std::string& nodename, uint16_t port, const std::string& ns, bool enabled); @@ -66,8 +66,7 @@ class StatsdClient { const std::string m_nodename; const std::string m_ns; }; -} // namespace statsd -extern std::unique_ptr g_stats_client; +extern std::unique_ptr g_stats_client; -#endif // BITCOIN_STATSD_CLIENT_H +#endif // BITCOIN_STATS_CLIENT_H diff --git a/src/test/util/setup_common.cpp b/src/test/util/setup_common.cpp index e3453a9a6e401..04bcfe43bb035 100644 --- a/src/test/util/setup_common.cpp +++ b/src/test/util/setup_common.cpp @@ -39,7 +39,7 @@ #include #include