LCOV - code coverage report
Current view: top level - source/server/admin - stats_params.h (source / functions) Hit Total Coverage
Test: coverage.dat Lines: 0 21 0.0 %
Date: 2024-01-05 06:35:25 Functions: 0 13 0.0 %

          Line data    Source code
       1             : #pragma once
       2             : 
       3             : #include <memory>
       4             : #include <string>
       5             : 
       6             : #include "envoy/buffer/buffer.h"
       7             : #include "envoy/http/codes.h"
       8             : 
       9             : #include "source/server/admin/utils.h"
      10             : 
      11             : #include "re2/re2.h"
      12             : 
      13             : namespace Envoy {
      14             : namespace Server {
      15             : 
      16             : namespace StatLabels {
      17             : constexpr absl::string_view All = "All";
      18             : constexpr absl::string_view Counters = "Counters";
      19             : constexpr absl::string_view Gauges = "Gauges";
      20             : constexpr absl::string_view Histograms = "Histograms";
      21             : constexpr absl::string_view TextReadouts = "TextReadouts";
      22             : } // namespace StatLabels
      23             : 
      24             : enum class StatsFormat {
      25             : #ifdef ENVOY_ADMIN_HTML
      26             :   Html,
      27             :   ActiveHtml,
      28             : #endif
      29             :   Json,
      30             :   Prometheus,
      31             :   Text,
      32             : };
      33             : 
      34             : // The order is used to linearize the ordering of stats of all types.
      35             : enum class StatsType {
      36             :   TextReadouts,
      37             :   Counters,
      38             :   Gauges,
      39             :   Histograms,
      40             :   All,
      41             : };
      42             : 
      43             : enum class HiddenFlag {
      44             :   Include,  // Will include hidden stats along side non-hidden stats
      45             :   ShowOnly, // Will only show hidden stats and exclude hidden stats
      46             :   Exclude,  // Default behavior. Will exclude all hidden stats
      47             : };
      48             : 
      49             : struct StatsParams {
      50             :   /**
      51             :    * Parses the URL's query parameter, populating this.
      52             :    *
      53             :    * @param url the URL from which to parse the query params.
      54             :    * @param response used to write error messages, if necessary.
      55             :    */
      56             :   Http::Code parse(absl::string_view url, Buffer::Instance& response);
      57             : 
      58             :   /**
      59             :    * @return a string representation for a type.
      60             :    */
      61             :   static absl::string_view typeToString(StatsType type);
      62             : 
      63             :   StatsType type_{StatsType::All};
      64             :   bool used_only_{false};
      65             :   bool prometheus_text_readouts_{false};
      66             :   bool pretty_{false};
      67             :   StatsFormat format_{StatsFormat::Text};
      68             :   HiddenFlag hidden_{HiddenFlag::Exclude};
      69             :   std::string filter_string_;
      70             :   std::shared_ptr<re2::RE2> re2_filter_;
      71             :   Utility::HistogramBucketsMode histogram_buckets_mode_{Utility::HistogramBucketsMode::NoBuckets};
      72             :   Http::Utility::QueryParamsMulti query_;
      73             : 
      74             :   /**
      75             :    * Determines whether a metric should be shown based on the specified query-parameters. This
      76             :    * covers:
      77             :    * ``usedonly``, hidden, and filter.
      78             :    *
      79             :    * @param metric the metric to test
      80             :    * @param name_out if non-null, and the return value is true,
      81             :    *   will contain the metric name. This improves performance because computing the name is
      82             :    *   somewhat expensive, and in some cases it isn't needed.
      83             :    */
      84           0 :   template <class StatType> bool shouldShowMetric(const StatType& metric) const {
      85           0 :     if (!shouldShowMetricWithoutFilter(metric)) {
      86           0 :       return false;
      87           0 :     }
      88             : 
      89           0 :     if (re2_filter_ != nullptr && !re2::RE2::PartialMatch(metric.name(), *re2_filter_)) {
      90           0 :       return false;
      91           0 :     }
      92             : 
      93           0 :     return true;
      94           0 :   }
      95             : 
      96           0 :   template <class StatType> bool shouldShowMetricWithoutFilter(const StatType& metric) const {
      97           0 :     if (used_only_ && !metric.used()) {
      98           0 :       return false;
      99           0 :     }
     100           0 :     if (hidden_ == HiddenFlag::ShowOnly && !metric.hidden()) {
     101           0 :       return false;
     102           0 :     }
     103           0 :     if (hidden_ == HiddenFlag::Exclude && metric.hidden()) {
     104           0 :       return false;
     105           0 :     }
     106             : 
     107           0 :     return true;
     108           0 :   }
     109             : };
     110             : 
     111             : } // namespace Server
     112             : } // namespace Envoy

Generated by: LCOV version 1.15