From e7a7e8bbf5aa2cb706f2f7eeb85fd91b33701e30 Mon Sep 17 00:00:00 2001 From: alyssawilk Date: Tue, 7 Jan 2020 09:34:37 -0500 Subject: [PATCH] runtime: splitting classes into two files (#9576) Risk Level: n/a (just moving code) Testing: n/a Docs Changes: n/a Release Notes: n/a Signed-off-by: Alyssa Wilk --- source/common/runtime/BUILD | 18 ++++++- source/common/runtime/runtime_features.h | 39 --------------- source/common/runtime/runtime_protos.h | 49 +++++++++++++++++++ .../adaptive_concurrency_filter.h | 2 +- .../filters/http/ext_authz/ext_authz.h | 2 +- .../network/local_ratelimit/local_ratelimit.h | 2 +- test/common/runtime/BUILD | 4 +- ...eatures_test.cc => runtime_protos_test.cc} | 2 +- 8 files changed, 71 insertions(+), 47 deletions(-) create mode 100644 source/common/runtime/runtime_protos.h rename test/common/runtime/{runtime_features_test.cc => runtime_protos_test.cc} (98%) diff --git a/source/common/runtime/BUILD b/source/common/runtime/BUILD index 0e5c67750cf5..bdd0a6412ad6 100644 --- a/source/common/runtime/BUILD +++ b/source/common/runtime/BUILD @@ -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", diff --git a/source/common/runtime/runtime_features.h b/source/common/runtime/runtime_features.h index cd3663609755..56ffb73f4d91 100644 --- a/source/common/runtime/runtime_features.h +++ b/source/common/runtime/runtime_features.h @@ -2,11 +2,6 @@ #include -#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" @@ -44,39 +39,5 @@ class RuntimeFeatures { using RuntimeFeaturesDefaults = ConstSingleton; -// 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 diff --git a/source/common/runtime/runtime_protos.h b/source/common/runtime/runtime_protos.h new file mode 100644 index 000000000000..c45b4a1236e0 --- /dev/null +++ b/source/common/runtime/runtime_protos.h @@ -0,0 +1,49 @@ +#pragma once + +#include + +#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 diff --git a/source/extensions/filters/http/adaptive_concurrency/adaptive_concurrency_filter.h b/source/extensions/filters/http/adaptive_concurrency/adaptive_concurrency_filter.h index 043fb2844316..ed92e189810a 100644 --- a/source/extensions/filters/http/adaptive_concurrency/adaptive_concurrency_filter.h +++ b/source/extensions/filters/http/adaptive_concurrency/adaptive_concurrency_filter.h @@ -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" diff --git a/source/extensions/filters/http/ext_authz/ext_authz.h b/source/extensions/filters/http/ext_authz/ext_authz.h index a51252a800fc..70ea196828cd 100644 --- a/source/extensions/filters/http/ext_authz/ext_authz.h +++ b/source/extensions/filters/http/ext_authz/ext_authz.h @@ -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" diff --git a/source/extensions/filters/network/local_ratelimit/local_ratelimit.h b/source/extensions/filters/network/local_ratelimit/local_ratelimit.h index 8cc66a64ae85..c83cad35e933 100644 --- a/source/extensions/filters/network/local_ratelimit/local_ratelimit.h +++ b/source/extensions/filters/network/local_ratelimit/local_ratelimit.h @@ -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 { diff --git a/test/common/runtime/BUILD b/test/common/runtime/BUILD index 3820a728a1ed..2eca7a1c6d59 100644 --- a/test/common/runtime/BUILD +++ b/test/common/runtime/BUILD @@ -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", diff --git a/test/common/runtime/runtime_features_test.cc b/test/common/runtime/runtime_protos_test.cc similarity index 98% rename from test/common/runtime/runtime_features_test.cc rename to test/common/runtime/runtime_protos_test.cc index fc8d61e16043..20ccdea17ef9 100644 --- a/test/common/runtime/runtime_features_test.cc +++ b/test/common/runtime/runtime_protos_test.cc @@ -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"