[metric] fix summary (#777)

* [metric] fix summary

* fix format
This commit is contained in:
saipubw 2024-09-20 12:53:10 +08:00 committed by GitHub
parent 8b6b947f9c
commit 39ea3e8db0
No known key found for this signature in database
GPG Key ID: B5690EEEBB952194
2 changed files with 9 additions and 8 deletions

View File

@ -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>
@ -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);

View File

@ -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();