server: add --fine-grain-log-levels CLI argument for startup log verbosity#44067
server: add --fine-grain-log-levels CLI argument for startup log verbosity#44067Retr0-XD wants to merge 1 commit intoenvoyproxy:mainfrom
Conversation
|
Hi @Retr0-XD, welcome and thank you for your contribution. We will try to review your Pull Request as quickly as possible. In the meantime, please take a look at the contribution guidelines if you have not done so already. |
|
CC @envoyproxy/api-shepherds: Your approval is needed for changes made to |
|
@Retr0-XD Please fix the DCO. /wait |
Added DCO |
8ff12d4 to
20992b5
Compare
|
Assigning @botengyao as code-owner |
|
@botengyao please review this PR :) |
|
/gemini review |
There was a problem hiding this comment.
Code Review
This pull request introduces a new command-line option, --fine-grain-log-levels, to enable file-level logging verbosity configuration. This feature allows users to specify log levels for specific file patterns, building upon the existing --enable-fine-grain-logging functionality. The changes include updating the CommandLineOptions proto, extending the Options interface, implementing argument parsing and validation in options_impl.cc, and applying these settings to the FineGrainLogContext. Feedback from the review suggests improving the Doxygen comment for the new fineGrainLogLevels method for clarity and optimizing the parseFineGrainLogLevels function by utilizing absl::string_view to enhance memory efficiency.
| * @return const std::vector<std::pair<std::string, spdlog::level::level_enum>>& pair of | ||
| * glob-pattern,log-level for all configured fine-grain log overrides. |
There was a problem hiding this comment.
The Doxygen comment for @return is a bit confusing as it includes the return type, and the description is awkwardly phrased across two lines. For better clarity and adherence to common Doxygen style, consider rephrasing it to focus only on the description of the returned value on a single line.
* @return A vector of (glob-pattern, log-level) pairs for fine-grain log overrides.There was a problem hiding this comment.
kind of leaning towards this AI comment ;-)
| std::vector<std::string> log_levels = absl::StrSplit(fine_grain_log_levels, ','); | ||
| for (auto& level : log_levels) { | ||
| std::vector<std::string> glob_level = absl::StrSplit(level, absl::MaxSplits(':', 1)); | ||
| if (glob_level.size() != 2) { | ||
| logError( | ||
| fmt::format("error: fine-grain log level not correctly specified '{}'", level)); | ||
| } | ||
| const std::string glob = glob_level[0]; | ||
| auto status_or_error = parseAndValidateLogLevel(glob_level[1]); | ||
| if (!status_or_error.status().ok()) { | ||
| logError(std::string(status_or_error.status().message())); | ||
| } | ||
| fine_grain_log_levels_.push_back(std::make_pair(glob, status_or_error.value())); | ||
| } |
There was a problem hiding this comment.
This function can be made more efficient by using absl::string_view to avoid intermediate string allocations when splitting the input string. absl::StrSplit can produce a vector of string_views which refer to slices of the original input string, which is more memory-efficient than creating new strings for each split part.
std::vector<absl::string_view> log_levels = absl::StrSplit(fine_grain_log_levels, ',');
for (absl::string_view level : log_levels) {
std::vector<absl::string_view> glob_level = absl::StrSplit(level, absl::MaxSplits(':', 1));
if (glob_level.size() != 2) {
logError(
fmt::format("error: fine-grain log level not correctly specified '{}'", level));
}
const std::string glob(glob_level[0]);
auto status_or_error = parseAndValidateLogLevel(glob_level[1]);
if (!status_or_error.status().ok()) {
logError(std::string(status_or_error.status().message()));
}
fine_grain_log_levels_.emplace_back(glob, status_or_error.value());
}0e1625c to
02f5844
Compare
botengyao
left a comment
There was a problem hiding this comment.
sorry for the delay, and thanks for the great contribution. Could you pls also add a changelog at changelogs/current.yaml?
/wait
| @@ -722,6 +722,8 @@ def check_source_line(self, line, file_path, report_error): | |||
| report_error("Don't use 'using testing::Test;, elaborate the type instead") | |||
| if line.startswith("using testing::TestWithParams;"): | |||
| report_error("Don't use 'using testing::Test;, elaborate the type instead") | |||
| if re.match(r"^\s*using\s+\w+\s*=\s*[^;]*\*[^;]*;", line) and "(" not in line: | |||
| report_error("Don't type alias raw pointers") | |||
| if "[[fallthrough]];" in line: | |||
| report_error("Use 'FALLTHRU;' instead like the other parts of the code") | |||
| if self.config.re["test_name_starting_lc"].search(line): | |||
| @@ -722,6 +722,8 @@ def check_source_line(self, line, file_path, report_error): | |||
| report_error("Don't use 'using testing::Test;, elaborate the type instead") | |||
| if line.startswith("using testing::TestWithParams;"): | |||
| report_error("Don't use 'using testing::Test;, elaborate the type instead") | |||
| if re.match(r"^\s*using\s+\w+\s*=\s*[^;]*\*[^;]*;", line) and "(" not in line: | |||
There was a problem hiding this comment.
could you remind me why the check format is added here?
| if (!status_or_error.status().ok()) { | ||
| logError(std::string(status_or_error.status().message())); | ||
| } | ||
| fine_grain_log_levels_.push_back(std::make_pair(glob, status_or_error.value())); |
There was a problem hiding this comment.
prefer avoiding the std::make_pair temp construct, and it can be fine_grain_log_levels_.emplace_back(glob, level)
|
Will update the PR based on the comments and will share the changelog |
|
could you fix DCO please? |
5fb40c3 to
6c4dadf
Compare
|
fixed |
|
please don't force push, since don't know what is the change since last review. |
|
looks like the comments are not addressed. /wait |
44a8431 to
5f8518b
Compare
Adds a new CLI flag --fine-grain-log-levels that allows per-file log verbosity control when fine-grain logging is enabled. Accepts a comma-separated list of glob-pattern:log-level pairs. Requires --enable-fine-grain-logging to be set. Signed-off-by: Retr0-XD <sakthi.harish@edgeverve.com>
d4507d8 to
cd4c5d5
Compare
|
Apologies for force push , I'm facing restriction from my organization device. Please let me know once reviewed :) |
botengyao
left a comment
There was a problem hiding this comment.
lgtm, thanks module the gemini comments.
/wait
| * @return const std::vector<std::pair<std::string, spdlog::level::level_enum>>& pair of | ||
| * glob-pattern,log-level for all configured fine-grain log overrides. |
There was a problem hiding this comment.
kind of leaning towards this AI comment ;-)
| std::vector<std::string> log_levels = absl::StrSplit(fine_grain_log_levels, ','); | ||
| for (auto& level : log_levels) { | ||
| std::vector<std::string> glob_level = absl::StrSplit(level, absl::MaxSplits(':', 1)); | ||
| if (glob_level.size() != 2) { | ||
| logError( | ||
| fmt::format("error: fine-grain log level not correctly specified '{}'", level)); | ||
| } | ||
| const std::string glob = glob_level[0]; | ||
| auto status_or_error = parseAndValidateLogLevel(glob_level[1]); | ||
| if (!status_or_error.status().ok()) { | ||
| logError(std::string(status_or_error.status().message())); | ||
| } | ||
| fine_grain_log_levels_.push_back(std::make_pair(glob, status_or_error.value())); | ||
| } |
Description
Closes #41028
Currently, fine-grain logging (per-source-file log level control) can only be configured at runtime via the admin API. This is inconvenient for containerized deployments (e.g. Kubernetes) where users want file-level log verbosity from startup without admin access.
This PR adds
--fine-grain-log-levelsas a startup CLI argument that accepts a comma-separated list ofglob:levelpairs, mirroring the format already supported by the admin/logging?paths=…endpoint.Example usage
envoy --enable-fine-grain-logging \ --fine-grain-log-levels "*filter*:debug,source/common/common/*:trace"Glob patterns follow the existing
FineGrainLogContext::safeFileNameMatchsemantics:/are matched against the base filename only./are matched against the full source path.Changes
envoy/server/options.hfineGrainLogLevels()PURE virtual methodsource/server/options_impl_base.hfine_grain_log_levels_member + accessorsource/server/options_impl.cc--fine-grain-log-levelsTCLAP arg +parseFineGrainLogLevels()source/server/options_impl.hparseFineGrainLogLevels()source/exe/main_common.ccgetFineGrainLogContext().updateVerbositySetting()at startupapi/envoy/admin/v3/server_info.protofine_grain_log_levelsfield (field 43)test/mocks/server/options.hfineGrainLogLevels()test/server/options_impl_test.ccRisk
Low. The flag is completely opt-in — it is a no-op unless
--enable-fine-grain-loggingis also set, and it calls the sameupdateVerbositySettingAPI already used by the admin endpoint.AI disclosure: GitHub Copilot was used during implementation and test writing. I fully understand all changes made in this PR.
Commit Message: See PR title
Risk Level: Low
Testing: Unit tests added/verified
Docs Changes: N/A
Release Notes: N/A
Platform Specific Features: N/A