@@ -419,6 +419,10 @@ class Quantile final : public Metric
419419
420420 void to_prometheus (std::stringstream &out, Metric::LabelMap add_labels = {}) const override
421421 {
422+ if (_quantile.is_empty ()) {
423+ return ;
424+ }
425+
422426 std::vector<T> quantiles;
423427 if (_quantiles_sum.empty ()) {
424428 const double fractions[4 ]{0.50 , 0.90 , 0.95 , 0.99 };
@@ -614,8 +618,11 @@ class TopN final : public Metric
614618
615619 void to_prometheus (std::stringstream &out, Metric::LabelMap add_labels, std::function<std::string(const T &)> formatter) const
616620 {
617- LabelMap l (add_labels);
618621 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);
619626 auto threshold = _get_threshold (items);
620627 out << " # HELP " << base_name_snake () << ' ' << _desc << std::endl;
621628 out << " # TYPE " << base_name_snake () << " gauge" << std::endl;
@@ -631,8 +638,11 @@ class TopN final : public Metric
631638
632639 void to_prometheus (std::stringstream &out, Metric::LabelMap add_labels, std::function<void (LabelMap &, const std::string &, const T &)> formatter) const
633640 {
634- LabelMap l (add_labels);
635641 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);
636646 auto threshold = _get_threshold (items);
637647 out << " # HELP " << base_name_snake () << ' ' << _desc << std::endl;
638648 out << " # TYPE " << base_name_snake () << " gauge" << std::endl;
@@ -665,8 +675,11 @@ class TopN final : public Metric
665675
666676 void to_prometheus (std::stringstream &out, Metric::LabelMap add_labels = {}) const override
667677 {
668- LabelMap l (add_labels);
669678 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);
670683 auto threshold = _get_threshold (items);
671684 out << " # HELP " << base_name_snake () << ' ' << _desc << std::endl;
672685 out << " # TYPE " << base_name_snake () << " gauge" << std::endl;
0 commit comments