stats: const-ify variables and arguments

We cannot convert `DEFAULT_STATSD*` to `std::string_view`s as they're
being used as default arguments and `GetArgs` expects `std::string`s
This commit is contained in:
Kittywhiskers Van Gogh 2024-09-05 20:04:47 +00:00
parent 9f96723774
commit 0401c581eb
No known key found for this signature in database
GPG Key ID: 30CD0C065E5C4AAD
2 changed files with 12 additions and 12 deletions

View File

@ -61,8 +61,8 @@ bool StatsdClient::ShouldSend(float sample_rate)
return sample_rate > std::uniform_real_distribution<float>(0.f, 1.f)(insecure_rand);
}
StatsdClient::StatsdClient(const std::string& host, const std::string& nodename, uint16_t port, const std::string& ns,
bool enabled)
StatsdClient::StatsdClient(const std::string& host, const std::string& nodename, uint16_t port,
const std::string& ns, bool enabled)
: m_port{port}, m_host{host}, m_nodename{nodename}, m_ns{ns}
{
if (!enabled) {

View File

@ -13,22 +13,22 @@
#include <string>
#include <memory>
static const bool DEFAULT_STATSD_ENABLE = false;
static const uint16_t DEFAULT_STATSD_PORT = 8125;
static const std::string DEFAULT_STATSD_HOST = "127.0.0.1";
static const std::string DEFAULT_STATSD_HOSTNAME = "";
static const std::string DEFAULT_STATSD_NAMESPACE = "";
static constexpr bool DEFAULT_STATSD_ENABLE{false};
static constexpr uint16_t DEFAULT_STATSD_PORT{8125};
static const std::string DEFAULT_STATSD_HOST{"127.0.0.1"};
static const std::string DEFAULT_STATSD_HOSTNAME{""};
static const std::string DEFAULT_STATSD_NAMESPACE{""};
// schedule periodic measurements, in seconds: default - 1 minute, min - 5 sec, max - 1h.
static const int DEFAULT_STATSD_PERIOD = 60;
static const int MIN_STATSD_PERIOD = 5;
static const int MAX_STATSD_PERIOD = 60 * 60;
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 {
public:
explicit StatsdClient(const std::string& host, const std::string& nodename, uint16_t port, const std::string& ns,
bool enabled);
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);