Skip to content

Commit

Permalink
[metric] fix summary
Browse files Browse the repository at this point in the history
  • Loading branch information
poor-circle committed Sep 20, 2024
1 parent 8b6b947 commit 9c26069
Show file tree
Hide file tree
Showing 2 changed files with 9 additions and 8 deletions.
11 changes: 4 additions & 7 deletions include/ylt/metric/summary_impl.hpp
Original file line number Diff line number Diff line change
Expand Up @@ -9,9 +9,6 @@
#include <memory>
#include <vector>

#include "ylt/easylog.hpp"
#include "ylt/metric/counter.hpp"

namespace ylt::metric::detail {

template <std::size_t frac_bit = 6>
Expand Down Expand Up @@ -316,15 +313,15 @@ class summary_impl {
std::vector<float> result;
result.reserve(rate_.size());
float v = -float16_max;
for (auto e : rate_) {
if (e < 0) [[unlikely]] {
for (double e : rate_) {
if (std::isnan(e) || e < 0) {
result.push_back(v);
continue;
}
else if (e > 1) {
else if (e > 1) [[unlikely]] {
e = 1;
}
auto target_count = std::min<int64_t>(e * count, count);
auto target_count = std::min<double>(e * count, count);
while (true) {
if (target_count <= count_now) [[unlikely]] {
result.push_back(v);
Expand Down
6 changes: 5 additions & 1 deletion src/metric/tests/test_metric.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -449,12 +449,16 @@ using my_manager = static_metric_manager<my_tag>;
auto g_pair = my_manager::instance().create_metric_static<counter_t>(
"test_g_counter", "");

TEST_CASE("test no lable") {
TEST_CASE("test no label") {
{
std::map<std::string, std::string> customMap = {};
auto summary = std::make_shared<summary_t>(
"test", "help", std::vector{0.5, 0.9, 0.95, 0.99}, customMap);
summary->observe(100);
auto result = summary->get_rates();
for (auto&e: result) {
CHECK(e==100);
}
}
auto g_counter = g_pair.second;
g_counter->inc();
Expand Down

0 comments on commit 9c26069

Please sign in to comment.