Skip to content

Commit

Permalink
add namespace
Browse files Browse the repository at this point in the history
  • Loading branch information
qicosmos committed Jun 13, 2024
1 parent 4141415 commit ad47f8c
Show file tree
Hide file tree
Showing 11 changed files with 37 additions and 44 deletions.
4 changes: 2 additions & 2 deletions example/main.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -10,7 +10,7 @@
#include "metric_conf.hpp"

using namespace cinatra;
using namespace ylt;
using namespace ylt::metric;
using namespace std::chrono_literals;

void create_file(std::string filename, size_t file_size = 64) {
Expand Down Expand Up @@ -429,7 +429,7 @@ async_simple::coro::Lazy<void> basic_usage() {
}

void use_metric() {
using namespace ylt;
using namespace ylt::metric;
auto c =
std::make_shared<counter_t>("request_count", "request count",
std::vector<std::string>{"method", "url"});
Expand Down
12 changes: 6 additions & 6 deletions include/cinatra/coro_http_server.hpp
Original file line number Diff line number Diff line change
Expand Up @@ -184,11 +184,11 @@ class coro_http_server {

void use_metrics(std::string url_path = "/metrics") {
init_metrics();
set_http_handler<http_method::GET>(
url_path, [](coro_http_request &req, coro_http_response &res) {
std::string str = ylt::default_metric_manager::serialize_static();
res.set_status_and_content(status_type::ok, std::move(str));
});
set_http_handler<http_method::GET>(url_path, [](coro_http_request &req,
coro_http_response &res) {
std::string str = ylt::metric::default_metric_manager::serialize_static();
res.set_status_and_content(status_type::ok, std::move(str));
});
}

template <http_method... method, typename... Aspects>
Expand Down Expand Up @@ -899,7 +899,7 @@ class coro_http_server {

private:
void init_metrics() {
using namespace ylt;
using namespace ylt::metric;

cinatra_metric_conf::enable_metric = true;
default_metric_manager::create_metric_static<counter_t>(
Expand Down
40 changes: 16 additions & 24 deletions include/cinatra/metric_conf.hpp
Original file line number Diff line number Diff line change
Expand Up @@ -25,9 +25,8 @@ struct cinatra_metric_conf {
return;
}

static auto m =
ylt::default_metric_manager::get_metric_static<ylt::counter_t>(
server_total_req);
static auto m = ylt::metric::default_metric_manager::get_metric_static<
ylt::metric::counter_t>(server_total_req);
if (m == nullptr) {
return;
}
Expand All @@ -38,9 +37,8 @@ struct cinatra_metric_conf {
if (!enable_metric) {
return;
}
static auto m =
ylt::default_metric_manager::get_metric_static<ylt::counter_t>(
server_failed_req);
static auto m = ylt::metric::default_metric_manager::get_metric_static<
ylt::metric::counter_t>(server_failed_req);
if (m == nullptr) {
return;
}
Expand All @@ -51,9 +49,8 @@ struct cinatra_metric_conf {
if (!enable_metric) {
return;
}
static auto m =
ylt::default_metric_manager::get_metric_static<ylt::gauge_t>(
server_total_fd);
static auto m = ylt::metric::default_metric_manager::get_metric_static<
ylt::metric::gauge_t>(server_total_fd);
if (m == nullptr) {
return;
}
Expand All @@ -64,9 +61,8 @@ struct cinatra_metric_conf {
if (!enable_metric) {
return;
}
static auto m =
ylt::default_metric_manager::get_metric_static<ylt::gauge_t>(
server_total_fd);
static auto m = ylt::metric::default_metric_manager::get_metric_static<
ylt::metric::gauge_t>(server_total_fd);
if (m == nullptr) {
return;
}
Expand All @@ -77,9 +73,8 @@ struct cinatra_metric_conf {
if (!enable_metric) {
return;
}
static auto m =
ylt::default_metric_manager::get_metric_static<ylt::counter_t>(
server_total_recv_bytes);
static auto m = ylt::metric::default_metric_manager::get_metric_static<
ylt::metric::counter_t>(server_total_recv_bytes);
if (m == nullptr) {
return;
}
Expand All @@ -90,9 +85,8 @@ struct cinatra_metric_conf {
if (!enable_metric) {
return;
}
static auto m =
ylt::default_metric_manager::get_metric_static<ylt::counter_t>(
server_total_send_bytes);
static auto m = ylt::metric::default_metric_manager::get_metric_static<
ylt::metric::counter_t>(server_total_send_bytes);
if (m == nullptr) {
return;
}
Expand All @@ -103,9 +97,8 @@ struct cinatra_metric_conf {
if (!enable_metric) {
return;
}
static auto m =
ylt::default_metric_manager::get_metric_static<ylt::histogram_t>(
server_req_latency);
static auto m = ylt::metric::default_metric_manager::get_metric_static<
ylt::metric::histogram_t>(server_req_latency);
if (m == nullptr) {
return;
}
Expand All @@ -116,9 +109,8 @@ struct cinatra_metric_conf {
if (!enable_metric) {
return;
}
static auto m =
ylt::default_metric_manager::get_metric_static<ylt::histogram_t>(
server_read_latency);
static auto m = ylt::metric::default_metric_manager::get_metric_static<
ylt::metric::histogram_t>(server_read_latency);
if (m == nullptr) {
return;
}
Expand Down
4 changes: 2 additions & 2 deletions include/cinatra/ylt/metric/counter.hpp
Original file line number Diff line number Diff line change
Expand Up @@ -4,7 +4,7 @@

#include "metric.hpp"

namespace ylt {
namespace ylt::metric {
enum class op_type_t { INC, DEC, SET };

#ifdef CINATRA_ENABLE_METRIC_JSON
Expand Down Expand Up @@ -309,4 +309,4 @@ class counter_t : public metric_t {
std::less<std::vector<std::string>>>
value_map_;
};
} // namespace ylt
} // namespace ylt::metric
2 changes: 1 addition & 1 deletion include/cinatra/ylt/metric/detail/ckms_quantiles.hpp
Original file line number Diff line number Diff line change
Expand Up @@ -5,7 +5,7 @@

// https://github.com/jupp0r/prometheus-cpp/blob/master/core/include/prometheus/detail/ckms_quantiles.h

namespace ylt {
namespace ylt::metric {
class CKMSQuantiles {
public:
struct Quantile {
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -2,7 +2,7 @@
#include "ckms_quantiles.hpp"
// https://github.com/jupp0r/prometheus-cpp/blob/master/core/include/prometheus/detail/time_window_quantiles.h

namespace ylt {
namespace ylt::metric {
class TimeWindowQuantiles {
using Clock = std::chrono::steady_clock;

Expand Down
4 changes: 2 additions & 2 deletions include/cinatra/ylt/metric/gauge.hpp
Original file line number Diff line number Diff line change
Expand Up @@ -3,7 +3,7 @@

#include "counter.hpp"

namespace ylt {
namespace ylt::metric {
class gauge_t : public counter_t {
public:
gauge_t(std::string name, std::string help)
Expand Down Expand Up @@ -49,4 +49,4 @@ class gauge_t : public counter_t {
}
}
};
} // namespace ylt
} // namespace ylt::metric
4 changes: 2 additions & 2 deletions include/cinatra/ylt/metric/histogram.hpp
Original file line number Diff line number Diff line change
Expand Up @@ -8,7 +8,7 @@
#include "counter.hpp"
#include "metric.hpp"

namespace ylt {
namespace ylt::metric {
#ifdef CINATRA_ENABLE_METRIC_JSON
struct json_histogram_metric_t {
std::map<double, int64_t> quantiles;
Expand Down Expand Up @@ -123,4 +123,4 @@ class histogram_t : public metric_t {
std::vector<std::shared_ptr<counter_t>> bucket_counts_; // readonly
std::shared_ptr<gauge_t> sum_;
};
} // namespace ylt
} // namespace ylt::metric
4 changes: 2 additions & 2 deletions include/cinatra/ylt/metric/metric.hpp
Original file line number Diff line number Diff line change
Expand Up @@ -27,7 +27,7 @@ inline char* to_chars_float(T value, char* buffer) {

#include <iguana/json_writer.hpp>
#endif
namespace ylt {
namespace ylt::metric {
enum class MetricType {
Counter,
Gauge,
Expand Down Expand Up @@ -524,4 +524,4 @@ struct metric_manager_t {
};

using default_metric_manager = metric_manager_t<0>;
} // namespace ylt
} // namespace ylt::metric
4 changes: 2 additions & 2 deletions include/cinatra/ylt/metric/summary.hpp
Original file line number Diff line number Diff line change
Expand Up @@ -6,7 +6,7 @@
#include "ylt/coro_io/coro_io.hpp"
#include "ylt/util/concurrentqueue.h"

namespace ylt {
namespace ylt::metric {
#ifdef CINATRA_ENABLE_METRIC_JSON
struct json_summary_metric_t {
std::map<double, double> quantiles;
Expand Down Expand Up @@ -174,4 +174,4 @@ class summary_t : public metric_t {
asio::io_context ctx_;
std::thread thd_;
};
} // namespace ylt
} // namespace ylt::metric
1 change: 1 addition & 0 deletions tests/test_metric.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -11,6 +11,7 @@
#include "cinatra/ylt/metric/summary.hpp"
#include "doctest/doctest.h"
using namespace ylt;
using namespace ylt::metric;

TEST_CASE("test no lable") {
{
Expand Down

0 comments on commit ad47f8c

Please sign in to comment.