[logging] Reduce line count for gRPC experiment output

pull/36150/head
Craig Tiller 1 year ago
parent bb9f4466e1
commit 04d04225fb
  1. 81
      src/core/lib/experiments/config.cc

@ -25,7 +25,7 @@
#include <utility> #include <utility>
#include "absl/functional/any_invocable.h" #include "absl/functional/any_invocable.h"
#include "absl/strings/str_cat.h" #include "absl/strings/str_join.h"
#include "absl/strings/str_split.h" #include "absl/strings/str_split.h"
#include "absl/strings/string_view.h" #include "absl/strings/string_view.h"
#include "absl/strings/strip.h" #include "absl/strings/strip.h"
@ -187,42 +187,53 @@ bool IsTestExperimentEnabled(size_t experiment_id) {
} }
void PrintExperimentsList() { void PrintExperimentsList() {
size_t max_experiment_length = 0; std::map<std::string, std::string> experiment_status;
// Populate visitation order into a std::map so that iteration results in a std::set<std::string> defaulted_on_experiments;
// lexical ordering of experiment names.
// The lexical ordering makes it nice and easy to find the experiment you're
// looking for in the output spam that we generate.
std::map<absl::string_view, size_t> visitation_order;
for (size_t i = 0; i < kNumExperiments; i++) { for (size_t i = 0; i < kNumExperiments; i++) {
max_experiment_length = const char* name = g_experiment_metadata[i].name;
std::max(max_experiment_length, strlen(g_experiment_metadata[i].name)); const bool enabled = IsExperimentEnabled(i);
visitation_order[g_experiment_metadata[i].name] = i; const bool default_enabled = g_experiment_metadata[i].default_value;
} const bool forced = g_forced_experiments[i].forced;
for (auto name_index : visitation_order) { if (!default_enabled && !enabled) continue;
const size_t i = name_index.second; if (default_enabled && enabled) {
gpr_log( defaulted_on_experiments.insert(name);
GPR_INFO, "%s", continue;
absl::StrCat( }
"gRPC EXPERIMENT ", g_experiment_metadata[i].name, if (enabled) {
std::string(max_experiment_length - if (g_check_constraints_cb != nullptr &&
strlen(g_experiment_metadata[i].name) + 1, (*g_check_constraints_cb)(g_experiment_metadata[i])) {
' '), experiment_status[name] = "on:constraints";
IsExperimentEnabled(i) ? "ON " : "OFF", continue;
" (default:", g_experiment_metadata[i].default_value ? "ON" : "OFF", }
(g_check_constraints_cb != nullptr if (forced && g_forced_experiments[i].value) {
? absl::StrCat( experiment_status[name] = "on:forced";
" + ", g_experiment_metadata[i].additional_constaints, continue;
" => ", }
(*g_check_constraints_cb)(g_experiment_metadata[i]) experiment_status[name] = "on";
? "ON " } else {
: "OFF") if (forced && !g_forced_experiments[i].value) {
: std::string()), experiment_status[name] = "off:forced";
g_forced_experiments[i].forced continue;
? absl::StrCat(" force:", }
g_forced_experiments[i].value ? "ON" : "OFF") experiment_status[name] = "off";
: std::string(), }
")") }
if (experiment_status.empty()) {
if (!defaulted_on_experiments.empty()) {
gpr_log(GPR_INFO, "gRPC experiments enabled: %s",
absl::StrJoin(defaulted_on_experiments, ", ").c_str());
}
} else {
if (defaulted_on_experiments.empty()) {
gpr_log(GPR_INFO, "gRPC experiments: %s",
absl::StrJoin(experiment_status, ", ", absl::PairFormatter(":"))
.c_str()); .c_str());
} else {
gpr_log(GPR_INFO, "gRPC experiments: %s; default-enabled: %s",
absl::StrJoin(experiment_status, ", ", absl::PairFormatter(":"))
.c_str(),
absl::StrJoin(defaulted_on_experiments, ", ").c_str());
}
} }
} }

Loading…
Cancel
Save