12
12
13
13
#include " source/common/common/matchers.h"
14
14
#include " source/common/protobuf/utility.h"
15
+ #include " source/common/runtime/runtime_features.h"
15
16
16
17
#include " absl/container/node_hash_map.h"
17
18
#include " absl/container/node_hash_set.h"
@@ -34,12 +35,43 @@ class RouteConfigProviderManager {
34
35
35
36
RouteConfigProviderPtr
36
37
addStaticProvider (std::function<RouteConfigProviderPtr()> create_static_provider);
38
+
39
+ template <class RdsConfig >
37
40
RouteConfigProviderSharedPtr
38
- addDynamicProvider (const Protobuf::Message & rds, const std::string& route_config_name,
41
+ addDynamicProvider (const RdsConfig & rds, const std::string& route_config_name,
39
42
Init::Manager& init_manager,
40
43
std::function<std::pair<RouteConfigProviderSharedPtr, const Init::Target*>(
41
44
uint64_t manager_identifier)>
42
- create_dynamic_provider);
45
+ create_dynamic_provider) {
46
+
47
+ uint64_t manager_identifier;
48
+
49
+ if (Runtime::runtimeFeatureEnabled (" envoy.reloadable_features.normalize_rds_provider_config" )) {
50
+ // Normalize the config_source part of the passed config. Some parts of the config_source
51
+ // do not affect selection of the RDS provider. They will be cleared (zeroed) and restored
52
+ // after calculating hash.
53
+ // Since rds is passed as const, the constness must be casted away before modifying rds.
54
+ auto * orig_initial_timeout =
55
+ const_cast <RdsConfig&>(rds).mutable_config_source ()->release_initial_fetch_timeout ();
56
+ manager_identifier = MessageUtil::hash (rds);
57
+ const_cast <RdsConfig&>(rds).mutable_config_source ()->set_allocated_initial_fetch_timeout (
58
+ orig_initial_timeout);
59
+
60
+ } else {
61
+ manager_identifier = MessageUtil::hash (rds);
62
+ }
63
+
64
+ auto existing_provider =
65
+ reuseDynamicProvider (manager_identifier, init_manager, route_config_name);
66
+
67
+ if (existing_provider) {
68
+ return existing_provider;
69
+ }
70
+ auto new_provider = create_dynamic_provider (manager_identifier);
71
+ init_manager.add (*new_provider.second );
72
+ dynamic_route_config_providers_.insert ({manager_identifier, new_provider});
73
+ return new_provider.first ;
74
+ }
43
75
44
76
private:
45
77
// TODO(jsedgwick) These two members are prime candidates for the owned-entry list/map
0 commit comments