Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Make incompatible command-line args an error #35570

Merged
merged 4 commits into from
Aug 5, 2024
Merged
Show file tree
Hide file tree
Changes from 2 commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
3 changes: 2 additions & 1 deletion docs/root/operations/cli.rst
Original file line number Diff line number Diff line change
Expand Up @@ -109,6 +109,7 @@ following are the command line options that Envoy supports.
never set this option. For example, if you want ``upstream`` component to run at ``debug`` level and
``connection`` component to run at ``trace`` level, you should pass ``upstream:debug,connection:trace`` to
this flag. See ``ALL_LOGGER_IDS`` in :repo:`/source/common/common/logger.h` for a list of components.
This option is incompatible with :option:`--enable-fine-grain-logging`.

.. option:: --cpuset-threads

Expand Down Expand Up @@ -193,7 +194,7 @@ following are the command line options that Envoy supports.
interface. If enabled, main log macros including ``ENVOY_LOG``, ``ENVOY_CONN_LOG``, ``ENVOY_STREAM_LOG`` and
``ENVOY_FLUSH_LOG`` will use a per-file logger, and the usage doesn't need ``Envoy::Logger::Loggable`` any
more. The administration interface usage is similar. Please see :ref:`Administration interface
<operations_admin_interface>` for more detail.
<operations_admin_interface>` for more detail. This option is incompatible with :option:`--component-log-level`.

.. option:: --socket-path <path string>

Expand Down
5 changes: 5 additions & 0 deletions source/server/options_impl.cc
Original file line number Diff line number Diff line change
Expand Up @@ -214,7 +214,12 @@ OptionsImpl::OptionsImpl(std::vector<std::string> args,
log_format_ = log_format.getValue();
log_format_set_ = log_format.isSet();
log_format_escaped_ = log_format_escaped.getValue();

enable_fine_grain_logging_ = enable_fine_grain_logging.getValue();
if (enable_fine_grain_logging_ && !component_log_level.getValue().empty()) {
throw MalformedArgvException(
std::string{"error: --component-log-level will not work with --enable-fine-grain-logging"});
Copy link
Member

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

nit: std::string can be removed?

}

parseComponentLogLevels(component_log_level.getValue());

Expand Down
15 changes: 13 additions & 2 deletions test/server/options_impl_test.cc
Original file line number Diff line number Diff line change
Expand Up @@ -61,6 +61,13 @@ TEST_F(OptionsImplTest, InvalidMode) {
EXPECT_THROW_WITH_REGEX(createOptionsImpl("envoy --mode bogus"), MalformedArgvException, "bogus");
}

TEST_F(OptionsImplTest, InvalidComponentLogLevelWithFineGrainLogging) {
EXPECT_THROW_WITH_REGEX(
createOptionsImpl("envoy --enable-fine-grain-logging --component-log-level http:info"),
MalformedArgvException,
"--component-log-level will not work with --enable-fine-grain-logging");
}

TEST_F(OptionsImplTest, InvalidCommandLine) {
EXPECT_THROW_WITH_REGEX(createOptionsImpl("envoy --blah"), MalformedArgvException,
"Couldn't find match for argument");
Expand Down Expand Up @@ -98,7 +105,7 @@ TEST_F(OptionsImplTest, All) {
"--file-flush-interval-msec 9000 "
"--skip-hot-restart-on-no-parent "
"--skip-hot-restart-parent-stats "
"--drain-time-s 60 --log-format [%v] --enable-fine-grain-logging --parent-shutdown-time-s 90 "
"--drain-time-s 60 --log-format [%v] --parent-shutdown-time-s 90 "
"--log-path "
"/foo/bar "
"--disable-hot-restart --cpuset-threads --allow-unknown-static-fields "
Expand All @@ -119,7 +126,7 @@ TEST_F(OptionsImplTest, All) {
EXPECT_TRUE(options->skipHotRestartParentStats());
EXPECT_TRUE(options->skipHotRestartOnNoParent());
EXPECT_EQ("/foo/bar", options->logPath());
EXPECT_EQ(true, options->enableFineGrainLogging());
EXPECT_EQ(false, options->enableFineGrainLogging());
EXPECT_EQ("cluster", options->serviceClusterName());
EXPECT_EQ("node", options->serviceNodeName());
EXPECT_EQ("zone", options->serviceZone());
Expand All @@ -139,6 +146,10 @@ TEST_F(OptionsImplTest, All) {

options = createOptionsImpl("envoy --mode init_only");
EXPECT_EQ(Server::Mode::InitOnly, options->mode());

// Tested separately because it's mutually exclusive with --component-log-level.
options = createOptionsImpl("envoy --enable-fine-grain-logging");
EXPECT_EQ(true, options->enableFineGrainLogging());
}

// Either variants of allow-unknown-[static-]-fields works.
Expand Down
Loading