Skip to content

Commit

Permalink
fix typo
Browse files Browse the repository at this point in the history
  • Loading branch information
qicosmos committed Jun 7, 2024
1 parent a16455a commit acfd687
Show file tree
Hide file tree
Showing 5 changed files with 48 additions and 46 deletions.
2 changes: 1 addition & 1 deletion include/ylt/metric/metric.hpp
Original file line number Diff line number Diff line change
Expand Up @@ -312,5 +312,5 @@ struct metric_manager_t {
static inline std::once_flag flag_;
};

using default_metric_manger = metric_manager_t<0>;
using default_metric_manager = metric_manager_t<0>;
} // namespace ylt
16 changes: 8 additions & 8 deletions include/ylt/standalone/cinatra/coro_http_server.hpp
Original file line number Diff line number Diff line change
Expand Up @@ -187,7 +187,7 @@ class coro_http_server {
set_http_handler<http_method::GET>(
url_path, [](coro_http_request &req, coro_http_response &res) {
std::string str = async_simple::coro::syncAwait(
ylt::default_metric_manger::serialize_static());
ylt::default_metric_manager::serialize_static());
res.set_status_and_content(status_type::ok, std::move(str));
});
}
Expand Down Expand Up @@ -903,20 +903,20 @@ class coro_http_server {
using namespace ylt;

cinatra_metric_conf::enable_metric = true;
default_metric_manger::create_metric_static<counter_t>(
default_metric_manager::create_metric_static<counter_t>(
cinatra_metric_conf::server_total_req, "");
default_metric_manger::create_metric_static<counter_t>(
default_metric_manager::create_metric_static<counter_t>(
cinatra_metric_conf::server_failed_req, "");
default_metric_manger::create_metric_static<counter_t>(
default_metric_manager::create_metric_static<counter_t>(
cinatra_metric_conf::server_total_recv_bytes, "");
default_metric_manger::create_metric_static<counter_t>(
default_metric_manager::create_metric_static<counter_t>(
cinatra_metric_conf::server_total_send_bytes, "");
default_metric_manger::create_metric_static<gauge_t>(
default_metric_manager::create_metric_static<gauge_t>(
cinatra_metric_conf::server_total_fd, "");
default_metric_manger::create_metric_static<histogram_t>(
default_metric_manager::create_metric_static<histogram_t>(
cinatra_metric_conf::server_req_latency, "",
std::vector<double>{30, 40, 50, 60, 70, 80, 90, 100, 150});
default_metric_manger::create_metric_static<histogram_t>(
default_metric_manager::create_metric_static<histogram_t>(
cinatra_metric_conf::server_read_latency, "",
std::vector<double>{3, 5, 7, 9, 13, 18, 23, 35, 50});
}
Expand Down
22 changes: 12 additions & 10 deletions include/ylt/standalone/cinatra/metric_conf.hpp
Original file line number Diff line number Diff line change
Expand Up @@ -26,7 +26,7 @@ struct cinatra_metric_conf {
}

static auto m =
ylt::default_metric_manger::get_metric_static<ylt::counter_t>(
ylt::default_metric_manager::get_metric_static<ylt::counter_t>(
server_total_req);
if (m == nullptr) {
return;
Expand All @@ -39,7 +39,7 @@ struct cinatra_metric_conf {
return;
}
static auto m =
ylt::default_metric_manger::get_metric_static<ylt::counter_t>(
ylt::default_metric_manager::get_metric_static<ylt::counter_t>(
server_failed_req);
if (m == nullptr) {
return;
Expand All @@ -51,8 +51,9 @@ struct cinatra_metric_conf {
if (!enable_metric) {
return;
}
static auto m = ylt::default_metric_manger::get_metric_static<ylt::gauge_t>(
server_total_fd);
static auto m =
ylt::default_metric_manager::get_metric_static<ylt::gauge_t>(
server_total_fd);
if (m == nullptr) {
return;
}
Expand All @@ -63,8 +64,9 @@ struct cinatra_metric_conf {
if (!enable_metric) {
return;
}
static auto m = ylt::default_metric_manger::get_metric_static<ylt::gauge_t>(
server_total_fd);
static auto m =
ylt::default_metric_manager::get_metric_static<ylt::gauge_t>(
server_total_fd);
if (m == nullptr) {
return;
}
Expand All @@ -76,7 +78,7 @@ struct cinatra_metric_conf {
return;
}
static auto m =
ylt::default_metric_manger::get_metric_static<ylt::counter_t>(
ylt::default_metric_manager::get_metric_static<ylt::counter_t>(
server_total_recv_bytes);
if (m == nullptr) {
return;
Expand All @@ -89,7 +91,7 @@ struct cinatra_metric_conf {
return;
}
static auto m =
ylt::default_metric_manger::get_metric_static<ylt::counter_t>(
ylt::default_metric_manager::get_metric_static<ylt::counter_t>(
server_total_send_bytes);
if (m == nullptr) {
return;
Expand All @@ -102,7 +104,7 @@ struct cinatra_metric_conf {
return;
}
static auto m =
ylt::default_metric_manger::get_metric_static<ylt::histogram_t>(
ylt::default_metric_manager::get_metric_static<ylt::histogram_t>(
server_req_latency);
if (m == nullptr) {
return;
Expand All @@ -115,7 +117,7 @@ struct cinatra_metric_conf {
return;
}
static auto m =
ylt::default_metric_manger::get_metric_static<ylt::histogram_t>(
ylt::default_metric_manager::get_metric_static<ylt::histogram_t>(
server_read_latency);
if (m == nullptr) {
return;
Expand Down
32 changes: 16 additions & 16 deletions src/metric/tests/test_metric.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -222,55 +222,55 @@ TEST_CASE("test summary") {
TEST_CASE("test register metric") {
auto c = std::make_shared<counter_t>(std::string("get_count"),
std::string("get counter"));
default_metric_manger::register_metric_static(c);
CHECK_FALSE(default_metric_manger::register_metric_static(c));
default_metric_manager::register_metric_static(c);
CHECK_FALSE(default_metric_manager::register_metric_static(c));

auto g = std::make_shared<gauge_t>(std::string("get_guage_count"),
std::string("get counter"));
default_metric_manger::register_metric_static(g);
default_metric_manager::register_metric_static(g);

auto map1 = default_metric_manger::metric_map_static();
auto map1 = default_metric_manager::metric_map_static();
for (auto& [k, v] : map1) {
bool r = k == "get_count" || k == "get_guage_count";
break;
}

CHECK(default_metric_manger::metric_count_static() >= 2);
CHECK(default_metric_manger::metric_keys_static().size() >= 2);
CHECK(default_metric_manager::metric_count_static() >= 2);
CHECK(default_metric_manager::metric_keys_static().size() >= 2);

c->inc();
g->inc();

auto map = default_metric_manger::metric_map_static();
auto map = default_metric_manager::metric_map_static();
CHECK(map["get_count"]->as<counter_t>()->value() == 1);
CHECK(map["get_guage_count"]->as<gauge_t>()->value() == 1);

auto s =
async_simple::coro::syncAwait(default_metric_manger::serialize_static());
async_simple::coro::syncAwait(default_metric_manager::serialize_static());
std::cout << s << "\n";
CHECK(s.find("get_count 1") != std::string::npos);
CHECK(s.find("get_guage_count 1") != std::string::npos);

auto m = default_metric_manger::get_metric_static<counter_t>("get_count");
auto m = default_metric_manager::get_metric_static<counter_t>("get_count");
CHECK(m->as<counter_t>()->value() == 1);

auto m1 =
default_metric_manger::get_metric_static<gauge_t>("get_guage_count");
default_metric_manager::get_metric_static<gauge_t>("get_guage_count");
CHECK(m1->as<gauge_t>()->value() == 1);

{
// because the first regiter_metric is set no lock, so visit
// default_metric_manger with lock will throw.
// default_metric_manager with lock will throw.
auto c1 = std::make_shared<counter_t>(std::string(""), std::string(""));
CHECK_THROWS_AS(default_metric_manger::register_metric_dynamic(c1),
CHECK_THROWS_AS(default_metric_manager::register_metric_dynamic(c1),
std::invalid_argument);
CHECK_THROWS_AS(default_metric_manger::metric_count_dynamic(),
CHECK_THROWS_AS(default_metric_manager::metric_count_dynamic(),
std::invalid_argument);
CHECK_THROWS_AS(default_metric_manger::metric_keys_dynamic(),
CHECK_THROWS_AS(default_metric_manager::metric_keys_dynamic(),
std::invalid_argument);
CHECK_THROWS_AS(default_metric_manger::metric_map_dynamic(),
CHECK_THROWS_AS(default_metric_manager::metric_map_dynamic(),
std::invalid_argument);
CHECK_THROWS_AS(default_metric_manger::get_metric_dynamic<counter_t>(""),
CHECK_THROWS_AS(default_metric_manager::get_metric_dynamic<counter_t>(""),
std::invalid_argument);
}
}
Expand Down
22 changes: 11 additions & 11 deletions website/docs/zh/metric/metrict_introduction.md
Original file line number Diff line number Diff line change
Expand Up @@ -243,36 +243,36 @@ class metric_t {
```cpp
auto c = std::make_shared<counter_t>("qps_count", "qps help");
auto g = std::make_shared<gauge_t>("fd_count", "fd count help");
default_metric_manger::register_metric_static(c);
default_metric_manger::register_metric_static(g);
default_metric_manager::register_metric_static(c);
default_metric_manager::register_metric_static(g);
c->inc();
g->inc();
auto m = default_metric_manger::get_metric_static("qps_count");
auto m = default_metric_manager::get_metric_static("qps_count");
CHECK(m->as<counter_t>()->value() == 1);
auto m1 = default_metric_manger::get_metric_static("fd_count");
auto m1 = default_metric_manager::get_metric_static("fd_count");
CHECK(m1->as<gauge_t>()->value() == 1);
```

如果希望动态注册的到管理器则应该调用register_metric_dynamic接口,后面根据名称获取指标对象时则调用get_metric_dynamic接口,dynamic接口内部会加锁。
```cpp
auto c = std::make_shared<counter_t>("qps_count", "qps help");
auto g = std::make_shared<gauge_t>("fd_count", "fd count help");
default_metric_manger::register_metric_dynamic(c);
default_metric_manger::register_metric_dynamic(g);
default_metric_manager::register_metric_dynamic(c);
default_metric_manager::register_metric_dynamic(g);

c->inc();
g->inc();

auto m = default_metric_manger::get_metric_dynamic("qps_count");
auto m = default_metric_manager::get_metric_dynamic("qps_count");
CHECK(m->as<counter_t>()->value() == 1);

auto m1 = default_metric_manger::get_metric_dynamic("fd_count");
auto m1 = default_metric_manager::get_metric_dynamic("fd_count");
CHECK(m1->as<gauge_t>()->value() == 1);
```
注意:一旦注册时使用了static或者dynamic,那么后面调用default_metric_manger时则应该使用相同后缀的接口,比如注册时使用了get_metric_static,那么后面调用根据名称获取指标对象的方法必须是get_metric_static,否则会抛异常。同样,如果注册使用register_metric_dynamic,则后面应该get_metric_dynamic,否则会抛异常。
注意:一旦注册时使用了static或者dynamic,那么后面调用default_metric_manager时则应该使用相同后缀的接口,比如注册时使用了get_metric_static,那么后面调用根据名称获取指标对象的方法必须是get_metric_static,否则会抛异常。同样,如果注册使用register_metric_dynamic,则后面应该get_metric_dynamic,否则会抛异常。
指标管理器的api
```cpp
Expand Down Expand Up @@ -317,9 +317,9 @@ struct metric_manager_t {
static async_simple::coro::Lazy<std::string> serialize_static();
static async_simple::coro::Lazy<std::string> serialize_dynamic();
};
using default_metric_manger = metric_manager_t<0>;
using default_metric_manager = metric_manager_t<0>;
```
metric_manager_t默认为default_metric_manger,如果希望有多个metric manager,用户可以自定义新的metric manager,如:
metric_manager_t默认为default_metric_manager,如果希望有多个metric manager,用户可以自定义新的metric manager,如:

```cpp
constexpr size_t metric_id = 100;
Expand Down

0 comments on commit acfd687

Please sign in to comment.