Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

[metric] fix summary #777

Merged
merged 2 commits into from
Sep 20, 2024
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
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
Loading