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

Redis mirroring should work when default value is zero, not just greater than zero #8089

Merged
merged 6 commits into from
Sep 11, 2019
Prev Previous commit
use ternary operator with nullopt as fallback
Signed-off-by: Nicolas Flacco <[email protected]>
  • Loading branch information
commit 5f4b164e9e6a73cec6d8844a835300ab7dbbc71a
9 changes: 5 additions & 4 deletions source/extensions/filters/network/redis_proxy/router_impl.cc
Original file line number Diff line number Diff line change
Expand Up @@ -10,8 +10,9 @@ MirrorPolicyImpl::MirrorPolicyImpl(const envoy::config::filter::network::redis_p
const ConnPool::InstanceSharedPtr upstream,
Runtime::Loader& runtime)
: runtime_key_(config.runtime_fraction().runtime_key()),
has_runtime_fraction_(config.has_runtime_fraction()),
default_value_(config.runtime_fraction().default_value()),
default_value_(config.has_runtime_fraction() ? absl::optional<envoy::type::FractionalPercent>(
config.runtime_fraction().default_value())
: absl::nullopt),
exclude_read_commands_(config.exclude_read_commands()), upstream_(upstream),
runtime_(runtime) {}

Expand All @@ -24,8 +25,8 @@ bool MirrorPolicyImpl::shouldMirror(const std::string& command) const {
return false;
}

if (has_runtime_fraction_) {
return runtime_.snapshot().featureEnabled(runtime_key_, default_value_);
if (default_value_.has_value()) {
return runtime_.snapshot().featureEnabled(runtime_key_, default_value_.value());
}

return true;
Expand Down
3 changes: 1 addition & 2 deletions source/extensions/filters/network/redis_proxy/router_impl.h
Original file line number Diff line number Diff line change
Expand Up @@ -37,8 +37,7 @@ class MirrorPolicyImpl : public MirrorPolicy {

private:
const std::string runtime_key_;
const bool has_runtime_fraction_;
const envoy::type::FractionalPercent default_value_;
const absl::optional<envoy::type::FractionalPercent> default_value_;
const bool exclude_read_commands_;
ConnPool::InstanceSharedPtr upstream_;
Runtime::Loader& runtime_;
Expand Down