LCOV - code coverage report
Current view: top level - source/server - utils.cc (source / functions) Hit Total Coverage
Test: coverage.dat Lines: 24 36 66.7 %
Date: 2024-01-05 06:35:25 Functions: 3 3 100.0 %

          Line data    Source code
       1             : #include "source/server/utils.h"
       2             : 
       3             : #include "envoy/common/exception.h"
       4             : 
       5             : #include "source/common/common/assert.h"
       6             : 
       7             : namespace Envoy {
       8             : namespace Server {
       9             : namespace Utility {
      10             : 
      11             : envoy::admin::v3::ServerInfo::State serverState(Init::Manager::State state,
      12         205 :                                                 bool health_check_failed) {
      13         205 :   switch (state) {
      14          13 :   case Init::Manager::State::Uninitialized:
      15          13 :     return envoy::admin::v3::ServerInfo::PRE_INITIALIZING;
      16           4 :   case Init::Manager::State::Initializing:
      17           4 :     return envoy::admin::v3::ServerInfo::INITIALIZING;
      18         188 :   case Init::Manager::State::Initialized:
      19         188 :     return health_check_failed ? envoy::admin::v3::ServerInfo::DRAINING
      20         188 :                                : envoy::admin::v3::ServerInfo::LIVE;
      21         205 :   }
      22           0 :   IS_ENVOY_BUG("unexpected server state enum");
      23           0 :   return envoy::admin::v3::ServerInfo::PRE_INITIALIZING;
      24         205 : }
      25             : 
      26             : absl::Status assertExclusiveLogFormatMethod(
      27             :     const Options& options,
      28           6 :     const envoy::config::bootstrap::v3::Bootstrap::ApplicationLogConfig& application_log_config) {
      29           6 :   if (options.logFormatSet() && application_log_config.has_log_format()) {
      30           0 :     return absl::InvalidArgumentError(
      31           0 :         "Only one of ApplicationLogConfig.log_format or CLI option --log-format can be specified.");
      32           0 :   }
      33           6 :   return absl::OkStatus();
      34           6 : }
      35             : 
      36             : absl::Status maybeSetApplicationLogFormat(
      37           6 :     const envoy::config::bootstrap::v3::Bootstrap::ApplicationLogConfig& application_log_config) {
      38           6 :   if (!application_log_config.has_log_format()) {
      39           5 :     return absl::OkStatus();
      40           5 :   }
      41             : 
      42           1 :   if (application_log_config.log_format().has_text_format()) {
      43           1 :     Logger::Registry::setLogFormat(application_log_config.log_format().text_format());
      44           1 :   } else if (application_log_config.log_format().has_json_format()) {
      45           0 :     const auto status =
      46           0 :         Logger::Registry::setJsonLogFormat(application_log_config.log_format().json_format());
      47             : 
      48           0 :     if (!status.ok()) {
      49           0 :       return absl::InvalidArgumentError(
      50           0 :           fmt::format("setJsonLogFormat error: {}", status.ToString()));
      51           0 :     }
      52           0 :   }
      53           1 :   return absl::OkStatus();
      54           1 : }
      55             : 
      56             : } // namespace Utility
      57             : } // namespace Server
      58             : } // namespace Envoy

Generated by: LCOV version 1.15