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

          Line data    Source code
       1             : #include "source/server/admin/stats_params.h"
       2             : 
       3             : namespace Envoy {
       4             : namespace Server {
       5             : 
       6           0 : Http::Code StatsParams::parse(absl::string_view url, Buffer::Instance& response) {
       7           0 :   query_ = Http::Utility::QueryParamsMulti::parseAndDecodeQueryString(url);
       8           0 :   used_only_ = query_.getFirstValue("usedonly").has_value();
       9           0 :   pretty_ = query_.getFirstValue("pretty").has_value();
      10           0 :   prometheus_text_readouts_ = query_.getFirstValue("text_readouts").has_value();
      11             : 
      12           0 :   auto filter_val = query_.getFirstValue("filter");
      13           0 :   if (filter_val.has_value() && !filter_val.value().empty()) {
      14           0 :     filter_string_ = filter_val.value();
      15           0 :     re2::RE2::Options options;
      16           0 :     options.set_log_errors(false);
      17           0 :     re2_filter_ = std::make_shared<re2::RE2>(filter_string_, options);
      18           0 :     if (!re2_filter_->ok()) {
      19           0 :       response.add("Invalid re2 regex");
      20           0 :       return Http::Code::BadRequest;
      21           0 :     }
      22           0 :   }
      23             : 
      24           0 :   absl::Status status = Utility::histogramBucketsParam(query_, histogram_buckets_mode_);
      25           0 :   if (!status.ok()) {
      26           0 :     response.add(status.message());
      27           0 :     return Http::Code::BadRequest;
      28           0 :   }
      29             : 
      30           0 :   auto parse_type = [](absl::string_view str, StatsType& type) {
      31           0 :     if (str == StatLabels::Gauges) {
      32           0 :       type = StatsType::Gauges;
      33           0 :     } else if (str == StatLabels::Counters) {
      34           0 :       type = StatsType::Counters;
      35           0 :     } else if (str == StatLabels::Histograms) {
      36           0 :       type = StatsType::Histograms;
      37           0 :     } else if (str == StatLabels::TextReadouts) {
      38           0 :       type = StatsType::TextReadouts;
      39           0 :     } else if (str == StatLabels::All) {
      40           0 :       type = StatsType::All;
      41           0 :     } else {
      42           0 :       return false;
      43           0 :     }
      44           0 :     return true;
      45           0 :   };
      46             : 
      47           0 :   auto type_val = query_.getFirstValue("type");
      48           0 :   if (type_val.has_value() && !type_val.value().empty() && !parse_type(type_val.value(), type_)) {
      49           0 :     response.add("invalid &type= param");
      50           0 :     return Http::Code::BadRequest;
      51           0 :   }
      52             : 
      53           0 :   const absl::optional<std::string> hidden_value = query_.getFirstValue("hidden");
      54           0 :   if (hidden_value.has_value() && !hidden_value.value().empty()) {
      55           0 :     if (hidden_value.value() == "include") {
      56           0 :       hidden_ = HiddenFlag::Include;
      57           0 :     } else if (hidden_value.value() == "only") {
      58           0 :       hidden_ = HiddenFlag::ShowOnly;
      59           0 :     } else if (hidden_value.value() == "exclude") {
      60           0 :       hidden_ = HiddenFlag::Exclude;
      61           0 :     } else {
      62           0 :       response.add("usage: /stats?hidden=(include|only|exclude)\n\n");
      63           0 :       return Http::Code::BadRequest;
      64           0 :     }
      65           0 :   }
      66             : 
      67           0 :   const absl::optional<std::string> format_value = Utility::formatParam(query_);
      68           0 :   if (format_value.has_value() && !format_value.value().empty()) {
      69           0 :     if (format_value.value() == "prometheus") {
      70           0 :       format_ = StatsFormat::Prometheus;
      71           0 :     } else if (format_value.value() == "json") {
      72           0 :       format_ = StatsFormat::Json;
      73           0 :     } else if (format_value.value() == "text") {
      74           0 :       format_ = StatsFormat::Text;
      75           0 :     } else if (format_value.value() == "html") {
      76           0 : #ifdef ENVOY_ADMIN_HTML
      77           0 :       format_ = StatsFormat::Html;
      78             : #else
      79             :       response.add("HTML output was disabled by building with --define=admin_html=disabled");
      80             :       return Http::Code::BadRequest;
      81             : #endif
      82           0 :     } else if (format_value.value() == "active-html") {
      83           0 : #ifdef ENVOY_ADMIN_HTML
      84           0 :       format_ = StatsFormat::ActiveHtml;
      85             : #else
      86             :       response.add("Active HTML output was disabled by building with --define=admin_html=disabled");
      87             :       return Http::Code::BadRequest;
      88             : #endif
      89           0 :     } else {
      90           0 :       response.add("usage: /stats?format=(html|active-html|json|prometheus|text)\n\n");
      91           0 :       return Http::Code::BadRequest;
      92           0 :     }
      93           0 :   }
      94             : 
      95           0 :   return Http::Code::OK;
      96           0 : }
      97             : 
      98           0 : absl::string_view StatsParams::typeToString(StatsType type) {
      99           0 :   absl::string_view ret;
     100           0 :   switch (type) {
     101           0 :   case StatsType::TextReadouts:
     102           0 :     ret = StatLabels::TextReadouts;
     103           0 :     break;
     104           0 :   case StatsType::Counters:
     105           0 :     ret = StatLabels::Counters;
     106           0 :     break;
     107           0 :   case StatsType::Gauges:
     108           0 :     ret = StatLabels::Gauges;
     109           0 :     break;
     110           0 :   case StatsType::Histograms:
     111           0 :     ret = StatLabels::Histograms;
     112           0 :     break;
     113           0 :   case StatsType::All:
     114           0 :     ret = StatLabels::All;
     115           0 :     break;
     116           0 :   }
     117           0 :   return ret;
     118           0 : }
     119             : 
     120             : } // namespace Server
     121             : } // namespace Envoy

Generated by: LCOV version 1.15