Skip to content

Commit 3828a2b

Browse files
David Huynh (Infra)meta-codesync[bot]
authored andcommitted
Add a flavor option to disable flavor override
Summary: Adds a `--disable-flavor-override` standalone CLI toggle and a corresponding `disable_flavor_override` option that can be set in flavor JSON to skip reading `.override` files from `/etc/mcrouter/`. The disable mechanism works through two paths: a global atomic flag set during standalone CLI init (via `disableFlavorOverride()`), and a per-opts-map check for the key in the flavor JSON `options` section. The global flag covers the standalone binary case, while the opts-map check covers the library embedding case where the option can be set directly in the flavor JSON. This is helpful to add to unit test and integration test for our devservers. Otherwise we won't be properly testing the prod routing changes and instead test the devproxy routes instead. The server side already protect against direct connections from dev servers. Reviewed By: disylh, ghostonhuang Differential Revision: D92323131 fbshipit-source-id: a18e0f241d69009ba0a54828c83b3ca7a8224005
1 parent ecd7502 commit 3828a2b

File tree

3 files changed

+18
-3
lines changed

3 files changed

+18
-3
lines changed

mcrouter/StandaloneUtils.cpp

Lines changed: 14 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -417,12 +417,25 @@ void getFlavorOptionsAndApplyOverrides(
417417
// may affect the way we read from flavors (fb-only).
418418
standalonePreInitFromCommandLineOpts(cmdLineOpts.standaloneOptionsOverrides);
419419

420+
// Extract disable_flavor_override from CLI opts to pass through the
421+
// flavor loading call chain (fb-only: controls override file reading).
422+
bool disableFlavorOverride = false;
423+
auto disableIt =
424+
cmdLineOpts.standaloneOptionsOverrides.find("disable_flavor_override");
425+
if (disableIt != cmdLineOpts.standaloneOptionsOverrides.end()) {
426+
disableFlavorOverride =
427+
(disableIt->second == "1" || disableIt->second == "true");
428+
}
429+
420430
if (cmdLineOpts.flavor.empty()) {
421431
libmcrouterOptionsDict = cmdLineOpts.libmcrouterOptionsOverrides;
422432
standaloneOptionsDict = cmdLineOpts.standaloneOptionsOverrides;
423433
} else {
424434
read_standalone_flavor(
425-
cmdLineOpts.flavor, libmcrouterOptionsDict, standaloneOptionsDict);
435+
cmdLineOpts.flavor,
436+
libmcrouterOptionsDict,
437+
standaloneOptionsDict,
438+
disableFlavorOverride);
426439
for (auto& it : cmdLineOpts.libmcrouterOptionsOverrides) {
427440
libmcrouterOptionsDict[it.first] = it.second;
428441
}

mcrouter/mcrouter_config.cpp

Lines changed: 2 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -34,7 +34,8 @@ bool readLibmcrouterFlavor(
3434
bool read_standalone_flavor(
3535
const std::string& flavor,
3636
std::unordered_map<std::string, std::string>& option_dict,
37-
std::unordered_map<std::string, std::string>& st_option_dict) {
37+
std::unordered_map<std::string, std::string>& st_option_dict,
38+
bool /*disableFlavorOverride*/) {
3839
if (!readFlavor(flavor, st_option_dict, option_dict)) {
3940
LOG(ERROR) << "CRITICAL: Couldn't initialize from standalone flavor file "
4041
<< flavor;

mcrouter/mcrouter_config.h

Lines changed: 2 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -120,7 +120,8 @@ bool readLibmcrouterFlavor(
120120
bool read_standalone_flavor(
121121
const std::string& flavor,
122122
std::unordered_map<std::string, std::string>& option_dict,
123-
std::unordered_map<std::string, std::string>& st_option_dict);
123+
std::unordered_map<std::string, std::string>& st_option_dict,
124+
bool disableFlavorOverride = false);
124125

125126
std::unique_ptr<ConfigApi> createConfigApi(const McrouterOptions& opts);
126127

0 commit comments

Comments
 (0)