Skip to content

Commit

Permalink
Ensure the commands are lower case when deciding whether to mirror th…
Browse files Browse the repository at this point in the history
…e request. (envoyproxy#8530)

Signed-off-by: Henry Yang <[email protected]>
  • Loading branch information
HenryYYang authored and mattklein123 committed Oct 8, 2019
1 parent 48c7c20 commit 99fcced
Show file tree
Hide file tree
Showing 3 changed files with 17 additions and 3 deletions.
5 changes: 4 additions & 1 deletion source/extensions/filters/network/redis_proxy/router_impl.cc
Original file line number Diff line number Diff line change
Expand Up @@ -21,7 +21,10 @@ bool MirrorPolicyImpl::shouldMirror(const std::string& command) const {
return false;
}

if (exclude_read_commands_ && Common::Redis::SupportedCommands::isReadCommand(command)) {
std::string to_lower_string(command);
to_lower_table_.toLowerCase(to_lower_string);

if (exclude_read_commands_ && Common::Redis::SupportedCommands::isReadCommand(to_lower_string)) {
return false;
}

Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -41,6 +41,7 @@ class MirrorPolicyImpl : public MirrorPolicy {
const bool exclude_read_commands_;
ConnPool::InstanceSharedPtr upstream_;
Runtime::Loader& runtime_;
const ToLowerTable to_lower_table_;
};

class Prefix : public Route {
Expand Down
14 changes: 12 additions & 2 deletions test/extensions/filters/network/redis_proxy/router_impl_test.cc
Original file line number Diff line number Diff line change
Expand Up @@ -199,6 +199,8 @@ TEST(MirrorPolicyImplTest, ShouldMirrorDefault) {

EXPECT_EQ(true, policy.shouldMirror("get"));
EXPECT_EQ(true, policy.shouldMirror("set"));
EXPECT_EQ(true, policy.shouldMirror("GET"));
EXPECT_EQ(true, policy.shouldMirror("SET"));
}

TEST(MirrorPolicyImplTest, MissingUpstream) {
Expand All @@ -210,6 +212,8 @@ TEST(MirrorPolicyImplTest, MissingUpstream) {

EXPECT_EQ(false, policy.shouldMirror("get"));
EXPECT_EQ(false, policy.shouldMirror("set"));
EXPECT_EQ(false, policy.shouldMirror("GET"));
EXPECT_EQ(false, policy.shouldMirror("SET"));
}

TEST(MirrorPolicyImplTest, ExcludeReadCommands) {
Expand All @@ -223,6 +227,8 @@ TEST(MirrorPolicyImplTest, ExcludeReadCommands) {

EXPECT_EQ(false, policy.shouldMirror("get"));
EXPECT_EQ(true, policy.shouldMirror("set"));
EXPECT_EQ(false, policy.shouldMirror("GET"));
EXPECT_EQ(true, policy.shouldMirror("SET"));
}

TEST(MirrorPolicyImplTest, DefaultValueZero) {
Expand Down Expand Up @@ -257,18 +263,22 @@ TEST(MirrorPolicyImplTest, DeterminedByRuntimeFraction) {
EXPECT_CALL(
runtime.snapshot_,
featureEnabled("runtime_key", Matcher<const envoy::type::FractionalPercent&>(Percent(50))))
.Times(2)
.Times(4)
.WillRepeatedly(Return(true));
EXPECT_EQ(true, policy.shouldMirror("get"));
EXPECT_EQ(true, policy.shouldMirror("set"));
EXPECT_EQ(true, policy.shouldMirror("GET"));
EXPECT_EQ(true, policy.shouldMirror("SET"));

EXPECT_CALL(
runtime.snapshot_,
featureEnabled("runtime_key", Matcher<const envoy::type::FractionalPercent&>(Percent(50))))
.Times(2)
.Times(4)
.WillRepeatedly(Return(false));
EXPECT_EQ(false, policy.shouldMirror("get"));
EXPECT_EQ(false, policy.shouldMirror("set"));
EXPECT_EQ(false, policy.shouldMirror("GET"));
EXPECT_EQ(false, policy.shouldMirror("SET"));
}

} // namespace RedisProxy
Expand Down

0 comments on commit 99fcced

Please sign in to comment.