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
18 changes: 16 additions & 2 deletions source/common/runtime/BUILD
Original file line number Diff line number Diff line change
Expand Up @@ -9,17 +9,31 @@ load(
envoy_package()

envoy_cc_library(
name = "runtime_lib",
name = "runtime_features_lib",
srcs = [
"runtime_features.cc",
"runtime_impl.cc",
],
hdrs = [
"runtime_features.h",
],
deps = [
"//source/common/common:hash_lib",
"//source/common/singleton:const_singleton",
],
)

envoy_cc_library(
name = "runtime_lib",
srcs = [
"runtime_impl.cc",
],
hdrs = [
"runtime_impl.h",
"runtime_protos.h",
],
external_deps = ["ssl"],
deps = [
":runtime_features_lib",
"//include/envoy/config:subscription_interface",
"//include/envoy/event:dispatcher_interface",
"//include/envoy/init:manager_interface",
Expand Down
39 changes: 0 additions & 39 deletions source/common/runtime/runtime_features.h
Original file line number Diff line number Diff line change
Expand Up @@ -2,11 +2,6 @@

#include <string>

#include "envoy/config/core/v3alpha/base.pb.h"
#include "envoy/runtime/runtime.h"
#include "envoy/type/v3alpha/percent.pb.h"

#include "common/protobuf/utility.h"
#include "common/singleton/const_singleton.h"

#include "absl/container/flat_hash_set.h"
Expand Down Expand Up @@ -44,39 +39,5 @@ class RuntimeFeatures {

using RuntimeFeaturesDefaults = ConstSingleton<RuntimeFeatures>;

// Helper class for runtime-derived boolean feature flags.
class FeatureFlag {
public:
FeatureFlag(const envoy::config::core::v3alpha::RuntimeFeatureFlag& feature_flag_proto,
Runtime::Loader& runtime)
: runtime_key_(feature_flag_proto.runtime_key()),
default_value_(PROTOBUF_GET_WRAPPED_OR_DEFAULT(feature_flag_proto, default_value, true)),
runtime_(runtime) {}

bool enabled() const { return runtime_.snapshot().getBoolean(runtime_key_, default_value_); }

private:
const std::string runtime_key_;
const bool default_value_;
Runtime::Loader& runtime_;
};

// Helper class for runtime-derived fractional percent flags.
class FractionalPercent {
public:
FractionalPercent(
const envoy::config::core::v3alpha::RuntimeFractionalPercent& fractional_percent_proto,
Runtime::Loader& runtime)
: runtime_key_(fractional_percent_proto.runtime_key()),
default_value_(fractional_percent_proto.default_value()), runtime_(runtime) {}

bool enabled() const { return runtime_.snapshot().featureEnabled(runtime_key_, default_value_); }

private:
const std::string runtime_key_;
const envoy::type::v3alpha::FractionalPercent default_value_;
Runtime::Loader& runtime_;
};

} // namespace Runtime
} // namespace Envoy
49 changes: 49 additions & 0 deletions source/common/runtime/runtime_protos.h
Original file line number Diff line number Diff line change
@@ -0,0 +1,49 @@
#pragma once

#include <string>

#include "envoy/config/core/v3alpha/base.pb.h"
#include "envoy/runtime/runtime.h"
#include "envoy/type/v3alpha/percent.pb.h"

#include "common/protobuf/utility.h"

namespace Envoy {
namespace Runtime {

// Helper class for runtime-derived boolean feature flags.
class FeatureFlag {
public:
FeatureFlag(const envoy::config::core::v3alpha::RuntimeFeatureFlag& feature_flag_proto,
Runtime::Loader& runtime)
: runtime_key_(feature_flag_proto.runtime_key()),
default_value_(PROTOBUF_GET_WRAPPED_OR_DEFAULT(feature_flag_proto, default_value, true)),
runtime_(runtime) {}

bool enabled() const { return runtime_.snapshot().getBoolean(runtime_key_, default_value_); }

private:
const std::string runtime_key_;
const bool default_value_;
Runtime::Loader& runtime_;
};

// Helper class for runtime-derived fractional percent flags.
class FractionalPercent {
public:
FractionalPercent(
const envoy::config::core::v3alpha::RuntimeFractionalPercent& fractional_percent_proto,
Runtime::Loader& runtime)
: runtime_key_(fractional_percent_proto.runtime_key()),
default_value_(fractional_percent_proto.default_value()), runtime_(runtime) {}

bool enabled() const { return runtime_.snapshot().featureEnabled(runtime_key_, default_value_); }

private:
const std::string runtime_key_;
const envoy::type::v3alpha::FractionalPercent default_value_;
Runtime::Loader& runtime_;
};

} // namespace Runtime
} // namespace Envoy
Original file line number Diff line number Diff line change
Expand Up @@ -12,7 +12,7 @@
#include "envoy/stats/stats_macros.h"

#include "common/common/cleanup.h"
#include "common/runtime/runtime_features.h"
#include "common/runtime/runtime_protos.h"

#include "extensions/filters/http/adaptive_concurrency/concurrency_controller/concurrency_controller.h"
#include "extensions/filters/http/common/pass_through_filter.h"
Expand Down
2 changes: 1 addition & 1 deletion source/extensions/filters/http/ext_authz/ext_authz.h
Original file line number Diff line number Diff line change
Expand Up @@ -19,7 +19,7 @@
#include "common/common/matchers.h"
#include "common/http/codes.h"
#include "common/http/header_map_impl.h"
#include "common/runtime/runtime_features.h"
#include "common/runtime/runtime_protos.h"

#include "extensions/filters/common/ext_authz/ext_authz.h"
#include "extensions/filters/common/ext_authz/ext_authz_grpc_impl.h"
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -7,7 +7,7 @@
#include "envoy/stats/stats_macros.h"

#include "common/common/thread_synchronizer.h"
#include "common/runtime/runtime_features.h"
#include "common/runtime/runtime_protos.h"

namespace Envoy {
namespace Extensions {
Expand Down
4 changes: 2 additions & 2 deletions test/common/runtime/BUILD
Original file line number Diff line number Diff line change
Expand Up @@ -27,8 +27,8 @@ envoy_cc_test_library(
)

envoy_cc_test(
name = "runtime_features_test",
srcs = ["runtime_features_test.cc"],
name = "runtime_protos_test",
srcs = ["runtime_protos_test.cc"],
deps = [
"//source/common/runtime:runtime_lib",
"//test/mocks/runtime:runtime_mocks",
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -4,7 +4,7 @@
#include "envoy/config/core/v3alpha/base.pb.validate.h"
#include "envoy/type/v3alpha/percent.pb.h"

#include "common/runtime/runtime_features.h"
#include "common/runtime/runtime_protos.h"

#include "test/mocks/runtime/mocks.h"
#include "test/test_common/utility.h"
Expand Down