Skip to content
Merged
Show file tree
Hide file tree
Changes from all 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
8 changes: 8 additions & 0 deletions docs/configuration/overview/runtime.rst
Original file line number Diff line number Diff line change
Expand Up @@ -70,6 +70,14 @@ that :option:`--service-cluster` has been set to ``my-cluster``. Envoy will firs
If found, the value will override any value found in the primary lookup path. This allows the user
to customize the runtime values for individual clusters on top of global defaults.

Comments
--------

Lines starting with ``#`` as the first character are treated as comments.

Comments can be used to provide context on an existing value. Comments are also useful in an
otherwise empty file to keep a placeholder for deployment in a time of need.

Updating runtime values via symbolic link swap
----------------------------------------------

Expand Down
12 changes: 11 additions & 1 deletion source/common/runtime/runtime_impl.cc
Original file line number Diff line number Diff line change
Expand Up @@ -224,7 +224,17 @@ void SnapshotImpl::walkDirectory(const std::string& path, const std::string& pre
// theoretically lead to issues.
ENVOY_LOG(debug, "reading file: {}", full_path);
Entry entry;
entry.string_value_ = Filesystem::fileReadToEnd(full_path);

// Read the file and remove any comments. A comment is a line starting with a '#' character.
// Comments are useful for placeholder files with no value.
const std::vector<std::string> lines =
StringUtil::split(Filesystem::fileReadToEnd(full_path), "\n");
for (const std::string& line : lines) {
if (!line.empty() && line.at(0) == '#') {
continue;
}
entry.string_value_ += line + "\n";
}
StringUtil::rtrim(entry.string_value_);

// As a perf optimization, attempt to convert the string into an integer. If we don't
Expand Down
5 changes: 5 additions & 0 deletions test/common/runtime/runtime_impl_test.cc
Original file line number Diff line number Diff line change
Expand Up @@ -110,6 +110,11 @@ TEST_F(RuntimeImplTest, All) {
EXPECT_EQ(2UL, loader->snapshot().getInteger("file3", 1));
EXPECT_EQ(123UL, loader->snapshot().getInteger("file4", 1));

// Files with comments.
EXPECT_EQ(123UL, loader->snapshot().getInteger("file5", 1));
EXPECT_EQ("/home#about-us", loader->snapshot().get("file6"));
EXPECT_EQ("", loader->snapshot().get("file7"));

// Feature enablement.
EXPECT_CALL(generator, random()).WillOnce(Return(1));
EXPECT_TRUE(loader->snapshot().featureEnabled("file3", 1));
Expand Down
2 changes: 2 additions & 0 deletions test/common/runtime/test_data/root/envoy/file5
Original file line number Diff line number Diff line change
@@ -0,0 +1,2 @@
# This is a comment in a file with an integer.
123
2 changes: 2 additions & 0 deletions test/common/runtime/test_data/root/envoy/file6
Original file line number Diff line number Diff line change
@@ -0,0 +1,2 @@
# This is a comment in a file with a string.
/home#about-us
2 changes: 2 additions & 0 deletions test/common/runtime/test_data/root/envoy/file7
Original file line number Diff line number Diff line change
@@ -0,0 +1,2 @@
# This is a comment in an empty file.
# This file was intentionally left blank.