Skip to content

Commit

Permalink
fix: fix issues found by CLion static analyzer
Browse files Browse the repository at this point in the history
  • Loading branch information
gjasny committed Apr 6, 2022
1 parent 01b42a9 commit 99d06d2
Show file tree
Hide file tree
Showing 14 changed files with 25 additions and 39 deletions.
4 changes: 2 additions & 2 deletions core/include/prometheus/family.h
Expand Up @@ -78,7 +78,7 @@ class PROMETHEUS_CPP_CORE_EXPORT Family : public Collectable {
///
/// http_requests_total{job= "prometheus"}
///
/// For further information see: [Quering Basics]
/// For further information see: [Querying Basics]
/// (https://prometheus.io/docs/prometheus/latest/querying/basics/)
///
/// \param name Set the metric name.
Expand Down Expand Up @@ -131,7 +131,7 @@ class PROMETHEUS_CPP_CORE_EXPORT Family : public Collectable {
/// \brief Returns the constant labels for this family.
///
/// \return All constant labels as key-value pairs.
const Labels GetConstantLabels() const;
const Labels& GetConstantLabels() const;

/// \brief Returns the current value of each dimensional data.
///
Expand Down
4 changes: 2 additions & 2 deletions core/include/prometheus/gauge.h
Expand Up @@ -29,7 +29,7 @@ class PROMETHEUS_CPP_CORE_EXPORT Gauge {
Gauge() = default;

/// \brief Create a gauge that starts at the given amount.
Gauge(double);
explicit Gauge(double);

/// \brief Increment the gauge by 1.
void Increment();
Expand All @@ -46,7 +46,7 @@ class PROMETHEUS_CPP_CORE_EXPORT Gauge {
/// \brief Set the gauge to the given value.
void Set(double);

/// \brief Set the gauge to the current unixtime in seconds.
/// \brief Set the gauge to the current unix time in seconds.
void SetToCurrentTime();

/// \brief Get the current value of the gauge.
Expand Down
2 changes: 1 addition & 1 deletion core/include/prometheus/histogram.h
Expand Up @@ -63,7 +63,7 @@ class PROMETHEUS_CPP_CORE_EXPORT Histogram {
/// this function must have already sorted the values into buckets).
/// Also increments the total sum of all observations by the given value.
void ObserveMultiple(const std::vector<double>& bucket_increments,
const double sum_of_values);
double sum_of_values);

/// \brief Get the current value of the histogram.
///
Expand Down
13 changes: 1 addition & 12 deletions core/src/detail/hash.h
Expand Up @@ -13,7 +13,7 @@ namespace detail {
/// \param seed Not effect.
inline void hash_combine(std::size_t*) {}

/// \brief Combine the given hash value with another obeject.
/// \brief Combine the given hash value with another object.
///
/// \param seed The given hash value. It's a input/output parameter.
/// \param value The object that will be combined with the given hash value.
Expand All @@ -34,17 +34,6 @@ inline void hash_combine(std::size_t* seed, const T& value,
hash_combine(seed, args...);
}

/// \brief Compute a hash value of the given args.
///
/// \param args The arguments that will be computed hash value.
/// \return The hash value of the given args.
template <typename... Types>
inline std::size_t hash_value(const Types&... args) {
std::size_t seed = 0;
hash_combine(&seed, args...);
return seed;
}

} // namespace detail

} // namespace prometheus
2 changes: 1 addition & 1 deletion core/src/family.cc
Expand Up @@ -81,7 +81,7 @@ const std::string& Family<T>::GetName() const {
}

template <typename T>
const Labels Family<T>::GetConstantLabels() const {
const Labels& Family<T>::GetConstantLabels() const {
return constant_labels_;
}

Expand Down
2 changes: 1 addition & 1 deletion core/tests/builder_test.cc
Expand Up @@ -26,7 +26,7 @@ class BuilderTest : public testing::Test {
std::vector<ClientMetric::Label> getExpectedLabels() {
std::vector<ClientMetric::Label> labels;

auto gen = [](std::pair<const std::string, std::string> p) {
auto gen = [](const std::pair<const std::string, std::string>& p) {
return ClientMetric::Label{p.first, p.second};
};

Expand Down
6 changes: 3 additions & 3 deletions core/tests/family_test.cc
Expand Up @@ -89,7 +89,7 @@ TEST(FamilyTest, throw_on_invalid_constant_label_name) {
auto create_family_with_invalid_labels = []() {
return std::make_unique<Family<Counter>>("total_requests",
"Counts all requests",
Labels{{"__inavlid", "counter1"}});
Labels{{"__invalid", "counter1"}});
};
EXPECT_ANY_THROW(create_family_with_invalid_labels());
}
Expand All @@ -109,10 +109,10 @@ TEST(FamilyTest, should_not_collect_empty_metrics) {
}

TEST(FamilyTest, query_family_if_metric_already_exists) {
Family<Counter> family{"total_rquests", "Counts all requests", {}};
Family<Counter> family{"total_requests", "Counts all requests", {}};
family.Add({{"name", "counter1"}});
EXPECT_TRUE(family.Has({{"name", "counter1"}}));
EXPECT_FALSE(family.Has({{"name", "couner2"}}));
EXPECT_FALSE(family.Has({{"name", "counter2"}}));
}

} // namespace
Expand Down
4 changes: 2 additions & 2 deletions core/tests/raii_locale.h
Expand Up @@ -4,7 +4,7 @@

class RAIILocale {
public:
RAIILocale(const char* name) : savedLocale_(std::locale::classic()) {
explicit RAIILocale(const char* name) {
std::locale::global(std::locale(name));
}

Expand All @@ -16,5 +16,5 @@ class RAIILocale {
RAIILocale& operator=(RAIILocale&&) = delete;

private:
const std::locale savedLocale_;
const std::locale savedLocale_ = std::locale{};
};
2 changes: 1 addition & 1 deletion core/tests/utils_test.cc
Expand Up @@ -12,7 +12,7 @@ class UtilsTest : public testing::Test {
};

TEST_F(UtilsTest, hash_labels_1) {
Labels labels{{"key1", "value1"}, {"key2", "vaule2"}};
Labels labels{{"key1", "value1"}, {"key2", "value2"}};
EXPECT_EQ(hasher(labels), hasher(labels));
}

Expand Down
3 changes: 1 addition & 2 deletions pull/include/prometheus/exposer.h
Expand Up @@ -21,8 +21,7 @@ class Endpoint;

class PROMETHEUS_CPP_PULL_EXPORT Exposer {
public:
explicit Exposer(const std::string& bind_address,
const std::size_t num_threads = 2,
explicit Exposer(const std::string& bind_address, std::size_t num_threads = 2,
const CivetCallbacks* callbacks = nullptr);
explicit Exposer(std::vector<std::string> options,
const CivetCallbacks* callbacks = nullptr);
Expand Down
10 changes: 5 additions & 5 deletions pull/tests/integration/integration_test.cc
Expand Up @@ -27,22 +27,22 @@ class IntegrationTest : public testing::Test {
base_url_ = std::string("http://127.0.0.1:") + std::to_string(ports.at(0));
}

struct Resonse {
struct Response {
long code = 0;
std::string body;
std::string contentType;
};

std::function<void(CURL*)> fetchPrePerform_;

Resonse FetchMetrics(std::string metrics_path) {
Response FetchMetrics(const std::string& metrics_path) const {
auto curl = std::shared_ptr<CURL>(curl_easy_init(), curl_easy_cleanup);
if (!curl) {
throw std::runtime_error("failed to initialize libcurl");
}

const auto url = base_url_ + metrics_path;
Resonse response;
Response response;

curl_easy_setopt(curl.get(), CURLOPT_URL, url.c_str());
curl_easy_setopt(curl.get(), CURLOPT_WRITEDATA, &response.body);
Expand All @@ -69,8 +69,8 @@ class IntegrationTest : public testing::Test {
}

std::shared_ptr<Registry> RegisterSomeCounter(const std::string& name,
const std::string& path) {
const auto registry = std::make_shared<Registry>();
const std::string& path) const {
auto registry = std::make_shared<Registry>();

BuildCounter().Name(name).Register(*registry).Add({}).Increment();

Expand Down
2 changes: 1 addition & 1 deletion pull/tests/integration/sample_server.cc
Expand Up @@ -14,7 +14,7 @@
int main() {
using namespace prometheus;

// create an http server running on port 8080
// create a http server running on port 8080
Exposer exposer{"127.0.0.1:8080"};

// create a metrics registry
Expand Down
8 changes: 3 additions & 5 deletions pull/tests/internal/base64_test.cc
Expand Up @@ -22,14 +22,12 @@ const TestVector testVector[] = {
{"foobar", "Zm9vYmFy"},
};

const unsigned nVectors = sizeof(testVector) / sizeof(testVector[0]);

using namespace testing;

TEST(Base64Test, decodeTest) {
for (unsigned i = 0; i < nVectors; ++i) {
std::string decoded = detail::base64_decode(testVector[i].encoded);
EXPECT_EQ(testVector[i].decoded, decoded);
for (const auto& test_case : testVector) {
std::string decoded = detail::base64_decode(test_case.encoded);
EXPECT_EQ(test_case.decoded, decoded);
}
}

Expand Down
2 changes: 1 addition & 1 deletion push/src/gateway.cc
Expand Up @@ -54,7 +54,7 @@ void Gateway::RegisterCollectable(const std::weak_ptr<Collectable>& collectable,

std::lock_guard<std::mutex> lock{mutex_};
CleanupStalePointers(collectables_);
collectables_.push_back(std::make_pair(collectable, ss.str()));
collectables_.emplace_back(collectable, ss.str());
}

std::string Gateway::getUri(const CollectableEntry& collectable) const {
Expand Down

0 comments on commit 99d06d2

Please sign in to comment.