fmt: apply clang-format-diff.py suggestions

This commit is contained in:
Kittywhiskers Van Gogh 2024-09-11 15:02:10 +00:00
parent 0401c581eb
commit cc998abec1
No known key found for this signature in database
GPG Key ID: 30CD0C065E5C4AAD
2 changed files with 12 additions and 18 deletions

View File

@ -61,9 +61,12 @@ bool StatsdClient::ShouldSend(float sample_rate)
return sample_rate > std::uniform_real_distribution<float>(0.f, 1.f)(insecure_rand); 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, StatsdClient::StatsdClient(const std::string& host, const std::string& nodename, uint16_t port, const std::string& ns,
const std::string& ns, bool enabled) bool enabled) :
: m_port{port}, m_host{host}, m_nodename{nodename}, m_ns{ns} m_port{port},
m_host{host},
m_nodename{nodename},
m_ns{ns}
{ {
if (!enabled) { if (!enabled) {
LogPrintf("Transmitting stats are disabled, will not init StatsdClient\n"); LogPrintf("Transmitting stats are disabled, will not init StatsdClient\n");
@ -99,22 +102,15 @@ StatsdClient::StatsdClient(const std::string& host, const std::string& nodename,
void StatsdClient::cleanup(std::string& key) void StatsdClient::cleanup(std::string& key)
{ {
auto pos = key.find_first_of(":|@"); auto pos = key.find_first_of(":|@");
while (pos != std::string::npos) while (pos != std::string::npos) {
{
key[pos] = '_'; key[pos] = '_';
pos = key.find_first_of(":|@"); pos = key.find_first_of(":|@");
} }
} }
bool StatsdClient::dec(const std::string& key, float sample_rate) bool StatsdClient::dec(const std::string& key, float sample_rate) { return count(key, -1, sample_rate); }
{
return count(key, -1, sample_rate);
}
bool StatsdClient::inc(const std::string& key, float sample_rate) bool StatsdClient::inc(const std::string& key, float sample_rate) { return count(key, 1, sample_rate); }
{
return count(key, 1, sample_rate);
}
bool StatsdClient::count(const std::string& key, int64_t value, float sample_rate) bool StatsdClient::count(const std::string& key, int64_t value, float sample_rate)
{ {
@ -148,8 +144,7 @@ bool StatsdClient::send(std::string key, int64_t value, const std::string& type,
} }
// partition stats by node name if set // partition stats by node name if set
if (!m_nodename.empty()) if (!m_nodename.empty()) key = key + "." + m_nodename;
key = key + "." + m_nodename;
cleanup(key); cleanup(key);
@ -173,8 +168,7 @@ bool StatsdClient::sendDouble(std::string key, double value, const std::string&
} }
// partition stats by node name if set // partition stats by node name if set
if (!m_nodename.empty()) if (!m_nodename.empty()) key = key + "." + m_nodename;
key = key + "." + m_nodename;
cleanup(key); cleanup(key);

View File

@ -22,7 +22,7 @@ static const std::string DEFAULT_STATSD_NAMESPACE{""};
// schedule periodic measurements, in seconds: default - 1 minute, min - 5 sec, max - 1h. // schedule periodic measurements, in seconds: default - 1 minute, min - 5 sec, max - 1h.
static constexpr int DEFAULT_STATSD_PERIOD{60}; 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 { namespace statsd {
class StatsdClient { class StatsdClient {