@@ -419,6 +419,10 @@ class Quantile final : public Metric
419
419
420
420
void to_prometheus (std::stringstream &out, Metric::LabelMap add_labels = {}) const override
421
421
{
422
+ if (_quantile.is_empty ()) {
423
+ return ;
424
+ }
425
+
422
426
std::vector<T> quantiles;
423
427
if (_quantiles_sum.empty ()) {
424
428
const double fractions[4 ]{0.50 , 0.90 , 0.95 , 0.99 };
@@ -614,8 +618,11 @@ class TopN final : public Metric
614
618
615
619
void to_prometheus (std::stringstream &out, Metric::LabelMap add_labels, std::function<std::string(const T &)> formatter) const
616
620
{
617
- LabelMap l (add_labels);
618
621
auto items = _fi.get_frequent_items (datasketches::frequent_items_error_type::NO_FALSE_NEGATIVES);
622
+ if (!std::min (_top_count, items.size ())) {
623
+ return ;
624
+ }
625
+ LabelMap l (add_labels);
619
626
auto threshold = _get_threshold (items);
620
627
out << " # HELP " << base_name_snake () << ' ' << _desc << std::endl;
621
628
out << " # TYPE " << base_name_snake () << " gauge" << std::endl;
@@ -631,8 +638,11 @@ class TopN final : public Metric
631
638
632
639
void to_prometheus (std::stringstream &out, Metric::LabelMap add_labels, std::function<void (LabelMap &, const std::string &, const T &)> formatter) const
633
640
{
634
- LabelMap l (add_labels);
635
641
auto items = _fi.get_frequent_items (datasketches::frequent_items_error_type::NO_FALSE_NEGATIVES);
642
+ if (!std::min (_top_count, items.size ())) {
643
+ return ;
644
+ }
645
+ LabelMap l (add_labels);
636
646
auto threshold = _get_threshold (items);
637
647
out << " # HELP " << base_name_snake () << ' ' << _desc << std::endl;
638
648
out << " # TYPE " << base_name_snake () << " gauge" << std::endl;
@@ -665,8 +675,11 @@ class TopN final : public Metric
665
675
666
676
void to_prometheus (std::stringstream &out, Metric::LabelMap add_labels = {}) const override
667
677
{
668
- LabelMap l (add_labels);
669
678
auto items = _fi.get_frequent_items (datasketches::frequent_items_error_type::NO_FALSE_NEGATIVES);
679
+ if (!std::min (_top_count, items.size ())) {
680
+ return ;
681
+ }
682
+ LabelMap l (add_labels);
670
683
auto threshold = _get_threshold (items);
671
684
out << " # HELP " << base_name_snake () << ' ' << _desc << std::endl;
672
685
out << " # TYPE " << base_name_snake () << " gauge" << std::endl;
0 commit comments